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