001: package org.enhydra.kelp.ant.deployer;
002:
003: /*
004: * Enhydra Java Application Server Project
005: *
006: * The contents of this file are subject to the Enhydra Public License
007: * Version 1.1 (the "License"); you may not use this file except in
008: * compliance with the License. You may obtain a copy of the License on
009: * the Enhydra web site ( http://www.enhydra.org/ ).
010: *
011: * Software distributed under the License is distributed on an "AS IS"
012: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
013: * the License for the specific terms governing rights and limitations
014: * under the License.
015: *
016: * The Initial Developer of the Enhydra Application Server is Lutris
017: * Technologies, Inc. The Enhydra Application Server and portions created
018: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
019: * All Rights Reserved.
020: *
021: * Contributor(s):
022: * Paul Mahar
023: *
024: */
025:
026: // ToolBox imports
027: import org.enhydra.tool.common.SwingUtil;
028:
029: // Standard imports
030: import java.awt.Dimension;
031: import java.awt.Dialog;
032: import java.awt.Frame;
033: import java.awt.GridBagLayout;
034: import java.awt.GridBagConstraints;
035: import java.awt.Insets;
036: import java.awt.Point;
037: import java.awt.event.ActionEvent;
038: import java.awt.event.ActionListener;
039: import java.io.File;
040: import java.beans.Beans;
041: import javax.swing.JButton;
042: import javax.swing.JDialog;
043: import javax.swing.JPanel;
044: import javax.swing.JTextField;
045: import javax.swing.JLabel;
046: import java.util.ResourceBundle;
047:
048: /**
049: * Class declaration
050: *
051: *
052: * @author
053: * @version %I%, %G%
054: */
055: public class AntDeployReplaceEditorDialog extends JDialog {
056: static ResourceBundle res = ResourceBundle
057: .getBundle("org.enhydra.kelp.common.Res"); // nores
058: public static final int ACTION_OK = 0;
059: public static final int ACTION_CANCEL = 1;
060: private static File startFolder = null;
061: private int option = ACTION_CANCEL;
062: private LocalButtonListener buttonListener = null;
063: private JPanel panelMain = new JPanel();
064: private GridBagLayout layoutMain;
065: private JPanel panelEntry;
066: private GridBagLayout layoutEntry;
067: private JPanel panelButtons;
068: private GridBagLayout layoutButton;
069: private JLabel labelFind;
070: private JTextField textFind;
071: private JButton buttonBrowse;
072: private JLabel labelReplaceWith;
073: private JTextField textReplaceWith;
074: private JButton buttonCancel;
075: private JButton buttonOK;
076:
077: /**
078: * Constructor declaration
079: *
080: *
081: * @param owner
082: * @param title
083: * @param modal
084: */
085: public AntDeployReplaceEditorDialog(Dialog owner, String title,
086: boolean modal) {
087: super (owner, title, modal);
088: construct();
089: }
090:
091: public AntDeployReplaceEditorDialog(Frame owner, String title,
092: boolean modal) {
093: super (owner, title, modal);
094: construct();
095: }
096:
097: private void construct() {
098: try {
099: jbInit();
100: pmInit();
101: pack();
102: } catch (Exception ex) {
103: ex.printStackTrace();
104: }
105: }
106:
107: /**
108: * Constructor declaration
109: *
110: */
111: public AntDeployReplaceEditorDialog() {
112: this (new Frame(), new String(), false);
113: }
114:
115: /**
116: * Method declaration
117: *
118: */
119: public void show() {
120: setResizable(false);
121: Point cPoint;
122:
123: invalidate();
124: doLayout();
125: pack();
126: cPoint = SwingUtil.getCenteringPoint(getSize());
127: setLocation(cPoint);
128: super .show();
129: }
130:
131: /**
132: * Method declaration
133: *
134: */
135: private void pmInit() {
136: buttonListener = new LocalButtonListener();
137: buttonBrowse.addActionListener(buttonListener);
138: buttonOK.addActionListener(buttonListener);
139: buttonCancel.addActionListener(buttonListener);
140: textFind.setText(new String());
141: textReplaceWith.setText(new String());
142: }
143:
144: /**
145: * Method declaration
146: *
147: *
148: * @throws Exception
149: */
150: private void jbInit() throws Exception {
151: layoutMain = (GridBagLayout) Beans.instantiate(getClass()
152: .getClassLoader(), GridBagLayout.class.getName());
153: panelEntry = (JPanel) Beans.instantiate(getClass()
154: .getClassLoader(), JPanel.class.getName());
155: layoutEntry = (GridBagLayout) Beans.instantiate(getClass()
156: .getClassLoader(), GridBagLayout.class.getName());
157: panelButtons = (JPanel) Beans.instantiate(getClass()
158: .getClassLoader(), JPanel.class.getName());
159: layoutButton = (GridBagLayout) Beans.instantiate(getClass()
160: .getClassLoader(), GridBagLayout.class.getName());
161: labelFind = (JLabel) Beans.instantiate(getClass()
162: .getClassLoader(), JLabel.class.getName());
163: textFind = (JTextField) Beans.instantiate(getClass()
164: .getClassLoader(), JTextField.class.getName());
165: buttonBrowse = (JButton) Beans.instantiate(getClass()
166: .getClassLoader(), JButton.class.getName());
167: labelReplaceWith = (JLabel) Beans.instantiate(getClass()
168: .getClassLoader(), JLabel.class.getName());
169: textReplaceWith = (JTextField) Beans.instantiate(getClass()
170: .getClassLoader(), JTextField.class.getName());
171: buttonCancel = (JButton) Beans.instantiate(getClass()
172: .getClassLoader(), JButton.class.getName());
173: buttonOK = (JButton) Beans.instantiate(getClass()
174: .getClassLoader(), JButton.class.getName());
175: panelMain.setLayout(layoutMain);
176: panelEntry.setLayout(layoutEntry);
177: panelButtons.setLayout(layoutButton);
178: labelFind.setText(res.getString("labelFind_Text"));
179: textFind.setPreferredSize(new Dimension(250, 21));
180: labelReplaceWith
181: .setText(res.getString("labelReplaceWith_Text"));
182: textReplaceWith.setPreferredSize(new Dimension(250, 21));
183: buttonBrowse.setText(res.getString("Browse"));
184: buttonCancel.setText(res.getString("Cancel"));
185: buttonOK.setText(res.getString("OK"));
186: getContentPane().add(panelMain);
187: panelMain.add(panelEntry, new GridBagConstraints(0, 0, 1, 1,
188: 0.2, 0.2, GridBagConstraints.CENTER,
189: GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
190: panelEntry.add(labelFind, new GridBagConstraints(0, 0, 1, 1,
191: 0.2, 0.2, GridBagConstraints.WEST,
192: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
193: 0, 0));
194: panelEntry.add(textFind, new GridBagConstraints(0, 1, 1, 1,
195: 0.4, 0.4, GridBagConstraints.WEST,
196: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
197: 200, 0));
198: panelEntry.add(labelReplaceWith, new GridBagConstraints(0, 2,
199: 1, 1, 0.2, 0.2, GridBagConstraints.WEST,
200: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
201: 0, 0));
202: panelEntry.add(textReplaceWith, new GridBagConstraints(0, 3, 1,
203: 1, 0.4, 0.4, GridBagConstraints.WEST,
204: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
205: 200, 0));
206: panelEntry.add(buttonBrowse, new GridBagConstraints(1, 3, 1, 1,
207: 0.2, 0.2, GridBagConstraints.CENTER,
208: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
209: panelMain.add(panelButtons, new GridBagConstraints(0, 1, 1, 1,
210: 0.2, 0.2, GridBagConstraints.CENTER,
211: GridBagConstraints.BOTH, new Insets(5, 5, 5, 0), 0, 0));
212: panelButtons.add(buttonOK, new GridBagConstraints(0, 0, 1, 1,
213: 0.0, 0.0, GridBagConstraints.CENTER,
214: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
215: panelButtons.add(buttonCancel, new GridBagConstraints(1, 0, 1,
216: 1, 0.0, 0.0, GridBagConstraints.CENTER,
217: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
218: }
219:
220: /**
221: * Method declaration
222: *
223: */
224: protected void closeDialog() {
225: setVisible(false);
226: removeAll();
227: dispose();
228: }
229:
230: /**
231: * Method declaration
232: *
233: *
234: * @return
235: */
236: protected int getOption() {
237: return option;
238: }
239:
240: /**
241: * Method declaration
242: *
243: *
244: * @return
245: */
246: protected String getFind() {
247: return textFind.getText();
248: }
249:
250: protected void setFind(String find) {
251: textFind.setText(find);
252: }
253:
254: /**
255: * Method declaration
256: *
257: *
258: * @return
259: */
260: protected String getReplaceWith() {
261: return textReplaceWith.getText();
262: }
263:
264: protected void setReplaceWith(String replace) {
265: textReplaceWith.setText(replace);
266: }
267:
268: /**
269: * Method declaration
270: *
271: *
272: * @param o
273: */
274: private void setOption(int o) {
275: option = o;
276: }
277:
278: /**
279: * Method declaration
280: *
281: */
282: private void browseAction() {
283: File choice;
284:
285: if (startFolder == null || !startFolder.exists()) {
286: startFolder = new File(textReplaceWith.getText());
287: }
288: choice = SwingUtil.getDirectoryChoice(this , startFolder, res
289: .getString("Select_folder_to_use"));
290: buttonBrowse.requestFocus();
291: if (choice != null) {
292: textReplaceWith.setText(choice.toString());
293: startFolder = choice; // persist this choice for next call
294: }
295: }
296:
297: class LocalButtonListener implements ActionListener {
298:
299: /**
300: * Method declaration
301: *
302: *
303: * @param event
304: */
305: public void actionPerformed(ActionEvent event) {
306: Object source = event.getSource();
307:
308: if (source == buttonBrowse) {
309: browseAction();
310: } else if (source == buttonOK) {
311: setOption(ACTION_OK);
312: closeDialog();
313: } else if (source == buttonCancel) {
314: setOption(ACTION_CANCEL);
315: closeDialog();
316: }
317: }
318:
319: }
320: }
|