KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > common > xmlc > XMLCInnerPanel


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  * Paul Mahar
21  *
22  */

23 package org.enhydra.kelp.common.xmlc;
24
25 // ToolBox
26
import org.enhydra.tool.ToolBoxInfo;
27 import org.enhydra.tool.common.DataValidationException;
28 import org.enhydra.tool.common.SwingUtil;
29
30 // AddinCore
31
import org.enhydra.kelp.KelpInfo;
32 import org.enhydra.kelp.common.Constants;
33 import org.enhydra.kelp.common.event.WriteEvent;
34 import org.enhydra.kelp.common.event.WriteListener;
35 import org.enhydra.kelp.common.node.OtterProject;
36 import org.enhydra.kelp.common.node.OtterFileNode;
37 import org.enhydra.kelp.common.node.OtterNode;
38 import org.enhydra.kelp.common.swing.AddinInnerPanel;
39 import org.enhydra.kelp.common.swing.FileNodeSelectionPanel;
40
41 // JDK
42
import java.util.ArrayList JavaDoc;
43 import java.util.Arrays JavaDoc;
44 import java.util.ResourceBundle JavaDoc;
45 import java.awt.*;
46 import java.beans.*;
47 import javax.swing.*;
48
49 //
50
public class XMLCInnerPanel extends AddinInnerPanel {
51
52     //
53
static ResourceBundle JavaDoc res =
54         ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); // nores
55

56     //
57
private FileNodeSelectionPanel selectionPanel = null;
58     private boolean standalone = false;
59     private JPanel panelOptionFiller0 = null;
60     private JPanel panelOptionFiller1 = null;
61     private JPanel panelOptionFiller2 = null;
62     private GridBagLayout layoutMain = null;
63     private JPanel propertyPanelHolder = null;
64     private AddinInnerPanel propertyPanel = null;
65     private XMLCOutputPanel outputPanel = null;
66     private JTabbedPane tab = null;
67     private WriteListener[] writeListeners = new WriteListener[0];
68     private String JavaDoc progressTitle = new String JavaDoc();
69
70     public static XMLCInnerPanel XMLCfindAncestor(Component comp) {
71         Component found = null;
72         XMLCInnerPanel ancestor = null;
73
74         found = AddinInnerPanel.findAncestor(comp);
75         if (found == null) {}
76         else if (found instanceof XMLCInnerPanel) {
77             ancestor = (XMLCInnerPanel) found;
78         }
79         return ancestor;
80     }
81
82     public XMLCInnerPanel() {
83         try {
84             jbInit();
85             pmInit();
86         } catch (Exception JavaDoc ex) {
87             ex.printStackTrace();
88         }
89     }
90
91     // overwrite org.enhydra.kelp.common.swing.InnerPanel
92
public void clearAll() {
93         super.clearAll();
94         layoutMain = null;
95         writeListeners = new WriteListener[0];
96     }
97
98     public FileNodeSelectionPanel getSelectionPanel() {
99         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 JavaDoc[] s) {
128         getSelectionPanel().setSelectText(s);
129     }
130
131     protected String JavaDoc[] 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 JavaDoc list = null;
141
142         list = new ArrayList JavaDoc(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.toArray(writeListeners);
148         }
149         list.clear();
150     }
151
152     protected synchronized void removeWriteListener(WriteListener l) {
153         ArrayList JavaDoc list = null;
154
155         list = new ArrayList JavaDoc(Arrays.asList(writeListeners));
156         if (list.contains(l)) {
157             list.remove(l);
158             list.trimToSize();
159             writeListeners = new WriteListener[list.size()];
160             writeListeners = (WriteListener[]) list.toArray(writeListeners);
161         }
162         list.clear();
163     }
164
165     /**
166      * Get source files that can be selected for compilation.
167      */

168     protected OtterFileNode[] getNodes() {
169         return selectionPanel.getNodes();
170     }
171
172     /**
173      * Set the source files that can be selected for compilation
174      */

175     protected void setNodes(OtterFileNode[] n) {
176         selectionPanel.setNodes(n);
177     }
178
179     // override AddinInnerPanel
180
public void read(OtterNode node) {
181         super.read(node);
182         propertyPanel.read(node);
183         outputPanel.setProject(getProject());
184     }
185
186     // override AddinInnerPanel
187
public void write(OtterNode node) throws DataValidationException {
188         super.write(node);
189         if (getProject() == null) {
190             System.err.println("XMLCInnerPanel.write(OtterProject p) : no project set");
191         } else {
192             propertyPanel.write(node);
193             outputPanel.setProject(getProject());
194         }
195     }
196
197     // override AddinInnerPanel
198
protected Component[] getFirstFocusComponents() {
199         Component[] comps = new Component[1];
200
201         comps[0] = tab;
202         return comps;
203     }
204
205     //
206
// PRIVATE
207
//
208
// override AddinInnerPanel
209
public void save() {
210         super.save();
211         propertyPanel.save();
212     }
213
214     protected void clearOutput() {
215         outputPanel.clearOutput();
216     }
217
218     //
219
// PRIVATE
220
//
221
private void selectTab(final JPanel goPanel) {
222         SelectTab runSwing = null;
223
224         runSwing = new SelectTab(tab, goPanel);
225         try {
226             if (SwingUtilities.isEventDispatchThread()) {
227                 runSwing.run();
228             } else {
229                 SwingUtilities.invokeAndWait(runSwing);
230             }
231         } catch (Exception JavaDoc e) {
232             e.printStackTrace();
233         }
234         try {
235             Thread.sleep(500);
236         } catch (InterruptedException JavaDoc e) {
237
238             //
239
}
240     }
241
242     /**
243      * Add listeners and other items that are not generated by
244      * the JBuilder designer.
245      */

246     private void pmInit() {
247         tab.add(res.getString("Selections"), selectionPanel);
248         tab.add(res.getString("Options"), panelOptionFiller0);
249         tab.add(res.getString("Output"), outputPanel);
250         addWriteListener(outputPanel);
251     }
252
253     /**
254      * UI code generated by JBuilder.
255      * <P><I>Do not modify the signature of this method.</I></P>
256      */

257     private void jbInit() throws Exception JavaDoc {
258         layoutMain =
259             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
260                                               GridBagLayout.class.getName());
261         panelOptionFiller0 =
262             (JPanel) Beans.instantiate(getClass().getClassLoader(),
263                                        JPanel.class.getName());
264         panelOptionFiller1 =
265             (JPanel) Beans.instantiate(getClass().getClassLoader(),
266                                        JPanel.class.getName());
267         panelOptionFiller2 =
268             (JPanel) Beans.instantiate(getClass().getClassLoader(),
269                                        JPanel.class.getName());
270         selectionPanel =
271             (FileNodeSelectionPanel) Beans.instantiate(getClass().getClassLoader(),
272                 FileNodeSelectionPanel.class.getName());
273         propertyPanelHolder =
274             (JPanel) Beans.instantiate(getClass().getClassLoader(),
275                                        JPanel.class.getName());
276         outputPanel =
277             (XMLCOutputPanel) Beans.instantiate(getClass().getClassLoader(),
278                                                 XMLCOutputPanel.class.getName());
279         tab = (JTabbedPane) Beans.instantiate(getClass().getClassLoader(),
280                                               JTabbedPane.class.getName());
281         panelOptionFiller0.setLayout(new GridBagLayout());
282         panelOptionFiller0.add(panelOptionFiller1,
283                                new GridBagConstraints(0, 0, 1, 1, 0.15, 0.15,
284                                GridBagConstraints.CENTER,
285                                GridBagConstraints.BOTH,
286                                new Insets(0, 0, 0, 0), 0, 0));
287         panelOptionFiller0.add(propertyPanelHolder,
288                                new GridBagConstraints(1, 0, 1, 4, 0.7, 0.7,
289                                GridBagConstraints.CENTER,
290                                GridBagConstraints.NONE,
291                                new Insets(0, 0, 0, 0), 0, 0));
292         panelOptionFiller0.add(panelOptionFiller2,
293                                new GridBagConstraints(2, 0, 1, 1, 0.15, 0.15,
294                                GridBagConstraints.CENTER,
295                                GridBagConstraints.BOTH,
296                                new Insets(0, 0, 0, 0), 0, 0));
297         this.setLayout(layoutMain);
298         this.add(tab,
299                  new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0,
300                                         GridBagConstraints.CENTER,
301                                         GridBagConstraints.BOTH,
302                                         new Insets(5, 5, 5, 5), 5, 5));
303     }
304
305     //
306
private class SelectTab implements Runnable JavaDoc {
307         private JTabbedPane tp = null;
308         private JPanel go = null;
309
310         protected SelectTab(JTabbedPane t, JPanel g) {
311             tp = t;
312             go = g;
313         }
314
315         synchronized public void run() {
316             tp.setSelectedComponent(go);
317             try {
318                 SwingUtilities.windowForComponent(tp).repaint();
319             } catch (NullPointerException JavaDoc e) {
320
321                 // ignore for windows not yet open.
322
}
323         }
324
325     }
326 }
327
Popular Tags