| 1 | package tmcsim.cadsimulator.viewer; |
|---|
| 2 | |
|---|
| 3 | import java.util.Iterator; |
|---|
| 4 | import java.util.Observable; |
|---|
| 5 | import java.util.TreeMap; |
|---|
| 6 | import javax.swing.JPanel; |
|---|
| 7 | import javax.swing.JTabbedPane; |
|---|
| 8 | import tmcsim.cadsimulator.videocontrol.DVDStatusUpdate; |
|---|
| 9 | import tmcsim.cadsimulator.videocontrol.DVDTitleUpdate; |
|---|
| 10 | import tmcsim.cadsimulator.viewer.model.CADMediaStatus; |
|---|
| 11 | |
|---|
| 12 | /** |
|---|
| 13 | * MediaStatusPanel is a GUI object used for displaying information for DVD |
|---|
| 14 | * connections created by the CAD Simulator. Tabs for each DVD are created and |
|---|
| 15 | * information is displayed on a DVDInfoPanel. All status and title updates are |
|---|
| 16 | * sent to the corresponding DVDInfoPanel. The DVDs are referenced by connection |
|---|
| 17 | * info, which is unique to each DVD player. |
|---|
| 18 | * |
|---|
| 19 | * @author jdalbey |
|---|
| 20 | */ |
|---|
| 21 | @SuppressWarnings("serial") |
|---|
| 22 | public class MediaStatusPanel extends JPanel |
|---|
| 23 | { |
|---|
| 24 | |
|---|
| 25 | /** |
|---|
| 26 | * Map of DVDInfoPanels(values) referenced by a DVD's connection info(key). |
|---|
| 27 | */ |
|---|
| 28 | private TreeMap<String, DVDInfoPanel> dvdPanels = null; |
|---|
| 29 | |
|---|
| 30 | /** |
|---|
| 31 | * Constructor. Initialize data and GUI components. |
|---|
| 32 | */ |
|---|
| 33 | public MediaStatusPanel() |
|---|
| 34 | { |
|---|
| 35 | |
|---|
| 36 | dvdPanels = new TreeMap<String, DVDInfoPanel>(); |
|---|
| 37 | |
|---|
| 38 | initComponents(); |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | public void refresh(Observable obs) |
|---|
| 42 | { |
|---|
| 43 | CADMediaStatus status = (CADMediaStatus) obs; |
|---|
| 44 | Iterator<DVDInfoPanel> iter = status.getDVDlist(); |
|---|
| 45 | // Remove existing tabs before adding them all back |
|---|
| 46 | mediaTabs.removeAll(); |
|---|
| 47 | // add a new tab for each dvd panel |
|---|
| 48 | while (iter.hasNext()) |
|---|
| 49 | { |
|---|
| 50 | DVDInfoPanel item = iter.next(); |
|---|
| 51 | mediaTabs.addTab( |
|---|
| 52 | "DVD " + (Integer.parseInt(item.connInfo |
|---|
| 53 | .substring(item.connInfo |
|---|
| 54 | .indexOf(":") + 1)) % 3000), |
|---|
| 55 | dvdPanels.get(item.connInfo)); |
|---|
| 56 | } |
|---|
| 57 | // mediaTabs.addTab( |
|---|
| 58 | // "DVD " + (Integer.parseInt(update.connectionInfo |
|---|
| 59 | // .substring(update.connectionInfo |
|---|
| 60 | // .indexOf(":") + 1)) % 3000), |
|---|
| 61 | // dvdPanels.get(update.connectionInfo)); |
|---|
| 62 | |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | /** |
|---|
| 66 | * Updates the current DVDInfoPanel with the status update. If a panel does |
|---|
| 67 | * not current exist, create one and add a new tab. |
|---|
| 68 | * |
|---|
| 69 | * @param update DVD status update. |
|---|
| 70 | */ |
|---|
| 71 | public void updateDVDStatus(DVDStatusUpdate update) |
|---|
| 72 | { |
|---|
| 73 | if (dvdPanels.get(update.connectionInfo) == null) |
|---|
| 74 | { |
|---|
| 75 | dvdPanels.put(update.connectionInfo, new DVDInfoPanel( |
|---|
| 76 | update.connectionInfo)); |
|---|
| 77 | |
|---|
| 78 | mediaTabs.addTab( |
|---|
| 79 | "DVD " + (Integer.parseInt(update.connectionInfo |
|---|
| 80 | .substring(update.connectionInfo |
|---|
| 81 | .indexOf(":") + 1)) % 3000), |
|---|
| 82 | dvdPanels.get(update.connectionInfo)); |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | dvdPanels.get(update.connectionInfo).updateDVDStatus(update); |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | /** |
|---|
| 90 | * Updates the current DVDInfoPanel with the title update. If a panel does |
|---|
| 91 | * not current exist, create one and add a new tab. |
|---|
| 92 | * |
|---|
| 93 | * @param update DVD title update. |
|---|
| 94 | */ |
|---|
| 95 | public void updateDVDTitle(DVDTitleUpdate update) |
|---|
| 96 | { |
|---|
| 97 | if (dvdPanels.get(update.connectionInfo) == null) |
|---|
| 98 | { |
|---|
| 99 | dvdPanels.put(update.connectionInfo, new DVDInfoPanel(update.connectionInfo)); |
|---|
| 100 | |
|---|
| 101 | mediaTabs.addTab("DVD " + dvdPanels.size(), |
|---|
| 102 | dvdPanels.get(update.connectionInfo)); |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | dvdPanels.get(update.connectionInfo).updateDVDTitle(update); |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | /** |
|---|
| 109 | * Initialize GUI components. |
|---|
| 110 | */ |
|---|
| 111 | private void initComponents() |
|---|
| 112 | { |
|---|
| 113 | mediaTabs = new JTabbedPane(); |
|---|
| 114 | |
|---|
| 115 | add(mediaTabs); |
|---|
| 116 | } |
|---|
| 117 | private JTabbedPane mediaTabs; |
|---|
| 118 | } |
|---|