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