001: /*
002: * SQLeonardo :: java database frontend
003: * Copyright (C) 2004 nickyb@users.sourceforge.net
004: *
005: * This program is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU General Public License
007: * as published by the Free Software Foundation; either version 2
008: * of the License, or (at your option) any later version.
009: *
010: * This program is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: * GNU General Public License for more details.
014: *
015: * You should have received a copy of the GNU General Public License
016: * along with this program; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
018: *
019: */
020:
021: package nickyb.sqleonardo.environment.ctrl.explorer;
022:
023: import java.awt.GridBagConstraints;
024: import java.awt.GridBagLayout;
025: import java.awt.Insets;
026:
027: import javax.swing.JCheckBox;
028: import javax.swing.JComponent;
029: import javax.swing.JLabel;
030: import javax.swing.JPanel;
031: import javax.swing.JPasswordField;
032: import javax.swing.JTextField;
033: import javax.swing.border.LineBorder;
034:
035: import nickyb.sqleonardo.common.util.Text;
036: import nickyb.sqleonardo.environment.Application;
037:
038: public class MaskDatasource extends JPanel {
039: private JTextField txtName;
040: private JTextField txtUrl;
041: private JTextField txtUid;
042: private JPasswordField txtPwd;
043:
044: private JCheckBox cbxRemember;
045: private JCheckBox cbxAutoconnect;
046:
047: MaskDatasource() {
048: setBorder(LineBorder.createGrayLineBorder());
049:
050: GridBagLayout gbl = new GridBagLayout();
051: setLayout(gbl);
052:
053: addField(gbl, "name:", txtName = new JTextField(), 0);
054: addField(gbl, "url:", txtUrl = new JTextField(), 25);
055: addField(gbl, "user:", txtUid = new JTextField(), 5);
056: addField(gbl, "password:", txtPwd = new JPasswordField(), 5);
057:
058: GridBagConstraints gbc = new GridBagConstraints();
059: gbc.anchor = GridBagConstraints.WEST;
060: gbc.gridwidth = GridBagConstraints.REMAINDER;
061: gbc.insets = new Insets(8, 5, 0, 0);
062:
063: cbxRemember = new JCheckBox("remember password");
064: gbl.setConstraints(cbxRemember, gbc);
065: add(cbxRemember);
066:
067: gbc.insets = new Insets(1, 5, 0, 0);
068: cbxAutoconnect = new JCheckBox("auto-connect on startup");
069: gbl.setConstraints(cbxAutoconnect, gbc);
070: add(cbxAutoconnect);
071: }
072:
073: private void addField(GridBagLayout gbl, String text,
074: JComponent txt, int top) {
075: GridBagConstraints gbc = new GridBagConstraints();
076: gbc.anchor = GridBagConstraints.WEST;
077: gbc.gridwidth = GridBagConstraints.REMAINDER;
078: gbc.insets = new Insets(top, 8, 1, 8);
079:
080: JLabel lbl = new JLabel(text);
081: gbl.setConstraints(lbl, gbc);
082: add(lbl);
083:
084: gbc.fill = GridBagConstraints.HORIZONTAL;
085: gbc.insets = new Insets(0, 8, 0, 8);
086: gbc.weightx = 1.0;
087:
088: gbl.setConstraints(txt, gbc);
089: add(txt);
090: }
091:
092: public void setEnabled(boolean b) {
093: super .setEnabled(b);
094: for (int i = 0; i < getComponentCount(); i++)
095: getComponent(i).setEnabled(b);
096: }
097:
098: void load(UoDatasource info) {
099: txtName.setText(info.name);
100: txtUrl.setText(info.url);
101: txtUid.setText(info.uid);
102: txtPwd.setText(info.remember ? info.pwd : null);
103:
104: cbxRemember.setSelected(info.remember);
105: cbxAutoconnect.setSelected(info.auto_connect);
106: }
107:
108: boolean unload(UoDatasource info) {
109: if (Text.isEmpty(txtName.getText())
110: || Text.isEmpty(txtUrl.getText())) {
111: Application.alert(Application.PROGRAM,
112: "please, enter a valid name.");
113: return false;
114: }
115:
116: if (txtName.getText().indexOf('.') != -1
117: || txtName.getText().indexOf(',') != -1
118: || txtName.getText().indexOf(';') != -1
119: || txtName.getText().indexOf(':') != -1
120: || txtName.getText().indexOf('|') != -1
121: || txtName.getText().indexOf('/') != -1
122: || txtName.getText().indexOf('<') != -1
123: || txtName.getText().indexOf('>') != -1
124: || txtName.getText().indexOf('@') != -1
125: || txtName.getText().indexOf('\\') != -1) {
126: Application
127: .alert(Application.PROGRAM,
128: "characters \\.|,/;<:>@ aren't allowed!\nplease, enter a valid name.");
129: return false;
130: }
131:
132: info.name = txtName.getText().trim();
133: info.url = txtUrl.getText().trim();
134: info.uid = txtUid.getText().trim();
135: info.pwd = String.valueOf(txtPwd.getPassword());
136:
137: info.remember = cbxRemember.isSelected();
138: info.auto_connect = cbxAutoconnect.isSelected();
139:
140: return true;
141: }
142: }
|