001: /*
002: JSmooth: a VM wrapper toolkit for Windows
003: Copyright (C) 2003 Rodrigo Reyes <reyes@charabia.net>
004:
005: This program is free software; you can redistribute it and/or modify
006: it under the terms of the GNU General Public License as published by
007: the Free Software Foundation; either version 2 of the License, or
008: (at your option) any later version.
009:
010: This program is distributed in the hope that it will be useful,
011: but WITHOUT ANY WARRANTY; without even the implied warranty of
012: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: GNU General Public License for more details.
014:
015: You should have received a copy of the GNU General Public License
016: along with this program; if not, write to the Free Software
017: Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
018:
019: */
020:
021: package net.charabia.jsmoothgen.application.gui.editors;
022:
023: import net.charabia.jsmoothgen.skeleton.*;
024: import net.charabia.jsmoothgen.application.*;
025: import net.charabia.jsmoothgen.application.gui.*;
026: import net.charabia.jsmoothgen.application.gui.util.*;
027: import javax.swing.*;
028: import java.awt.*;
029: import java.util.*;
030: import com.l2fprod.common.swing.*;
031: import com.l2fprod.common.propertysheet.*;
032:
033: public class SkeletonProperties extends Editor implements
034: JSmoothModelBean.SkeletonChangedListener {
035: private PropertySheetPanel m_skelprops = new PropertySheetPanel();
036: private String m_currentSkelName = null;
037: private SkeletonBean m_skel = null;
038:
039: protected String[] m_autourls = new String[] {
040: "JRE 1.5.0",
041: "http://java.sun.com/update/1.5.0/jinstall-1_5_0-windows-i586.cab",
042: "JRE 1.4.2_03",
043: "http://java.sun.com/update/1.4.2/jinstall-1_4_2_03-windows-i586.cab",
044: "JRE 1.4.2_02",
045: "http://java.sun.com/update/1.4.2/jinstall-1_4_2_02-windows-i586.cab",
046: "JRE 1.4.2_01",
047: "http://java.sun.com/update/1.4.2/jinstall-1_4_2_01-windows-i586.cab",
048: "JRE 1.4.2",
049: "http://java.sun.com/products/plugin/autodl/jinstall-1_4_2-windows-i586.cab",
050: "JRE 1.4.1_03",
051: "http://java.sun.com/products/plugin/autodl/jinstall-1_4_1_03-windows-i586.cab",
052: "JRE 1.4.1_02",
053: "http://java.sun.com/products/plugin/autodl/jinstall-1_4_1_02-windows-i586.cab",
054: "JRE 1.4.1_01",
055: "http://java.sun.com/products/plugin/autodl/jinstall-1_4_1_01-windows-i586.cab",
056: "JRE 1.4.1",
057: "http://java.sun.com/products/plugin/autodl/jinstall-1_4_1-windows-i586.cab",
058: "JRE 1.4.0_04",
059: "http://java.sun.com/products/plugin/autodl/jinstall-1_4_0_04-win.cab",
060: "JRE 1.4.0_03",
061: "http://java.sun.com/products/plugin/autodl/jinstall-1_4_0_03-win.cab",
062: "JRE 1.4.0_02",
063: "http://java.sun.com/products/plugin/autodl/jinstall-1_4_0_02-win.cab",
064: "JRE 1.4.0_01",
065: "http://java.sun.com/products/plugin/autodl/jinstall-1_4_0_01-win.cab",
066: "JRE 1.4.0",
067: "http://java.sun.com/products/plugin/autodl/jinstall-1_4_0-win.cab",
068: "JRE 1.3.1_08",
069: "http://java.sun.com/products/plugin/autodl/jinstall-1_3_1_08-windows-i586.cab",
070: "JRE 1.3.1_07",
071: "http://java.sun.com/products/plugin/autodl/jinstall-1_3_1_07-windows-i586.cab",
072: "JRE 1.3.1_06",
073: "http://java.sun.com/products/plugin/autodl/jinstall-1_3_1_06-windows-i586.cab",
074: "JRE 1.3.1_05",
075: "http://java.sun.com/products/plugin/autodl/jinstall-1_3_1_05-windows-i586.cab",
076: "JRE 1.3.1_04",
077: "http://java.sun.com/products/plugin/autodl/jinstall-1_3_1_04-win.cab",
078: "JRE 1.3.1_03",
079: "http://java.sun.com/products/plugin/autodl/jinstall-1_3_1_03-win.cab",
080: "JRE 1.3.1_02",
081: "http://java.sun.com/products/plugin/autodl/jinstall-1_3_1_02-win.cab",
082: "JRE 1.3.1_01",
083: "http://java.sun.com/products/plugin/autodl/jinstall-1_3_1_01-win.cab",
084: "JRE 1.3.0_05",
085: "http://java.sun.com/products/plugin/autodl/jinstall-1_3_0_05-win.cab" };
086:
087: public class SkelEditorFactory implements
088: com.l2fprod.common.propertysheet.PropertyEditorFactory {
089:
090: public java.beans.PropertyEditor createPropertyEditor(
091: Property property) {
092: if (property instanceof SkeletonPropertyProxy) {
093: SkeletonPropertyProxy spp = (SkeletonPropertyProxy) property;
094: String pname = spp.getTypeName();
095:
096: if (pname.equals("boolean"))
097: new com.l2fprod.common.beans.editor.BooleanAsCheckBoxPropertyEditor();
098: else if (pname.equals("textarea"))
099: return new com.l2fprod.common.beans.editor.StringPropertyEditor();
100: else if (pname.equals("string"))
101: return new com.l2fprod.common.beans.editor.StringPropertyEditor();
102: else if (pname.equals("autodownloadurl")) {
103: com.l2fprod.common.beans.editor.ComboBoxPropertyEditor ed = new com.l2fprod.common.beans.editor.ComboBoxPropertyEditor();
104: Object values[] = new Object[m_autourls.length / 2];
105: for (int i = 0; i < m_autourls.length; i += 2) {
106: values[(i + 1) / 2] = new com.l2fprod.common.beans.editor.ComboBoxPropertyEditor.Value(
107: m_autourls[i + 1], m_autourls[i]);
108: }
109: ed.setAvailableValues(values);
110: return ed;
111: }
112: return new com.l2fprod.common.beans.editor.BooleanAsCheckBoxPropertyEditor();
113: } else {
114: return new com.l2fprod.common.beans.editor.BooleanAsCheckBoxPropertyEditor();
115: }
116: }
117: }
118:
119: public class SkeletonPropertyProxy extends DefaultProperty {
120: SkeletonProperty m_property;
121:
122: public SkeletonPropertyProxy(SkeletonProperty prop) {
123: m_property = prop;
124: }
125:
126: public String getDisplayName() {
127: return m_property.getLabel();
128: }
129:
130: public String getName() {
131: System.out.println("proxy, getname "
132: + m_property.getIdName());
133: return m_property.getIdName();
134: }
135:
136: public String getShortDescription() {
137: return m_property.getDescription();
138: }
139:
140: public Class getType() {
141: if (m_property.getType().equals("boolean"))
142: return Boolean.class;
143: else if (m_property.getType().equals("textarea"))
144: return String.class;
145: else if (m_property.getType().equals("string"))
146: return String.class;
147: else if (m_property.getType().equals("autodownloadurl"))
148: return String.class;
149:
150: return String.class;
151: }
152:
153: public String getTypeName() {
154: return m_property.getType();
155: }
156:
157: public boolean isEditable() {
158: return true;
159: }
160:
161: public Object getValue() {
162: if (m_property.getType().equals("boolean"))
163: return new Boolean(m_property.getValue().equals("1"));
164: return m_property.getValue();
165: }
166:
167: public void setValue(Object o) {
168: System.out.println("SET VALUE " + o);
169: if (o instanceof Boolean) {
170: if (((Boolean) o).booleanValue() == true)
171: m_property.setValue("1");
172: else
173: m_property.setValue("0");
174: } else {
175: m_property.setValue(o.toString());
176: }
177: }
178: }
179:
180: public SkeletonProperties() {
181: setLayout(new BorderLayout());
182:
183: add(BorderLayout.CENTER, m_skelprops);
184: m_skelprops.setDescriptionVisible(true);
185: m_skelprops.setToolBarVisible(false);
186: }
187:
188: public Dimension getPreferredSize() {
189: return new Dimension(100, 200);
190: }
191:
192: public void setProperties() {
193: m_skel = null;
194: if (m_currentSkelName != null)
195: m_skel = Main.SKELETONS.getSkeleton(m_currentSkelName);
196:
197: SkeletonProperty[] sprops = null;
198: if (m_skel != null)
199: sprops = m_skel.getSkeletonProperties();
200: else
201: sprops = new SkeletonProperty[0];
202:
203: m_skelprops.setEditorFactory(new SkelEditorFactory());
204: SkeletonPropertyProxy[] proxy = new SkeletonPropertyProxy[sprops.length];
205: for (int i = 0; i < sprops.length; i++) {
206: proxy[i] = new SkeletonPropertyProxy(sprops[i]);
207: System.out
208: .println("Added property " + sprops[i].getLabel());
209: }
210:
211: JSmoothModelBean.Property[] jsprop = m_model
212: .getSkeletonProperties();
213: if (jsprop != null) {
214: for (int i = 0; i < jsprop.length; i++) {
215: // search for the proxy and set the value
216: for (int j = 0; j < proxy.length; j++) {
217: if (proxy[j].getName().equals(jsprop[i].getKey())) {
218: proxy[j].setValue(jsprop[i].getValue());
219: break;
220: }
221: }
222: }
223: }
224:
225: m_skelprops.setProperties(proxy);
226: }
227:
228: public void dataChanged() {
229: System.out.println("SkeletonProperties: data changed, "
230: + m_model.getSkeletonName());
231: if (m_model.getSkeletonName() == null) {
232: m_currentSkelName = null;
233: setProperties();
234: return;
235: }
236: if (!m_model.getSkeletonName().equalsIgnoreCase(
237: m_currentSkelName)) {
238: m_currentSkelName = m_model.getSkeletonName();
239: setProperties();
240: }
241: }
242:
243: public void updateModel() {
244: if (m_skel != null) {
245: SkeletonProperty[] sp = m_skel.getSkeletonProperties();
246: JSmoothModelBean.Property[] props = new JSmoothModelBean.Property[sp.length];
247: for (int i = 0; i < sp.length; i++) {
248: props[i] = new JSmoothModelBean.Property();
249: props[i].setKey(sp[i].getIdName());
250: props[i].setValue(sp[i].getValue());
251: System.out.println(props[i]);
252: }
253: m_model.setSkeletonProperties(props);
254: }
255: }
256:
257: public void skeletonChanged() {
258: dataChanged();
259: }
260:
261: public String getLabel() {
262: return "SKELETONPROPERTIES_LABEL";
263: }
264:
265: public String getDescription() {
266: return "SKELETONPROPERTIES_HELP";
267: }
268:
269: public boolean needsBigSpace() {
270: return true;
271: }
272:
273: }
|