01: /**
02: * L2FProd.com Common Components 7.3 License.
03: *
04: * Copyright 2005-2007 L2FProd.com
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */package com.l2fprod.common.demo;
18:
19: import com.l2fprod.common.propertysheet.Property;
20: import com.l2fprod.common.propertysheet.PropertySheet;
21: import com.l2fprod.common.propertysheet.PropertySheetPanel;
22: import com.l2fprod.common.swing.LookAndFeelTweaks;
23:
24: import java.beans.BeanInfo;
25: import java.beans.IntrospectionException;
26: import java.beans.Introspector;
27: import java.beans.PropertyChangeEvent;
28: import java.beans.PropertyChangeListener;
29: import java.beans.SimpleBeanInfo;
30:
31: import javax.swing.JButton;
32: import javax.swing.JPanel;
33: import javax.swing.JTextArea;
34:
35: /**
36: * PropertySheetPage2. <br>
37: *
38: */
39: public class PropertySheetPage2 extends JPanel {
40:
41: public PropertySheetPage2() {
42: setLayout(LookAndFeelTweaks.createVerticalPercentLayout());
43:
44: final JButton button = new JButton();
45: button.setText("Change my properties!");
46: BeanInfo beanInfo = new SimpleBeanInfo();
47: try {
48: beanInfo = Introspector.getBeanInfo(JButton.class);
49: } catch (IntrospectionException e) {
50: e.printStackTrace();
51: }
52: final PropertySheetPanel sheet = new PropertySheetPanel();
53: sheet.setMode(PropertySheet.VIEW_AS_FLAT_LIST);
54: sheet.setToolBarVisible(false);
55: sheet.setDescriptionVisible(false);
56: sheet.setBeanInfo(beanInfo);
57:
58: final JPanel panel = new JPanel(LookAndFeelTweaks
59: .createBorderLayout());
60: panel.add("Center", sheet);
61: panel.add("East", button);
62:
63: // initialize the properties with the value from the object
64: // one can use sheet.readFromObject(button)
65: // but I encountered some issues with Java Web Start. The method
66: // getLocationOnScreen on the button is throwing an exception, it
67: // does not happen when not using Web Start. Load properties one
68: // by one as follow will do the trick
69: Property[] properties = sheet.getProperties();
70: for (int i = 0, c = properties.length; i < c; i++) {
71: try {
72: properties[i].readFromObject(button);
73: } catch (Exception e) {
74: }
75: }
76:
77: // everytime a property change, update the button with it
78: PropertyChangeListener listener = new PropertyChangeListener() {
79: public void propertyChange(PropertyChangeEvent evt) {
80: Property prop = (Property) evt.getSource();
81: prop.writeToObject(button);
82: button.repaint();
83: }
84: };
85: sheet.addPropertySheetChangeListener(listener);
86:
87: JTextArea message = new JTextArea();
88: message.setText(PropertySheetMain.RESOURCE
89: .getString("Main.sheet2.message"));
90: LookAndFeelTweaks.makeMultilineLabel(message);
91: panel.add("North", message);
92:
93: add(panel, "*");
94: }
95:
96: }
|