Ignore:
Timestamp:
06/23/2016 06:30:20 PM (10 years ago)
Author:
jdalbey
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/tmcsim/cadsimulator/viewer/MediaStatusPanel.java

    r2 r44  
    11package tmcsim.cadsimulator.viewer; 
    22 
     3import java.util.Iterator; 
     4import java.util.Observable; 
    35import java.util.TreeMap; 
    4  
    56import javax.swing.JPanel; 
    67import javax.swing.JTabbedPane; 
    7  
    88import tmcsim.cadsimulator.videocontrol.DVDStatusUpdate; 
    99import tmcsim.cadsimulator.videocontrol.DVDTitleUpdate; 
     10import tmcsim.cadsimulator.viewer.model.CADMediaStatus; 
    1011 
    1112/** 
    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 
     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 
    2120 */ 
    2221@SuppressWarnings("serial") 
    23 public class MediaStatusPanel extends JPanel { 
    24      
    25     /** Map of DVDInfoPanels(values) referenced by a DVD's connection info(key). */ 
     22public class MediaStatusPanel extends JPanel 
     23{ 
     24 
     25    /** 
     26     * Map of DVDInfoPanels(values) referenced by a DVD's connection info(key). 
     27     */ 
    2628    private TreeMap<String, DVDInfoPanel> dvdPanels = null; 
    2729 
    2830    /** 
    29      * Constructor.  Initialize data and GUI components. 
     31     * Constructor. Initialize data and GUI components. 
    3032     */ 
    31     public MediaStatusPanel() { 
     33    public MediaStatusPanel() 
     34    { 
    3235 
    33         dvdPanels   = new TreeMap<String, DVDInfoPanel>(); 
    34          
     36        dvdPanels = new TreeMap<String, DVDInfoPanel>(); 
     37 
    3538        initComponents(); 
    3639    } 
    37      
     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 
    3865    /** 
    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      *  
     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     * 
    4369     * @param update DVD status update. 
    4470     */ 
    45     public void updateDVDStatus(DVDStatusUpdate update) { 
    46         if(dvdPanels.get(update.connectionInfo) == null) { 
     71    public void updateDVDStatus(DVDStatusUpdate update) 
     72    { 
     73        if (dvdPanels.get(update.connectionInfo) == null) 
     74        { 
    4775            dvdPanels.put(update.connectionInfo, new DVDInfoPanel( 
    4876                    update.connectionInfo)); 
     
    5078            mediaTabs.addTab( 
    5179                    "DVD " + (Integer.parseInt(update.connectionInfo 
    52                                     .substring(update.connectionInfo 
    53                                             .indexOf(":")+1)) % 3000),  
     80                    .substring(update.connectionInfo 
     81                    .indexOf(":") + 1)) % 3000), 
    5482                    dvdPanels.get(update.connectionInfo)); 
    5583        } 
    56          
    57          
     84 
     85 
    5886        dvdPanels.get(update.connectionInfo).updateDVDStatus(update); 
    5987    } 
    60      
     88 
    6189    /** 
    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      *  
     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     * 
    6693     * @param update DVD title update. 
    6794     */ 
    68     public void updateDVDTitle(DVDTitleUpdate update) { 
    69         if(dvdPanels.get(update.connectionInfo) == null) { 
     95    public void updateDVDTitle(DVDTitleUpdate update) 
     96    { 
     97        if (dvdPanels.get(update.connectionInfo) == null) 
     98        { 
    7099            dvdPanels.put(update.connectionInfo, new DVDInfoPanel(update.connectionInfo)); 
    71              
    72             mediaTabs.addTab("DVD " + dvdPanels.size(),  
     100 
     101            mediaTabs.addTab("DVD " + dvdPanels.size(), 
    73102                    dvdPanels.get(update.connectionInfo)); 
    74103        } 
    75          
     104 
    76105        dvdPanels.get(update.connectionInfo).updateDVDTitle(update); 
    77106    } 
    78      
     107 
    79108    /** 
    80109     * Initialize GUI components. 
    81110     */ 
    82     private void initComponents() { 
     111    private void initComponents() 
     112    { 
    83113        mediaTabs = new JTabbedPane(); 
    84          
     114 
    85115        add(mediaTabs); 
    86116    } 
    87      
    88117    private JTabbedPane mediaTabs; 
    89      
    90118} 
Note: See TracChangeset for help on using the changeset viewer.