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