Source code: openfuture/editxml/applet/SaveAsDialog.java
1 package openfuture.editxml.applet;
2
3 /*
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.<p>
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.<p>
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA<br>
17 * http://www.gnu.org/copyleft/lesser.html
18 */
19
20 import java.awt.Component;
21 import java.awt.Container;
22 import java.awt.Dimension;
23 import java.awt.Frame;
24 import java.awt.event.ActionEvent;
25 import java.awt.event.ActionListener;
26 import java.awt.event.FocusEvent;
27 import java.awt.event.FocusListener;
28 import java.util.ResourceBundle;
29 import javax.swing.JButton;
30 import javax.swing.JLabel;
31 import javax.swing.JOptionPane;
32 import javax.swing.JTextField;
33 import openfuture.editxml.servlet.EditorServletProxy;
34 import openfuture.util.layout.XmFormLayout;
35
36 /**
37 * Configuration Management Information:
38 * -------------------------------------
39 * $Id: SaveAsDialog.java,v 1.1 2001/07/22 09:17:44 wreissen Exp $
40 *
41 * Version History:
42 * ----------------
43 * $Log: SaveAsDialog.java,v $
44 * Revision 1.1 2001/07/22 09:17:44 wreissen
45 * initial version
46 *
47 *
48 */
49
50 /**
51 * Dialog to save as file under a new name.<p>
52 *
53 *
54 * Created: Tue Jul 10 22:54:00 2001
55 *
56 * @author <a href="mailto: wolfgang@openfuture.de">Wolfgang Reissenberger</a>
57 * @version $Revision: 1.1 $
58 */
59
60 public class SaveAsDialog extends AbsDialog {
61
62 private JButton okButton;
63 private JTextField domainField;
64 private JTextField filenameField;
65
66 private String DOMAIN_FIELD = "field.domain";
67 private String FILENAME_FIELD = "field.filename";
68
69 /**
70 *
71 * @param theRoot the parent component
72 * @param title window title
73 * @param resourceBundle the resource bundle
74 * @param controller the main controller
75 */
76 public SaveAsDialog(Component theRoot, String title,
77 ResourceBundle resourceBundle,
78 RootController controller) {
79 super(JOptionPane.getFrameForComponent(theRoot), title,
80 resourceBundle, controller);
81
82 setRoot(theRoot);
83 setResourceBundle(resourceBundle);
84 setController(controller);
85
86 String[] constraints = {
87 "domain:Label.top = form.top + 10",
88 "domain:Label.left = form.left + 10",
89 "domain:Label.right = domain:Label.left + 100",
90
91 "filename:Label.top = domain:Label.bottom + 10",
92 "filename:Label.left = domain:Label.left",
93 "filename:Label.right = domain:Label.right",
94
95 "domain:TextField.bottom = domain:Label.bottom",
96 "domain:TextField.left = domain:Label.right + 10",
97 "domain:TextField.right = ok:Button.right",
98
99 "filename:TextField.bottom = filename:Label.bottom",
100 "filename:TextField.left = domain:TextField.left",
101 "filename:TextField.right = domain:TextField.right",
102
103 "ok:Button.bottom = form.bottom - 5",
104 "ok:Button.right = form.right - 5",
105 "ok:Button.left = ok:Button.right - 120",
106
107 "cancel:Button.bottom = ok:Button.bottom",
108 "cancel:Button.right = ok:Button.left - 10",
109 "cancel:Button.left = cancel:Button.right - 120",
110 };
111
112
113 // labels
114 final JLabel domainLabel = createLabel("label.domain");
115 final JLabel fileLabel = createLabel("label.file");
116
117 // domain field
118 domainField = createTextField(DOMAIN_FIELD, getDomainName());
119 domainField.setEnabled(false);
120 // file name field
121 filenameField = createTextField(FILENAME_FIELD,
122 getController().getFilename());
123
124 //buttons
125 final JButton cancelButton = createButton("button.cancel");
126 okButton = createButton("button.ok");
127
128 //Put everything into the content pane.
129 Container contentPane = getContentPane();
130
131 contentPane.setLayout(new XmFormLayout(constraints));
132
133 contentPane.setSize(new Dimension(400, 140));
134 contentPane.add(domainLabel, "domain:Label");
135 contentPane.add(fileLabel, "filename:Label");
136
137 contentPane.add(filenameField, "filename:TextField");
138 contentPane.add(domainField, "domain:TextField");
139
140 contentPane.add(cancelButton, "cancel:Button");
141 contentPane.add(okButton, "ok:Button");
142
143 // define listeners
144 cancelButton.addActionListener(new ActionListener() {
145 public void actionPerformed(ActionEvent e) {
146 filename = null;
147 setVisible(false);
148 }
149 });
150 okButton.addActionListener(new ActionListener() {
151 public void actionPerformed(ActionEvent e) {
152 setVisible(false);
153 }
154 });
155
156 getRootPane().setDefaultButton(okButton);
157
158 filenameField.addActionListener(new ActionListener() {
159 public void actionPerformed(ActionEvent e) {
160 filename = filenameField.getText();
161 }
162 });
163
164 filenameField.addFocusListener(new FocusListener() {
165 public void focusLost(FocusEvent e) {
166 if (! e.isTemporary()) {
167 filename = filenameField.getText();
168 }
169 }
170 public void focusGained(FocusEvent e) {}
171 });
172
173 checkComplete();
174 pack();
175 }
176
177
178 /**
179 * Show the dialog.
180 *
181 * @return a <code>String</code> value
182 */
183 public String getFilename() {
184 domainField.setText(getController().getDomainName());
185 filenameField.setText(getController().getFilename());
186 setLocationRelativeTo(root);
187 setVisible(true);
188
189 return filename;
190 }
191
192
193 /**
194 * Check, if all data is entered.
195 *
196 */
197 public void checkComplete() {
198 }
199
200
201 }// SaveAsDialog