JGoodies Binding: Presentation Bean Channel Example : Data Binding « Swing Components « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » Swing Components » Data BindingScreenshots 
JGoodies Binding: Presentation Bean Channel Example
JGoodies Binding: Presentation Bean Channel Example

/*
Code revised from Desktop Java Live:
http://www.sourcebeat.com/downloads/
*/
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.jgoodies.binding.PresentationModel;
import com.jgoodies.binding.adapter.BasicComponentFactory;
import com.jgoodies.binding.beans.Model;
import com.jgoodies.binding.value.ValueModel;
import com.jgoodies.forms.builder.DefaultFormBuilder;
import com.jgoodies.forms.layout.FormLayout;

public class PresentationBeanChannelExample extends JPanel {
    private PersonBean personBean1;
    private PersonBean personBean2;
    private PresentationModel presentationModel;

    public PresentationBeanChannelExample() {
        DefaultFormBuilder defaultFormBuilder = new DefaultFormBuilder(new FormLayout("p, 2dlu, p:g"));
        defaultFormBuilder.setDefaultDialogBorder();

        this.personBean1 = new PersonBean("Scott""Delap");
        this.personBean2 = new PersonBean("Matt""Raible");

        this.presentationModel = new PresentationModel(this.personBean1);

        ValueModel firstNameAdapter = presentationModel.getModel("firstName");
        ValueModel lastNameAdapter = presentationModel.getModel("lastName");

        JTextField firstNameTextField = BasicComponentFactory.createTextField(firstNameAdapter);
        JTextField lastNameTextField = BasicComponentFactory.createTextField(lastNameAdapter);

        defaultFormBuilder.append("First Name: ", firstNameTextField);
        defaultFormBuilder.append("Last Name: ", lastNameTextField);
        defaultFormBuilder.append(new JButton(new ChangeBeanAction())3);
        defaultFormBuilder.append(new JButton(new ConvertValueToUpperCaseAction())3);
        defaultFormBuilder.append(new JButton(new ConvertValueToLowerCaseAction())3);
        defaultFormBuilder.append(new JButton(new ShowValueHolderValueAction())3);

        add(defaultFormBuilder.getPanel());
    }

    private class ChangeBeanAction extends AbstractAction {
        public ChangeBeanAction() {
            super("Change PersonBean");
        }

        public void actionPerformed(ActionEvent event) {
            if (presentationModel.getBean() == personBean1) {
                presentationModel.setBean(personBean2);
            else {
                presentationModel.setBean(personBean1);
            }
        }
    }

    private class ConvertValueToUpperCaseAction extends AbstractAction {
        public ConvertValueToUpperCaseAction() {
            super("Convert Value To UpperCase");
        }

        public void actionPerformed(ActionEvent event) {
            PersonBean personBean = (PersonBeanpresentationModel.getBean();

            personBean.setFirstName(personBean.getFirstName().toUpperCase());
            personBean.setLastName(personBean.getLastName().toUpperCase());
        }
    }

    private class ConvertValueToLowerCaseAction extends AbstractAction {
        public ConvertValueToLowerCaseAction() {
            super("Convert Value To LowerCase");
        }

        public void actionPerformed(ActionEvent event) {
            PersonBean personBean = (PersonBeanpresentationModel.getBean();

            personBean.setFirstName(personBean.getFirstName().toLowerCase());
            personBean.setLastName(personBean.getLastName().toLowerCase());
        }
    }

    private class ShowValueHolderValueAction extends AbstractAction {
        public ShowValueHolderValueAction() {
            super("Show Value");
        }

        public void actionPerformed(ActionEvent event) {
            PersonBean personBean = (PersonBeanpresentationModel.getBean();

            StringBuffer message = new StringBuffer();
            message.append("<html>");
            message.append("<b>First Name:</b> ");
            message.append(personBean.getFirstName());
            message.append("<br><b>Last Name:</b> ");
            message.append(personBean.getLastName());
            message.append("</html>");

            JOptionPane.showMessageDialog(null, message.toString());
        }
    }

    public class PersonBean extends Model {
        private String firstName;
        private String lastName;

        public static final String FIRST_NAME_PROPERTY = "firstName";
        public static final String LAST_NAME_PROPERTY = "lastName";

        public PersonBean(String firstName, String lastName) {
            this.firstName = firstName;
            this.lastName = lastName;
        }

        public String getFirstName() {
            return firstName;
        }

        public void setFirstName(String firstName) {
            String oldValue = this.firstName;
            this.firstName = firstName;
            firePropertyChange(FIRST_NAME_PROPERTY, oldValue, this.firstName);
        }

        public String getLastName() {
            return lastName;
        }

        public void setLastName(String lastName) {
            String oldValue = this.lastName;
            this.lastName = lastName;
            firePropertyChange(LAST_NAME_PROPERTY, oldValue, this.lastName);
        }
    }

    public static void main(String[] a){
      JFrame f = new JFrame("Presentation Bean Channel Example");
      f.setDefaultCloseOperation(2);
      f.add(new PresentationBeanChannelExample());
      f.pack();
      f.setVisible(true);
    }
}


           
       
jgoodiesDataBinding.zip( 254 k)
Related examples in the same category
1. Demonstrates three different styles when to commit changesDemonstrates three different styles when to commit changes
2. Builds an editor with components bound to the domain object propertiesBuilds an editor with components bound to the domain object properties
3. Using buffered adapting ValueModels created by a PresentationModelUsing buffered adapting ValueModels created by a PresentationModel
4. Builds an editor that copies data from the domain back and forthBuilds an editor that copies data from the domain back and forth
5. JGoodies Binding: Selection In List Bean Channel ExampleJGoodies Binding: Selection In List Bean Channel Example
6. JGoodies Binding: Selection In List ExampleJGoodies Binding: Selection In List Example
7. JGoodies Binding: Selection In List Model ExampleJGoodies Binding: Selection In List Model Example
8. JGoodies Binding: Toggle Button Adapter ExampleJGoodies Binding: Toggle Button Adapter Example
9. JGoodies Binding: Value Holder ExampleJGoodies Binding: Value Holder Example
10. JGoodies Binding: Abstract Table Model ExampleJGoodies Binding: Abstract Table Model Example
11. JGoodies Binding: Basic Component Factory ExampleJGoodies Binding: Basic Component Factory Example
12. JGoodies Binding: Bean Adapter ExampleJGoodies Binding: Bean Adapter Example
13. JGoodies Binding: Bounded Range Adapter ExampleJGoodies Binding: Bounded Range Adapter Example
14. JGoodies Binding: Buffering Presentation Model ExampleJGoodies Binding: Buffering Presentation Model Example
15. JGoodies Binding: ComboBox Adapter ExampleJGoodies Binding: ComboBox Adapter Example
16. JGoodies Binding: Converter Factory ExampleJGoodies Binding: Converter Factory Example
17. JGoodies Binding: Feed Bean Example 1JGoodies Binding: Feed Bean Example 1
18. JGoodies Binding: Feed Bean Example 2JGoodies Binding: Feed Bean Example 2
19. JGoodies Binding: Feed Bean Example 3JGoodies Binding: Feed Bean Example 3
20. JGoodies Binding: Presentation Bean Property Change Listener ExampleJGoodies Binding: Presentation Bean Property Change Listener Example
21. JGoodies Binding: Presentation Model Property Change ExampleJGoodies Binding: Presentation Model Property Change Example
22. JGoodies Binding: Property Adapter Example 1JGoodies Binding: Property Adapter Example 1
23. JGoodies Binding: Property Adapter Example 2JGoodies Binding: Property Adapter Example 2
24. JGoodies Binding: Property Adapter Example 3JGoodies Binding: Property Adapter Example 3
25. JGoodies Binding: Property Connector ExampleJGoodies Binding: Property Connector Example
26. JGoodies Binding: Radio Button Adapter ExampleJGoodies Binding: Radio Button Adapter Example
27. Swingx: Swing Data BindingSwingx: Swing Data Binding
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.