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.application.gui.skeleditors.*;
024:
025: import net.charabia.jsmoothgen.skeleton.*;
026: import net.charabia.jsmoothgen.application.*;
027: import net.charabia.jsmoothgen.application.gui.*;
028: import net.charabia.jsmoothgen.application.gui.util.*;
029: import javax.swing.*;
030: import java.awt.*;
031: import java.util.*;
032: import com.l2fprod.common.swing.*;
033: import com.l2fprod.common.propertysheet.*;
034:
035: import se.datadosen.component.RiverLayout;
036:
037: public class SkeletonPropertiesEditor extends Editor implements
038: JSmoothModelBean.SkeletonChangedListener {
039: private String m_currentSkelName = null;
040: private SkeletonBean m_skel = null;
041: private SkelPanel m_panel = new SkelPanel();
042: private Vector m_editors = new Vector();
043:
044: public SkeletonPropertiesEditor() {
045: setLayout(new BorderLayout());
046: add(m_panel, BorderLayout.CENTER);
047: }
048:
049: public void rebuildProperties() {
050: // System.out.println("=============================================");
051: // System.out.println("=============================================");
052: // System.out.println("=== REBUILD PROPERTIES !!!! ===========");
053: // System.out.println("=============================================");
054: // System.out.println("=============================================");
055:
056: m_skel = null;
057: if (m_currentSkelName != null)
058: m_skel = Main.SKELETONS.getSkeleton(m_currentSkelName);
059:
060: SkeletonProperty[] sprops = null;
061: if (m_skel != null)
062: sprops = m_skel.getSkeletonProperties();
063: else
064: sprops = new SkeletonProperty[0];
065:
066: m_panel.removeAll();
067: m_panel.setLayout(new RiverLayout());
068: m_editors.clear();
069:
070: for (int i = 0; i < sprops.length; i++) {
071: SkelPropEditor spe = null;
072: if (sprops[i].getType().equalsIgnoreCase(
073: SkeletonProperty.TYPE_STRING)) {
074: spe = new StringEditor();
075: } else if (sprops[i].getType().equalsIgnoreCase(
076: SkeletonProperty.TYPE_TEXTAREA)) {
077: spe = new TextAreaEditor();
078: } else if (sprops[i].getType().equalsIgnoreCase(
079: SkeletonProperty.TYPE_BOOLEAN)) {
080: spe = new CheckBoxEditor();
081: } else if (sprops[i].getType().equalsIgnoreCase(
082: SkeletonProperty.TYPE_AUTODOWNLOADURL)) {
083: spe = new AutoDownloadURLEditor();
084: }
085:
086: if (spe == null) {
087: spe = new StringEditor();
088: }
089:
090: m_editors.add(spe);
091: spe.bind(sprops[i]);
092:
093: if (spe.labelAtLeft()) {
094: m_panel.add("br", new JLabel(Main.local(sprops[i]
095: .getLabel())));
096: m_panel.add("tab", new HelpButton(Main.local(sprops[i]
097: .getDescription())));
098: m_panel.add("tab hfill", spe.getGUI());
099: } else {
100: m_panel.add("br right", spe.getGUI());
101: m_panel.add("tab", new HelpButton(Main.local(sprops[i]
102: .getDescription())));
103: m_panel.add("tab hfill", new JLabel(Main
104: .local(sprops[i].getLabel())));
105: }
106: }
107:
108: revalidate();
109: m_panel.revalidate();
110: doLayout();
111: m_panel.doLayout();
112: }
113:
114: public void dataChanged() {
115: // System.out.println("========================================================");
116: // System.out.println("SkeletonPropertiesEditor: data changed, " + m_model.getSkeletonName());
117: if (m_model.getSkeletonName() == null) {
118: // System.out.println("SkeletonPropertiesEditor, no name");
119: m_currentSkelName = null;
120: rebuildProperties();
121: }
122:
123: if ((m_model != null)
124: && (m_model.getSkeletonName() != null)
125: && (!m_model.getSkeletonName().equalsIgnoreCase(
126: m_currentSkelName))) {
127: // System.out.println("SkeletonPropertiesEditor, different...");
128: m_currentSkelName = m_model.getSkeletonName();
129: rebuildProperties();
130: }
131:
132: JSmoothModelBean.Property[] jsprop = m_model
133: .getSkeletonProperties();
134: // System.out.println("jsprop is null ? " + jsprop + " / " + ((jsprop!=null)?jsprop.length:-1));
135: if (jsprop != null) {
136: for (Enumeration e = m_editors.elements(); e
137: .hasMoreElements();) {
138: SkelPropEditor spe = (SkelPropEditor) e.nextElement();
139: JSmoothModelBean.Property p = getPropertyInstance(spe
140: .getIdName());
141: if (p != null)
142: spe.valueChanged(p.getValue());
143: }
144: } else { // if no properties are defined for this model, we use the default values
145:
146: SkeletonBean skel = Main.SKELETONS.getSkeleton(m_model
147: .getSkeletonName());
148: SkeletonProperty[] sprops = null;
149: if (skel != null)
150: sprops = skel.getSkeletonProperties();
151:
152: if (sprops != null) {
153: for (Enumeration e = m_editors.elements(); e
154: .hasMoreElements();) {
155: SkelPropEditor spe = (SkelPropEditor) e
156: .nextElement();
157: for (int i = 0; i < sprops.length; i++) {
158: if (sprops[i].getIdName().equals(
159: spe.getIdName()))
160: spe.valueChanged(sprops[i].getValue());
161: }
162: }
163: }
164: }
165:
166: // System.out.println("DONE NOTHING! " +m_currentSkelName + "/" + m_model.getSkeletonName());
167: }
168:
169: JSmoothModelBean.Property getPropertyInstance(String name) {
170: JSmoothModelBean.Property[] jsprop = m_model
171: .getSkeletonProperties();
172: for (int i = 0; i < jsprop.length; i++) {
173: if (jsprop[i].getKey().equals(name))
174: return jsprop[i];
175: }
176: return null;
177: }
178:
179: public void updateModel() {
180: if (m_skel != null) {
181: JSmoothModelBean.Property[] props = new JSmoothModelBean.Property[m_editors
182: .size()];
183: int index = 0;
184: for (Enumeration e = m_editors.elements(); e
185: .hasMoreElements();) {
186: SkelPropEditor spe = (SkelPropEditor) e.nextElement();
187: // System.out.println("IMODEL property " + spe + "/" + spe.getIdName() + "=" + spe.get());
188: props[index] = new JSmoothModelBean.Property();
189: props[index].setKey(spe.getIdName());
190: props[index].setValue(spe.get());
191: index++;
192: }
193: m_model.setSkeletonProperties(props);
194: }
195:
196: // if (m_skel != null)
197: // {
198: // System.out.println("UPDATE MODEL for skeletons...");
199: // SkeletonProperty[] sp = m_skel.getSkeletonProperties();
200: // JSmoothModelBean.Property[] props = new JSmoothModelBean.Property[sp.length];
201: // for (int i=0; i<sp.length; i++)
202: // {
203: // props[i] = new JSmoothModelBean.Property();
204: // props[i].setKey(sp[i].getIdName());
205: // props[i].setValue(sp[i].getValue());
206: // System.out.println(props[i]);
207: // }
208: // m_model.setSkeletonProperties(props);
209: // }
210:
211: }
212:
213: public void skeletonChanged() {
214: // dataChanged();
215: rebuildProperties();
216: dataChanged();
217: }
218:
219: public String getLabel() {
220: return "SKELETONPROPERTIES_LABEL";
221: }
222:
223: public String getDescription() {
224: return "SKELETONPROPERTIES_HELP";
225: }
226:
227: public boolean needsBigSpace() {
228: return true;
229: }
230:
231: }
|