KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > ant > deployer > AntDeployInnerPanel


1 package org.enhydra.kelp.ant.deployer;
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.ant.swing.AntOutputPanel;
28
29
30 // JDK
31
import java.util.ArrayList JavaDoc;
32 import java.util.Arrays JavaDoc;
33 import java.util.ResourceBundle JavaDoc;
34 import java.awt.*;
35 import java.beans.*;
36 import javax.swing.*;
37 import org.enhydra.tool.common.ButtonPanel;
38 import org.enhydra.tool.swing.layout.*;
39 //import com.borland.jbcl.layout.*;
40

41 //
42
public class AntDeployInnerPanel extends AddinInnerPanel {
43
44     //
45
static ResourceBundle JavaDoc res =
46         ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); // nores
47

48     //
49

50     private boolean standalone = false;
51    // private JPanel panelOptionFiller0 = null;
52
// private JPanel panelOptionFiller1 = null;
53
// private JPanel panelOptionFiller2 = null;
54
private GridBagLayout layoutMain = null;
55    // private JPanel propertyPanelHolder = null;
56
// private AddinInnerPanel propertyPanel = null;
57
private AntOutputPanel outputPanel = null;
58     private AntDeployGeneralPanel generalPanel = null;
59     private AntDeployInputPanel inputPanel = null;
60     private AntDeployContentPanel contentPanel = null;
61     private JTabbedPane tab = null;
62     private WriteListener[] writeListeners = new WriteListener[0];
63     private String JavaDoc progressTitle = new String JavaDoc();
64     XYLayout xYLayout1 = new XYLayout();
65
66     public static AntDeployInnerPanel XMLCfindAncestor(Component comp) {
67         Component found = null;
68         AntDeployInnerPanel ancestor = null;
69
70         found = AddinInnerPanel.findAncestor(comp);
71         if (found == null) {}
72         else if (found instanceof AntDeployInnerPanel) {
73             ancestor = (AntDeployInnerPanel) found;
74         }
75         return ancestor;
76     }
77
78     public AntDeployInnerPanel() {
79         try {
80             jbInit();
81             pmInit();
82         } catch (Exception JavaDoc ex) {
83             ex.printStackTrace();
84         }
85     }
86
87     // override AddinInnerPanel
88
public void initPreferredSize() {
89         Dimension d = new Dimension();
90
91         d.height = 425;
92         d.width = 550;
93         setPreferredSize(d);
94     }
95
96     // overwrite org.enhydra.kelp.common.swing.InnerPanel
97
public void clearAll() {
98         super.clearAll();
99         layoutMain = null;
100         writeListeners = new WriteListener[0];
101     }
102 // //7.2.2003
103
// public FileNodeSelectionPanel getSelectionPanel() {
104
// return selectionPanel;
105
// }
106
// protected void setSelectText(String[] s) {
107
// getSelectionPanel().setSelectText(s);
108
// }
109
// protected String[] getSelectText() {
110
// return getSelectionPanel().getSelectText();
111
// }
112
// /**
113
// * Get source files that can be selected for compilation.
114
// */
115
// protected OtterFileNode[] getNodes() {
116
// return selectionPanel.getNodes();
117
// }
118
protected void setNodes(OtterFileNode[] n) {
119         inputPanel.setNodes(n);
120     }
121
122     public void selectOutputTab() {
123         selectTab(outputPanel);
124     }
125
126     //
127
// PROTECTED
128
//
129

130     public synchronized WriteListener[] getWriteListeners() {
131         return writeListeners;
132     }
133
134     public synchronized void addWriteListener(WriteListener l) {
135         ArrayList JavaDoc list = null;
136         list = new ArrayList JavaDoc(Arrays.asList(writeListeners));
137         if (!list.contains(l)) {
138             list.add(l);
139             list.trimToSize();
140             writeListeners = new WriteListener[list.size()];
141             writeListeners = (WriteListener[]) list.toArray(writeListeners);
142         }
143         list.clear();
144     }
145
146     public synchronized void removeWriteListener(WriteListener l) {
147         ArrayList JavaDoc list = null;
148         list = new ArrayList JavaDoc(Arrays.asList(writeListeners));
149         if (list.contains(l)) {
150             list.remove(l);
151             list.trimToSize();
152             writeListeners = new WriteListener[list.size()];
153             writeListeners = (WriteListener[]) list.toArray(writeListeners);
154         }
155         list.clear();
156     }
157
158
159     // override AddinInnerPanel
160
public void read(OtterNode node) {
161         super.read(node);
162         generalPanel.setProject(getProject());
163         outputPanel.setProject(getProject());
164         inputPanel.setProject(getProject());
165         contentPanel.setProject(getProject());
166     }
167
168     // override AddinInnerPanel
169
public void write(OtterNode node) throws DataValidationException {
170         super.write(node);
171         if (getProject() == null) {
172             System.err.println("AntDeployInnerPanel.write(OtterProject p) : no project set");
173         } else {
174             outputPanel.setProject(getProject());
175         }
176     }
177
178     // override AddinInnerPanel
179
protected Component[] getFirstFocusComponents() {
180         Component[] comps = new Component[1];
181
182         comps[0] = tab;
183         return comps;
184     }
185
186     //
187
// PRIVATE
188
//
189
// override AddinInnerPanel
190
public void save() {
191         super.save();
192 // FIXME project.save()
193
}
194 //DACHA{
195
//protected void clearOutput() {
196
public void clearOutput() {
197 //}DACHA
198
outputPanel.clearOutput();
199     }
200
201     protected void back() {
202         int index = tab.getSelectedIndex();
203         int indexNew =0;
204         if (index > 0) {
205             indexNew = --index;
206             tab.setSelectedIndex(indexNew);
207         }
208         refresh();
209     }
210
211     protected void next() {
212         int index = tab.getSelectedIndex();
213         int indexNew =0;
214         if (index < tab.getTabCount()) {
215                 indexNew = ++index;
216                 tab.setSelectedIndex(indexNew);
217         }
218         refresh();
219     }
220     //
221
// PRIVATE
222
//
223
private void refresh() {
224         Component back = null;
225         Component next = null;
226         boolean backEnable = true;
227         boolean nextEnable = true;
228
229         back = getBack();
230         next = getNext();
231         int index = tab.getSelectedIndex();
232
233         if (index == 0) {
234             backEnable = false;
235         } else if (index == (tab.getTabCount() - 1)) {
236             nextEnable = false;
237         }
238         if (back != null) {
239             back.setEnabled(backEnable);
240         }
241         if (next != null) {
242             next.setEnabled(nextEnable);
243         }
244         //getSelectedStep().refresh();
245
}
246
247     private Component getNext() {
248         Component comp = ButtonPanel.findButton(getTopLevelAncestor(),
249                                                 ButtonPanel.COMMAND_NEXT);
250         return comp;
251     }
252
253     private Component getBack() {
254         Component comp = ButtonPanel.findButton(getTopLevelAncestor(),
255                                                 ButtonPanel.COMMAND_BACK);
256         return comp;
257     }
258     private void selectTab(final JPanel goPanel) {
259         SelectTab runSwing = null;
260
261         runSwing = new SelectTab(tab, goPanel);
262         try {
263             if (SwingUtilities.isEventDispatchThread()) {
264                 runSwing.run();
265             } else {
266                 SwingUtilities.invokeAndWait(runSwing);
267             }
268         } catch (Exception JavaDoc e) {
269             e.printStackTrace();
270         }
271         try {
272             Thread.sleep(500);
273         } catch (InterruptedException JavaDoc e) {
274
275             //
276
}
277     }
278
279     /**
280      * Add listeners and other items that are not generated by
281      * the JBuilder designer.
282      */

283     private void pmInit() {
284         tab.add(res.getString("General"), generalPanel);
285         tab.add(res.getString("Input"), inputPanel);
286         tab.add(res.getString("Content"), contentPanel);
287         tab.add(res.getString("Output"), outputPanel);
288         addWriteListener(outputPanel);
289     }
290
291     /**
292      * UI code generated by JBuilder.
293      * <P><I>Do not modify the signature of this method.</I></P>
294      */

295     private void jbInit() throws Exception JavaDoc {
296         layoutMain =
297             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
298                                               GridBagLayout.class.getName());
299
300         outputPanel =
301             (AntOutputPanel) Beans.instantiate(getClass().getClassLoader(),
302                                                 AntOutputPanel.class.getName());
303
304         generalPanel =
305           (AntDeployGeneralPanel) Beans.instantiate(getClass().getClassLoader(),
306                                   AntDeployGeneralPanel.class.getName());
307
308         inputPanel =
309           (AntDeployInputPanel) Beans.instantiate(getClass().getClassLoader(),
310                                   AntDeployInputPanel.class.getName());
311
312         contentPanel =
313           (AntDeployContentPanel) Beans.instantiate(getClass().getClassLoader(),
314                                   AntDeployContentPanel.class.getName());
315
316         tab = (JTabbedPane) Beans.instantiate(getClass().getClassLoader(),
317                                               JTabbedPane.class.getName());
318
319         this.setLayout(layoutMain);
320         this.setMinimumSize(new Dimension(20, 20));
321         this.setPreferredSize(new Dimension(20, 20));
322         this.add(tab, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0
323             ,GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, -1, 6, 9), 5, 5));
324     }
325
326     private class SelectTab implements Runnable JavaDoc {
327         private JTabbedPane tp = null;
328         private JPanel go = null;
329
330         protected SelectTab(JTabbedPane t, JPanel g) {
331             tp = t;
332             go = g;
333         }
334
335         synchronized public void run() {
336             tp.setSelectedComponent(go);
337             try {
338                 SwingUtilities.windowForComponent(tp).repaint();
339             } catch (NullPointerException JavaDoc e) {
340
341                 // ignore for windows not yet open.
342
}
343         }
344
345     }
346
347 }
348
349
Popular Tags