001: /*
002: * Copyright (C) 2004 Nicky BRAMANTE
003: *
004: * This file is part of FreeQueryBuilder
005: *
006: * FreeQueryBuilder is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: * Send questions or suggestions to nickyb@interfree.it
021: */
022:
023: package it.frb.admin;
024:
025: import it.frb.DataReport;
026:
027: import java.awt.Dimension;
028: import java.awt.GridBagConstraints;
029: import java.awt.GridBagLayout;
030: import java.awt.Insets;
031:
032: import java.awt.event.ActionEvent;
033: import java.awt.event.ActionListener;
034:
035: import javax.swing.Box;
036: import javax.swing.BoxLayout;
037: import javax.swing.JButton;
038: import javax.swing.JComboBox;
039: import javax.swing.JLabel;
040: import javax.swing.JPanel;
041: import javax.swing.JTextField;
042:
043: import javax.swing.border.EmptyBorder;
044:
045: public class InfoDriverPane extends DefaultPanel implements
046: ActionListener {
047: private InfoDriverPane.InfoElement info;
048: private DialogAdministrator admin;
049:
050: private JComboBox cbxFile;
051: private JTextField txtName;
052: private JTextField txtDriver;
053: private JTextField txtExample;
054:
055: private JButton btnApply;
056:
057: public InfoDriverPane(DialogAdministrator admin) {
058: super (2, 2);
059: this .admin = admin;
060:
061: txtName = new JTextField();
062: txtDriver = new JTextField();
063: txtExample = new JTextField();
064:
065: cbxFile = new JComboBox(new String[] { "$CLASSPATH" });
066: cbxFile.setPreferredSize(txtName.getPreferredSize());
067: cbxFile.setFont(DataReport.fontPLAIN);
068: cbxFile.setSize(txtName.getSize());
069:
070: JPanel detail = new JPanel();
071: detail.setPreferredSize(new Dimension(199, 199));
072:
073: GridBagLayout gbl = new GridBagLayout();
074: detail.setLayout(gbl);
075: detail.setBorder(new EmptyBorder(4, 4, 4, 4));
076:
077: GridBagConstraints gbc = new GridBagConstraints();
078: gbc.gridwidth = GridBagConstraints.REMAINDER;
079: gbc.fill = GridBagConstraints.BOTH;
080: gbc.weightx = 1.0;
081:
082: JLabel lbl;
083: gbl.setConstraints(lbl = new JLabel("name:"), gbc);
084: detail.add(lbl);
085:
086: gbc.insets = new Insets(0, 0, 30, 0);
087: gbl.setConstraints(txtName, gbc);
088: detail.add(txtName);
089:
090: gbc.insets = new Insets(0, 0, 0, 0);
091: gbl.setConstraints(lbl = new JLabel("file:"), gbc);
092: detail.add(lbl);
093: gbl.setConstraints(cbxFile, gbc);
094: detail.add(cbxFile);
095:
096: gbc.weightx = 1.0;
097: gbl.setConstraints(lbl = new JLabel("driver:"), gbc);
098: detail.add(lbl);
099: gbl.setConstraints(txtDriver, gbc);
100: detail.add(txtDriver);
101:
102: gbl.setConstraints(lbl = new JLabel("example:"), gbc);
103: detail.add(lbl);
104:
105: gbc.insets = new Insets(0, 0, 30, 0);
106: gbl.setConstraints(txtExample, gbc);
107: detail.add(txtExample);
108:
109: Box bar = new Box(BoxLayout.X_AXIS);
110: bar.add(btnApply = UIUtilities
111: .createCustomButton("apply", this ));
112: bar.add(Box.createHorizontalGlue());
113:
114: setCenterComponent(new DefaultScrollPane("edit driver", detail,
115: false));
116: setSouthComponent(bar);
117: }
118:
119: void addFile(String filename) {
120: cbxFile.addItem(filename);
121: }
122:
123: void removeFile(String filename) {
124: cbxFile.removeItem(filename);
125: }
126:
127: void setInfo(InfoDriverPane.InfoElement info) {
128: this .info = info;
129:
130: cbxFile.setSelectedItem(info.file);
131: txtName.setText(info.name);
132: txtDriver.setText(info.driver);
133: txtExample.setText(info.example);
134: }
135:
136: public void actionPerformed(ActionEvent e) {
137: String name = txtName.getText();
138:
139: if (name.indexOf(';') != -1)
140: return;
141: if (!name.equals(info.name)
142: && UserSession.jdbc.containsKey(name + ".driver"))
143: return;
144:
145: if (e.getSource() == btnApply) {
146: info.name = name;
147: info.file = cbxFile.getSelectedItem().toString();
148: info.driver = txtDriver.getText();
149: info.example = txtExample.getText();
150:
151: admin.save();
152: }
153: }
154:
155: static class InfoElement {
156: private static int counter = 0;
157:
158: String name = new String();
159: String file = new String();
160: String driver = new String();
161: String example = new String();
162:
163: InfoElement() {
164: this ("new_driver_" + (++counter));
165: }
166:
167: InfoElement(String name) {
168: this .name = name;
169: this .file = "$CLASSPATH";
170: }
171:
172: public String toString() {
173: return name;
174: }
175: }
176: }
|