001: package com.pk;
002:
003: import java.awt.BorderLayout;
004:
005: import java.awt.Dimension;
006: import java.awt.GridBagConstraints;
007: import java.awt.GridBagLayout;
008: import java.awt.event.ActionEvent;
009: import java.awt.event.ActionListener;
010: import java.awt.event.KeyEvent;
011: import java.util.ArrayList;
012: import java.util.List;
013:
014: import javax.swing.AbstractAction;
015: import javax.swing.JButton;
016: import javax.swing.JDialog;
017:
018: import javax.swing.JLabel;
019: import javax.swing.JPanel;
020: import javax.swing.JScrollPane;
021: import javax.swing.JTable;
022: import javax.swing.JTextArea;
023: import javax.swing.KeyStroke;
024: import javax.swing.ListSelectionModel;
025: import javax.swing.SwingConstants;
026: import javax.swing.UIManager;
027:
028: import javax.swing.event.ListSelectionEvent;
029: import javax.swing.event.ListSelectionListener;
030:
031: /*
032: * Created on Mar 14, 2004
033: *
034: * To change the template for this generated file go to
035: * Window>Preferences>Java>Code Generation>Code and Comments
036: */
037:
038: /**
039: * @author Isabelle
040: *
041: * To change the template for this generated type comment go to
042: * Window>Preferences>Java>Code Generation>Code and Comments
043: */
044: public class History extends JPanel implements ActionListener {
045: /**
046: *
047: */
048: private static final long serialVersionUID = 2626675347388205019L;
049: private JTable table = null;
050: private JButton okButton = null;
051: private JButton cancelButton = null;
052: private MyInternalFrame parentFram = null;
053: private JDialog jDialog = null;
054: private JTextArea sqlTextArea = null;
055:
056: private class CloseAction extends AbstractAction {
057:
058: /**
059: *
060: */
061: private static final long serialVersionUID = -2872623569240568050L;
062:
063: /* (non-Javadoc)
064: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
065: */
066: public void actionPerformed(ActionEvent arg0) {
067: jDialog.dispose();
068: }
069: }
070:
071: public History(MyInternalFrame argMif, JDialog argJDialog) {
072: parentFram = argMif;
073: jDialog = argJDialog;
074:
075: CloseAction closeAction = new CloseAction();
076: getInputMap()
077: .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
078: "ESCAPE");
079: getActionMap().put("ESCAPE", closeAction);
080:
081: String tmp = null;
082: List dataList = new ArrayList();
083: for (int x = parentFram.getSqls().size() - 1; x >= 0; x--) {
084: tmp = (String) parentFram.getSqls().get(x);
085: if (tmp != null && tmp.length() > 0) {
086: dataList.add(tmp);
087: }
088: }
089: this .setLayout(new GridBagLayout());
090: GridBagConstraints gridBagConstraints = new GridBagConstraints();
091: HistoryTableModel historyTableModel = new HistoryTableModel();
092: historyTableModel.setStatmentHistory(dataList);
093: table = new JTable(historyTableModel);
094: table.getSelectionModel().addListSelectionListener(
095: new ListSelectionListener() {
096: public void valueChanged(ListSelectionEvent e) {
097: //Ignore extra messages.
098: if (e.getValueIsAdjusting())
099: return;
100:
101: ListSelectionModel lsm = (ListSelectionModel) e
102: .getSource();
103: if (!lsm.isSelectionEmpty()) {
104: sqlTextArea.setText((String) table
105: .getValueAt(table.getSelectedRow(),
106: table.getSelectedColumn()));
107: }
108: }
109: });
110: table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
111: JScrollPane scrollPane = new JScrollPane(table);
112: table
113: .setPreferredScrollableViewportSize(new Dimension(500,
114: 70));
115: gridBagConstraints = new GridBagConstraints();
116: gridBagConstraints.ipady = 40;
117: gridBagConstraints.weightx = 3.0;
118: gridBagConstraints.gridwidth = 3;
119: gridBagConstraints.gridx = 0;
120: gridBagConstraints.gridy = 1;
121: add(scrollPane, gridBagConstraints);
122:
123: JLabel tmpJLabel = new JLabel("Preview");
124: //tmpJLabel.setBorder(new LineBorder(Color.black));
125: tmpJLabel.setHorizontalAlignment(SwingConstants.CENTER);
126: tmpJLabel.setVerticalAlignment(SwingConstants.BOTTOM);
127: gridBagConstraints = new GridBagConstraints();
128: gridBagConstraints.ipadx = 50;
129: gridBagConstraints.ipady = 40;
130: gridBagConstraints.weightx = 0.0;
131: gridBagConstraints.gridwidth = 1;
132: gridBagConstraints.gridx = 1;
133: gridBagConstraints.gridy = 2;
134: add(tmpJLabel, gridBagConstraints);
135:
136: sqlTextArea = new JTextArea(10, 45);
137: gridBagConstraints = new GridBagConstraints();
138: sqlTextArea.setEditable(false);
139: JScrollPane sqlScrollPane = new JScrollPane(sqlTextArea);
140: table
141: .setPreferredScrollableViewportSize(new Dimension(500,
142: 70));
143: gridBagConstraints.ipadx = 0;
144: gridBagConstraints.ipady = 40;
145: gridBagConstraints.weightx = 0.0;
146: gridBagConstraints.gridwidth = 1;
147: gridBagConstraints.gridx = 1;
148: gridBagConstraints.gridy = 3;
149: add(sqlScrollPane, gridBagConstraints);
150:
151: JPanel buttonPanel = new JPanel(new BorderLayout(0, 2));
152:
153: okButton = new JButton("Ok");
154: okButton.addActionListener(this );
155: okButton.setMnemonic(KeyEvent.VK_K);
156:
157: cancelButton = new JButton("Cancel");
158: cancelButton.addActionListener(this );
159: cancelButton.setMnemonic(KeyEvent.VK_C);
160:
161: buttonPanel.add(okButton, BorderLayout.NORTH);
162: buttonPanel.add(cancelButton, BorderLayout.SOUTH);
163: gridBagConstraints = new GridBagConstraints();
164: gridBagConstraints.gridx = 3;
165: gridBagConstraints.gridy = 1;
166: gridBagConstraints.gridheight = 1;
167: gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
168: gridBagConstraints.anchor = GridBagConstraints.CENTER;
169: gridBagConstraints.gridwidth = 1;
170: add(buttonPanel, gridBagConstraints);
171:
172: }
173:
174: public void test() {
175: UIManager.getDefaults();
176: }
177:
178: /* (non-Javadoc)
179: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
180: */
181: public void actionPerformed(ActionEvent arg0) {
182: if (arg0.getSource().equals(okButton)) {
183: if (table.getSelectedRow() > -1
184: && table.getSelectedColumn() > -1
185: && parentFram != null) {
186: System.out.print(table.getValueAt(table
187: .getSelectedRow(), table.getSelectedColumn()));
188: parentFram.sqlTextArea.setText((String) table
189: .getValueAt(table.getSelectedRow(), table
190: .getSelectedColumn()));
191: }
192:
193: }
194: jDialog.dispose();
195: }
196: }
|