001: /*
002: ** $Id: ConfigConnectionView.java,v 1.7 2000/10/21 14:37:18 mrw Exp $
003: **
004: ** Dialog to edit the details of one connection.
005: **
006: ** Mike Wilson, July 2000, mrw@whisperingwind.co.uk
007: **
008: ** (C) Copyright 2000, Mike Wilson, Reading, Berkshire, UK
009: **
010: ** This program is free software; you can redistribute it and/or modify
011: ** it under the terms of the GNU General Public License as published by
012: ** the Free Software Foundation; either version 2 of the License, or
013: ** (at your option) any later version.
014: **
015: ** This program is distributed in the hope that it will be useful,
016: ** but WITHOUT ANY WARRANTY; without even the implied warranty of
017: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
018: ** GNU General Public License for more details.
019: **
020: ** You should have received a copy of the GNU Library General
021: ** Public License along with this library; if not, write to the
022: ** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
023: ** Boston, MA 02111-1307 USA.
024: */
025:
026: package uk.co.whisperingwind.vienna;
027:
028: import java.awt.BorderLayout;
029: import java.awt.GridBagConstraints;
030: import java.awt.GridBagLayout;
031: import java.awt.Insets;
032: import javax.swing.JButton;
033: import javax.swing.JFrame;
034: import javax.swing.JLabel;
035: import javax.swing.JPanel;
036: import javax.swing.JTextField;
037: import uk.co.whisperingwind.framework.ActionFactory;
038: import uk.co.whisperingwind.framework.ModelEvent;
039: import uk.co.whisperingwind.framework.PanelDialogView;
040:
041: class ConfigConnectionView extends PanelDialogView {
042: private ActionFactory.DefaultAction okAction = null;
043: private ActionFactory.DefaultAction cancelAction = null;
044: private ActionFactory.DefaultAction testAction = null;
045: private String originalName;
046: private JTextField textName = new JTextField(16);
047: private JTextField textDriverClass = new JTextField(32);
048: private JTextField textUrl = new JTextField(32);
049: private JTextField textUserName = new JTextField(32);
050: private JTextField textPassword = new JTextField(32);
051:
052: public ConfigConnectionView(JFrame parent, boolean modal) {
053: super (parent, modal);
054: createActions();
055:
056: panel.add(new ConnectionPanel(), BorderLayout.CENTER);
057:
058: JButton okButton = okAction.toolButtonFactory(buttonPanel);
059: cancelAction.toolButtonFactory(buttonPanel);
060: testAction.toolButtonFactory(buttonPanel);
061:
062: content.pack();
063: content.setResizable(false);
064: content.getRootPane().setDefaultButton(okButton);
065: }
066:
067: /*
068: ** Set the original name of the connection. If the name is null, I
069: ** assume I am creating a new connection and clear out all fields.
070: */
071:
072: public void setOriginalName(String name) {
073: originalName = name;
074:
075: if (originalName == null) {
076: content.setTitle("New connection");
077: textName.setText("Untitled");
078:
079: textDriverClass.setText("");
080: textUrl.setText("");
081: textUserName.setText("");
082: textPassword.setText("");
083: } else {
084: textName.setText(originalName);
085: content.setTitle("Edit connection " + originalName);
086: }
087: }
088:
089: /*
090: ** Set the name of the connection.
091: */
092:
093: public void setName(String name) {
094: textName.setText(name);
095: textName.requestFocus();
096: }
097:
098: /*
099: ** Set the driver class of the connection.
100: */
101:
102: public void setDriverClass(String driverClass) {
103: textDriverClass.setText(driverClass);
104: }
105:
106: /*
107: ** Set the URL of the connection.
108: */
109:
110: public void setUrl(String url) {
111: textUrl.setText(url);
112: }
113:
114: /*
115: ** Set the user name of the connection.
116: */
117:
118: public void setUserName(String userName) {
119: textUserName.setText(userName);
120: }
121:
122: /*
123: ** Set the password of the connection.
124: */
125:
126: public void setPassword(String password) {
127: textPassword.setText(password);
128: }
129:
130: public String getOriginalName() {
131: return originalName;
132: }
133:
134: public String getName() {
135: return textName.getText();
136: }
137:
138: public String getUserName() {
139: return textUserName.getText();
140: }
141:
142: public String getPassword() {
143: return textPassword.getText();
144: }
145:
146: public String getDriverClass() {
147: return textDriverClass.getText();
148: }
149:
150: public String getUrl() {
151: return textUrl.getText();
152: }
153:
154: protected void modelEvent(ModelEvent event) {
155: }
156:
157: protected void cleanUp() {
158: }
159:
160: /*
161: ** Create the Action instances used by this dialog.
162: */
163:
164: private void createActions() {
165: ConfigActionFactory factory = new ConfigActionFactory(
166: "/uk/co/whisperingwind/images");
167:
168: okAction = factory.createAction("ok");
169: cancelAction = factory.createAction("cancel");
170: testAction = factory.createAction("test");
171:
172: okAction.addActionListener(actionListener);
173: cancelAction.addActionListener(actionListener);
174: testAction.addActionListener(actionListener);
175: }
176:
177: /*
178: ** Panel containing the connection details.
179: */
180:
181: private class ConnectionPanel extends JPanel {
182: public ConnectionPanel() {
183: setLayout(new GridBagLayout());
184: GridBagConstraints constraints = new GridBagConstraints();
185:
186: constraints.anchor = GridBagConstraints.WEST;
187: constraints.insets = new Insets(4, 4, 4, 4);
188: constraints.fill = GridBagConstraints.NONE;
189: constraints.gridwidth = 1;
190: constraints.weightx = 0.0;
191: constraints.weighty = 0.0;
192: add(new JLabel("Connection name"), constraints);
193:
194: constraints.gridwidth = GridBagConstraints.REMAINDER;
195: constraints.fill = GridBagConstraints.NONE;
196: constraints.weightx = 1.0;
197: add(textName, constraints);
198:
199: constraints.gridwidth = 1;
200: constraints.fill = GridBagConstraints.NONE;
201: constraints.weightx = 0.0;
202: add(new JLabel("Driver class"), constraints);
203:
204: constraints.gridwidth = GridBagConstraints.REMAINDER;
205: constraints.fill = GridBagConstraints.HORIZONTAL;
206: constraints.weightx = 1.0;
207: add(textDriverClass, constraints);
208:
209: constraints.gridwidth = 1;
210: constraints.fill = GridBagConstraints.NONE;
211: constraints.weightx = 0.0;
212: add(new JLabel("URL"), constraints);
213:
214: constraints.gridwidth = GridBagConstraints.REMAINDER;
215: constraints.fill = GridBagConstraints.HORIZONTAL;
216: constraints.weightx = 1.0;
217: add(textUrl, constraints);
218:
219: constraints.gridwidth = 1;
220: constraints.fill = GridBagConstraints.NONE;
221: constraints.weightx = 0.0;
222: add(new JLabel("User name"), constraints);
223:
224: constraints.gridwidth = GridBagConstraints.REMAINDER;
225: constraints.fill = GridBagConstraints.NONE;
226: constraints.weightx = 1.0;
227: add(textUserName, constraints);
228:
229: constraints.gridwidth = 1;
230: constraints.fill = GridBagConstraints.NONE;
231: constraints.weightx = 0.0;
232: add(new JLabel("Password"), constraints);
233:
234: constraints.gridwidth = GridBagConstraints.REMAINDER;
235: constraints.fill = GridBagConstraints.NONE;
236: constraints.weightx = 1.0;
237: add(textPassword, constraints);
238: }
239: }
240: }
|