KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > ant > xmlc > AntXMLCInnerPanel


1 package org.enhydra.kelp.ant.xmlc;
2
3 /**
4  * <p>Title: </p>
5  * <p>Description: New dialog for Kelp XML Compiler based on Ant tool.</p>
6  * <p>Copyright: Copyright (c) 2003</p>
7  * <p>Company: </p>
8  * @author Damir Milovic
9  * @version 1.0
10  */

11
12 // ToolBox
13
import org.enhydra.tool.ToolBoxInfo;
14 import org.enhydra.tool.common.DataValidationException;
15 import org.enhydra.tool.common.SwingUtil;
16
17 // AddinCore
18
import org.enhydra.kelp.KelpInfo;
19 import org.enhydra.kelp.common.Constants;
20 import org.enhydra.kelp.common.event.WriteEvent;
21 import org.enhydra.kelp.common.event.WriteListener;
22 import org.enhydra.kelp.common.node.OtterProject;
23 import org.enhydra.kelp.common.node.OtterFileNode;
24 import org.enhydra.kelp.common.node.OtterNode;
25 import org.enhydra.kelp.common.swing.AddinInnerPanel;
26 import org.enhydra.kelp.common.swing.FileNodeSelectionPanel;
27 //import org.enhydra.kelp.common.xmlc.XMLCOutputPanel;
28
import org.enhydra.kelp.ant.swing.AntOutputPanel;
29
30
31 // JDK
32
import java.util.ArrayList JavaDoc;
33 import java.util.Arrays JavaDoc;
34 import java.util.ResourceBundle JavaDoc;
35 import java.awt.*;
36 import java.beans.*;
37 import javax.swing.*;
38
39 //
40
public class AntXMLCInnerPanel extends AddinInnerPanel {
41
42     //
43
static ResourceBundle JavaDoc res =
44         ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); // nores
45
private boolean standalone = false;
46
47     private FileNodeSelectionPanel selectionPanel = null;
48     private GridBagLayout layoutMain = null;
49     private AntOutputPanel outputPanel = null;
50     private JTabbedPane tab = null;
51     private WriteListener[] writeListeners = new WriteListener[0];
52     private String JavaDoc progressTitle = new String JavaDoc();
53     AntXMLCOptionsPanel optionsPanel = null;
54
55     public static AntXMLCInnerPanel XMLCfindAncestor(Component comp) {
56         Component found = null;
57         AntXMLCInnerPanel ancestor = null;
58
59         found = AddinInnerPanel.findAncestor(comp);
60         if (found == null) {}
61         else if (found instanceof AntXMLCInnerPanel) {
62             ancestor = (AntXMLCInnerPanel) found;
63         }
64         return ancestor;
65     }
66
67     public AntXMLCInnerPanel() {
68         try {
69             jbInit();
70             pmInit();
71         } catch (Exception JavaDoc ex) {
72             ex.printStackTrace();
73         }
74     }
75
76     // overwrite org.enhydra.kelp.common.swing.InnerPanel
77
public void clearAll() {
78         super.clearAll();
79         layoutMain = null;
80         writeListeners = new WriteListener[0];
81     }
82     //7.2.2003
83
public FileNodeSelectionPanel getSelectionPanel() {
84         return selectionPanel;
85     }
86     protected void setSelectText(String JavaDoc[] s) {
87         getSelectionPanel().setSelectText(s);
88     }
89     protected String JavaDoc[] getSelectText() {
90         return getSelectionPanel().getSelectText();
91     }
92     /**
93      * Get source files that can be selected for compilation.
94      */

95     protected OtterFileNode[] getNodes() {
96         return selectionPanel.getNodes();
97     }
98     /**
99      * Set the source files that can be selected for compilation
100      */

101     protected void setNodes(OtterFileNode[] n) {
102         selectionPanel.setNodes(n);
103     }
104
105
106     public AntXMLCOptionsPanel getOptionsPanel() {
107         return optionsPanel;
108     }
109
110     public void selectOutputTab() {
111         selectTab(outputPanel);
112     }
113
114     public void selectOptionTab() {
115         selectTab(optionsPanel);
116     }
117
118     //
119
// PROTECTED
120
//
121

122     public synchronized WriteListener[] getWriteListeners() {
123         return writeListeners;
124     }
125
126     public synchronized void addWriteListener(WriteListener l) {
127         ArrayList JavaDoc list = null;
128         list = new ArrayList JavaDoc(Arrays.asList(writeListeners));
129         if (!list.contains(l)) {
130             list.add(l);
131             list.trimToSize();
132             writeListeners = new WriteListener[list.size()];
133             writeListeners = (WriteListener[]) list.toArray(writeListeners);
134         }
135         list.clear();
136     }
137
138     public synchronized void removeWriteListener(WriteListener l) {
139         ArrayList JavaDoc list = null;
140         list = new ArrayList JavaDoc(Arrays.asList(writeListeners));
141         if (list.contains(l)) {
142             list.remove(l);
143             list.trimToSize();
144             writeListeners = new WriteListener[list.size()];
145             writeListeners = (WriteListener[]) list.toArray(writeListeners);
146         }
147         list.clear();
148     }
149
150
151     // override AddinInnerPanel
152
public void read(OtterNode node) {
153         super.read(node);
154         outputPanel.setProject(getProject());
155         optionsPanel.setProject(getProject());
156     }
157
158     // override AddinInnerPanel
159
public void write(OtterNode node) throws DataValidationException {
160         super.write(node);
161         if (getProject() == null) {
162             System.err.println("AntXMLCInnerPanel.write(OtterProject p) : no project set");
163         } else {
164             outputPanel.setProject(getProject());
165         }
166     }
167
168     // override AddinInnerPanel
169
protected Component[] getFirstFocusComponents() {
170         Component[] comps = new Component[1];
171
172         comps[0] = tab;
173         return comps;
174     }
175
176     //
177
// PRIVATE
178
//
179
// override AddinInnerPanel
180
public void save() {
181         super.save();
182 // FIXME project.save()
183
}
184 //DACHA{
185
//protected void clearOutput() {
186
public void clearOutput() {
187 //}DACHA
188
outputPanel.clearOutput();
189     }
190
191     //
192
// PRIVATE
193
//
194

195     private void selectTab(final JPanel goPanel) {
196         SelectTab runSwing = null;
197
198         runSwing = new SelectTab(tab, goPanel);
199         try {
200             if (SwingUtilities.isEventDispatchThread()) {
201                 runSwing.run();
202             } else {
203                 SwingUtilities.invokeAndWait(runSwing);
204             }
205         } catch (Exception JavaDoc e) {
206             e.printStackTrace();
207         }
208         try {
209             Thread.sleep(500);
210         } catch (InterruptedException JavaDoc e) {
211
212             //
213
}
214     }
215
216     /**
217      * Add listeners and other items that are not generated by
218      * the JBuilder designer.
219      */

220     private void pmInit() {
221         tab.add(res.getString("Selections"), selectionPanel);
222         tab.add(res.getString("Options"), optionsPanel);
223         tab.add(res.getString("Output"), outputPanel);
224         addWriteListener(outputPanel);
225     }
226
227     /**
228      * UI code generated by JBuilder.
229      * <P><I>Do not modify the signature of this method.</I></P>
230      */

231     private void jbInit() throws Exception JavaDoc {
232         layoutMain =
233             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
234                                               GridBagLayout.class.getName());
235
236         optionsPanel = (AntXMLCOptionsPanel) Beans.instantiate(getClass().getClassLoader(),
237                                                 AntXMLCOptionsPanel.class.getName());
238
239         selectionPanel =
240             (FileNodeSelectionPanel) Beans.instantiate(getClass().getClassLoader(),
241                 FileNodeSelectionPanel.class.getName());
242
243         outputPanel =
244             (AntOutputPanel) Beans.instantiate(getClass().getClassLoader(),
245                                                 AntOutputPanel.class.getName());
246         tab = (JTabbedPane) Beans.instantiate(getClass().getClassLoader(),
247                                               JTabbedPane.class.getName());
248
249         this.setLayout(layoutMain);
250         this.add(tab,
251                  new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0,
252                                         GridBagConstraints.CENTER,
253                                         GridBagConstraints.BOTH,
254                                         new Insets(5, 5, 5, 5), 5, 5));
255     }
256
257     private class SelectTab implements Runnable JavaDoc {
258         private JTabbedPane tp = null;
259         private JPanel go = null;
260
261         protected SelectTab(JTabbedPane t, JPanel g) {
262             tp = t;
263             go = g;
264         }
265
266         synchronized public void run() {
267             tp.setSelectedComponent(go);
268             try {
269                 SwingUtilities.windowForComponent(tp).repaint();
270             } catch (NullPointerException JavaDoc e) {
271
272                 // ignore for windows not yet open.
273
}
274         }
275
276     }
277
278 }
279
Popular Tags