KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ist > coach > coachEmfClientComponents > gui > LogArchiveFrame


1 package ist.coach.coachEmfClientComponents.gui;
2
3
4 import javax.swing.JTable JavaDoc;
5 import javax.swing.table.AbstractTableModel JavaDoc;
6
7 import javax.swing.DefaultCellEditor JavaDoc;
8 import javax.swing.event.ListSelectionListener JavaDoc;
9 import javax.swing.ListSelectionModel JavaDoc;
10 import javax.swing.event.ListSelectionEvent JavaDoc;
11
12 import javax.swing.JScrollPane JavaDoc;
13 import javax.swing.JFrame JavaDoc;
14 import javax.swing.JPanel JavaDoc;
15 import javax.swing.JSpinner JavaDoc;
16 import javax.swing.SpinnerNumberModel JavaDoc;
17 import javax.swing.SpinnerModel JavaDoc;
18 import javax.swing.SwingUtilities JavaDoc;
19 import javax.swing.JOptionPane JavaDoc;
20 import javax.swing.JButton JavaDoc;
21 import javax.swing.JLabel JavaDoc;
22 import javax.swing.JComboBox JavaDoc;
23 import javax.swing.JTextField JavaDoc;
24 import javax.swing.border.Border JavaDoc;
25 import javax.swing.border.EtchedBorder JavaDoc;
26 import javax.swing.border.Border JavaDoc;
27 import javax.swing.BorderFactory JavaDoc;
28 import java.awt.*;
29 import java.awt.event.*;
30
31 import ist.coach.coachEmfServices.EmfBasicLog.LogRecord;
32
33 public class LogArchiveFrame extends JFrame JavaDoc
34 implements ActionListener, Runnable JavaDoc {
35
36     GuiMaster master;
37     private LogTableModel logModel = null;
38     private String JavaDoc[] logDaySelectionStrings = new String JavaDoc[31];
39     private String JavaDoc[] logMonthSelectionStrings = {
40               "January",
41               "February",
42               "March",
43               "April",
44               "May",
45               "June",
46               "July",
47               "August",
48               "September",
49               "October",
50               "November",
51               "December"
52     };
53     JSpinner JavaDoc hoursSpinner, minSpinner, secSpinner, recordsSpinner;
54     JComboBox JavaDoc logSelectionList, logYearSelectionList, logDaySelectionList, logMonthSelectionList;
55     JTextField JavaDoc records_data;
56     private int selectedRow, selectedCol;
57
58     private String JavaDoc[] logYearSelectionStrings = {"2004", "2005", "2006"};
59
60     public LogArchiveFrame(GuiMaster master,
61           int x_pos, int y_pos) {
62
63         super(GuiMessages.log_archives_title);
64         this.master = master;
65         logModel = new LogTableModel();
66                     /** Setup the LOG Panel ****/
67         JPanel JavaDoc logPanel = new JPanel JavaDoc();
68         logPanel.setLayout(new BorderLayout());
69
70         records_data = new JTextField JavaDoc(80);
71         records_data.setEditable(false);
72         records_data.setBackground(java.awt.Color.LIGHT_GRAY);
73         java.awt.Font JavaDoc textDisplayFont = records_data.getFont();
74         textDisplayFont = textDisplayFont.deriveFont((float) textDisplayFont.getSize()-1);
75         records_data.setFont(textDisplayFont);
76
77         JPanel JavaDoc logOptionsPanel = new JPanel JavaDoc(new java.awt.FlowLayout JavaDoc(java.awt.FlowLayout.LEFT, 20, 0));
78
79               // set up box to hold log time options
80
JPanel JavaDoc logDatePanel = new JPanel JavaDoc();
81         logDatePanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
82         JLabel JavaDoc logDayLabel =new JLabel JavaDoc("From Date: ");
83         logDatePanel.add(logDayLabel);
84
85         for(int i = 0; i < 31; i++)
86           logDaySelectionStrings[i] = String.valueOf(i+1);
87
88         logDaySelectionList = new JComboBox JavaDoc(logDaySelectionStrings);
89         logDaySelectionList.setSelectedIndex(0);
90        // logDaySelectionList.addActionListener(this);
91
logDatePanel.add(logDaySelectionList);
92
93         logMonthSelectionList = new JComboBox JavaDoc(logMonthSelectionStrings);
94         logMonthSelectionList.setSelectedIndex(0);
95         //logMonthSelectionList.addActionListener(this);
96
logDatePanel.add(logMonthSelectionList);
97
98         logYearSelectionList = new JComboBox JavaDoc(logYearSelectionStrings);
99         logYearSelectionList.setSelectedIndex(0);
100         //logYearSelectionList.addActionListener(this);
101
logDatePanel.add(logYearSelectionList);
102
103         JLabel JavaDoc timeLabel =new JLabel JavaDoc("Time: ");
104         JLabel JavaDoc timeLabel2 =new JLabel JavaDoc(":");
105
106         logDatePanel.add(timeLabel);
107         SpinnerModel JavaDoc hoursModel = new SpinnerNumberModel JavaDoc(00, //initial value
108
00, //min
109
23, //max
110
1);
111         hoursSpinner = new JSpinner JavaDoc(hoursModel); //getValue()
112
hoursSpinner.setEditor(new javax.swing.JSpinner.NumberEditor(hoursSpinner, "00"));
113         //timeLabel.setLabelFor(hoursSpinner);
114
logDatePanel.add(hoursSpinner);
115         logDatePanel.add(timeLabel2);
116
117         SpinnerModel JavaDoc minModel = new SpinnerNumberModel JavaDoc(00, //initial value
118
00, //min
119
59, //max
120
1);
121         minSpinner = new JSpinner JavaDoc(minModel); //getValue()
122
minSpinner.setEditor(new javax.swing.JSpinner.NumberEditor(minSpinner, "00"));
123         logDatePanel.add(minSpinner);
124         JLabel JavaDoc timeLabel3 =new JLabel JavaDoc(":");
125         logDatePanel.add(timeLabel3);
126
127         SpinnerModel JavaDoc secModel = new SpinnerNumberModel JavaDoc(00, //initial value
128
00, //min
129
59, //max
130
1);
131         secSpinner = new JSpinner JavaDoc(secModel); //getValue()
132
secSpinner.setEditor(new javax.swing.JSpinner.NumberEditor(secSpinner, "00"));
133         logDatePanel.add(secSpinner);
134
135         //logOptionsPanel.add(logDatePanel);
136

137                           // set up box to hold log name options
138
JPanel JavaDoc logSelectionPanel = new JPanel JavaDoc();
139         logSelectionPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
140         JLabel JavaDoc logSelectionLabel = new JLabel JavaDoc("Select Log Archive: ");
141         logSelectionPanel.add(logSelectionLabel);
142
143         String JavaDoc[] logSelectionStrings = master.get_all_logs();
144         System.err.println("logSelectionStrings length = " + logSelectionStrings.length);
145         logSelectionList = new JComboBox JavaDoc(logSelectionStrings);
146         //logSelectionList.setSelectedIndex(1);
147
// logSelectionList.addActionListener(this);
148
logSelectionPanel.add(logSelectionList);
149
150         logOptionsPanel.add(logSelectionPanel);
151
152         JPanel JavaDoc logRecordsPanel = new JPanel JavaDoc();
153
154                           // add how many records choice
155
JLabel JavaDoc logHowManyLabel =new JLabel JavaDoc("Number of Records: ");
156         logRecordsPanel.add(logHowManyLabel);
157         SpinnerModel JavaDoc recordsModel = new SpinnerNumberModel JavaDoc(1, //initial value
158
1, //min
159
100, //max
160
1);
161         recordsSpinner = new JSpinner JavaDoc(recordsModel); //getValue()
162
logHowManyLabel.setLabelFor(recordsSpinner);
163         logRecordsPanel.add(recordsSpinner);
164
165         logRecordsPanel.add(javax.swing.Box.createHorizontalGlue());
166         JButton JavaDoc ok_button = new JButton JavaDoc(GuiMessages.browse_str);
167         ok_button.addActionListener(this);
168         ok_button.setToolTipText(GuiMessages.browse_tooltip_str);
169         logRecordsPanel.add(ok_button);
170         logOptionsPanel.add(logRecordsPanel);
171                         // Setup the log Table panel....
172
JLogTable logTable = new JLogTable(logModel);
173
174         logTable.setPreferredScrollableViewportSize(new Dimension(700, 200));
175         logTable.setCellSelectionEnabled(false);
176         //logTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
177

178         logTable.getColumnModel().getSelectionModel().
179             addListSelectionListener( new ListSelectionListener JavaDoc() {
180
181                 public void valueChanged(ListSelectionEvent JavaDoc e) {
182
183                     if(e.getValueIsAdjusting()) return;
184                     ListSelectionModel JavaDoc lsm = (ListSelectionModel JavaDoc)e.getSource();
185                     if (! lsm.isSelectionEmpty()) {
186                         selectedCol = lsm.getMinSelectionIndex();
187                         if (logModel.getValueAt(selectedRow, selectedCol) != null)
188                             records_data.setText((String JavaDoc) logModel.getValueAt(selectedRow, selectedCol));
189                     }
190                 }
191         });
192         logTable.getSelectionModel().addListSelectionListener(new ListSelectionListener JavaDoc() {
193
194             public void valueChanged(ListSelectionEvent JavaDoc e) {
195
196                     if(e.getValueIsAdjusting()) return;
197                     ListSelectionModel JavaDoc lsm = (ListSelectionModel JavaDoc)e.getSource();
198                     if (! lsm.isSelectionEmpty()) {
199                         selectedRow = lsm.getMinSelectionIndex();
200                         if (logModel.getValueAt(selectedRow, selectedCol) != null)
201                             records_data.setText((String JavaDoc) logModel.getValueAt(selectedRow, selectedCol));
202                     }
203             }
204             }
205         );
206
207         logTable.getColumnModel().getColumn(AlarmTableModel.TIME_C).setPreferredWidth(120);
208         logTable.getColumnModel().getColumn(AlarmTableModel.EVENT_C).setPreferredWidth(100);
209         logTable.getColumnModel().getColumn(AlarmTableModel.SOURCE_C).setPreferredWidth(200);
210         logTable.getColumnModel().getColumn(AlarmTableModel.SOURCE_T_C).setPreferredWidth(100);
211         logTable.getColumnModel().getColumn(AlarmTableModel.ID_C).setPreferredWidth(60);
212         logTable.getColumnModel().getColumn(AlarmTableModel.DETAILS_C).setPreferredWidth(120);
213
214         JScrollPane JavaDoc scrollPane = new JScrollPane JavaDoc(logTable);
215
216         scrollPane.setPreferredSize(new Dimension(700, 350));
217         scrollPane.setMinimumSize(new Dimension(10, 10));
218
219         JPanel JavaDoc logParamPanel = new JPanel JavaDoc();
220         logParamPanel.setLayout(new java.awt.GridLayout JavaDoc(2, 1, 0, 0));
221
222         logParamPanel.add(logDatePanel);
223         logParamPanel.add(logOptionsPanel);
224         logPanel.add(logParamPanel, BorderLayout.NORTH);
225
226         logPanel.add(scrollPane, BorderLayout.CENTER);
227         logPanel.add(records_data, BorderLayout.SOUTH);
228         logPanel.setBorder(BorderFactory.createTitledBorder(GuiMessages.gui_client_log));
229
230         getContentPane().add(logPanel, BorderLayout.CENTER);
231               /* add window control */
232         setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
233         /********
234         addWindowListener(new WindowAdapter() {
235             public void windowClosing(WindowEvent e) {
236                 this.dispose();
237             }
238         });
239         ********/

240         setLocation(x_pos, y_pos);
241         pack();
242         setVisible(true);
243     }
244
245     public void run() {}
246
247     public void actionPerformed(ActionEvent e) {
248
249         JButton JavaDoc source = (JButton JavaDoc) (e.getSource());
250         if (source.getText().equals(GuiMessages.browse_str)) {
251 /************************
252             System.err.println("Browse button pressed");
253             System.err.println("Day Selection = " + logDaySelectionList.getSelectedItem()
254                       + "(" + logDaySelectionList.getSelectedIndex() + ")");
255             System.err.println("Month Selection = " + logMonthSelectionList.getSelectedItem()
256                       + "(" + logMonthSelectionList.getSelectedIndex() + ")");
257             System.err.println("Year Selection = " + logYearSelectionList.getSelectedItem()
258                       + "(" + logYearSelectionList.getSelectedIndex() + ")");
259             System.err.println("Hour Selection = " + hoursSpinner.getValue());
260             System.err.println("Secs Selection = " + minSpinner.getValue());
261             System.err.println("Min Selection = " + secSpinner.getValue());
262             System.err.println("Records Selection = " + recordsSpinner.getValue());
263             System.err.println("Logs Selection = " + logSelectionList.getSelectedItem()
264                       + "(" + logSelectionList.getSelectedIndex() + ")");
265 ********/

266
267             java.text.DecimalFormat JavaDoc df1 = new java.text.DecimalFormat JavaDoc("00");
268             String JavaDoc requested_date = df1.format(
269                 (int) logDaySelectionList.getSelectedIndex() + 1);
270
271             requested_date += "/";
272
273             requested_date +=df1.format(logMonthSelectionList.getSelectedIndex() + 1);
274
275             requested_date += "/";
276             requested_date +=logYearSelectionList.getSelectedItem() + " ";
277
278             requested_date += hoursSpinner.getValue() + ":" +
279                               minSpinner.getValue() + ":" +
280                             secSpinner.getValue();
281
282             //System.err.println("Requested Date is " + requested_date);
283

284             java.text.SimpleDateFormat JavaDoc formatter =
285                     new java.text.SimpleDateFormat JavaDoc ("dd/MM/yyyy HH:mm:ss");
286             //java.util.Date currentTime_1 = new java.util.Date();
287
//String dateString = formatter.format(currentTime_1);
288

289             // Parse the previous string back into a Date.
290
java.text.ParsePosition JavaDoc pos = new java.text.ParsePosition JavaDoc(0);
291             java.util.Date JavaDoc requestedDateObj = formatter.parse(requested_date, pos);
292             //System.err.println("requested date = " + requestedDateObj + "(" +
293
// requestedDateObj.getTime() +")");
294

295             //java.sql.Timestamp logTimestamp = new java.sql.Timestamp(requestedDateObj.getTime());
296
//String logTimestampStr = logTimestamp.toString();
297
//System.err.println("my date = " + requestedDateObj + ", timestamp = " +
298
// logTimestampStr );
299

300             int num_of_records = ((Integer JavaDoc) recordsSpinner.getValue()).intValue();
301             //System.err.println("num_of_records = " + num_of_records);
302
LogRecord[] records = master.retrieve_logs(
303                     (String JavaDoc) logSelectionList.getSelectedItem(),
304                     requestedDateObj.getTime(),
305                     num_of_records);
306                     //Integer.parseInt((String) recordsSpinner.getValue()));
307
//System.err.println("LogArchiveFrame> LogRecords recieved = " + records.length);
308
logModel.clear();
309             logModel.updateLogArchives(records);
310             records_data.setText(records.length + " records retrieved...");
311
312
313         }
314
315     }
316 }
317
Popular Tags