001: package net.sourceforge.squirrel_sql.client.session.mainpanel;
002:
003: import net.sourceforge.squirrel_sql.fw.util.StringManager;
004: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
005: import net.sourceforge.squirrel_sql.fw.gui.SortableTable;
006: import net.sourceforge.squirrel_sql.fw.gui.SortableTableModel;
007:
008: import javax.swing.*;
009: import java.awt.*;
010: import java.awt.event.*;
011: import java.util.prefs.Preferences;
012:
013: public class SQLHistoryDlg extends JDialog {
014: private static final String PREF_KEY_SQL_HISTORY_DLG_WIDTH = "Squirrel.sqlHistoryDlgWidth";
015: private static final String PREF_KEY_SQL_HISTORY_DLG_HEIGHT = "Squirrel.sqlHistoryDlgHeight";
016: private static final String PREF_KEY_SQL_HISTORY_DLG_DIV_LOC = "Squirrel.sqlHistoryDlgDivLoc";
017:
018: /** Internationalized strings for this class. */
019: private static final StringManager s_stringMgr = StringManagerFactory
020: .getStringManager(SQLHistoryDlg.class);
021:
022: SortableTable tblHistoryItems;
023: JButton btnClose;
024: JTextField txtFilter;
025: JButton btnApplyFilter;
026: JComboBox cboFilterItems;
027: JCheckBox chkFiltered;
028: JSplitPane splSpilt;
029: JTextArea txtSQL;
030:
031: public SQLHistoryDlg(JFrame mainFrame,
032: String sqlPanelParentFrameName) {
033: // i18n[SQLHistoryDlg.title=SQL History for {0}]
034: super (mainFrame, s_stringMgr.getString("SQLHistoryDlg.title",
035: sqlPanelParentFrameName), false);
036:
037: setLayout(new GridBagLayout());
038:
039: GridBagConstraints gbc;
040:
041: gbc = new GridBagConstraints(0, 0, 1, 1, 0, 0,
042: GridBagConstraints.NORTHWEST,
043: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
044: 0, 0);
045: getContentPane().add(createFilterPanel(), gbc);
046:
047: gbc = new GridBagConstraints(0, 1, 1, 1, 1, 1,
048: GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH,
049: new Insets(0, 5, 5, 5), 0, 0);
050: splSpilt = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
051: getContentPane().add(splSpilt, gbc);
052:
053: tblHistoryItems = new SortableTable(
054: new SortableTableModel(null));
055: tblHistoryItems
056: .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
057: tblHistoryItems.getTableHeader().setResizingAllowed(true);
058: tblHistoryItems.getTableHeader().setReorderingAllowed(true);
059: tblHistoryItems.setAutoCreateColumnsFromModel(false);
060: tblHistoryItems.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
061: splSpilt.setTopComponent(new JScrollPane(tblHistoryItems));
062:
063: txtSQL = new JTextArea();
064: txtSQL.setEditable(false);
065: splSpilt.setBottomComponent(new JScrollPane(txtSQL));
066:
067: Dimension size = getDimension(mainFrame);
068: setSize(size);
069:
070: splSpilt.setDividerLocation(Preferences.userRoot().getInt(
071: PREF_KEY_SQL_HISTORY_DLG_DIV_LOC, size.height / 3));
072:
073: addWindowListener(new WindowAdapter() {
074: boolean onWindowClosedCalled = false;
075:
076: public void windowClosed(WindowEvent e) {
077: if (false == onWindowClosedCalled) {
078: onWindowClosed();
079: }
080: }
081:
082: public void windowClosing(WindowEvent e) {
083: onWindowClosed();
084: onWindowClosedCalled = true;
085: }
086: });
087: }
088:
089: void close() {
090: setVisible(false);
091: dispose();
092: }
093:
094: private JPanel createFilterPanel() {
095: JPanel ret = new JPanel();
096:
097: ret.setLayout(new GridBagLayout());
098:
099: GridBagConstraints gbc;
100:
101: gbc = new GridBagConstraints(0, 0, 1, 1, 0, 0,
102: GridBagConstraints.WEST, GridBagConstraints.NONE,
103: new Insets(0, 5, 0, 5), 0, 0);
104: // i18n[SQLHistoryDlg.SQLPref=SQL]
105: ret.add(new JLabel(s_stringMgr
106: .getString("SQLHistoryDlg.SQLPref")), gbc);
107:
108: gbc = new GridBagConstraints(1, 0, 1, 1, 0, 0,
109: GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
110: new Insets(0, 5, 0, 5), 0, 0);
111: cboFilterItems = new JComboBox();
112: ret.add(cboFilterItems, gbc);
113: for (FilterCboItems filterCboItem : FilterCboItems.values()) {
114: cboFilterItems.addItem(filterCboItem);
115: }
116:
117: gbc = new GridBagConstraints(2, 0, 1, 1, 1, 0,
118: GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
119: new Insets(0, 5, 0, 5), 0, 0);
120: txtFilter = new JTextField();
121: ret.add(txtFilter, gbc);
122: SwingUtilities.invokeLater(new Runnable() {
123: public void run() {
124: txtFilter.requestFocus();
125: }
126: });
127:
128: gbc = new GridBagConstraints(3, 0, 1, 1, 0, 0,
129: GridBagConstraints.WEST, GridBagConstraints.NONE,
130: new Insets(0, 5, 0, 5), 0, 0);
131: // i18n[SQLHistoryDlg.applyFilter=Apply]
132: btnApplyFilter = new JButton(s_stringMgr
133: .getString("SQLHistoryDlg.applyFilter"));
134: ret.add(btnApplyFilter, gbc);
135: getRootPane().setDefaultButton(btnApplyFilter);
136:
137: gbc = new GridBagConstraints(4, 0, 1, 1, 0, 0,
138: GridBagConstraints.WEST, GridBagConstraints.NONE,
139: new Insets(0, 5, 0, 5), 0, 0);
140: // i18n[SQLHistoryDlg.filtered=Filtered]
141: chkFiltered = new JCheckBox(s_stringMgr
142: .getString("SQLHistoryDlg.filtered"));
143: ret.add(chkFiltered, gbc);
144:
145: // i18n[SQLHistoryDlg.close=Close]
146: btnClose = new JButton(s_stringMgr
147: .getString("SQLHistoryDlg.close"));
148: gbc = new GridBagConstraints(5, 0, 1, 1, 0, 0,
149: GridBagConstraints.EAST, GridBagConstraints.NONE,
150: new Insets(0, 5, 0, 5), 0, 0);
151: ret.add(btnClose, gbc);
152:
153: return ret;
154: }
155:
156: private Dimension getDimension(JFrame mainFrame) {
157: int prefWidth = Preferences.userRoot().getInt(
158: PREF_KEY_SQL_HISTORY_DLG_WIDTH, 600);
159: int perfHeight = Preferences.userRoot().getInt(
160: PREF_KEY_SQL_HISTORY_DLG_HEIGHT, 600);
161: return new Dimension(Math.min(prefWidth,
162: mainFrame.getSize().width), Math.min(perfHeight,
163: mainFrame.getSize().height));
164: }
165:
166: private void onWindowClosed() {
167: Dimension size = getSize();
168: Preferences.userRoot().putInt(PREF_KEY_SQL_HISTORY_DLG_WIDTH,
169: size.width);
170: Preferences.userRoot().putInt(PREF_KEY_SQL_HISTORY_DLG_HEIGHT,
171: size.height);
172: Preferences.userRoot().putInt(PREF_KEY_SQL_HISTORY_DLG_DIV_LOC,
173: splSpilt.getDividerLocation());
174: }
175:
176: static enum FilterCboItems {
177: // i18n[SQLHistoryDlg.filterCboContains=contains]
178: CONTAINS(s_stringMgr
179: .getString("SQLHistoryDlg.filterCboContains")),
180:
181: // i18n[SQLHistoryDlg.filterCboStartsWith=starts with]
182: STARTS_WITH(s_stringMgr
183: .getString("SQLHistoryDlg.filterCboStartsWith")),
184:
185: // i18n[SQLHistoryDlg.filterCboEndsWith=ends with]
186: ENDS_WITH(s_stringMgr
187: .getString("SQLHistoryDlg.filterCboEndsWith")),
188:
189: // i18n[SQLHistoryDlg.filterCboRegEx=regular exp]
190: REG_EX(s_stringMgr.getString("SQLHistoryDlg.filterCboRegEx"));
191: private String _name;
192:
193: FilterCboItems(String name) {
194: _name = name;
195: }
196:
197: public String toString() {
198: return _name;
199: }
200: }
201:
202: }
|