source: tmcsimulator/trunk/src/tmcsim/simulationmanager/IncidentHistoryPanel.java @ 2

Revision 2, 5.5 KB checked in by jdalbey, 10 years ago (diff)

Initial Import of project files

Line 
1package tmcsim.simulationmanager;
2
3import java.awt.Dimension;
4
5import javax.swing.BorderFactory;
6import javax.swing.Box;
7import javax.swing.BoxLayout;
8import javax.swing.JLabel;
9import javax.swing.JPanel;
10import javax.swing.JScrollPane;
11import javax.swing.JTable;
12import javax.swing.JTextField;
13import javax.swing.border.EtchedBorder;
14
15import tmcsim.client.cadclientgui.data.IncidentEvent;
16import tmcsim.simulationmanager.model.IncidentHistoryTableModel;
17import tmcsim.simulationmanager.model.IncidentTimeCellRenderer;
18import tmcsim.simulationmanager.model.LogEntryCellRenderer;
19import tmcsim.simulationmanager.model.IncidentHistoryTableModel.EVENT_HIST_COLUMNS;
20
21/**
22 *
23 * @author Matthew Cechini
24 * @version
25 */
26@SuppressWarnings("serial")
27public class IncidentHistoryPanel extends JPanel {
28
29    /**  */
30    private JTable eventHistoryTable = null;
31   
32    /**  */
33    private IncidentHistoryTableModel eventHistoryTableModel;
34   
35   
36    public IncidentHistoryPanel() {
37       
38        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
39        setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
40   
41        incTypeLbl = new JLabel("Type:");
42        incTypeLbl.setAlignmentX(Box.LEFT_ALIGNMENT);
43       
44        incTypeTF = new JTextField();
45        incTypeTF.setAlignmentX(Box.LEFT_ALIGNMENT);
46        //incTypeBox.setMinimumSize(new Dimension(50, 20));
47        //incTypeBox.setPreferredSize(new Dimension(100, 20));
48        incTypeTF.setMaximumSize(new Dimension(200, 20));
49        incTypeTF.setEditable(false);
50       
51        Box incTypeBox = Box.createVerticalBox();
52        incTypeBox.setAlignmentY(Box.CENTER_ALIGNMENT);
53        incTypeBox.add(incTypeLbl);
54        incTypeBox.add(incTypeTF);
55        incTypeBox.setBorder(BorderFactory.createEmptyBorder(10,0,10,0));
56
57       
58        incLocLbl = new JLabel("Location:");
59        incLocLbl.setAlignmentX(Box.LEFT_ALIGNMENT);
60       
61        incLocTF = new JTextField();
62        incLocTF.setAlignmentX(Box.LEFT_ALIGNMENT);
63        incLocTF.setMaximumSize(new Dimension(800, 20));
64        incLocTF.setEditable(false);
65       
66        Box incLocBox = Box.createVerticalBox();
67        incLocBox.setAlignmentY(Box.CENTER_ALIGNMENT);
68        incLocBox.add(incLocLbl);
69        incLocBox.add(incLocTF);
70               
71        Box incidentInfoBox = Box.createHorizontalBox();
72        incidentInfoBox.setAlignmentX(Box.CENTER_ALIGNMENT);
73        incidentInfoBox.setMaximumSize(new Dimension(1000, 75));
74        incidentInfoBox.add(Box.createHorizontalStrut(10));
75        incidentInfoBox.add(incTypeBox);
76        incidentInfoBox.add(Box.createHorizontalStrut(10));
77        incidentInfoBox.add(incLocBox);
78        incidentInfoBox.add(Box.createHorizontalStrut(10));
79        incidentInfoBox.setBorder(BorderFactory.createTitledBorder(
80                BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), 
81                "Incident Information"));
82       
83       
84
85        eventHistoryTableModel = new IncidentHistoryTableModel();
86        eventHistoryTable = new JTable(eventHistoryTableModel); 
87        eventHistoryTable.getTableHeader().setReorderingAllowed(false); 
88       
89        for(int c = 0; c < eventHistoryTable.getColumnCount(); c++) {
90            eventHistoryTable.getColumnModel().getColumn(c).setMinWidth(
91                    eventHistoryTableModel.getColumnMinWidth(c));
92            eventHistoryTable.getColumnModel().getColumn(c).setMaxWidth(
93                    eventHistoryTableModel.getColumnMaxWidth(c));
94            eventHistoryTable.getColumnModel().getColumn(c).setPreferredWidth(
95                    eventHistoryTableModel.getColumnPrefWidth(c));
96            eventHistoryTable.getColumnModel().getColumn(c).setResizable(true);
97           
98            if(c == EVENT_HIST_COLUMNS.TIME_COL.colNum)
99                eventHistoryTable.getColumnModel().getColumn(c).setCellRenderer(
100                        new IncidentTimeCellRenderer());
101            else if (c == EVENT_HIST_COLUMNS.EVENT_DESC_COL.colNum)
102                eventHistoryTable.getColumnModel().getColumn(c).setCellRenderer(
103                        new LogEntryCellRenderer());           
104               
105        }       
106       
107        logScrollPane     = new JScrollPane(new JLabel(""), 
108                javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
109                javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
110        logScrollPane.setAlignmentX(Box.CENTER_ALIGNMENT);     
111        logScrollPane.setViewportView(eventHistoryTable);
112        logScrollPane.setBorder(BorderFactory.createTitledBorder(
113                BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Log Entries"));
114       
115   
116        add(incidentInfoBox);
117        add(Box.createVerticalStrut(10));
118        add(logScrollPane);
119    }
120   
121    public void updateIncidentHistory(IncidentEvent event) {
122       
123        if(event.eventInfo.getHeader().type.trim().length() > 0 &&
124            !incTypeTF.getText().trim().equals(event.eventInfo.getHeader().type.trim())) 
125        {
126            incTypeTF.setText(event.eventInfo.getHeader().type.trim());         
127        }
128
129        if(event.eventInfo.getHeader().fullLocation.trim().length() > 0&&
130            !incLocTF.getText().trim().equals(event.eventInfo.getHeader().fullLocation.trim()))
131        {
132            incLocTF.setText(event.eventInfo.getHeader().fullLocation.trim());
133        }
134
135        eventHistoryTableModel.addEvent(event);
136    }
137       
138    private JLabel incTypeLbl;
139    private JLabel incLocLbl;
140   
141    private JTextField incTypeTF;
142    private JTextField incLocTF;
143   
144    private JScrollPane logScrollPane;
145
146}
Note: See TracBrowser for help on using the repository browser.