package samples.s01; * * Copyright (c) 2008 willems piet pwProTech All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * */
import com.jgoodies.binding.beans.Model;
public class CustomerBean extends Model { public static final String NAME_PROPERTY = "name"; public static final String OCCUPATION_PROPERTY = "occupation"; private String name; private String occupation;
* * Copyright (c) 2008 willems piet pwProTech All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * */
commitButton = new JButton(presentationModel.getCommitAction()); resetButton = new JButton(presentationModel.getResetAction()); sendButton = new JButton(presentationModel.getSendAction()); }
public void constructGui() { JFrame frame = new JFrame(); JPanel CustomBeanFrm = new JPanel(); frame.getContentPane().setLayout(new RiverLayout()); frame.getContentPane().add(CustomBeanFrm);
CustomBeanFrm.add("br", new JLabel("Name")); CustomBeanFrm.add("tab hfill", nameInput);
CustomBeanFrm.add("br", new JLabel("Occupation")); CustomBeanFrm.add("tab hfill", occupationInput); CustomBeanFrm.add("br hfill", separator(Color.GRAY));
CustomBeanFrm.add("p br left", resetButton); // The button ins't really located to the left side CustomBeanFrm.add("center", sendButton); CustomBeanFrm.add("right", commitButton); CustomBeanFrm.add("br hfill", separator(Color.GRAY));
}
public static void clearForm() { commitButton.setEnabled(false); nameInput.setText(""); occupationInput.setText("");
}
private static TextField separator(Color c) { TextField separator = new TextField(); separator.setBackground(c); separator.setPreferredSize(new Dimension(20, 2)); return separator; } }
CustomerPresentationModel.java
package samples.s01;
* * Copyright (c) 2008 willems piet pwProTech All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * */
public class CustomerPresentationModel extends PresentationModel {
private static final long serialVersionUID = 1L; CommitAction commitAction; ResetAction resetAction; SendAction sendAction; ClearAction clearAction; private final CustomerBean customerBean;
@SuppressWarnings("unchecked") public CustomerPresentationModel(CustomerBean customerBean) { super(customerBean); this.customerBean = customerBean; commitAction = new CommitAction(); resetAction = new ResetAction(); sendAction = new SendAction(); clearAction = new ClearAction();
}
public Action getCommitAction() { return commitAction; }
public Action getSendAction() { return sendAction; }
public Action getResetAction() { return resetAction; }
public Action getClearAction() { return clearAction; }
private class CommitAction extends AbstractAction { /** * */ private static final long serialVersionUID = 1L;
public void actionPerformed(final ActionEvent e) {
// getBean(); if (PresentationModelBuild.resetButton.isEnabled()) { PresentationModelBuild.resetButton.setEnabled(true); }
if (isBuffering()) { PresentationModelBuild.commitButton.setEnabled(true);
displayBufferAndBean("SEND Bufferd :true :: Not yet committed"); } else { PresentationModelBuild.commitButton.setEnabled(false); displayBufferAndBean("SEND Bufferd :true :: yet Committed"); //Bufferd still true so by a reset the bufferd values are still available }
}
}
private class ResetAction extends AbstractAction {
public ResetAction() { super("Reset"); }
public void actionPerformed(ActionEvent e) {
// release(): // Removes the PropertyChangeHandler from the observed bean, if the // bean is not null. Also removes all listeners from the bean that // have been registered with #addBeanPropertyChangeListener before. if (isBuffering()) { triggerFlush(); resetChanged(); System.out.println("RESET action : If changes : Previous restored"); PresentationModelBuild.commitButton.setEnabled(false); } } }
private class ClearAction extends AbstractAction { // Not Used
* * Copyright (c) 2008 willems piet pwProTech All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * */
public class CustomBeanlaunch {
/** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub PresentationModelBuild pme = new PresentationModelBuild(); pme.constructGui(); } }
RESULTAAT
Result SEND Bufferd :true :: Not yet committed ------------------------------------------------- Bufferd values : Buffered beanvalue name :piet Buffered beanvalue occupation :job
Bean values : CustomerBean value name :null CustomerBean value occupation :null --------------------------------------------------- RESET action : If changes : Previous restored Result SEND Bufferd :true :: Not yet committed ------------------------------------------------- Bufferd values : Buffered beanvalue name :piet Buffered beanvalue occupation :job
Bean values : CustomerBean value name :null CustomerBean value occupation :null --------------------------------------------------- Result COMMIT action: ------------------------------------------------- Bufferd values : Buffered beanvalue name :piet Buffered beanvalue occupation :job
Bean values : CustomerBean value name :piet CustomerBean value occupation :job --------------------------------------------------- Tags :: RiverLayout , JGoodies , Valueholder , bindings, formmodel , model , sample, samples, java
/* * Copyright (c) 2008 - 2008 willems piet pwProTech All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
public class CustomComboAdapter extends JPanel { private String CMD_OK = "cmd.ok"/* NOI18N */;
private JButton okButton;
public ComboValueHolder ch, cl; // static
public CustomComboAdapter() { JPanel panel = new JPanel(new RiverLayout()); panel.setBorder(new EmptyBorder(6, 6, 6, 6)); riverFormBuilder(panel); add(panel); }
private void riverFormBuilder(JPanel panel) { ArrayList<String> countries = new ArrayList<String>(); countries.add("England"); countries.add("Scotland"); countries.add("Iereland"); countries.add("Nedtherlands"); countries.add("Flanders");
ArrayList<String> languages = new ArrayList<String>(); languages.add("Dutch"); languages.add("English"); languages.add("Spanish"); languages.add("German"); languages.add("Russian");
Dimension d = new Dimension(150, 20); Font userfont = new Font("Arial",1,12);
public static void main(String[] a) { JFrame f = new JFrame("Custom ComboBox"); f.setDefaultCloseOperation(2); f.add(new CustomComboAdapter()); f.pack(); f.setVisible(true); }
public class ComboValueHolder { String startselection;
ValueModel selectionHolder;
public ValueModel ComboHolder() { ValueModel selectionHolder = new ValueHolder(this.startselection); setSelectionHolder(selectionHolder); return selectionHolder; }
public JComboBox customComboBox(ArrayList countries, Dimension d, Font font, Color color) {
ComboBoxAdapter comboBoxAdapter = new ComboBoxAdapter(countries,ComboHolder()); JComboBox comboBox = new JComboBox(); comboBox.setPreferredSize(d); comboBox.setFont(font); comboBox.setBackground(color); comboBox.setModel(comboBoxAdapter); return comboBox; }
public String getStartselection() { return startselection; }
public void setStartselection(String startselection) { this.startselection = startselection; }
public ValueModel getSelectionHolder() { return selectionHolder; }
public void setSelectionHolder(ValueModel selectionHolder) { this.selectionHolder = selectionHolder; }
/* * Copyright (c) 2008 - 2008 willems piet pwProTech All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
import com.jgoodies.binding.beans.Model;
//This configuration is more advanced then the tripleform bean and uses JGoodies beans.model
public class SingleForm extends Model { String name, street, nr, towncity, occupation;
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String getNr() { return nr; }
public void setNr(String nr) { this.nr = nr; }
public String getOccupation() { return occupation; }
public void setOccupation(String occupation) { this.occupation = occupation; }
public String getStreet() { return street; }
public void setStreet(String street) { this.street = street; }
public String getTowncity() { return towncity; }
public void setTowncity(String towncity) { this.towncity = towncity; }
}
TripleForm.java
package beans;
/* * Copyright (c) 2008 - 2008 willems piet pwProTech All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
public void addPropertyChangeListener(PropertyChangeListener x) { changeSupport.addPropertyChangeListener(x); }
public void removePropertyChangeListener(PropertyChangeListener x) { changeSupport.removePropertyChangeListener(x); }
public boolean isMenuItemEnabled() { return menuItemEnabled; }
public void setMenuItemEnabled(boolean menuItemEnabled) { this.menuItemEnabled = menuItemEnabled; }
}
SingleMasterForm.java
package forms.masterforms;
/* * Copyright (c) 2008 - 2008 willems piet pwProTech All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
public JPanel buildform(final JFrame f, final JMenuItem menuitem) { okButton = new JButton(); okButton.setText("ok"); okButton.setActionCommand(CMD_OK); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { // windowAction(event); System.out .println("ACTION : BUTTON OK WAS CLICKED and Menu item enabled"); System.out.println(okButton.getActionCommand()); menuitem.setEnabled(true);//and close MenuBar.FrameClearAction(f); } });
SingleForm bean = new SingleForm(); BeanAdapter adapter = new BeanAdapter(bean, true);
// SingleMasterForm JPanel SingleMasterForm = new JPanel(); SingleMasterForm.setLayout(new RiverLayout()); SingleMasterForm.add("right", new JLabel("Single Form demo")); SingleMasterForm.add("p left", new JLabel("Name")); SingleMasterForm.add("tab hfill", nameinput); SingleMasterForm.add("br", new JLabel("Street")); SingleMasterForm.add("tab hfill", streetinput); SingleMasterForm.add("br vtop", new JLabel("nr")); SingleMasterForm.add("tab", nrinput); nrinput.setColumns(5); SingleMasterForm.add("br vtop", new JLabel("Town/City")); SingleMasterForm.add("tab hfill", towncityinput); SingleMasterForm.add("br vtop", new JLabel("Occupation")); SingleMasterForm.add("tab hfill", occupationinput); SingleMasterForm.add("p right", okButton); SingleMasterForm.setBorder(Borders.DIALOG_BORDER);
return SingleMasterForm; } }
TripleMasterForm.java
package forms.masterforms;
/* * Copyright (c) 2008 - 2008 willems piet pwProTech All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
public class TripleMasterForm extends TripleForm {
private String CMD_OK = "cmd.ok"/* NOI18N */;
private JButton okButton, ok1Button, ok2Button;
public JPanel formRegistration(final JFrame f, final JMenuItem menuitem) { okButton = new JButton(); okButton.setText("ok"); okButton.setActionCommand(CMD_OK);
okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { // windowAction(event); System.out .println("ACTION : BUTTON OK WAS CLICKED and menu item enabled"); System.out.println(okButton.getActionCommand()); menuitem.setEnabled(true);//and close MenuBar.FrameClearAction(f); } });
ok1Button = new JButton(); ok1Button.setText("ok 1"); ok1Button.setActionCommand(CMD_OK); ok1Button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { // windowAction(event); System.out.println("ACTION : BUTTON 1 OK WAS CLICKED"); System.out.println(ok1Button.getActionCommand()); menuitem.setEnabled(true);//and close MenuBar.FrameClearAction(f); } });
ok2Button = new JButton(); // we'll need this soon ok2Button.setText("ok 2"); ok2Button.setActionCommand(CMD_OK); ok2Button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { // windowAction(event); System.out.println("ACTION : BUTTON 2 OK WAS CLICKED"); System.out.println(ok2Button.getActionCommand()); menuitem.setEnabled(true);//and close MenuBar.FrameClearAction(f); } });
TripleForm bean = new TripleForm(); BeanAdapter adapter = new BeanAdapter(bean, true);
// left JPanel left = new JPanel(); left.setLayout(new RiverLayout()); left.add("right", new JLabel("Registration form left")); left.add("p left", new JLabel("Name")); left.add("tab hfill", userinput); left.add("br", new JLabel("Age")); ageinput.setColumns(5); left.add("tab", ageinput); left.add("br vtop", new JLabel("Comment")); commentinput.setRows(3); left.add("tab hfill vfill", new JScrollPane(commentinput)); left.add("p right", okButton); // added to level the content of the 3 panels left.setBorder(Borders.DIALOG_BORDER);
// center JPanel center = new JPanel(); center.setLayout(new RiverLayout()); center.add("right", new JLabel("Registration form center")); center.add("p left", new JLabel("Name-center")); center.add("tab hfill", userinput01); center.add("br", new JLabel("Age-center")); ageinput01.setColumns(2); center.add("tab", ageinput01); center.add("br vtop", new JLabel("Comment-center")); center.add("tab hfill vfill", new JScrollPane(commentinput01)); center.add("p right", ok1Button); center.add(left); // added to level the content of the 3 panels center.setBorder(Borders.DIALOG_BORDER);
JPanel right = new JPanel(); right.setLayout(new RiverLayout()); right.add("right", new JLabel("Registration form right")); right.add("p left", new JLabel("Name-right")); right.add("tab hfill", userinput02); right.add("br", new JLabel("Age-right")); ageinput02.setColumns(3); right.add("tab", ageinput02); right.add("br vtop", new JLabel("Comment-right")); right.add("tab hfill vfill", new JScrollPane(commentinput02)); right.add("p right", ok2Button); // added to level the content of the 3 panels right.setBorder(new EmptyBorder(6, 0, 6, 0));
JSplitPane splitPane0 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panel1, right);
JPanel masterform = new JPanel(); masterform.setLayout(new RiverLayout()); masterform.add("vfill hfill", splitPane0);
return masterform; } }
MenuBar.java
package src;
/* * Copyright (c) 2008 - 2008 willems piet pwProTech All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
//Build the first menu. menu = new JMenu("TestMenu 1"); menu.setMnemonic(KeyEvent.VK_A); //menu.getAccessibleContext().setAccessibleDescription( // "The only menu in this program that has menu items"); menuBar.add(menu);
//a group of JMenuItems menuItem1 = new JMenuItem("Clear test", KeyEvent.VK_T); menuItem1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK)); menuItem1.setName("een"); menu.add(menuItem1);
// Text - icon sample menuItem2 = new JMenuItem("Single form", new ImageIcon( "images/yourpic.gif"));
protected JMenuItem getMenuItem(int menuIndex, int itemIndex) { //JMenuBar menuBar; JMenu menu = menuBar.getMenu(menuIndex); System.out.println(menu.getName()); return menu.getItem(itemIndex); }
}
OpeningForm.java
package src;
/* * Copyright (c) 2008 - 2008 willems piet pwProTech All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
/* * Copyright (c) 2008 - 2008 willems piet pwProTech All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
/* TopLevelDemo.java requires no other files. */ public class RiverLayoutTest { /** * Create the GUI and show it. */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("Test Layout"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(new RiverLayout());
//Set the menu bar and add the openingForm to the content pane. frame.setJMenuBar(new MenuBar().MenuBarRegistration(frame)); frame.getContentPane().add("hfill", src.OpeningForm.buildForm());
//Display the window. frame.setLocation(150, 200); frame.pack(); frame.setVisible(true); }
public static void main(String[] args) { //creating and showing this application's GUI. javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } }
Tags : RiverLayout , sample , java , example , jgoodies , valuemodel, model
// left JPanel left = new JPanel(); left.setLayout(new RiverLayout()); left.add("right", new JLabel("Registration form left")); left.add("p left", new JLabel("Name")); left.add("tab hfill", userinput); left.add("br", new JLabel("Age")); ageinput.setColumns(5); left.add("tab", ageinput); left.add("br vtop", new JLabel("Comment")); commentinput.setRows(3); left.add("tab hfill vfill", new JScrollPane(commentinput)); left.add("p right", okButton); // added to level the content of the 3 panels left.setBorder(Borders.DIALOG_BORDER);
// center JPanel center = new JPanel(); center.setLayout(new RiverLayout()); center.add("right", new JLabel("Registration form center")); center.add("p left", new JLabel("Name-center")); center.add("tab hfill", userinput01); center.add("br", new JLabel("Age-center")); ageinput01.setColumns(2); center.add("tab", ageinput01); center.add("br vtop", new JLabel("Comment-center")); center.add("tab hfill vfill", new JScrollPane(commentinput01)); center.add("p right", ok1Button); center.add(left); // added to level the content of the 3 panels center.setBorder(Borders.DIALOG_BORDER);
JPanel right = new JPanel(); right.setLayout(new RiverLayout()); right.add("right", new JLabel("Registration form right")); right.add("p left", new JLabel("Name-right")); right.add("tab hfill", userinput02); right.add("br", new JLabel("Age-right")); ageinput02.setColumns(3); right.add("tab", ageinput02); right.add("br vtop", new JLabel("Comment-right")); right.add("tab hfill vfill", new JScrollPane(commentinput02)); right.add("p right", ok2Button); // added to level the content of the 3 panels right.setBorder(new EmptyBorder(6, 0, 6, 0));
JSplitPane splitPane0 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panel1, right);
JTextField userinput = BasicComponentFactory.createTextField(nameModel); JTextField ageinput = BasicComponentFactory.createTextField(ageModel); ageinput.setColumns(3); // When this configuration isn't done the BasicComponentFactory //will not configure the width and the JTextField will be redused to //a few millimeter. JTextArea commentinput = BasicComponentFactory.createTextArea(commentModel);
Container c = f.getContentPane(); c.setLayout(new RiverLayout()); c.add("right", new JLabel("Registration form")); c.add("p left", new JLabel("Name")); c.add("tab hfill", userinput); c.add("br", new JLabel("Age")); c.add("tab", ageinput); c.add("br vtop", new JLabel("Comment")); c.add("tab hfill vfill", new JScrollPane(commentinput)); c.add("p center", okButton); return c; }
Structured Query Language
Hibernate Query Language
Java Data Objects
Data Access Object
iBATIS
is a persistence framework which enables mapping SQL
queries to POJOs
Apache Struts
is an open-source web application framework for
developing Java EE web applications.
WebWork
is a Java-based web application framework developed
by OpenSymphony.
Tapestry
is an open-source framework for creating dynamic,
robust, highly scalable web applications in Java.
TopLink
is an object-relational mapping package for Java
developers.
Hibernate
is an object-relational mapping (ORM) library for the
Java language, providing a framework for mapping an object-oriented
domain model to a traditional relational database.
Spring
Spring is a layered Java/J2EE application framework,
based on code published in Expert One-on-One J2EE Design and Development
by Rod Johnson (Wrox, 2002).
Exel : Woorden vervangen in tekst m.b..v een macro
Macro voor excel om een lijst woorden in één
keer te vervangen in een tekst.
De code voor Visual Basic macro "Vervang"
De lijst woorden die men wenst te vervangen bevindt zich in dit voorbeeld in de kolom C4 tot C13.De wisselwoorden in de kolom daarnaast [Offset(0, 1)].
Sub Vervang()
'author piet :: pwProTech
For Each c In Worksheets(1).Range("C4:C13")
Sheets("Blad2").Cells.Replace What:=c.Value, Replacement:=c.Offset(0, 1).Value,
LookAt:=xlPart _
, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _
ReplaceFormat:=False
Next c
End Sub
De inhoud van excel Blad1
Range C4 tot C13 :
Hier plaats je de woorden die je wil vervangen en de veervangtekst
Vb.:Blad1:
Op dit blad kan je ook de knop [VERVANG] (die de macro "Vervang" start)
aanbrengen.:
A
B
C
D
...
1
2
3
Te vervangen:
met:
4
Event
DB_action
5
event
db_action
...
...
...
De inhoud van excel Blad2
Op Blad2 plaats je de tekst die bewerkt moet worden.
Je plakt best de hele tekst in één enkele cel zodat je hem weer gemakelijk kan copiëren Hoe : dubbele klik in de cel die je verkiest en plakken
Noot: Je kan ook een knop voorzien om de woorden op "Blad1" te verwijderen met de macro "Reset"
Code:
Sub Reset()
'author piet :: pwProTech
For Each c In Worksheets(1).Range("C4:C13") c.Value = "" c.Offset(0, 1).Value = "" Next c
Systray : verwijderen tags ( icoon ) taakbalk . Wijzigingen start programma's enz. 1Ga naar start 2.Klik op "Uitvoeren" [run] in het geopend menu. 3.Type in de ingavebalk : msconfig 4.Klik ok
Het venster "Hulpprogramma voor systeemconfiguratie" wordt geopend.
5.In het gegeven venster kan je nu de nodige veranderingen doorvoeren.
Tip :Programma's met "onbekend" als leverancier of "" (prog's die geen indentificartie hebben) zijn dikwijls dubieus tenzij je natuurlijk het programma kent of het zelf geinstalleerd hebt.
Noot -icoons taakbalk bevinden zich onder de tab "Opstarten" -wat bvb. het icoon van het gevaarlijke "antivirusgear" betreft : het bevat in de tab "opstarten" geen gegevens.Het kan wel via deze weg verwijderd worden doch het programma zelf moet apart verwijderd worden.
/*
* User toevoegen aan de database
*/
System.out.println("user toegevoegd voor");
UserDao userDao = new UserDao();
User user = new User();
userDao.create(user);
user.setNaam("De Gavere");
user.setWachtwoord("gaverzicht");
user.setAansluiting(now);
userDao.update(user);
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>user
toegevoegd");
userDao.findAll();
/*
* Klant toevoegen aan de database
*/
KlantDao klantDao = new KlantDao();
Klant klant = new Klant();
klantDao.create(klant);
klant.setVoornaam("Kere-gerom");
klant.setAchternaam("Reuzegom");
klant.setStraat("Lange Wapperstraat");
klant.setHuisnr("12");
klant.setPostnr("8640");
klant.setGemeente("Papoptvier");
klantDao.update(klant);
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>klant
toegevoegd");
klantDao.findAll();
public class HibernateFactory {
private static SessionFactory sessionFactory;
private static Log log = LogFactory.getLog(HibernateFactory.class);
/*
* Maakt een nieuwe Singleton SessionFactory aan
*/
public static SessionFactory buildSessionFactory() throws
HibernateException {
System.out.println("sessionfact build");
if (sessionFactory != null) {
closeFactory();
}
return configureSessionFactory();
}
/*
* Maakt een nieuwe Singleton SessionFactory aan indien nodig.
*/
public static SessionFactory buildIfNeeded() throws
DataAccessError{
if (sessionFactory != null) {
return sessionFactory;
}
try {
return
configureSessionFactory();
} catch (HibernateException err) {
throw new DataAccessError("build if
needed mislukt >> "+err);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
/*
* Nieuwe Klant toevoegen aan database.
*/
public void create(Klant klant) throws DataAccessError {
super.saveOrUpdate(klant);
}
/*
* Een Klant verwijderen van de database.
*/
public void delete(Klant klant) throws DataAccessError {
super.delete(klant);
}
/*
* Een Klant vinden met de primary key.
*/
public Klant find(Long id) throws DataAccessError {
System.out.print("klant update");
return (Klant) super.find(Klant.class, id);
}
/*
* Klant toevoegen aan - of wijzigen in de database.
*/
public void update(Klant klant) throws DataAccessError {
System.out.print("klant update");
super.saveOrUpdate(klant);
}
/**
* Zoek alle klanten in de database.
*/
public List findAll() throws DataAccessError{
return super.findAll(Klant.class);
}
public class UserDao extends ConstructDao {
public UserDao() {
super();
}
/*
* Een User toevoegen aan - wijzigen in de database.
*/
public void create(User user) throws DataAccessError {
super.saveOrUpdate(user);
}
/*
* Een User verwijderen uit de database.
*/
public void delete(User user) throws DataAccessError {
super.delete(user);
}
/**
* Find an Event by its primary key.
* @param id
* @return
*/
public User find(Long id) throws DataAccessError {
return (User) super.find(User.class, id);
}
/*
* User toevoegen aan - of wijzigen in de database.
*/
public void update(User user) throws DataAccessError {
System.out.println(">>>>> user update");
super.saveOrUpdate(user);
}
/*
* Haal alle users op uit de database.
*/
public List findAll() throws DataAccessError{
return super.findAll(User.class);
}
<!-- JDBC connection pool (use the built-in) --> <property name="connection.pool_size">1</property> <!-- Volgende lijn uit commentaar zetten om de database opnieuw te laten aanmaken --> <!--property name="hbm2ddl.auto">create</property-->
CREATE TABLE `leverancier` ( `id` int(11) NOT NULL auto_increment, `firmanaam` varchar(30) NOT NULL, `rechtspers` varchar(6) NOT NULL, `straat` varchar(50) NOT NULL, `nr` int(11) NOT NULL, `postcode` int(11) NOT NULL, `gemeente` varchar(30) NOT NULL, `telefoon` varchar(9) NOT NULL, `fax` varchar(9) NOT NULL, `GSM` varchar(10) NOT NULL, `email` varchar(50) NOT NULL, `vertegenwoordiger` varchar(30) NOT NULL, `vertegen_GSM` varchar(10) NOT NULL, `vertegen_email` varchar(50) NOT NULL, `tweede_naam` varchar(50) NOT NULL, `tweede_straat` varchar(50) NOT NULL, `tweede_nr` int(11) NOT NULL, `tweede_postcode` int(11) NOT NULL, `tweede_gemeente` varchar(30) NOT NULL, `tweede_telefoon` varchar(9) NOT NULL, `tweede_GSM` varchar(10) NOT NULL, `beschrijving` varchar(255) NOT NULL, `info` varchar(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=0;
-- -- Gegevens worden uitgevoerd voor tabel `leverancier` --