source: tmcsimulator/trunk/src/tmcsim/cadsimulator/viewer/model/CADMediaStatus.java @ 44

Revision 44, 2.3 KB checked in by jdalbey, 10 years ago (diff)

MultiFile? commit: Add CADViewer Interface and change CADSimulator to Observer Pattern.

Line 
1package tmcsim.cadsimulator.viewer.model;
2
3import java.util.Iterator;
4import java.util.Observable;
5import java.util.TreeMap;
6import tmcsim.cadsimulator.videocontrol.DVDStatusUpdate;
7import tmcsim.cadsimulator.videocontrol.DVDTitleUpdate;
8import 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")
19public 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}
Note: See TracBrowser for help on using the repository browser.