001: package net.sourceforge.squirrel_sql.plugins.sqlval;
002:
003: /*
004: * Copyright (C) 2002-2003 Colin Bell
005: * colbell@users.sourceforge.net
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021: import java.awt.BorderLayout;
022: import java.awt.GridBagConstraints;
023: import java.awt.GridBagLayout;
024: import java.awt.Insets;
025: import java.awt.event.ActionEvent;
026: import java.awt.event.ActionListener;
027:
028: import javax.swing.BorderFactory;
029: import javax.swing.JCheckBox;
030: import javax.swing.JLabel;
031: import javax.swing.JPanel;
032: import javax.swing.JPasswordField;
033: import javax.swing.JScrollPane;
034: import javax.swing.JTextField;
035:
036: import net.sourceforge.squirrel_sql.fw.gui.MultipleLineLabel;
037: import net.sourceforge.squirrel_sql.fw.gui.OutputLabel;
038: import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
039: import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
040: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
041: import net.sourceforge.squirrel_sql.fw.util.StringManager;
042:
043: class AppPreferencesPanel extends JPanel {
044:
045: private static final StringManager s_stringMgr = StringManagerFactory
046: .getStringManager(AppPreferencesPanel.class);
047:
048: /** Logger for this class. */
049: private final static ILogger s_log = LoggerController
050: .createLogger(AppPreferencesPanel.class);
051:
052: // i18n[sqlval.info=This plugin uses version 1.0 of the SQL Validator Web Service developed by MimerSQL http://sqlvalidator.mimer.com. The SQL Statement is stored anonymously to be used by the ISO SQL Standards committee.]
053: private static final String INFO = s_stringMgr
054: .getString("sqlval.info");
055:
056: /** Preferences object. */
057: private final WebServicePreferences _prefs;
058:
059: /** Logon on as Anonymus checkbox. */
060:
061: // i18n[sqlval.anonymous=Anonymous]
062: private JCheckBox _anonLogonChk = new JCheckBox(s_stringMgr
063: .getString("sqlval.anonymous"));
064:
065: /** Use anonymous client. */
066:
067: // i18n[sqlval.anonymous2=Anonymous]
068: private JCheckBox _anonClientChk = new JCheckBox(s_stringMgr
069: .getString("sqlval.anonymous2"));
070:
071: /** User name D/E. */
072: private JTextField _userNameText = new JTextField();
073:
074: /** Password D/E. */
075: private JPasswordField _passwordText = new JPasswordField();
076:
077: /** Client name. */
078: private OutputLabel _clientNameLbl = new OutputLabel(" ");
079:
080: /** Client version. */
081: private OutputLabel _clientVersionLbl = new OutputLabel(" ");
082:
083: AppPreferencesPanel(WebServicePreferences prefs) {
084: super (new GridBagLayout());
085:
086: if (prefs == null) {
087: throw new IllegalArgumentException(
088: "WebServicePreferences == null");
089: }
090:
091: _prefs = prefs;
092: createGUI();
093: loadData();
094: }
095:
096: void loadData() {
097: _anonLogonChk.setSelected(_prefs.getUseAnonymousLogon());
098: _userNameText.setText(_prefs.getUserName());
099: _passwordText.setText(_prefs.retrievePassword());
100: _anonClientChk.setSelected(_prefs.getUseAnonymousClient());
101: _clientNameLbl.setText(_prefs.getClientName());
102: _clientVersionLbl.setText(_prefs.getClientVersion());
103:
104: setControlState();
105: }
106:
107: /**
108: * Save panel contents to preferences.
109: */
110: void save() {
111: _prefs.setUseAnonymousLogon(_anonLogonChk.isSelected());
112: _prefs.setUserName(_userNameText.getText());
113: _prefs.setPassword(new String(_passwordText.getPassword()));
114: _prefs.setUseAnonymousClient(_anonClientChk.isSelected());
115: _prefs.setClientName(_clientNameLbl.getText());
116: _prefs.setClientVersion(_clientVersionLbl.getText());
117: }
118:
119: /**
120: * Set the state of the controls from the preferences.
121: */
122: private void setControlState() {
123: setAnonymousUserControlState(_prefs.getUseAnonymousLogon());
124: }
125:
126: /**
127: * Set control state depending on the current state of the "anonymous user"
128: * checkbox.
129: */
130: private void setAnonymousUserControlState(boolean state) {
131: _userNameText.setEnabled(!state);
132: _passwordText.setEnabled(!state);
133: }
134:
135: /**
136: * Create this panel.
137: */
138: private void createGUI() {
139: setBorder(BorderFactory.createEmptyBorder(2, 4, 2, 4));
140:
141: final GridBagConstraints gbc = new GridBagConstraints();
142: gbc.fill = GridBagConstraints.BOTH;
143: gbc.insets = new Insets(1, 4, 1, 4);
144: gbc.weightx = 1;
145:
146: gbc.weighty = 1;
147: gbc.gridx = 0;
148: gbc.gridy = 0;
149: add(createInfoPanel(), gbc);
150:
151: gbc.weighty = 0;
152: ++gbc.gridy;
153: add(createLogonPanel(), gbc);
154:
155: ++gbc.gridy;
156: add(createClientPanel(), gbc);
157: }
158:
159: /**
160: * This creates the info panel.
161: *
162: * @return New panel.
163: */
164: private JPanel createInfoPanel() {
165: final JPanel pnl = new JPanel();
166: // i18n[sqlval.infoBorder=Info]
167: pnl.setBorder(BorderFactory.createTitledBorder(s_stringMgr
168: .getString("sqlval.infoBorder")));
169: pnl.setLayout(new BorderLayout());
170: final MultipleLineLabel lbl = new MultipleLineLabel(INFO);
171: lbl.setCaretPosition(0);
172: lbl.setRows(3);
173: lbl.setColumns(30);
174: final JScrollPane sp = new JScrollPane(lbl);
175: sp.setBorder(BorderFactory.createEmptyBorder());
176: pnl.add(sp, BorderLayout.CENTER);
177: return pnl;
178: }
179:
180: /**
181: * This creates the panel containing the logon information.
182: *
183: * @return New panel.
184: */
185: private JPanel createLogonPanel() {
186: _userNameText.setColumns(15);
187: _passwordText.setColumns(15);
188:
189: JPanel pnl = new JPanel();
190: // i18n[sqlval.loOnAs=Log on as]
191: pnl.setBorder(BorderFactory.createTitledBorder(s_stringMgr
192: .getString("sqlval.loOnAs")));
193:
194: pnl.setLayout(new GridBagLayout());
195: final GridBagConstraints gbc = new GridBagConstraints();
196: gbc.insets = new Insets(2, 4, 2, 4);
197:
198: gbc.gridx = 0;
199: gbc.gridy = 0;
200: gbc.gridwidth = 1;
201: gbc.gridheight = 2;
202: gbc.anchor = GridBagConstraints.NORTHWEST;
203: pnl.add(_anonLogonChk, gbc);
204:
205: gbc.fill = GridBagConstraints.HORIZONTAL;
206: gbc.anchor = GridBagConstraints.EAST;
207: gbc.gridheight = 1;
208: gbc.weightx = 1;
209: ++gbc.gridx;
210: // i18n[sqlval.user=User:]
211: pnl.add(new JLabel(s_stringMgr.getString("sqlval.user"),
212: JLabel.RIGHT), gbc);
213:
214: ++gbc.gridy;
215: // i18n[sqlval.pwdPref=Password:]
216: pnl.add(new JLabel(s_stringMgr.getString("sqlval.pwdPref"),
217: JLabel.RIGHT), gbc);
218:
219: gbc.fill = GridBagConstraints.NONE;
220: ++gbc.gridx;
221: gbc.gridy = 0;
222: gbc.weightx = 0;
223: pnl.add(_userNameText, gbc);
224:
225: ++gbc.gridy;
226: pnl.add(_passwordText, gbc);
227:
228: _anonLogonChk
229: .addActionListener(new AnonymousCheckBoxListener());
230:
231: return pnl;
232: }
233:
234: /**
235: * This creates the panel containing the client information.
236: *
237: * @return New panel.
238: */
239: private JPanel createClientPanel() {
240: JPanel pnl = new JPanel();
241: // i18n[sqlval.clientBorder=Client]
242: pnl.setBorder(BorderFactory.createTitledBorder(s_stringMgr
243: .getString("sqlval.clientBorder")));
244:
245: pnl.setLayout(new GridBagLayout());
246: final GridBagConstraints gbc = new GridBagConstraints();
247: gbc.fill = GridBagConstraints.HORIZONTAL;
248: gbc.insets = new Insets(2, 4, 2, 4);
249:
250: gbc.gridx = 0;
251: gbc.gridy = 0;
252: gbc.gridwidth = 2;
253: pnl.add(_anonClientChk, gbc);
254:
255: gbc.gridwidth = 1;
256: ++gbc.gridy;
257: // i18n[sqlval.clientLogon=Client:]
258: pnl.add(new JLabel(s_stringMgr.getString("sqlval.clientLogon"),
259: JLabel.RIGHT), gbc);
260:
261: ++gbc.gridy;
262: // i18n[sqlval.version=Version:]
263: pnl.add(new JLabel(s_stringMgr.getString("sqlval.version"),
264: JLabel.RIGHT), gbc);
265:
266: gbc.gridx = 1;
267: gbc.gridy = 1;
268: gbc.weightx = 1;
269: pnl.add(_clientNameLbl, gbc);
270:
271: ++gbc.gridy;
272: pnl.add(_clientVersionLbl, gbc);
273:
274: return pnl;
275: }
276:
277: /**
278: * Listener for the "Anonymous Logon" checkbox. This keeps the
279: * user and password fields enabled/disabled appropriately.
280: */
281: private final class AnonymousCheckBoxListener implements
282: ActionListener {
283: public void actionPerformed(ActionEvent evt) {
284: setAnonymousUserControlState(_anonLogonChk.isSelected());
285: }
286: }
287: }
|