001: package org.jsqltool.gui;
002:
003: import java.awt.*;
004: import javax.swing.*;
005: import java.awt.event.*;
006: import java.util.*;
007: import org.jsqltool.model.*;
008: import org.jsqltool.conn.DbConnectionUtil;
009: import org.jsqltool.utils.Options;
010: import org.jsqltool.utils.ImageLoader;
011:
012: /**
013: * <p>Title: JSqlTool Project</p>
014: * <p>Description: Dialog used to select an old query.
015: * </p>
016: * <p>Copyright: Copyright (C) 2006 Mauro Carniel</p>
017: *
018: * <p> This file is part of JSqlTool project.
019: * This library is free software; you can redistribute it and/or
020: * modify it under the terms of the (LGPL) Lesser General Public
021: * License as published by the Free Software Foundation;
022: *
023: * GNU LESSER GENERAL PUBLIC LICENSE
024: * Version 2.1, February 1999
025: *
026: * This library is distributed in the hope that it will be useful,
027: * but WITHOUT ANY WARRANTY; without even the implied warranty of
028: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
029: * Library General Public License for more details.
030: *
031: * You should have received a copy of the GNU Library General Public
032: * License along with this library; if not, write to the Free
033: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
034: *
035: * The author may be contacted at:
036: * maurocarniel@tin.it</p>
037: *
038: * @author Mauro Carniel
039: * @version 1.0
040: */
041: public class SQLStatementRecallDialog extends JDialog {
042: JPanel mainPanel = new JPanel();
043: BorderLayout borderLayout1 = new BorderLayout();
044: JPanel centerPanel = new JPanel();
045: JPanel buttonsPanel = new JPanel();
046: JButton cancelButton = new JButton();
047: JButton okButton = new JButton();
048: JScrollPane scrollPane = new JScrollPane();
049: BorderLayout borderLayout2 = new BorderLayout();
050: CustomTableModel model = new CustomTableModel(
051: new String[] { "SQL" }, new Class[] { String.class });
052: JTable oldQueries = new JTable(model);
053: private SQLFrame frame = null;
054:
055: public SQLStatementRecallDialog(JFrame parent,
056: DbConnectionUtil dbConnUtil, SQLFrame frame) {
057: super (parent, Options.getInstance().getResource(
058: "old sql statements"), true);
059: this .frame = frame;
060: try {
061: jbInit();
062: Dimension frameSize = new Dimension(750, 400);
063: setSize(frameSize);
064: Dimension screenSize = parent.getSize();
065: if (frameSize.height > screenSize.height) {
066: frameSize.height = screenSize.height;
067: }
068: if (frameSize.width > screenSize.width) {
069: frameSize.width = screenSize.width;
070: }
071: setLocation((screenSize.width - frameSize.width) / 2,
072: (screenSize.height - frameSize.height) / 2);
073: init(dbConnUtil);
074: } catch (Exception ex) {
075: ex.printStackTrace();
076: }
077: }
078:
079: public SQLStatementRecallDialog() {
080: this (null, null, null);
081: }
082:
083: private void init(DbConnectionUtil dbConnUtil) {
084: ArrayList oldQueries = dbConnUtil.getDbConnection()
085: .getOldQueries();
086: model.setEditMode(model.DETAIL_REC);
087: for (int i = 0; i < oldQueries.size(); i++)
088: model.addRow(new Object[] { oldQueries.get(i).toString() });
089: }
090:
091: private void jbInit() throws Exception {
092: mainPanel.setLayout(borderLayout1);
093: cancelButton.setMnemonic(Options.getInstance().getResource(
094: "cancelbutton.mnemonic").charAt(0));
095: cancelButton.setText(Options.getInstance().getResource(
096: "cancelbutton.text"));
097: cancelButton
098: .addActionListener(new SQLStatementRecallDialog_cancelButton_actionAdapter(
099: this ));
100: okButton.setMnemonic(Options.getInstance().getResource(
101: "okbutton.mnemonic").charAt(0));
102: okButton.setText(Options.getInstance().getResource(
103: "okbutton.text"));
104: okButton
105: .addActionListener(new SQLStatementRecallDialog_okButton_actionAdapter(
106: this ));
107: buttonsPanel.setBorder(BorderFactory.createEtchedBorder());
108: centerPanel.setLayout(borderLayout2);
109: oldQueries
110: .addMouseListener(new SQLStatementRecallDialog_oldQueries_mouseAdapter(
111: this ));
112: getContentPane().add(mainPanel);
113: mainPanel.add(centerPanel, BorderLayout.CENTER);
114: centerPanel.add(scrollPane, BorderLayout.CENTER);
115: mainPanel.add(buttonsPanel, BorderLayout.SOUTH);
116: buttonsPanel.add(okButton, null);
117: buttonsPanel.add(cancelButton, null);
118: scrollPane.getViewport().add(oldQueries, null);
119: }
120:
121: void cancelButton_actionPerformed(ActionEvent e) {
122: setVisible(false);
123: dispose();
124: }
125:
126: void okButton_actionPerformed(ActionEvent e) {
127: if (oldQueries.getSelectedRow() != -1) {
128: frame.setEditorContent(oldQueries.getValueAt(
129: oldQueries.getSelectedRow(), 0).toString());
130: setVisible(false);
131: dispose();
132: }
133: }
134:
135: void oldQueries_mouseClicked(MouseEvent e) {
136: if (e.getClickCount() == 2) {
137: okButton_actionPerformed(null);
138: }
139: }
140: }
141:
142: class SQLStatementRecallDialog_cancelButton_actionAdapter implements
143: java.awt.event.ActionListener {
144: SQLStatementRecallDialog adaptee;
145:
146: SQLStatementRecallDialog_cancelButton_actionAdapter(
147: SQLStatementRecallDialog adaptee) {
148: this .adaptee = adaptee;
149: }
150:
151: public void actionPerformed(ActionEvent e) {
152: adaptee.cancelButton_actionPerformed(e);
153: }
154: }
155:
156: class SQLStatementRecallDialog_okButton_actionAdapter implements
157: java.awt.event.ActionListener {
158: SQLStatementRecallDialog adaptee;
159:
160: SQLStatementRecallDialog_okButton_actionAdapter(
161: SQLStatementRecallDialog adaptee) {
162: this .adaptee = adaptee;
163: }
164:
165: public void actionPerformed(ActionEvent e) {
166: adaptee.okButton_actionPerformed(e);
167: }
168: }
169:
170: class SQLStatementRecallDialog_oldQueries_mouseAdapter extends
171: java.awt.event.MouseAdapter {
172: SQLStatementRecallDialog adaptee;
173:
174: SQLStatementRecallDialog_oldQueries_mouseAdapter(
175: SQLStatementRecallDialog adaptee) {
176: this .adaptee = adaptee;
177: }
178:
179: public void mouseClicked(MouseEvent e) {
180: adaptee.oldQueries_mouseClicked(e);
181: }
182: }
|