001: package org.enhydra.kelp.ant.xmlc;
002:
003: /**
004: * <p>Title: </p>
005: * <p>Description: New dialog for Kelp XML Compiler based on Ant tool.</p>
006: * <p>Copyright: Copyright (c) 2003</p>
007: * <p>Company: </p>
008: * @author Damir Milovic
009: * @version 1.0
010: */
011:
012: // ToolBox
013: import org.enhydra.tool.common.DataValidationException;
014:
015: // AddinCore
016: import org.enhydra.kelp.common.event.WriteListener;
017: import org.enhydra.kelp.common.node.OtterFileNode;
018: import org.enhydra.kelp.common.node.OtterNode;
019: import org.enhydra.kelp.common.swing.AddinInnerPanel;
020: import org.enhydra.kelp.common.swing.FileNodeSelectionPanel;
021: import org.enhydra.kelp.ant.swing.AntOutputPanel;
022:
023: // JDK
024: import java.util.ArrayList;
025: import java.util.Arrays;
026: import java.util.ResourceBundle;
027: import java.awt.*;
028: import java.beans.*;
029: import javax.swing.*;
030:
031: //
032: public class AntXMLCInnerPanel extends AddinInnerPanel {
033:
034: //
035: static ResourceBundle res = ResourceBundle
036: .getBundle("org.enhydra.kelp.common.Res"); // nores
037:
038: private FileNodeSelectionPanel selectionPanel = null;
039: private GridBagLayout layoutMain = null;
040: private AntOutputPanel outputPanel = null;
041: private JTabbedPane tab = null;
042: private WriteListener[] writeListeners = new WriteListener[0];
043: AntXMLCOptionsPanel optionsPanel = null;
044:
045: public static AntXMLCInnerPanel XMLCfindAncestor(Component comp) {
046: Component found = null;
047: AntXMLCInnerPanel ancestor = null;
048:
049: found = AddinInnerPanel.findAncestor(comp);
050: if (found == null) {
051: } else if (found instanceof AntXMLCInnerPanel) {
052: ancestor = (AntXMLCInnerPanel) found;
053: }
054: return ancestor;
055: }
056:
057: public AntXMLCInnerPanel() {
058: try {
059: jbInit();
060: pmInit();
061: } catch (Exception ex) {
062: ex.printStackTrace();
063: }
064: }
065:
066: // overwrite org.enhydra.kelp.common.swing.InnerPanel
067: public void clearAll() {
068: super .clearAll();
069: layoutMain = null;
070: writeListeners = new WriteListener[0];
071: }
072:
073: //7.2.2003
074: public FileNodeSelectionPanel getSelectionPanel() {
075: return selectionPanel;
076: }
077:
078: protected void setSelectText(String[] s) {
079: getSelectionPanel().setSelectText(s);
080: }
081:
082: protected String[] getSelectText() {
083: return getSelectionPanel().getSelectText();
084: }
085:
086: /**
087: * Get source files that can be selected for compilation.
088: */
089: protected OtterFileNode[] getNodes() {
090: return selectionPanel.getNodes();
091: }
092:
093: /**
094: * Set the source files that can be selected for compilation
095: */
096: protected void setNodes(OtterFileNode[] n) {
097: selectionPanel.setNodes(n);
098: }
099:
100: public AntXMLCOptionsPanel getOptionsPanel() {
101: return optionsPanel;
102: }
103:
104: public void selectOutputTab() {
105: selectTab(outputPanel);
106: }
107:
108: public void selectOptionTab() {
109: selectTab(optionsPanel);
110: }
111:
112: //
113: // PROTECTED
114: //
115:
116: public synchronized WriteListener[] getWriteListeners() {
117: return writeListeners;
118: }
119:
120: public synchronized void addWriteListener(WriteListener l) {
121: ArrayList list = null;
122: list = new ArrayList(Arrays.asList(writeListeners));
123: if (!list.contains(l)) {
124: list.add(l);
125: list.trimToSize();
126: writeListeners = new WriteListener[list.size()];
127: writeListeners = (WriteListener[]) list
128: .toArray(writeListeners);
129: }
130: list.clear();
131: }
132:
133: public synchronized void removeWriteListener(WriteListener l) {
134: ArrayList list = null;
135: list = new ArrayList(Arrays.asList(writeListeners));
136: if (list.contains(l)) {
137: list.remove(l);
138: list.trimToSize();
139: writeListeners = new WriteListener[list.size()];
140: writeListeners = (WriteListener[]) list
141: .toArray(writeListeners);
142: }
143: list.clear();
144: }
145:
146: // override AddinInnerPanel
147: public void read(OtterNode node) {
148: super .read(node);
149: outputPanel.setProject(getProject());
150: optionsPanel.setProject(getProject());
151: }
152:
153: // override AddinInnerPanel
154: public void write(OtterNode node) throws DataValidationException {
155: super .write(node);
156: if (getProject() == null) {
157: System.err
158: .println("AntXMLCInnerPanel.write(OtterProject p) : no project set");
159: } else {
160: outputPanel.setProject(getProject());
161: }
162: }
163:
164: // override AddinInnerPanel
165: protected Component[] getFirstFocusComponents() {
166: Component[] comps = new Component[1];
167:
168: comps[0] = tab;
169: return comps;
170: }
171:
172: //
173: // PRIVATE
174: //
175: // override AddinInnerPanel
176: public void save() {
177: super .save();
178: // FIXME project.save()
179: }
180:
181: //DACHA{
182: //protected void clearOutput() {
183: public void clearOutput() {
184: //}DACHA
185: outputPanel.clearOutput();
186: }
187:
188: //
189: // PRIVATE
190: //
191:
192: private void selectTab(final JPanel goPanel) {
193: SelectTab runSwing = null;
194:
195: runSwing = new SelectTab(tab, goPanel);
196: try {
197: if (SwingUtilities.isEventDispatchThread()) {
198: runSwing.run();
199: } else {
200: SwingUtilities.invokeAndWait(runSwing);
201: }
202: } catch (Exception e) {
203: e.printStackTrace();
204: }
205: try {
206: Thread.sleep(500);
207: } catch (InterruptedException e) {
208:
209: //
210: }
211: }
212:
213: /**
214: * Add listeners and other items that are not generated by
215: * the JBuilder designer.
216: */
217: private void pmInit() {
218: tab.add(res.getString("Selections"), selectionPanel);
219: tab.add(res.getString("Options"), optionsPanel);
220: tab.add(res.getString("Output"), outputPanel);
221: addWriteListener(outputPanel);
222: }
223:
224: /**
225: * UI code generated by JBuilder.
226: * <P><I>Do not modify the signature of this method.</I></P>
227: */
228: private void jbInit() throws Exception {
229: layoutMain = (GridBagLayout) Beans.instantiate(getClass()
230: .getClassLoader(), GridBagLayout.class.getName());
231:
232: optionsPanel = (AntXMLCOptionsPanel) Beans.instantiate(
233: getClass().getClassLoader(), AntXMLCOptionsPanel.class
234: .getName());
235:
236: selectionPanel = (FileNodeSelectionPanel) Beans.instantiate(
237: getClass().getClassLoader(),
238: FileNodeSelectionPanel.class.getName());
239:
240: outputPanel = (AntOutputPanel) Beans.instantiate(getClass()
241: .getClassLoader(), AntOutputPanel.class.getName());
242: tab = (JTabbedPane) Beans.instantiate(getClass()
243: .getClassLoader(), JTabbedPane.class.getName());
244:
245: this .setLayout(layoutMain);
246: this .add(tab, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0,
247: GridBagConstraints.CENTER, GridBagConstraints.BOTH,
248: new Insets(5, 5, 5, 5), 5, 5));
249: }
250:
251: private class SelectTab implements Runnable {
252: private JTabbedPane tp = null;
253: private JPanel go = null;
254:
255: protected SelectTab(JTabbedPane t, JPanel g) {
256: tp = t;
257: go = g;
258: }
259:
260: synchronized public void run() {
261: tp.setSelectedComponent(go);
262: try {
263: SwingUtilities.windowForComponent(tp).repaint();
264: } catch (NullPointerException e) {
265:
266: // ignore for windows not yet open.
267: }
268: }
269:
270: }
271:
272: }
|