| 1 | package tmcsim.cadsimulator.viewer; |
|---|
| 2 | |
|---|
| 3 | import java.awt.Dimension; |
|---|
| 4 | import javax.swing.BorderFactory; |
|---|
| 5 | import javax.swing.Box; |
|---|
| 6 | import javax.swing.JLabel; |
|---|
| 7 | import javax.swing.JPanel; |
|---|
| 8 | import javax.swing.JScrollPane; |
|---|
| 9 | import javax.swing.JTable; |
|---|
| 10 | import javax.swing.JTextField; |
|---|
| 11 | import tmcsim.cadsimulator.videocontrol.DVDStatusUpdate; |
|---|
| 12 | import tmcsim.cadsimulator.videocontrol.DVDTitleUpdate; |
|---|
| 13 | import tmcsim.cadsimulator.viewer.model.DVDStatusTableModel; |
|---|
| 14 | import tmcsim.cadsimulator.viewer.model.DVDTitleTableModel; |
|---|
| 15 | |
|---|
| 16 | /** |
|---|
| 17 | * DVDInfoPanel is a GUI component used in the CADSimulatorViewer. The panel |
|---|
| 18 | * displays information regarding the DVD player's connection information. One |
|---|
| 19 | * table on the panel shows all DVD title that have been played or repeated. A |
|---|
| 20 | * second table shows all DVD status updates that have been received from the |
|---|
| 21 | * controller. |
|---|
| 22 | * |
|---|
| 23 | * @author Matthew Cechini |
|---|
| 24 | * @version |
|---|
| 25 | */ |
|---|
| 26 | @SuppressWarnings("serial") |
|---|
| 27 | public class DVDInfoPanel extends JPanel |
|---|
| 28 | { |
|---|
| 29 | |
|---|
| 30 | /** |
|---|
| 31 | * DVD player connection info. |
|---|
| 32 | */ |
|---|
| 33 | public final String connInfo; |
|---|
| 34 | /** |
|---|
| 35 | * Table model for the title table. |
|---|
| 36 | */ |
|---|
| 37 | private DVDTitleTableModel titleTableModel; |
|---|
| 38 | /** |
|---|
| 39 | * Table to display DVD title plays and repeats. |
|---|
| 40 | */ |
|---|
| 41 | private JTable titleTable; |
|---|
| 42 | /** |
|---|
| 43 | * Table model for the Status table. |
|---|
| 44 | */ |
|---|
| 45 | private DVDStatusTableModel statusTableModel; |
|---|
| 46 | /** |
|---|
| 47 | * Table to display DVD status updates. |
|---|
| 48 | */ |
|---|
| 49 | private JTable statusTable; |
|---|
| 50 | |
|---|
| 51 | /** |
|---|
| 52 | * Constructor. Initialize the panel GUI components. |
|---|
| 53 | * |
|---|
| 54 | * @param connectionInfo DVD player connection info. |
|---|
| 55 | */ |
|---|
| 56 | public DVDInfoPanel(String connectionInfo) |
|---|
| 57 | { |
|---|
| 58 | connInfo = connectionInfo; |
|---|
| 59 | |
|---|
| 60 | initComponents(); |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | /** |
|---|
| 64 | * This method updates the DVD status table with the new update object. |
|---|
| 65 | * |
|---|
| 66 | * @param update Update DVD Status update. |
|---|
| 67 | */ |
|---|
| 68 | public void updateDVDStatus(DVDStatusUpdate update) |
|---|
| 69 | { |
|---|
| 70 | statusTableModel.addStatusUpdate(update); |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | /** |
|---|
| 74 | * This method updates the DVD title table with the new update object. |
|---|
| 75 | * |
|---|
| 76 | * @param update Update DVD Status update. |
|---|
| 77 | */ |
|---|
| 78 | public void updateDVDTitle(DVDTitleUpdate update) |
|---|
| 79 | { |
|---|
| 80 | titleTableModel.addTitleUpdate(update); |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | /** |
|---|
| 84 | * Initialize the GUI components. |
|---|
| 85 | */ |
|---|
| 86 | private void initComponents() |
|---|
| 87 | { |
|---|
| 88 | |
|---|
| 89 | connInfoLbl = new JLabel("Connection Info:"); |
|---|
| 90 | connInfoLbl.setAlignmentX(Box.LEFT_ALIGNMENT); |
|---|
| 91 | connInfoTF = new JTextField(connInfo); |
|---|
| 92 | connInfoTF.setColumns(30); |
|---|
| 93 | connInfoTF.setAlignmentX(Box.LEFT_ALIGNMENT); |
|---|
| 94 | connInfoTF.setEditable(false); |
|---|
| 95 | |
|---|
| 96 | Box connInfoBox = Box.createVerticalBox(); |
|---|
| 97 | connInfoBox.add(connInfoLbl); |
|---|
| 98 | connInfoBox.add(connInfoTF); |
|---|
| 99 | connInfoBox.setAlignmentX(Box.CENTER_ALIGNMENT); |
|---|
| 100 | |
|---|
| 101 | titleTableModel = new DVDTitleTableModel(); |
|---|
| 102 | titleTable = new JTable(titleTableModel); |
|---|
| 103 | titleTable.getTableHeader().setReorderingAllowed(false); |
|---|
| 104 | |
|---|
| 105 | for (int c = 0; c < titleTable.getColumnCount(); c++) |
|---|
| 106 | { |
|---|
| 107 | titleTable.getColumnModel().getColumn(c).setMinWidth( |
|---|
| 108 | titleTableModel.getColumnMinWidth(c)); |
|---|
| 109 | titleTable.getColumnModel().getColumn(c).setMaxWidth( |
|---|
| 110 | titleTableModel.getColumnMaxWidth(c)); |
|---|
| 111 | titleTable.getColumnModel().getColumn(c).setPreferredWidth( |
|---|
| 112 | titleTableModel.getColumnPrefWidth(c)); |
|---|
| 113 | titleTable.getColumnModel().getColumn(c).setResizable(true); |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | titlePane = new JScrollPane(); |
|---|
| 117 | titlePane.setAlignmentX(Box.CENTER_ALIGNMENT); |
|---|
| 118 | //titlePane.setMinimumSize(new Dimension(,)); |
|---|
| 119 | titlePane.setPreferredSize(new Dimension(425, 225)); |
|---|
| 120 | titlePane.setViewportView(titleTable); |
|---|
| 121 | titlePane.setBorder(BorderFactory.createTitledBorder( |
|---|
| 122 | BorderFactory.createRaisedBevelBorder(), "Title Updates")); |
|---|
| 123 | |
|---|
| 124 | statusTableModel = new DVDStatusTableModel(); |
|---|
| 125 | statusTable = new JTable(statusTableModel); |
|---|
| 126 | statusTable.getTableHeader().setReorderingAllowed(false); |
|---|
| 127 | |
|---|
| 128 | for (int c = 0; c < statusTable.getColumnCount(); c++) |
|---|
| 129 | { |
|---|
| 130 | statusTable.getColumnModel().getColumn(c).setMinWidth( |
|---|
| 131 | statusTableModel.getColumnMinWidth(c)); |
|---|
| 132 | statusTable.getColumnModel().getColumn(c).setMaxWidth( |
|---|
| 133 | statusTableModel.getColumnMaxWidth(c)); |
|---|
| 134 | statusTable.getColumnModel().getColumn(c).setPreferredWidth( |
|---|
| 135 | statusTableModel.getColumnPrefWidth(c)); |
|---|
| 136 | statusTable.getColumnModel().getColumn(c).setResizable(true); |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | statusPane = new JScrollPane(); |
|---|
| 140 | statusPane.setAlignmentX(Box.CENTER_ALIGNMENT); |
|---|
| 141 | //statusPane.setMinimumSize(new Dimension(,)); |
|---|
| 142 | statusPane.setPreferredSize(new Dimension(425, 150)); |
|---|
| 143 | statusPane.setViewportView(statusTable); |
|---|
| 144 | statusPane.setBorder(BorderFactory.createTitledBorder( |
|---|
| 145 | BorderFactory.createRaisedBevelBorder(), "Status Updates")); |
|---|
| 146 | |
|---|
| 147 | Box panelBox = Box.createVerticalBox(); |
|---|
| 148 | panelBox.add(connInfoBox); |
|---|
| 149 | panelBox.add(Box.createVerticalStrut(10)); |
|---|
| 150 | panelBox.add(titlePane); |
|---|
| 151 | panelBox.add(Box.createVerticalStrut(10)); |
|---|
| 152 | panelBox.add(statusPane); |
|---|
| 153 | panelBox.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
|---|
| 154 | |
|---|
| 155 | add(panelBox); |
|---|
| 156 | } |
|---|
| 157 | private JScrollPane titlePane; |
|---|
| 158 | private JScrollPane statusPane; |
|---|
| 159 | private JLabel connInfoLbl; |
|---|
| 160 | private JTextField connInfoTF; |
|---|
| 161 | } |
|---|