Download presentation
Presentation is loading. Please wait.
Published byAngela Hopkins Modified over 8 years ago
1
Beans Binding Framework & Swing Application Framework Geertjan Wielenga http://blogs.sun.com/geertjan http//netbeans.dzone.com
2
2 Agenda ● Goals ● Beans Binding Framework ● Swing Application Framework ● Conclusion
3
3 ● Goals ● Beans Binding Framework ● Swing Application Framework ● Conclusion Agenda
4
4 Example
5
5
6
6
7
7
8
8 faceSlider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { face.setFaceStyle(faceSlider.getValue()); } }); face.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { if (e.getPropertyName() == “faceStyle”) { faceSlider.setValue(caricature.getFaceStyle()); } } });
9
9 bind(faceObject, eye, slider1, value); bind(faceObject, hair, slider2, value); bind(faceObject, face, slider3, value);
10
10
11
11 BindingGroup bindingGroup = new BindingGroup();
12
12 BindingGroup bindingGroup = new BindingGroup(); Binding binding1 = Bindings.createAutoBinding( AutoBinding.UpdateStrategy.READ_WRITE, field, ELProperty.create("${text}"), slider, BeanProperty.create("value"));
13
13 BindingGroup bindingGroup = new BindingGroup(); Binding binding1 = Bindings.createAutoBinding( AutoBinding.UpdateStrategy.READ_WRITE, field, ELProperty.create("${text}"), slider, BeanProperty.create("value")); bindingGroup.addBinding(binding1); bindingGroup.bind();
14
14 Demo JFrame in Plain Java Class
15
15 validators & converters
16
16 Sample in the IDE
17
17 Summary ● Different update strategies ● Read once, read only from source, keep source and target in sync ● Ability to do validation ● Ability to transform value ● String to Color, Date to String
18
18 Demo Beans Binding Framework with “Matisse” GUI Builder
19
19 Latest Developments ● Expression language is no longer mandatory ● Subclasses for complex cases ● JTable binding ● Column binding ● JComboBox binding ● JList binding
20
20 ● When will Beans Binding be in the JDK? ● Planned - Java Platform 7 ● I can't wait. Where can I get it? ● Version 1.2.1 ● Released November 2, 2007 ● Available at https://beansbinding.dev.java.net/ https://beansbinding.dev.java.net/ ● Bundled in NetBeans 6.0 When and Where?
21
21 ● Goals ● Beans Binding Framework ● Swing Application Framework ● Conclusion Agenda
22
22 public static void main(String args[]) { // good luck! } Problem Statement
23
23 ● Goals: ● As small as possible ● Explain it all in an hour ● Work well for small/medium apps ● Nice consequence: toolable Framework Goals
24
24 ● Lifecycle support ● Resources ● Actions ● Tasks ● Session state Framework Features
25
25 ● Modular system ● Docking system ● File system ● Data model ● Help system ● Update mechanism Out of Scope
26
26 Framework Architecture
27
27 import javax.swing.JFrame; import javax.swing.JLabel; public class HelloWorldSwing { public static void main(String[] args) { JFrame frame = new JFrame("HelloWorldSwing"); final JLabel label = new JLabel("Hello World"); frame.getContentPane().add(label); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); } Lifecycle Support (On your own)
28
28 import javax.swing.JLabel; import org.jdesktop.application.Application; import org.jdesktop.application.SingleFrameApplication; public class MyApp extends SingleFrameApplication { @Override protected void startup() { JLabel label = new JLabel("Hello World"); show(label); } public static void main(String[] args) { Application.launch(MyApp.class, args); } Lifecycle Support
29
29 Lifecycle Support Calls initialize(), startup(), ready() on EDT thread. Performs initializations that must happen before the GUI is created like setting look & feel. Creates the initial GUI and shows it. All applications will override this method. Any work that must wait until the GUI is visible and ready for input. Calls shutdown() if the exitListeners do not veto. Main frame's Windowlistener calls exit(). Take the GUI down and do final cleanup.
30
30 ● Defined with regular ResourceBundles ● ResourceManager class is used ● Three options: ● Manually load, use ResourceMap objects ● Automatically inject resources into UI components ● Automatically inject resources into object fields Resources
31
31 ● Instead of ActionListeners ● Asynchronous actions are easy ● @Action annotation ● Possible simple logic @Action(enabledProperty = "changesPending") public void save() {... } public boolean getChangesPending() {... } Actions
32
32 // define sayHello Action – pops up message Dialog @Action public void sayHello() { String s = textField.getText(); JOptionPane.showMessageDialog(s); } // use sayHello – set the action property Action sayHello = Application.getContext(). getActionMap(MyForm.class, this).get("sayHello"); textField.setAction(sayHello); button.setAction(sayHello); Actions
33
33 ● Inherit the SwingWorker API ● Support for monitoring ● Title, Start/Done, etc. ● Asynchronous @Actions return Tasks ● Easy to handle non-blocking actions Tasks
34
34 ● Easily save properties: ● Window size ● Application position ● Sizes of columns in jTable, etc. ● ApplicationContext.getSessionStorage() ● SessionStorage.save(RootComponent, filename) ● Default for SingleFrameApplication is windowname + “.session.xml” ● Uses XMLEncoder & XMLDecoder Session State
35
35 Demo Flickr Search Application
36
36 ● NetBeans Platform is for applications that need more: ● Window system ● File/Data systems ● Help system ● Update system ● Visual designer ● Explorer widgets ● etc.... JSR 296 vs. NB Platform
37
37 ● When will JSR-296 be in a JDK? ● Planned - Java Platform 7 ● I can't wait. Where can I get it? ● Version 1.0 packaged with NetBeans 6 ● Source available as a NetBeans project at https://appframework.dev.java.net/ When and Where?
38
38 Conclusion ● JSR 295 and 296 are making Swing development fun again ● Both are very well supported in NetBeans GUI builder (project Matisse) ● Desktop Java becoming interesting for “Delphi” and “VB” developers ● Desktop Java is well and alive!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.