Source code: cor/gui/JspmCoreDbLogin.java
1 package cor.gui;
2
3 /*
4 * Java classes
5 */
6 import java.awt.*;
7 import java.awt.event.*;
8 import java.io.*;
9
10 /*
11 * Swing classes
12 */
13 import javax.swing.*;
14
15 /*
16 * Jspm classes
17 */
18 import com.gui.*;
19
20 /**
21 * This class is displaying the repository login dialog. The OK button is the
22 * default button, pressing return will automatically close the dialog and return
23 * the default values.
24 *
25 * @author Steve Randall (strand012001@yahoo.com)
26 * @version 0.0.1
27 * @date 08/03/2001
28 */
29 public class JspmCoreDbLogin
30 {
31 private JTextField userNameField;
32 private JTextField passwordField;
33 private JTextField serverField;
34 // private JComboBox typeCombo;
35 private JPanel mainPanel;
36 private JDialog dialog;
37 private JButton okButton;
38 private boolean result = false;
39 private JFrame frame = new JFrame();
40 private String osName = null;
41
42 /**
43 * Simple Constructor
44 *
45 * @param host (String) The repository host.
46 * @param helpDir (String) Where to find the help files.
47 */
48 public JspmCoreDbLogin(String host, String helpDir) {
49
50 int sizeX = 350;
51 int sizeY = 250;
52 osName = System.getProperty("os.name");
53
54 mainPanel = new JPanel();
55 createConnectionDialog(host, helpDir);
56
57 /*
58 * Get the graphics enviroment
59 */
60 JspmGraphicsEnvironment jge = new JspmGraphicsEnvironment();
61
62 dialog = new JDialog( frame, "Select Repository", true);
63 dialog.getContentPane().add(mainPanel, BorderLayout.CENTER);
64 Dimension size = dialog.getPreferredSize();
65 dialog.setLocation(new Point(jge.centerX - size.width/2, jge.centerY - size.height/2 ));
66 dialog.getRootPane().setDefaultButton(okButton);
67 dialog.pack();
68 dialog.show();
69 }
70
71 /**
72 * Return the result of this dialog. If true the OK button was pressed else
73 * the CANCEL button was pressed.
74 * @return <code>state</code> Whether or not the OK button was pressed.
75 */
76 public boolean getResult() {
77 return(result);
78 }
79
80 /**
81 * Return the result of host text field.
82 * @return <code>host</code> The selected repository host.
83 */
84 public String getHost() {
85 return(serverField.getText());
86 }
87
88 /**
89 * Return the result of user text field.
90 * @return <code>user</code> The repository user.
91 */
92 public String getUser() {
93 return(userNameField.getText());
94 }
95
96 /**
97 * Return the result of password text field.
98 * @return <code>passwd</code> The repository password.
99 */
100 public String getPasswd() {
101 return(passwordField.getText());
102 }
103
104 /**
105 * Return the result of password text field.
106 * @return <code>passwd</code> The repository password.
107 */
108 /* public int getType() {
109 return(typeCombo.getSelectedIndex());
110 }*/
111
112 /**
113 * Actually create the dialog, with the fileds and he button panel.
114 * @param <code>host</code> The repository default host
115 * @param <code>helpdir</code> The help directory.
116 */
117 private void createConnectionDialog(String host, final String helpDir) {
118 JLabel userNameLabel;
119 JLabel passwordLabel;
120 JLabel serverLabel;
121 // JLabel typeLabel;
122 JButton cancelButton, helpButton;
123 JPanel connectionPanel;
124 JPanel buttonPanel;
125
126 /* The OK button, this is the default button */
127 okButton = new JButton(" OK ");
128 okButton.addActionListener(new ActionListener() {
129 public void actionPerformed(ActionEvent e) {
130 result = true;
131 dialog.dispose();
132 }
133 });
134
135 /* The CANCEL button */
136 cancelButton = new JButton("Cancel");
137 cancelButton.addActionListener(new ActionListener() {
138 public void actionPerformed(ActionEvent e) {
139 result = false;
140 dialog.dispose();
141 }
142 });
143
144 /* The HELP button, this will show the help file in a web browser */
145 helpButton = new JButton(" Help ");
146 helpButton.addActionListener(new ActionListener() {
147 public void actionPerformed(ActionEvent e) {
148 /* try {
149 SlaBrowserLauncher.openURL("file://"+SlaConstants.HELP_DIR+"/repositoryconnection.html");
150 } catch (IOException ex) {
151 SlaUtil.debugMessage(2, "SlaRepositoryDialog", "Error: "+ex.getMessage());
152 }*/
153 }
154 });
155
156 /* Create the button panel on the bottom of the dialog */
157 buttonPanel = new JPanel(false);
158 buttonPanel.setLayout(new FlowLayout());
159 buttonPanel.setBorder(BorderFactory.createLoweredBevelBorder());
160 buttonPanel.add(okButton);
161 buttonPanel.add(cancelButton);
162 buttonPanel.add(helpButton);
163
164 /* Create the labels and text fields */
165 // typeLabel = new JLabel("DB Type: ", JLabel.RIGHT);
166
167 /* Create the labels and text fields */
168 userNameLabel = new JLabel("User name: ", JLabel.RIGHT);
169
170 if(osName.equals("SunOS") || osName.equals("Solaris"))
171 userNameField = new JTextField("Jspmadmin", 20);
172 else
173 userNameField = new JTextField("Jspmadmin", 20);
174
175 passwordLabel = new JLabel("Password: ", JLabel.RIGHT);
176 passwordField = new JPasswordField(20);
177
178 serverLabel = new JLabel("Host: ", JLabel.RIGHT);
179 serverField = new JTextField(host, 20);
180
181 // typeCombo = new JComboBox();
182 // typeCombo.addItem("MSSqlServer");
183 // typeCombo.addItem("MySql");
184 // typeCombo.setSelectedIndex(1);
185
186 GridBagLayout gridbag = new GridBagLayout();
187 GridBagConstraints c = new GridBagConstraints();
188
189 c.fill = GridBagConstraints.BOTH;
190 c.weightx = 1.0;
191 c.insets = new Insets(5, 5, 5, 5);
192
193 JPanel namePanel = new JPanel(false);
194 namePanel.setLayout(gridbag);
195 namePanel.setBorder(BorderFactory.createLoweredBevelBorder());
196
197 // c.gridwidth = 1;
198 // gridbag.setConstraints(typeLabel, c);
199 // namePanel.add(typeLabel);
200 // c.gridwidth = GridBagConstraints.REMAINDER;
201 // gridbag.setConstraints(typeCombo, c);
202 // namePanel.add(typeCombo);
203
204 c.gridwidth = 1;
205 gridbag.setConstraints(serverLabel, c);
206 namePanel.add(serverLabel);
207 c.gridwidth = GridBagConstraints.REMAINDER;
208 gridbag.setConstraints(serverField, c);
209 namePanel.add(serverField);
210
211 c.gridwidth = 1;
212 gridbag.setConstraints(userNameLabel, c);
213 namePanel.add(userNameLabel);
214 c.gridwidth = GridBagConstraints.REMAINDER;
215 gridbag.setConstraints(userNameField, c);
216 namePanel.add(userNameField);
217
218 c.gridwidth = 1;
219 gridbag.setConstraints(passwordLabel, c);
220 namePanel.add(passwordLabel);
221 c.gridwidth = GridBagConstraints.REMAINDER;
222 gridbag.setConstraints(passwordField, c);
223 namePanel.add(passwordField);
224
225 connectionPanel = new JPanel(false);
226 connectionPanel.setLayout(new BorderLayout());
227
228 connectionPanel.add(namePanel, BorderLayout.CENTER);
229 connectionPanel.add(buttonPanel, BorderLayout.SOUTH);
230
231 mainPanel.add(connectionPanel);
232 }
233 }
234
235
236
237
238
239
240
241
242