KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > common > deployer > ReplaceEditorDialog


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

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

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

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

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

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

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

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

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

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

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

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

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

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