001: /*
002: ** $Id: LoginView.java,v 1.5 2000/10/21 14:56:29 mrw Exp $
003: **
004: ** View which allows the user to amend the driver class, url, user
005: ** name and password.
006: **
007: ** Mike Wilson, October 2000, mrw@whisperingwind.co.uk
008: **
009: ** (C) Copyright 2000, Mike Wilson, Reading, Berkshire, UK
010: **
011: ** This program is free software; you can redistribute it and/or modify
012: ** it under the terms of the GNU General Public License as published by
013: ** the Free Software Foundation; either version 2 of the License, or
014: ** (at your option) any later version.
015: **
016: ** This program is distributed in the hope that it will be useful,
017: ** but WITHOUT ANY WARRANTY; without even the implied warranty of
018: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
019: ** GNU General Public License for more details.
020: **
021: ** You should have received a copy of the GNU Library General
022: ** Public License along with this library; if not, write to the
023: ** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
024: ** Boston, MA 02111-1307 USA.
025: */
026:
027: package uk.co.whisperingwind.vienna;
028:
029: import uk.co.whisperingwind.framework.PanelDialogView;
030: import uk.co.whisperingwind.framework.ModelEvent;
031: import uk.co.whisperingwind.framework.ActionFactory;
032: import javax.swing.JTextField;
033: import javax.swing.JButton;
034: import javax.swing.JLabel;
035: import java.awt.GridBagLayout;
036: import java.awt.GridBagConstraints;
037: import java.awt.Insets;
038:
039: class LoginView extends PanelDialogView {
040: private ActionFactory.DefaultAction okAction = null;
041: private ActionFactory.DefaultAction cancelAction = null;
042:
043: private JTextField textDriverClass = new JTextField(32);
044: private JTextField textUrl = new JTextField(32);
045: private JTextField textUserName = new JTextField(32);
046: private JTextField textPassword = new JTextField(32);
047: private JButton okButton = null;
048:
049: public LoginView(ConfigModel configModel, String configName) {
050: super (null, false);
051: content.setTitle("Database login");
052:
053: createActions();
054: createWindow();
055:
056: textDriverClass.setText(configModel
057: .getConnectionDriverClass(configName));
058: textUrl.setText(configModel.getConnectionUrl(configName));
059: textUserName.setText(configModel
060: .getConnectionUserName(configName));
061: textPassword.setText(configModel
062: .getConnectionPassword(configName));
063:
064: content.pack();
065: content.setResizable(false);
066: content.getRootPane().setDefaultButton(okButton);
067: content.setVisible(true);
068: textPassword.requestFocus();
069: }
070:
071: public String getDriverClass() {
072: return textDriverClass.getText();
073: }
074:
075: public String getUrl() {
076: return textUrl.getText();
077: }
078:
079: public String getUserName() {
080: return textUserName.getText();
081: }
082:
083: public String getPassword() {
084: return textPassword.getText();
085: }
086:
087: private void createActions() {
088: ActionFactory factory = new ActionFactory(
089: "/uk/co/whisperingwind/images");
090:
091: okAction = factory.createAction("ok");
092: cancelAction = factory.createAction("cancel");
093:
094: okButton = okAction.toolButtonFactory(buttonPanel);
095: cancelAction.toolButtonFactory(buttonPanel);
096:
097: okAction.addActionListener(actionListener);
098: cancelAction.addActionListener(actionListener);
099: }
100:
101: private void createWindow() {
102: GridBagConstraints constraints = new GridBagConstraints();
103: panel.setLayout(new GridBagLayout());
104:
105: constraints.anchor = GridBagConstraints.WEST;
106: constraints.insets = new Insets(4, 4, 4, 4);
107: constraints.fill = GridBagConstraints.NONE;
108: constraints.gridwidth = GridBagConstraints.RELATIVE;
109: constraints.weightx = 0.0;
110: constraints.weighty = 0.0;
111: panel.add(new JLabel("Driver class"), constraints);
112:
113: constraints.gridwidth = GridBagConstraints.REMAINDER;
114: constraints.weightx = 1.0;
115: panel.add(textDriverClass, constraints);
116:
117: constraints.gridwidth = GridBagConstraints.RELATIVE;
118: panel.add(new JLabel("URL"), constraints);
119:
120: constraints.gridwidth = GridBagConstraints.REMAINDER;
121: constraints.weightx = 1.0;
122: panel.add(textUrl, constraints);
123:
124: constraints.gridwidth = GridBagConstraints.RELATIVE;
125: panel.add(new JLabel("User name"), constraints);
126:
127: constraints.gridwidth = GridBagConstraints.REMAINDER;
128: constraints.weightx = 0.0;
129: panel.add(textUserName, constraints);
130:
131: constraints.gridwidth = GridBagConstraints.RELATIVE;
132: panel.add(new JLabel("Password"), constraints);
133:
134: constraints.gridwidth = GridBagConstraints.REMAINDER;
135: panel.add(textPassword, constraints);
136: }
137:
138: /*
139: ** I don't have a model, so this isn't needed.
140: */
141:
142: protected void modelEvent(ModelEvent event) {
143: }
144:
145: protected void cleanUp() {
146: }
147: }
|