001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: *
019: * Contributor(s):
020: * Paul Mahar
021: *
022: */
023: package org.enhydra.kelp.common.xmlc;
024:
025: // ToolBox
026: import org.enhydra.tool.ToolBoxInfo;
027: import org.enhydra.tool.common.DataValidationException;
028: import org.enhydra.tool.common.SwingUtil;
029:
030: // AddinCore
031: import org.enhydra.kelp.KelpInfo;
032: import org.enhydra.kelp.common.Constants;
033: import org.enhydra.kelp.common.event.WriteEvent;
034: import org.enhydra.kelp.common.event.WriteListener;
035: import org.enhydra.kelp.common.node.OtterProject;
036: import org.enhydra.kelp.common.node.OtterFileNode;
037: import org.enhydra.kelp.common.node.OtterNode;
038: import org.enhydra.kelp.common.swing.AddinInnerPanel;
039: import org.enhydra.kelp.common.swing.FileNodeSelectionPanel;
040:
041: // JDK
042: import java.util.ArrayList;
043: import java.util.Arrays;
044: import java.util.ResourceBundle;
045: import java.awt.*;
046: import java.beans.*;
047: import javax.swing.*;
048:
049: //
050: public class XMLCInnerPanel extends AddinInnerPanel {
051:
052: //
053: static ResourceBundle res = ResourceBundle
054: .getBundle("org.enhydra.kelp.common.Res"); // nores
055:
056: //
057: private FileNodeSelectionPanel selectionPanel = null;
058: private boolean standalone = false;
059: private JPanel panelOptionFiller0 = null;
060: private JPanel panelOptionFiller1 = null;
061: private JPanel panelOptionFiller2 = null;
062: private GridBagLayout layoutMain = null;
063: private JPanel propertyPanelHolder = null;
064: private AddinInnerPanel propertyPanel = null;
065: private XMLCOutputPanel outputPanel = null;
066: private JTabbedPane tab = null;
067: private WriteListener[] writeListeners = new WriteListener[0];
068: private String progressTitle = new String();
069:
070: public static XMLCInnerPanel XMLCfindAncestor(Component comp) {
071: Component found = null;
072: XMLCInnerPanel ancestor = null;
073:
074: found = AddinInnerPanel.findAncestor(comp);
075: if (found == null) {
076: } else if (found instanceof XMLCInnerPanel) {
077: ancestor = (XMLCInnerPanel) found;
078: }
079: return ancestor;
080: }
081:
082: public XMLCInnerPanel() {
083: try {
084: jbInit();
085: pmInit();
086: } catch (Exception ex) {
087: ex.printStackTrace();
088: }
089: }
090:
091: // overwrite org.enhydra.kelp.common.swing.InnerPanel
092: public void clearAll() {
093: super .clearAll();
094: layoutMain = null;
095: writeListeners = new WriteListener[0];
096: }
097:
098: public FileNodeSelectionPanel getSelectionPanel() {
099: return selectionPanel;
100: }
101:
102: public AddinInnerPanel getPropertyPanel() {
103: return propertyPanel;
104: }
105:
106: public void selectOutputTab() {
107: selectTab(outputPanel);
108: }
109:
110: public void selectOptionTab() {
111: selectTab(panelOptionFiller0);
112: }
113:
114: //
115: // PROTECTED
116: //
117: protected void setPropertyPanel(AddinInnerPanel p) {
118: if (propertyPanel == null) {
119: propertyPanelHolder.removeAll();
120: } else {
121: propertyPanelHolder.remove(propertyPanel);
122: }
123: propertyPanel = p;
124: propertyPanelHolder.add(propertyPanel, BorderLayout.CENTER);
125: }
126:
127: protected void setSelectText(String[] s) {
128: getSelectionPanel().setSelectText(s);
129: }
130:
131: protected String[] getSelectText() {
132: return getSelectionPanel().getSelectText();
133: }
134:
135: protected synchronized WriteListener[] getWriteListeners() {
136: return writeListeners;
137: }
138:
139: protected synchronized void addWriteListener(WriteListener l) {
140: ArrayList list = null;
141:
142: list = new ArrayList(Arrays.asList(writeListeners));
143: if (!list.contains(l)) {
144: list.add(l);
145: list.trimToSize();
146: writeListeners = new WriteListener[list.size()];
147: writeListeners = (WriteListener[]) list
148: .toArray(writeListeners);
149: }
150: list.clear();
151: }
152:
153: protected synchronized void removeWriteListener(WriteListener l) {
154: ArrayList list = null;
155:
156: list = new ArrayList(Arrays.asList(writeListeners));
157: if (list.contains(l)) {
158: list.remove(l);
159: list.trimToSize();
160: writeListeners = new WriteListener[list.size()];
161: writeListeners = (WriteListener[]) list
162: .toArray(writeListeners);
163: }
164: list.clear();
165: }
166:
167: /**
168: * Get source files that can be selected for compilation.
169: */
170: protected OtterFileNode[] getNodes() {
171: return selectionPanel.getNodes();
172: }
173:
174: /**
175: * Set the source files that can be selected for compilation
176: */
177: protected void setNodes(OtterFileNode[] n) {
178: selectionPanel.setNodes(n);
179: }
180:
181: // override AddinInnerPanel
182: public void read(OtterNode node) {
183: super .read(node);
184: propertyPanel.read(node);
185: outputPanel.setProject(getProject());
186: }
187:
188: // override AddinInnerPanel
189: public void write(OtterNode node) throws DataValidationException {
190: super .write(node);
191: if (getProject() == null) {
192: System.err
193: .println("XMLCInnerPanel.write(OtterProject p) : no project set");
194: } else {
195: propertyPanel.write(node);
196: outputPanel.setProject(getProject());
197: }
198: }
199:
200: // override AddinInnerPanel
201: protected Component[] getFirstFocusComponents() {
202: Component[] comps = new Component[1];
203:
204: comps[0] = tab;
205: return comps;
206: }
207:
208: //
209: // PRIVATE
210: //
211: // override AddinInnerPanel
212: public void save() {
213: super .save();
214: propertyPanel.save();
215: }
216:
217: protected void clearOutput() {
218: outputPanel.clearOutput();
219: }
220:
221: //
222: // PRIVATE
223: //
224: private void selectTab(final JPanel goPanel) {
225: SelectTab runSwing = null;
226:
227: runSwing = new SelectTab(tab, goPanel);
228: try {
229: if (SwingUtilities.isEventDispatchThread()) {
230: runSwing.run();
231: } else {
232: SwingUtilities.invokeAndWait(runSwing);
233: }
234: } catch (Exception e) {
235: e.printStackTrace();
236: }
237: try {
238: Thread.sleep(500);
239: } catch (InterruptedException e) {
240:
241: //
242: }
243: }
244:
245: /**
246: * Add listeners and other items that are not generated by
247: * the JBuilder designer.
248: */
249: private void pmInit() {
250: tab.add(res.getString("Selections"), selectionPanel);
251: tab.add(res.getString("Options"), panelOptionFiller0);
252: tab.add(res.getString("Output"), outputPanel);
253: addWriteListener(outputPanel);
254: }
255:
256: /**
257: * UI code generated by JBuilder.
258: * <P><I>Do not modify the signature of this method.</I></P>
259: */
260: private void jbInit() throws Exception {
261: layoutMain = (GridBagLayout) Beans.instantiate(getClass()
262: .getClassLoader(), GridBagLayout.class.getName());
263: panelOptionFiller0 = (JPanel) Beans.instantiate(getClass()
264: .getClassLoader(), JPanel.class.getName());
265: panelOptionFiller1 = (JPanel) Beans.instantiate(getClass()
266: .getClassLoader(), JPanel.class.getName());
267: panelOptionFiller2 = (JPanel) Beans.instantiate(getClass()
268: .getClassLoader(), JPanel.class.getName());
269: selectionPanel = (FileNodeSelectionPanel) Beans.instantiate(
270: getClass().getClassLoader(),
271: FileNodeSelectionPanel.class.getName());
272: propertyPanelHolder = (JPanel) Beans.instantiate(getClass()
273: .getClassLoader(), JPanel.class.getName());
274: outputPanel = (XMLCOutputPanel) Beans.instantiate(getClass()
275: .getClassLoader(), XMLCOutputPanel.class.getName());
276: tab = (JTabbedPane) Beans.instantiate(getClass()
277: .getClassLoader(), JTabbedPane.class.getName());
278: panelOptionFiller0.setLayout(new GridBagLayout());
279: panelOptionFiller0.add(panelOptionFiller1,
280: new GridBagConstraints(0, 0, 1, 1, 0.15, 0.15,
281: GridBagConstraints.CENTER,
282: GridBagConstraints.BOTH,
283: new Insets(0, 0, 0, 0), 0, 0));
284: panelOptionFiller0.add(propertyPanelHolder,
285: new GridBagConstraints(1, 0, 1, 4, 0.7, 0.7,
286: GridBagConstraints.CENTER,
287: GridBagConstraints.NONE,
288: new Insets(0, 0, 0, 0), 0, 0));
289: panelOptionFiller0.add(panelOptionFiller2,
290: new GridBagConstraints(2, 0, 1, 1, 0.15, 0.15,
291: GridBagConstraints.CENTER,
292: GridBagConstraints.BOTH,
293: new Insets(0, 0, 0, 0), 0, 0));
294: this .setLayout(layoutMain);
295: this .add(tab, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0,
296: GridBagConstraints.CENTER, GridBagConstraints.BOTH,
297: new Insets(5, 5, 5, 5), 5, 5));
298: }
299:
300: //
301: private class SelectTab implements Runnable {
302: private JTabbedPane tp = null;
303: private JPanel go = null;
304:
305: protected SelectTab(JTabbedPane t, JPanel g) {
306: tp = t;
307: go = g;
308: }
309:
310: synchronized public void run() {
311: tp.setSelectedComponent(go);
312: try {
313: SwingUtilities.windowForComponent(tp).repaint();
314: } catch (NullPointerException e) {
315:
316: // ignore for windows not yet open.
317: }
318: }
319:
320: }
321: }
|