001: /**
002: * L2FProd.com Common Components 7.3 License.
003: *
004: * Copyright 2005-2007 L2FProd.com
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package com.l2fprod.common.demo;
018:
019: import com.l2fprod.common.beans.BaseBeanInfo;
020: import com.l2fprod.common.beans.editor.ComboBoxPropertyEditor;
021: import com.l2fprod.common.propertysheet.PropertySheet;
022: import com.l2fprod.common.propertysheet.PropertySheetPanel;
023: import com.l2fprod.common.swing.LookAndFeelTweaks;
024:
025: import java.awt.Color;
026: import java.beans.PropertyChangeEvent;
027: import java.beans.PropertyVetoException;
028: import java.io.File;
029: import java.util.Arrays;
030: import java.util.ListResourceBundle;
031:
032: import javax.swing.Icon;
033: import javax.swing.JPanel;
034: import javax.swing.JTextArea;
035: import javax.swing.UIManager;
036:
037: /**
038: * PropertySheetPage. <br>
039: *
040: */
041: public class PropertySheetPage extends JPanel {
042:
043: public PropertySheetPage() {
044: setLayout(LookAndFeelTweaks.createVerticalPercentLayout());
045:
046: JTextArea message = new JTextArea();
047: message.setText(PropertySheetMain.RESOURCE
048: .getString("Main.sheet1.message"));
049: LookAndFeelTweaks.makeMultilineLabel(message);
050: add(message);
051:
052: final Bean data = new Bean();
053: data.setName("John Smith");
054: data.setText("Any text here");
055: data.setColor(Color.green);
056: data.setPath(new File("."));
057: data.setVisible(true);
058: data.setTime(System.currentTimeMillis());
059:
060: final PropertySheetPanel sheet = new PropertySheetPanel();
061: sheet.setMode(PropertySheet.VIEW_AS_CATEGORIES);
062: sheet.setDescriptionVisible(true);
063: sheet.setSortingCategories(true);
064: sheet.setSortingProperties(true);
065: sheet.setRestoreToggleStates(true);
066: add(sheet, "*");
067:
068: // everytime a property change, update the sheet with it
069: new BeanBinder(data, sheet);
070: }
071:
072: public static class Bean {
073:
074: private String name;
075:
076: public String getName() {
077: return name;
078: }
079:
080: public void setName(String name) {
081: this .name = name;
082: }
083:
084: private String text;
085:
086: public String getText() {
087: return text;
088: }
089:
090: public void setText(String text) {
091: this .text = text;
092: }
093:
094: private long time;
095:
096: public long getTime() {
097: return time;
098: }
099:
100: public void setTime(long time) {
101: this .time = time;
102: }
103:
104: public String getVersion() {
105: return "1.0";
106: }
107:
108: private boolean visible;
109:
110: public boolean isVisible() {
111: return visible;
112: }
113:
114: public void setVisible(boolean visible) {
115: this .visible = visible;
116: }
117:
118: private int id;
119:
120: public int getId() {
121: return id;
122: }
123:
124: public void setId(int id) {
125: this .id = id;
126: }
127:
128: private File path;
129:
130: public File getPath() {
131: return path;
132: }
133:
134: public void setPath(File path) {
135: this .path = path;
136: }
137:
138: private Color color = Color.blue;
139:
140: public Color getColor() {
141: return color;
142: }
143:
144: public void setColor(Color color) {
145: this .color = color;
146: }
147:
148: private double doubleValue = 121210.4343543;
149:
150: public void setADouble(double d) {
151: this .doubleValue = d;
152: }
153:
154: public double getADouble() {
155: return doubleValue;
156: }
157:
158: private String season;
159:
160: public void setSeason(String s) {
161: season = s;
162: }
163:
164: public String getSeason() {
165: return season;
166: }
167:
168: private String constrained;
169:
170: public String getConstrained() {
171: return constrained;
172: }
173:
174: public void setConstrained(String constrained)
175: throws PropertyVetoException {
176: if ("blah".equals(constrained)) {
177: throw new PropertyVetoException("e",
178: new PropertyChangeEvent(this , "constrained",
179: this .constrained, constrained));
180: }
181: this .constrained = constrained;
182: }
183:
184: public String toString() {
185: return "[name=" + getName() + ",text=" + getText()
186: + ",time=" + getTime() + ",version=" + getVersion()
187: + ",visible=" + isVisible() + ",id=" + getId()
188: + ",path=" + getPath() + ",aDouble=" + getADouble()
189: + ",season=" + getSeason() + "]";
190: }
191:
192: }
193:
194: public static class BeanBeanInfo extends BaseBeanInfo {
195:
196: public BeanBeanInfo() {
197: super (Bean.class);
198: addProperty("id").setCategory("General");
199: addProperty("name").setCategory("General");
200: addProperty("text").setCategory("General");
201: addProperty("visible").setCategory("General");
202:
203: // the File attribute will not be shown if running in Java Web
204: // Start, otherwise it will lead to exception when rendering the
205: // value
206: if (System.getProperty("javawebstart.version") == null) {
207: addProperty("path").setCategory("Details");
208: }
209:
210: addProperty("time").setCategory("Details");
211: addProperty("color").setCategory("Details");
212: addProperty("aDouble").setCategory("Numbers");
213: addProperty("season").setCategory("Details")
214: .setPropertyEditorClass(SeasonEditor.class);
215: // a readonly property
216: addProperty("version");
217: // a constrained property
218: addProperty("constrained");
219: }
220: }
221:
222: public static class SeasonEditor extends ComboBoxPropertyEditor {
223: public SeasonEditor() {
224: super ();
225: setAvailableValues(new String[] { "Spring", "Summer",
226: "Fall", "Winter", });
227: Icon[] icons = new Icon[4];
228: Arrays.fill(icons, UIManager.getIcon("Tree.openIcon"));
229: setAvailableIcons(icons);
230: }
231: }
232:
233: public static class BeanRB extends ListResourceBundle {
234:
235: protected Object[][] getContents() {
236: return new Object[][] {
237: { "name", "Name" },
238: {
239: "name.shortDescription",
240: "The name of this object<br>Here I'm using multple lines<br>for the property<br>so scrollbars will get enabled" },
241: { "text", "Text" },
242: { "time", "Time" },
243: { "color", "Background" },
244: { "aDouble", "a double" },
245: { "season", "Season" },
246: {
247: "constrained.shortDescription",
248: "This property is constrained. Try using <b>blah</b> as the value, the previous value will be restored" } };
249: }
250: }
251:
252: }
|