source: tmcsimulator/trunk/src/tmcsim/client/cadclientgui/screens/IncidentEditor.java @ 59

Revision 59, 20.2 KB checked in by jdalbey, 9 years ago (diff)

Merge CAD Client updates for multiple incident view windows.

Line 
1package tmcsim.client.cadclientgui.screens;
2
3import java.awt.Color;
4import java.awt.Component;
5import java.awt.Dimension;
6import java.awt.event.ActionEvent;
7import java.awt.event.ActionListener;
8import java.awt.event.MouseEvent;
9import java.awt.event.MouseListener;
10import java.rmi.RemoteException;
11import java.text.DateFormat;
12import java.text.SimpleDateFormat;
13import java.util.Calendar;
14import java.util.Date;
15import javax.swing.BorderFactory;
16import javax.swing.DefaultListModel;
17import javax.swing.JLabel;
18import javax.swing.JPanel;
19import javax.swing.JScrollBar;
20import javax.swing.JTable;
21import javax.swing.ListSelectionModel;
22import javax.swing.SwingConstants;
23import javax.swing.border.LineBorder;
24import javax.swing.table.DefaultTableCellRenderer;
25import javax.swing.table.DefaultTableModel;
26import javax.swing.table.TableCellRenderer;
27import tmcsim.client.cadclientgui.enums.CADDataEnums.TABLE;
28import tmcsim.client.cadclientgui.enums.TableHeaders;
29
30/**
31 * This class contains the view and controller for the IncidentEditor screen.
32 * The view is built using a GUI builder plug-in, and the controller uses
33 * listeners to control how the view and data act.
34 *
35 * @author Stuart
36 */
37public class IncidentEditor extends javax.swing.JFrame
38{
39    private final String[] monthNames =
40    {
41        "January", "February",
42        "March", "April", "May", "June", "July", "August", "September",
43        "October", "November", "December"
44    };
45    private final String[] dayNames =
46    {
47        "Sun", "Mon", "Tue", "Wed",
48        "Thu", "Fri", "Sat"
49    };
50    private DefaultTableModel blankTable;
51    private JTable calendarTable;
52    private int todayRow;
53    private int todayCol;
54
55    /**
56     * Creates new form IncidentEditor
57     */
58    public IncidentEditor()
59    {
60        declareComponents();
61        initControllers();
62        initLayout();
63    }
64
65    /**
66     * This method is called from within the constructor to initialize the form.
67     * WARNING: Do NOT modify this code. The content of this method is always
68     * regenerated by the Form Editor.
69     */
70    @SuppressWarnings("unchecked")
71    // <editor-fold defaultstate="collapsed"
72    // desc="Generated Code">//GEN-BEGIN:initComponents
73    private void declareComponents()
74    {
75
76        incidentLogScroll = new javax.swing.JScrollPane();
77        incidentLogTable = new javax.swing.JTable();
78        agencyTypeLabel = new javax.swing.JLabel();
79        jScrollPane1 = new javax.swing.JScrollPane();
80        agencyTypeList = new javax.swing.JList();
81        currentDatabaseLabel = new javax.swing.JLabel();
82        currentDatabaseCombo = new javax.swing.JComboBox();
83        searchLimitLabel = new javax.swing.JLabel();
84        reopenButton = new javax.swing.JButton();
85        duplicateCellButton = new javax.swing.JButton();
86        searchButton = new javax.swing.JButton();
87        printButton = new javax.swing.JButton();
88        viewButton = new javax.swing.JButton();
89        refreshButton = new javax.swing.JButton();
90        exitButton = new javax.swing.JButton();
91        fromLabel = new javax.swing.JLabel();
92        toLabel = new javax.swing.JLabel();
93        fromCalendar = new javax.swing.JPanel();
94        toCalendar = new javax.swing.JPanel();
95    }
96
97    public MouseListener newMouseListener()
98    {
99        return new MouseListener()
100        {
101            public void mouseClicked(MouseEvent e)
102            {
103                viewButton.setEnabled(true);
104            }
105
106            public void mouseEntered(MouseEvent e)
107            {
108            }
109
110            public void mouseExited(MouseEvent e)
111            {
112            }
113
114            public void mousePressed(MouseEvent e)
115            {
116            }
117
118            public void mouseReleased(MouseEvent e)
119            {
120            }
121        };
122    }
123
124    public ActionListener newSearchActionListener()
125    {
126        return new ActionListener()
127        {
128            public void actionPerformed(ActionEvent e)
129            {
130                ScreenManager.openSearch();
131            }
132        };
133    }
134
135    public ActionListener newViewActionListener()
136    {
137        return new ActionListener()
138        {
139            public void actionPerformed(ActionEvent e)
140            {
141                String masterInc = (String) incidentLogTable.getValueAt(
142                        incidentLogTable.getSelectedRow(), 5);
143                int incidentId = 0;
144                try
145                {
146                    incidentId = ScreenManager.theCoordinator
147                            .getIncidentId(masterInc);
148                } catch (RemoteException e1)
149                {
150                    e1.printStackTrace();
151                }
152                ScreenManager.openIncidentViewer(incidentId);
153            }
154        };
155    }
156
157    public ActionListener newRefreshActionListener()
158    {
159        return new ActionListener()
160        {
161            public void actionPerformed(ActionEvent e)
162            {
163                refreshInformation();
164            }
165        };
166    }
167
168    public ActionListener newExitActionListener()
169    {
170        return new ActionListener()
171        {
172            public void actionPerformed(ActionEvent arg0)
173            {
174                close();
175            }
176        };
177    }
178
179    private void initControllers()
180    {
181
182        incidentLogTable.addMouseListener(newMouseListener());
183
184        searchButton.addActionListener(newSearchActionListener());
185        viewButton.addActionListener(newViewActionListener());
186        refreshButton.addActionListener(newRefreshActionListener());
187        exitButton.addActionListener(newExitActionListener());
188    }
189
190    private void initLayout()
191    {
192        blankTable = new DefaultTableModel();
193        blankTable.setColumnIdentifiers(TableHeaders.INCIDENT_EDITOR_HEADERS);
194
195        setTitle("Incident Editor");
196        setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
197        setPreferredSize(new java.awt.Dimension(800, 600));
198
199        incidentLogTable.setOpaque(true);
200        incidentLogTable.setIntercellSpacing(new Dimension(1, 0));
201        incidentLogTable.setGridColor(Color.WHITE);
202        incidentLogTable.getTableHeader().setReorderingAllowed(false);
203        incidentLogTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
204        incidentLogTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
205        incidentLogTable.setAutoCreateRowSorter(true);
206        incidentLogScroll.setViewportView(incidentLogTable);
207
208        agencyTypeLabel.setText("Agency Type:");
209
210        DefaultListModel<String> dlm = new DefaultListModel();
211        dlm.addElement("CHP");
212        agencyTypeList.setModel(dlm);
213        agencyTypeList.setEnabled(false);
214
215        jScrollPane1.setViewportView(agencyTypeList);
216
217        currentDatabaseLabel.setText("Current Database:");
218
219        currentDatabaseCombo.setModel(new javax.swing.DefaultComboBoxModel(
220                new String[]
221        {
222            "System"
223        }));
224        currentDatabaseCombo.setEnabled(false);
225
226        searchLimitLabel.setText("Search Limit On Live System: 30 Days");
227
228        fromCalendar = createCalendar();
229        toCalendar = createCalendar();
230
231        reopenButton.setText("ReOpen");
232        reopenButton.setEnabled(false);
233
234        duplicateCellButton.setText("Duplicate Cell");
235        duplicateCellButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
236        duplicateCellButton.setEnabled(false);
237
238        searchButton.setText("Search");
239
240        printButton.setText("Print");
241        printButton.setEnabled(false);
242
243        viewButton.setText("View");
244        viewButton.setEnabled(false);
245
246        refreshButton.setText("Refresh");
247        exitButton.setText("Exit");
248
249        fromLabel.setText("From...");
250
251        toLabel.setText("To...");
252
253        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
254        getContentPane().setLayout(layout);
255        layout.setHorizontalGroup(
256                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
257                .addComponent(incidentLogScroll)
258                .addGroup(layout.createSequentialGroup()
259                .addContainerGap()
260                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
261                .addComponent(agencyTypeLabel)
262                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
263                .addGroup(layout.createSequentialGroup()
264                .addGap(10, 10, 10)
265                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
266                .addComponent(currentDatabaseLabel)
267                .addComponent(currentDatabaseCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)))
268                .addComponent(searchLimitLabel))
269                .addGap(32, 32, 32)
270                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
271                .addComponent(fromLabel)
272                .addComponent(fromCalendar, 200, 200, 200))
273                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 45, Short.MAX_VALUE)
274                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
275                .addComponent(toLabel)
276                .addComponent(toCalendar, 200, 200, 200))
277                .addGap(25, 25, 25)
278                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
279                .addComponent(reopenButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
280                .addComponent(duplicateCellButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
281                .addComponent(searchButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
282                .addComponent(printButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
283                .addComponent(viewButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
284                .addComponent(refreshButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
285                .addComponent(exitButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))));
286        layout.setVerticalGroup(
287                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
288                .addGroup(layout.createSequentialGroup()
289                .addComponent(incidentLogScroll, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
290                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
291                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
292                .addComponent(agencyTypeLabel)
293                .addComponent(reopenButton)
294                .addComponent(fromLabel)
295                .addComponent(toLabel))
296                .addGap(2, 2, 2)
297                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
298                .addGroup(layout.createSequentialGroup()
299                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
300                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
301                .addComponent(currentDatabaseLabel)
302                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
303                .addComponent(currentDatabaseCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
304                .addGap(18, 18, 18)
305                .addComponent(searchLimitLabel))
306                .addGroup(layout.createSequentialGroup()
307                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
308                .addComponent(fromCalendar, 150, 150, 150)
309                .addComponent(toCalendar, 150, 150, 150)))
310                .addGroup(layout.createSequentialGroup()
311                .addComponent(duplicateCellButton)
312                .addGap(2, 2, 2)
313                .addComponent(searchButton)
314                .addGap(2, 2, 2)
315                .addComponent(printButton)
316                .addGap(2, 2, 2)
317                .addComponent(viewButton)
318                .addGap(2, 2, 2)
319                .addComponent(refreshButton)
320                .addGap(2, 2, 2)
321                .addComponent(exitButton)))
322                .addGap(0, 41, Short.MAX_VALUE)));
323
324        pack();
325    }// </editor-fold>//GEN-END:initComponents
326
327    public JPanel createCalendar()
328    {
329
330        JPanel calendarPanel = new JPanel();
331        Calendar now = Calendar.getInstance();
332        calendarPanel.setBorder(new LineBorder(new Color(0, 0, 0)));
333        calendarPanel.setLayout(null);
334
335        JLabel monthLabel = new JLabel("New label");
336        monthLabel.setBounds(0, 0, 140, 20);
337        monthLabel.setHorizontalAlignment(SwingConstants.CENTER);
338        monthLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
339        monthLabel.setText(monthNames[now.get(Calendar.MONTH)]);
340        calendarPanel.add(monthLabel);
341
342        JLabel yearLabel = new JLabel("New label");
343        yearLabel.setHorizontalAlignment(SwingConstants.CENTER);
344        yearLabel.setBounds(140, 0, 60, 20);
345        yearLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
346        yearLabel.setText(Integer.toString(now.get(Calendar.YEAR)));
347        calendarPanel.add(yearLabel);
348
349        Date date = new Date();
350        DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
351        String dateString = dateFormat.format(date);
352
353        JLabel dateLabel1 = new JLabel("New label");
354        dateLabel1.setBounds(0, 130, 60, 20);
355        dateLabel1.setBorder(BorderFactory.createLineBorder(Color.BLACK));
356        dateLabel1.setText(dateString);
357        dateLabel1.setHorizontalAlignment(JLabel.CENTER);
358        calendarPanel.add(dateLabel1);
359
360        JLabel dateLabel2 = new JLabel("New label");
361        dateLabel2.setBounds(140, 130, 60, 20);
362        dateLabel2.setBorder(BorderFactory.createLineBorder(Color.BLACK));
363        dateLabel2.setText(dateString);
364        dateLabel2.setHorizontalAlignment(JLabel.CENTER);
365        calendarPanel.add(dateLabel2);
366
367        JScrollBar scrollBar = new JScrollBar();
368        scrollBar.setOrientation(JScrollBar.HORIZONTAL);
369        scrollBar.setBounds(60, 130, 80, 20);
370        scrollBar.setBorder(BorderFactory.createLineBorder(Color.BLACK));
371        scrollBar.setEnabled(false);
372        calendarPanel.add(scrollBar);
373
374        calendarTable = new JTable()
375        {
376            /*
377             * Custom renderer to set different background/foreground colors
378             * @see javax.swing.JTable#prepareRenderer(javax.swing.table.TableCellRenderer, int, int)
379             */
380            public Component prepareRenderer(TableCellRenderer renderer, int row, int column)
381            {
382                Component comp = super.prepareRenderer(renderer, row, column);
383                if (todayRow == row && todayCol == column)
384                {
385                    comp.setBackground(Color.BLUE);
386                    comp.setForeground(Color.WHITE);
387                }
388                else
389                {
390                    comp.setBackground(new Color(235, 235, 235));
391                    comp.setForeground(Color.BLACK);
392                }
393                return comp;
394            }
395        };
396        calendarTable.setModel(createDaysModel());
397        DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
398        centerRenderer.setHorizontalAlignment(JLabel.CENTER);
399        for (int i = 0; i < dayNames.length; i++)
400        {
401            calendarTable.getColumnModel().getColumn(i).setCellRenderer(centerRenderer);
402        }
403        calendarTable.setEnabled(false);
404        calendarTable.setBounds(0, 20, 200, 110);
405        calendarPanel.add(calendarTable);
406
407        return calendarPanel;
408    }
409
410    protected DefaultTableModel createDaysModel()
411    {
412
413        String[][] emptyModel =
414        {
415            {
416                "", "", "", "", "", "", ""
417            },
418            {
419                "", "", "", "", "", "", ""
420            },
421            {
422                "", "", "", "", "", "", ""
423            },
424            {
425                "", "", "", "", "", "", ""
426            },
427            {
428                "", "", "", "", "", "", ""
429            },
430            {
431                "", "", "", "", "", "", ""
432            },
433            {
434                "", "", "", "", "", "", ""
435            },
436            {
437                "", "", "", "", "", "", ""
438            }
439        };
440
441        String[] emptyHeader =
442        {
443            "", "", "", "", "", "", ""
444        };
445        DefaultTableModel calendarModel = new DefaultTableModel(emptyModel, emptyHeader);
446        int row = 0;
447        int col = 0;
448
449        Calendar today = Calendar.getInstance();
450        int tMonth = today.get(Calendar.MONTH);
451        int tYear = today.get(Calendar.YEAR);
452        int tDay = today.get(Calendar.DAY_OF_MONTH);
453
454        Calendar calendar = Calendar.getInstance();
455        calendar.set(Calendar.MONTH, tMonth);
456        calendar.set(Calendar.YEAR, tYear);
457        calendar.set(Calendar.DAY_OF_MONTH, 1);
458
459        Calendar iterator = (Calendar) calendar.clone();
460        iterator.add(Calendar.DAY_OF_MONTH,
461                -(iterator.get(Calendar.DAY_OF_WEEK) - 1));
462
463        Calendar maximum = (Calendar) calendar.clone();
464        maximum.add(Calendar.MONTH, +1);
465
466        for (int i = 0; i < dayNames.length; i++)
467        {
468            calendarModel.setValueAt(dayNames[i], row, col);
469            col++;
470        }
471        col = 0;
472        row = 1;
473
474        while (iterator.getTimeInMillis() < maximum.getTimeInMillis())
475        {
476            int lMonth = iterator.get(Calendar.MONTH);
477            int lYear = iterator.get(Calendar.YEAR);
478
479            if ((lMonth == tMonth) && (lYear == tYear))
480            {
481                int lDay = iterator.get(Calendar.DAY_OF_MONTH);
482                calendarModel.setValueAt(Integer.toString(lDay), row, col);
483                if ((tMonth == lMonth) && (tYear == lYear) && (tDay == lDay))
484                {
485                    todayRow = row;
486                    todayCol = col;
487                }
488            }
489            iterator.add(Calendar.DAY_OF_YEAR, +1);
490
491            col++;
492            if (col >= calendarModel.getColumnCount())
493            {
494                row++;
495                col = 0;
496            }
497        }
498
499
500        return calendarModel;
501    }
502
503    public void refreshInformation()
504    {
505        try
506        {
507            incidentLogTable.setModel(ScreenManager.theCoordinator
508                    .getCadDataTable(TABLE.INCIDENT_EDITOR));
509        } catch (RemoteException e)
510        {
511            e.printStackTrace();
512        }
513    }
514
515    /*
516     * Makes screen visible.
517     */
518    public void open()
519    {
520        incidentLogTable.setModel(blankTable);
521        viewButton.setEnabled(false);
522        setVisible(true);
523    }
524
525    /*
526     * Hides screen.
527     */
528    public void close()
529    {
530        setVisible(false);
531    }
532    // Variables declaration - do not modify//GEN-BEGIN:variables
533    private javax.swing.JLabel agencyTypeLabel;
534    private javax.swing.JList agencyTypeList;
535    private javax.swing.JComboBox currentDatabaseCombo;
536    private javax.swing.JLabel currentDatabaseLabel;
537    private javax.swing.JButton duplicateCellButton;
538    private javax.swing.JButton exitButton;
539    private javax.swing.JPanel fromCalendar;
540    private javax.swing.JLabel fromLabel;
541    private javax.swing.JScrollPane incidentLogScroll;
542    private javax.swing.JTable incidentLogTable;
543    private javax.swing.JPanel toCalendar;
544    private javax.swing.JScrollPane jScrollPane1;
545    private javax.swing.JButton printButton;
546    private javax.swing.JButton refreshButton;
547    private javax.swing.JButton reopenButton;
548    private javax.swing.JButton searchButton;
549    private javax.swing.JLabel searchLimitLabel;
550    private javax.swing.JLabel toLabel;
551    private javax.swing.JButton viewButton;
552    // End of variables declaration//GEN-END:variables
553}
Note: See TracBrowser for help on using the repository browser.