1 package ist.coach.coachEmfClientComponents.gui; 2 3 4 import javax.swing.JTable ; 5 import javax.swing.table.AbstractTableModel ; 6 7 import javax.swing.DefaultCellEditor ; 8 import javax.swing.event.ListSelectionListener ; 9 import javax.swing.ListSelectionModel ; 10 import javax.swing.event.ListSelectionEvent ; 11 12 import javax.swing.JScrollPane ; 13 import javax.swing.JFrame ; 14 import javax.swing.JPanel ; 15 import javax.swing.JSpinner ; 16 import javax.swing.SpinnerNumberModel ; 17 import javax.swing.SpinnerModel ; 18 import javax.swing.SwingUtilities ; 19 import javax.swing.JOptionPane ; 20 import javax.swing.JButton ; 21 import javax.swing.JLabel ; 22 import javax.swing.JComboBox ; 23 import javax.swing.JTextField ; 24 import javax.swing.border.Border ; 25 import javax.swing.border.EtchedBorder ; 26 import javax.swing.border.Border ; 27 import javax.swing.BorderFactory ; 28 import java.awt.*; 29 import java.awt.event.*; 30 31 import ist.coach.coachEmfServices.EmfBasicLog.LogRecord; 32 33 public class LogArchiveFrame extends JFrame 34 implements ActionListener, Runnable { 35 36 GuiMaster master; 37 private LogTableModel logModel = null; 38 private String [] logDaySelectionStrings = new String [31]; 39 private String [] 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 hoursSpinner, minSpinner, secSpinner, recordsSpinner; 54 JComboBox logSelectionList, logYearSelectionList, logDaySelectionList, logMonthSelectionList; 55 JTextField records_data; 56 private int selectedRow, selectedCol; 57 58 private String [] 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 67 JPanel logPanel = new JPanel (); 68 logPanel.setLayout(new BorderLayout()); 69 70 records_data = new JTextField (80); 71 records_data.setEditable(false); 72 records_data.setBackground(java.awt.Color.LIGHT_GRAY); 73 java.awt.Font textDisplayFont = records_data.getFont(); 74 textDisplayFont = textDisplayFont.deriveFont((float) textDisplayFont.getSize()-1); 75 records_data.setFont(textDisplayFont); 76 77 JPanel logOptionsPanel = new JPanel (new java.awt.FlowLayout (java.awt.FlowLayout.LEFT, 20, 0)); 78 79 JPanel logDatePanel = new JPanel (); 81 logDatePanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED)); 82 JLabel logDayLabel =new JLabel ("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 (logDaySelectionStrings); 89 logDaySelectionList.setSelectedIndex(0); 90 logDatePanel.add(logDaySelectionList); 92 93 logMonthSelectionList = new JComboBox (logMonthSelectionStrings); 94 logMonthSelectionList.setSelectedIndex(0); 95 logDatePanel.add(logMonthSelectionList); 97 98 logYearSelectionList = new JComboBox (logYearSelectionStrings); 99 logYearSelectionList.setSelectedIndex(0); 100 logDatePanel.add(logYearSelectionList); 102 103 JLabel timeLabel =new JLabel ("Time: "); 104 JLabel timeLabel2 =new JLabel (":"); 105 106 logDatePanel.add(timeLabel); 107 SpinnerModel hoursModel = new SpinnerNumberModel (00, 00, 23, 1); 111 hoursSpinner = new JSpinner (hoursModel); hoursSpinner.setEditor(new javax.swing.JSpinner.NumberEditor(hoursSpinner, "00")); 113 logDatePanel.add(hoursSpinner); 115 logDatePanel.add(timeLabel2); 116 117 SpinnerModel minModel = new SpinnerNumberModel (00, 00, 59, 1); 121 minSpinner = new JSpinner (minModel); minSpinner.setEditor(new javax.swing.JSpinner.NumberEditor(minSpinner, "00")); 123 logDatePanel.add(minSpinner); 124 JLabel timeLabel3 =new JLabel (":"); 125 logDatePanel.add(timeLabel3); 126 127 SpinnerModel secModel = new SpinnerNumberModel (00, 00, 59, 1); 131 secSpinner = new JSpinner (secModel); secSpinner.setEditor(new javax.swing.JSpinner.NumberEditor(secSpinner, "00")); 133 logDatePanel.add(secSpinner); 134 135 137 JPanel logSelectionPanel = new JPanel (); 139 logSelectionPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED)); 140 JLabel logSelectionLabel = new JLabel ("Select Log Archive: "); 141 logSelectionPanel.add(logSelectionLabel); 142 143 String [] logSelectionStrings = master.get_all_logs(); 144 System.err.println("logSelectionStrings length = " + logSelectionStrings.length); 145 logSelectionList = new JComboBox (logSelectionStrings); 146 logSelectionPanel.add(logSelectionList); 149 150 logOptionsPanel.add(logSelectionPanel); 151 152 JPanel logRecordsPanel = new JPanel (); 153 154 JLabel logHowManyLabel =new JLabel ("Number of Records: "); 156 logRecordsPanel.add(logHowManyLabel); 157 SpinnerModel recordsModel = new SpinnerNumberModel (1, 1, 100, 1); 161 recordsSpinner = new JSpinner (recordsModel); logHowManyLabel.setLabelFor(recordsSpinner); 163 logRecordsPanel.add(recordsSpinner); 164 165 logRecordsPanel.add(javax.swing.Box.createHorizontalGlue()); 166 JButton ok_button = new JButton (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 JLogTable logTable = new JLogTable(logModel); 173 174 logTable.setPreferredScrollableViewportSize(new Dimension(700, 200)); 175 logTable.setCellSelectionEnabled(false); 176 178 logTable.getColumnModel().getSelectionModel(). 179 addListSelectionListener( new ListSelectionListener () { 180 181 public void valueChanged(ListSelectionEvent e) { 182 183 if(e.getValueIsAdjusting()) return; 184 ListSelectionModel lsm = (ListSelectionModel )e.getSource(); 185 if (! lsm.isSelectionEmpty()) { 186 selectedCol = lsm.getMinSelectionIndex(); 187 if (logModel.getValueAt(selectedRow, selectedCol) != null) 188 records_data.setText((String ) logModel.getValueAt(selectedRow, selectedCol)); 189 } 190 } 191 }); 192 logTable.getSelectionModel().addListSelectionListener(new ListSelectionListener () { 193 194 public void valueChanged(ListSelectionEvent e) { 195 196 if(e.getValueIsAdjusting()) return; 197 ListSelectionModel lsm = (ListSelectionModel )e.getSource(); 198 if (! lsm.isSelectionEmpty()) { 199 selectedRow = lsm.getMinSelectionIndex(); 200 if (logModel.getValueAt(selectedRow, selectedCol) != null) 201 records_data.setText((String ) 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 scrollPane = new JScrollPane (logTable); 215 216 scrollPane.setPreferredSize(new Dimension(700, 350)); 217 scrollPane.setMinimumSize(new Dimension(10, 10)); 218 219 JPanel logParamPanel = new JPanel (); 220 logParamPanel.setLayout(new java.awt.GridLayout (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 232 setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 233 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 source = (JButton ) (e.getSource()); 250 if (source.getText().equals(GuiMessages.browse_str)) { 251 266 267 java.text.DecimalFormat df1 = new java.text.DecimalFormat ("00"); 268 String 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 284 java.text.SimpleDateFormat formatter = 285 new java.text.SimpleDateFormat ("dd/MM/yyyy HH:mm:ss"); 286 289 java.text.ParsePosition pos = new java.text.ParsePosition (0); 291 java.util.Date requestedDateObj = formatter.parse(requested_date, pos); 292 295 300 int num_of_records = ((Integer ) recordsSpinner.getValue()).intValue(); 301 LogRecord[] records = master.retrieve_logs( 303 (String ) logSelectionList.getSelectedItem(), 304 requestedDateObj.getTime(), 305 num_of_records); 306 logModel.clear(); 309 logModel.updateLogArchives(records); 310 records_data.setText(records.length + " records retrieved..."); 311 312 313 } 314 315 } 316 } 317 | Popular Tags |