KickJava   Java API By Example, From Geeks To Geeks.

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


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

25
26 // ToolBox imports
27
import org.enhydra.tool.common.DirectoryFilter;
28 import org.enhydra.tool.common.SwingUtil;
29
30 // Standard imports
31
import java.awt.Dimension JavaDoc;
32 import java.awt.Dialog JavaDoc;
33 import java.awt.Frame JavaDoc;
34 import java.awt.GridBagLayout JavaDoc;
35 import java.awt.GridBagConstraints JavaDoc;
36 import java.awt.Insets JavaDoc;
37 import java.awt.Point JavaDoc;
38 import java.awt.event.ActionEvent JavaDoc;
39 import java.awt.event.ActionListener JavaDoc;
40 import java.io.File JavaDoc;
41 import java.beans.Beans JavaDoc;
42 import javax.swing.JButton JavaDoc;
43 import javax.swing.JDialog JavaDoc;
44 import javax.swing.JPanel JavaDoc;
45 import javax.swing.JTextField JavaDoc;
46 import javax.swing.JLabel JavaDoc;
47 import java.util.ResourceBundle JavaDoc;
48
49 /**
50  * Class declaration
51  *
52  *
53  * @author
54  * @version %I%, %G%
55  */

56 public class AntDeployReplaceEditorDialog extends JDialog JavaDoc {
57     static ResourceBundle JavaDoc res =
58         ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); // nores
59
public static final int ACTION_OK = 0;
60     public static final int ACTION_CANCEL = 1;
61     private static File JavaDoc startFolder = null;
62     private int option = ACTION_CANCEL;
63     private LocalButtonListener buttonListener = null;
64     private JPanel JavaDoc panelMain = new JPanel JavaDoc();
65     private GridBagLayout JavaDoc layoutMain;
66     private JPanel JavaDoc panelEntry;
67     private GridBagLayout JavaDoc layoutEntry;
68     private JPanel JavaDoc panelButtons;
69     private GridBagLayout JavaDoc layoutButton;
70     private JLabel JavaDoc labelFind;
71     private JTextField JavaDoc textFind;
72     private JButton JavaDoc buttonBrowse;
73     private JLabel JavaDoc labelReplaceWith;
74     private JTextField JavaDoc textReplaceWith;
75     private JButton JavaDoc buttonCancel;
76     private JButton JavaDoc buttonOK;
77
78     /**
79      * Constructor declaration
80      *
81      *
82      * @param owner
83      * @param title
84      * @param modal
85      */

86     public AntDeployReplaceEditorDialog(Dialog JavaDoc owner, String JavaDoc title, boolean modal) {
87         super(owner, title, modal);
88         construct();
89     }
90
91     public AntDeployReplaceEditorDialog(Frame JavaDoc owner, String JavaDoc title, boolean modal) {
92         super(owner, title, modal);
93         construct();
94     }
95
96     private void construct() {
97         try {
98             jbInit();
99             pmInit();
100             pack();
101         } catch (Exception JavaDoc ex) {
102             ex.printStackTrace();
103         }
104     }
105
106     /**
107      * Constructor declaration
108      *
109      */

110     public AntDeployReplaceEditorDialog() {
111         this(new Frame JavaDoc(), new String JavaDoc(), false);
112     }
113
114     /**
115      * Method declaration
116      *
117      */

118     public void show() {
119         setResizable(false);
120         Point JavaDoc cPoint;
121
122         invalidate();
123         doLayout();
124         pack();
125         cPoint = SwingUtil.getCenteringPoint(getSize());
126         setLocation(cPoint);
127         super.show();
128     }
129
130     /**
131      * Method declaration
132      *
133      */

134     private void pmInit() {
135         buttonListener = new LocalButtonListener();
136         buttonBrowse.addActionListener(buttonListener);
137         buttonOK.addActionListener(buttonListener);
138         buttonCancel.addActionListener(buttonListener);
139         textFind.setText(new String JavaDoc());
140         textReplaceWith.setText(new String JavaDoc());
141     }
142
143     /**
144      * Method declaration
145      *
146      *
147      * @throws Exception
148      */

149     private void jbInit() throws Exception JavaDoc {
150         layoutMain =
151             (GridBagLayout JavaDoc) Beans.instantiate(getClass().getClassLoader(),
152                                               GridBagLayout JavaDoc.class.getName());
153         panelEntry = (JPanel JavaDoc) Beans.instantiate(getClass().getClassLoader(),
154                                                 JPanel JavaDoc.class.getName());
155         layoutEntry =
156             (GridBagLayout JavaDoc) Beans.instantiate(getClass().getClassLoader(),
157                                               GridBagLayout JavaDoc.class.getName());
158         panelButtons = (JPanel JavaDoc) Beans.instantiate(getClass().getClassLoader(),
159                                                   JPanel JavaDoc.class.getName());
160         layoutButton =
161             (GridBagLayout JavaDoc) Beans.instantiate(getClass().getClassLoader(),
162                                               GridBagLayout JavaDoc.class.getName());
163         labelFind = (JLabel JavaDoc) Beans.instantiate(getClass().getClassLoader(),
164                                                JLabel JavaDoc.class.getName());
165         textFind = (JTextField JavaDoc) Beans.instantiate(getClass().getClassLoader(),
166                                                   JTextField JavaDoc.class.getName());
167         buttonBrowse =
168             (JButton JavaDoc) Beans.instantiate(getClass().getClassLoader(),
169                                         JButton JavaDoc.class.getName());
170         labelReplaceWith =
171             (JLabel JavaDoc) Beans.instantiate(getClass().getClassLoader(),
172                                        JLabel JavaDoc.class.getName());
173         textReplaceWith =
174             (JTextField JavaDoc) Beans.instantiate(getClass().getClassLoader(),
175                                            JTextField JavaDoc.class.getName());
176         buttonCancel =
177             (JButton JavaDoc) Beans.instantiate(getClass().getClassLoader(),
178                                         JButton JavaDoc.class.getName());
179         buttonOK = (JButton JavaDoc) Beans.instantiate(getClass().getClassLoader(),
180                                                JButton JavaDoc.class.getName());
181         panelMain.setLayout(layoutMain);
182         panelEntry.setLayout(layoutEntry);
183         panelButtons.setLayout(layoutButton);
184         labelFind.setText(res.getString("labelFind_Text"));
185         textFind.setPreferredSize(new Dimension JavaDoc(250, 21));
186         labelReplaceWith.setText(res.getString("labelReplaceWith_Text"));
187         textReplaceWith.setPreferredSize(new Dimension JavaDoc(250, 21));
188         buttonBrowse.setText(res.getString("Browse"));
189         buttonCancel.setText(res.getString("Cancel"));
190         buttonOK.setText(res.getString("OK"));
191         getContentPane().add(panelMain);
192         panelMain.add(panelEntry,
193                       new GridBagConstraints JavaDoc(0, 0, 1, 1, 0.2, 0.2,
194                                              GridBagConstraints.CENTER,
195                                              GridBagConstraints.BOTH,
196                                              new Insets JavaDoc(0, 0, 0, 0), 0, 0));
197         panelEntry.add(labelFind,
198                        new GridBagConstraints JavaDoc(0, 0, 1, 1, 0.2, 0.2,
199                                               GridBagConstraints.WEST,
200                                               GridBagConstraints.HORIZONTAL,
201                                               new Insets JavaDoc(5, 5, 5, 5), 0, 0));
202         panelEntry.add(textFind,
203                        new GridBagConstraints JavaDoc(0, 1, 1, 1, 0.4, 0.4,
204                                               GridBagConstraints.WEST,
205                                               GridBagConstraints.HORIZONTAL,
206                                               new Insets JavaDoc(5, 5, 5, 5), 200,
207                                               0));
208         panelEntry.add(labelReplaceWith,
209                        new GridBagConstraints JavaDoc(0, 2, 1, 1, 0.2, 0.2,
210                                               GridBagConstraints.WEST,
211                                               GridBagConstraints.HORIZONTAL,
212                                               new Insets JavaDoc(5, 5, 5, 5), 0, 0));
213         panelEntry.add(textReplaceWith,
214                        new GridBagConstraints JavaDoc(0, 3, 1, 1, 0.4, 0.4,
215                                               GridBagConstraints.WEST,
216                                               GridBagConstraints.HORIZONTAL,
217                                               new Insets JavaDoc(5, 5, 5, 5), 200,
218                                               0));
219         panelEntry.add(buttonBrowse,
220                        new GridBagConstraints JavaDoc(1, 3, 1, 1, 0.2, 0.2,
221                                               GridBagConstraints.CENTER,
222                                               GridBagConstraints.NONE,
223                                               new Insets JavaDoc(5, 5, 5, 5), 0, 0));
224         panelMain.add(panelButtons,
225                       new GridBagConstraints JavaDoc(0, 1, 1, 1, 0.2, 0.2,
226                                              GridBagConstraints.CENTER,
227                                              GridBagConstraints.BOTH,
228                                              new Insets JavaDoc(5, 5, 5, 0), 0, 0));
229         panelButtons.add(buttonOK,
230                          new GridBagConstraints JavaDoc(0, 0, 1, 1, 0.0, 0.0,
231                                                 GridBagConstraints.CENTER,
232                                                 GridBagConstraints.NONE,
233                                                 new Insets JavaDoc(5, 5, 5, 5), 0,
234                                                 0));
235         panelButtons.add(buttonCancel,
236                          new GridBagConstraints JavaDoc(1, 0, 1, 1, 0.0, 0.0,
237                                                 GridBagConstraints.CENTER,
238                                                 GridBagConstraints.NONE,
239                                                 new Insets JavaDoc(5, 5, 5, 5), 0,
240                                                 0));
241     }
242
243     /**
244      * Method declaration
245      *
246      */

247     protected void closeDialog() {
248         setVisible(false);
249         removeAll();
250         dispose();
251     }
252
253     /**
254      * Method declaration
255      *
256      *
257      * @return
258      */

259     protected int getOption() {
260         return option;
261     }
262
263     /**
264      * Method declaration
265      *
266      *
267      * @return
268      */

269     protected String JavaDoc getFind() {
270         return textFind.getText();
271     }
272
273     protected void setFind(String JavaDoc find) {
274         textFind.setText(find);
275     }
276
277     /**
278      * Method declaration
279      *
280      *
281      * @return
282      */

283     protected String JavaDoc getReplaceWith() {
284         return textReplaceWith.getText();
285     }
286
287     protected void setReplaceWith(String JavaDoc replace) {
288         textReplaceWith.setText(replace);
289     }
290
291     /**
292      * Method declaration
293      *
294      *
295      * @param o
296      */

297     private void setOption(int o) {
298         option = o;
299     }
300
301     /**
302      * Method declaration
303      *
304      */

305     private void browseAction() {
306         File JavaDoc choice;
307
308         if (startFolder == null ||!startFolder.exists()) {
309             startFolder = new File JavaDoc(textReplaceWith.getText());
310         }
311         choice =
312             SwingUtil.getDirectoryChoice(this, startFolder,
313                                          res.getString("Select_folder_to_use"));
314         buttonBrowse.requestFocus();
315         if (choice != null) {
316             textReplaceWith.setText(choice.toString());
317             startFolder = choice; // persist this choice for next call
318
}
319     }
320
321     class LocalButtonListener implements ActionListener JavaDoc {
322
323         /**
324          * Method declaration
325          *
326          *
327          * @param event
328          */

329         public void actionPerformed(ActionEvent JavaDoc event) {
330             Object JavaDoc source = event.getSource();
331
332             if (source == buttonBrowse) {
333                 browseAction();
334             } else if (source == buttonOK) {
335                 setOption(ACTION_OK);
336                 closeDialog();
337             } else if (source == buttonCancel) {
338                 setOption(ACTION_CANCEL);
339                 closeDialog();
340             }
341         }
342
343     }
344 }
345
Popular Tags