001: package org.jsqltool.jgraph.gui;
002:
003: import javax.swing.*;
004: import java.awt.*;
005: import java.awt.event.*;
006: import javax.swing.event.*;
007: import java.io.*;
008: import java.util.*;
009:
010: import org.jsqltool.replication.*;
011: import org.jsqltool.gui.*;
012: import org.jsqltool.utils.ImageLoader;
013: import org.jsqltool.utils.Options;
014:
015: /**
016: * <p>Title: JSqlTool Project</p>
017: * <p>Description: Window used to load a database schema profile file.
018: * </p>
019: * <p>Copyright: Copyright (C) 2006 Mauro Carniel</p>
020: *
021: * <p> This file is part of JSqlTool project.
022: * This library is free software; you can redistribute it and/or
023: * modify it under the terms of the (LGPL) Lesser General Public
024: * License as published by the Free Software Foundation;
025: *
026: * GNU LESSER GENERAL PUBLIC LICENSE
027: * Version 2.1, February 1999
028: *
029: * This library is distributed in the hope that it will be useful,
030: * but WITHOUT ANY WARRANTY; without even the implied warranty of
031: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
032: * Library General Public License for more details.
033: *
034: * You should have received a copy of the GNU Library General Public
035: * License along with this library; if not, write to the Free
036: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
037: *
038: * The author may be contacted at:
039: * maurocarniel@tin.it</p>
040: *
041: * @author Mauro Carniel
042: * @version 1.0
043: */
044: public class LoadFileDialog extends JDialog {
045: JPanel mainPanel = new JPanel();
046: BorderLayout borderLayout1 = new BorderLayout();
047:
048: /** main frame */
049: private MainFrame frame = null;
050:
051: /** parent frame */
052: private SchemaFrame parentFrame = null;
053: GridBagLayout gridBagLayout1 = new GridBagLayout();
054: JLabel profilesLabel = new JLabel();
055: JScrollPane scrollPane = new JScrollPane();
056: JList profilesList = new JList();
057: JButton okButton = new JButton();
058: JButton cancelButton = new JButton();
059:
060: /** connection name (used as prefix in a profile file name) */
061: private String dbConnName = null;
062:
063: public LoadFileDialog(MainFrame frame, SchemaFrame parentFrame,
064: String dbConnName) {
065: super (frame, Options.getInstance().getResource(
066: "load database schema profile file"), true);
067: this .frame = frame;
068: this .parentFrame = parentFrame;
069: this .dbConnName = dbConnName;
070: init();
071: try {
072: jbInit();
073: setSize(400, 300);
074: Dimension screenSize = Toolkit.getDefaultToolkit()
075: .getScreenSize();
076: Dimension frameSize = this .getSize();
077: if (frameSize.height > screenSize.height) {
078: frameSize.height = screenSize.height;
079: }
080: if (frameSize.width > screenSize.width) {
081: frameSize.width = screenSize.width;
082: }
083: this .setLocation((screenSize.width - frameSize.width) / 2,
084: (screenSize.height - frameSize.height) / 2);
085: setDefaultCloseOperation(this .DISPOSE_ON_CLOSE);
086: setVisible(true);
087: } catch (Exception ex) {
088: ex.printStackTrace();
089: }
090: }
091:
092: /**
093: * Constructor not supported.
094: */
095: public LoadFileDialog() {
096: try {
097: jbInit();
098: pack();
099: } catch (Exception ex) {
100: ex.printStackTrace();
101: }
102: }
103:
104: /**
105: * Fill in the profiles list.
106: */
107: private void init() {
108: // retrieve .ini file list...
109: File dir = new File("profile");
110: dir.mkdir();
111: File[] files = dir.listFiles(new FileFilter() {
112: public boolean accept(File pathname) {
113: return pathname.getName().startsWith(dbConnName + "_")
114: && pathname.getName().endsWith(".sch");
115: }
116: });
117: DefaultListModel model = new DefaultListModel();
118: for (int i = 0; i < files.length; i++)
119: model.addElement(files[i].getName().substring(
120: (dbConnName + "_").length(),
121: files[i].getName().length() - 4).replace('_', ' '));
122: profilesList.setModel(model);
123: profilesList.revalidate();
124:
125: profilesList.addMouseListener(new MouseAdapter() {
126: public void mouseClicked(MouseEvent e) {
127: if (e.getClickCount() == 2
128: && profilesList.getSelectedIndex() != -1) {
129: parentFrame.loadProfile("profile/"
130: + dbConnName
131: + "_"
132: + profilesList.getSelectedValue()
133: .toString().replace(' ', '_')
134: + ".sch");
135: setVisible(false);
136: }
137: }
138: });
139:
140: }
141:
142: private void jbInit() throws Exception {
143: mainPanel.setLayout(gridBagLayout1);
144: profilesLabel.setText(Options.getInstance().getResource(
145: "profiles"));
146: profilesList
147: .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
148: okButton.setToolTipText("");
149: okButton.setText(Options.getInstance().getResource(
150: "okbutton.text"));
151: okButton
152: .addActionListener(new LoadFileDialog_okButton_actionAdapter(
153: this ));
154: okButton.setMnemonic(Options.getInstance().getResource(
155: "okbutton.mnemonic").charAt(0));
156: cancelButton.setText(Options.getInstance().getResource(
157: "cancelbutton.text"));
158: cancelButton
159: .addActionListener(new LoadFileDialog_cancelButton_actionAdapter(
160: this ));
161: cancelButton.setMnemonic(Options.getInstance().getResource(
162: "cancelbutton.mnemonic").charAt(0));
163: getContentPane().add(mainPanel);
164: mainPanel.add(profilesLabel, new GridBagConstraints(0, 0, 1, 1,
165: 0.0, 0.0, GridBagConstraints.NORTHWEST,
166: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
167: mainPanel.add(scrollPane, new GridBagConstraints(0, 1, 1, 2,
168: 1.0, 1.0, GridBagConstraints.NORTHWEST,
169: GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
170: scrollPane.getViewport().add(profilesList, null);
171: mainPanel.add(okButton, new GridBagConstraints(1, 1, 1, 1, 0.0,
172: 0.0, GridBagConstraints.NORTHWEST,
173: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
174: 0, 0));
175: mainPanel.add(cancelButton, new GridBagConstraints(1, 2, 1, 1,
176: 0.0, 0.0, GridBagConstraints.NORTHWEST,
177: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
178: 0, 0));
179: }
180:
181: void okButton_actionPerformed(ActionEvent e) {
182: if (profilesList.getSelectedIndex() != -1) {
183: parentFrame.loadProfile("profile/"
184: + dbConnName
185: + "_"
186: + profilesList.getSelectedValue().toString()
187: .replace(' ', '_') + ".sch");
188: setVisible(false);
189: }
190: }
191:
192: void cancelButton_actionPerformed(ActionEvent e) {
193: setVisible(false);
194: }
195:
196: }
197:
198: class LoadFileDialog_okButton_actionAdapter implements
199: java.awt.event.ActionListener {
200: LoadFileDialog adaptee;
201:
202: LoadFileDialog_okButton_actionAdapter(LoadFileDialog adaptee) {
203: this .adaptee = adaptee;
204: }
205:
206: public void actionPerformed(ActionEvent e) {
207: adaptee.okButton_actionPerformed(e);
208: }
209: }
210:
211: class LoadFileDialog_cancelButton_actionAdapter implements
212: java.awt.event.ActionListener {
213: LoadFileDialog adaptee;
214:
215: LoadFileDialog_cancelButton_actionAdapter(LoadFileDialog adaptee) {
216: this .adaptee = adaptee;
217: }
218:
219: public void actionPerformed(ActionEvent e) {
220: adaptee.cancelButton_actionPerformed(e);
221: }
222: }
|