| 1 | package tmcsim.cadsimulator.viewer; |
|---|
| 2 | |
|---|
| 3 | import java.util.TreeMap; |
|---|
| 4 | |
|---|
| 5 | import javax.swing.JPanel; |
|---|
| 6 | import javax.swing.JTabbedPane; |
|---|
| 7 | |
|---|
| 8 | import tmcsim.cadsimulator.videocontrol.DVDStatusUpdate; |
|---|
| 9 | import tmcsim.cadsimulator.videocontrol.DVDTitleUpdate; |
|---|
| 10 | |
|---|
| 11 | /** |
|---|
| 12 | * MediaStatusPanel is a GUI object used for displaying information |
|---|
| 13 | * for DVD connections created by the CAD Simulator. Tabs for each |
|---|
| 14 | * DVD are created and information is displayed on a DVDInfoPanel. |
|---|
| 15 | * All status and title updates are sent to the corresponding |
|---|
| 16 | * DVDInfoPanel. The DVDs are referenced by connection info, which |
|---|
| 17 | * is unique to each DVD player. |
|---|
| 18 | * |
|---|
| 19 | * @author Matthew Cechini |
|---|
| 20 | * @version |
|---|
| 21 | */ |
|---|
| 22 | @SuppressWarnings("serial") |
|---|
| 23 | public class MediaStatusPanel extends JPanel { |
|---|
| 24 | |
|---|
| 25 | /** Map of DVDInfoPanels(values) referenced by a DVD's connection info(key). */ |
|---|
| 26 | private TreeMap<String, DVDInfoPanel> dvdPanels = null; |
|---|
| 27 | |
|---|
| 28 | /** |
|---|
| 29 | * Constructor. Initialize data and GUI components. |
|---|
| 30 | */ |
|---|
| 31 | public MediaStatusPanel() { |
|---|
| 32 | |
|---|
| 33 | dvdPanels = new TreeMap<String, DVDInfoPanel>(); |
|---|
| 34 | |
|---|
| 35 | initComponents(); |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | /** |
|---|
| 39 | * Updates the current DVDInfoPanel with the status update. |
|---|
| 40 | * If a panel does not current exist, create one and add |
|---|
| 41 | * a new tab. |
|---|
| 42 | * |
|---|
| 43 | * @param update DVD status update. |
|---|
| 44 | */ |
|---|
| 45 | public void updateDVDStatus(DVDStatusUpdate update) { |
|---|
| 46 | if(dvdPanels.get(update.connectionInfo) == null) { |
|---|
| 47 | dvdPanels.put(update.connectionInfo, new DVDInfoPanel( |
|---|
| 48 | update.connectionInfo)); |
|---|
| 49 | |
|---|
| 50 | mediaTabs.addTab( |
|---|
| 51 | "DVD " + (Integer.parseInt(update.connectionInfo |
|---|
| 52 | .substring(update.connectionInfo |
|---|
| 53 | .indexOf(":")+1)) % 3000), |
|---|
| 54 | dvdPanels.get(update.connectionInfo)); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | dvdPanels.get(update.connectionInfo).updateDVDStatus(update); |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | /** |
|---|
| 62 | * Updates the current DVDInfoPanel with the title update. |
|---|
| 63 | * If a panel does not current exist, create one and add |
|---|
| 64 | * a new tab. |
|---|
| 65 | * |
|---|
| 66 | * @param update DVD title update. |
|---|
| 67 | */ |
|---|
| 68 | public void updateDVDTitle(DVDTitleUpdate update) { |
|---|
| 69 | if(dvdPanels.get(update.connectionInfo) == null) { |
|---|
| 70 | dvdPanels.put(update.connectionInfo, new DVDInfoPanel(update.connectionInfo)); |
|---|
| 71 | |
|---|
| 72 | mediaTabs.addTab("DVD " + dvdPanels.size(), |
|---|
| 73 | dvdPanels.get(update.connectionInfo)); |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | dvdPanels.get(update.connectionInfo).updateDVDTitle(update); |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | /** |
|---|
| 80 | * Initialize GUI components. |
|---|
| 81 | */ |
|---|
| 82 | private void initComponents() { |
|---|
| 83 | mediaTabs = new JTabbedPane(); |
|---|
| 84 | |
|---|
| 85 | add(mediaTabs); |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | private JTabbedPane mediaTabs; |
|---|
| 89 | |
|---|
| 90 | } |
|---|