Ignore:
Timestamp:
04/20/2016 02:29:52 PM (10 years ago)
Author:
jdalbey
Message:

Multifile commit. Add version # to Paramics Communicator. Move Load button in Sim Mgr. Add several tests. Add package jars target.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/tmcsim/paramicscommunicator/gui/ParamicsCommunicatorGUI.java

    r2 r6  
    1111import java.util.logging.LogRecord; 
    1212import java.util.logging.Logger; 
    13  
    1413import javax.swing.BorderFactory; 
    1514import javax.swing.Box; 
    1615import javax.swing.BoxLayout; 
    1716import javax.swing.JFrame; 
     17import javax.swing.JMenuBar; 
     18import javax.swing.JOptionPane; 
    1819import javax.swing.JScrollPane; 
    1920import javax.swing.JTabbedPane; 
    2021import javax.swing.JTextArea; 
    21  
     22import tmcsim.common.RevisionNumber; 
    2223import tmcsim.paramicscommunicator.FileIOUpdate; 
    2324import tmcsim.paramicscommunicator.FileRegUpdate; 
    2425 
    2526/** 
    26  * ParamicsCommunicatorGUI is the view class for the ParamicsCommunicator. 
    27  * The user interface shows a tab for each I/O reader or writer that has 
    28  * been registered with the ParamicsCommunicator.  The tab shows the  
    29  * history of I/O reads and writes, and the unique information for the 
    30  * target file and I/O interval. 
    31  *  
     27 * ParamicsCommunicatorGUI is the view class for the ParamicsCommunicator. The 
     28 * user interface shows a tab for each I/O reader or writer that has been 
     29 * registered with the ParamicsCommunicator. The tab shows the history of I/O 
     30 * reads and writes, and the unique information for the target file and I/O 
     31 * interval. 
     32 * 
    3233 * @author Matthew Cechini 
    3334 * @version 
    3435 */ 
    3536@SuppressWarnings("serial") 
    36 public class ParamicsCommunicatorGUI extends JFrame implements Observer { 
    37      
    38     /** 
    39      * Logging handler that writes all received log records to the 
    40      * error text area. 
     37public class ParamicsCommunicatorGUI extends JFrame implements Observer 
     38{ 
     39 
     40    /** 
     41     * Logging handler that writes all received log records to the error text 
     42     * area. 
     43     * 
    4144     * @author Matthew Cechini 
    4245     */ 
    43     protected class ParamicsLoggerHandler extends Handler { 
     46    protected class ParamicsLoggerHandler extends Handler 
     47    { 
    4448 
    4549        DateFormat timeFormat = DateFormat.getTimeInstance(); 
    46          
    47         public void close() throws SecurityException { 
    48         } 
    49          
    50         public void flush() { 
    51         } 
    52          
    53         public void publish(LogRecord record) { 
     50 
     51        public void close() throws SecurityException 
     52        { 
     53        } 
     54 
     55        public void flush() 
     56        { 
     57        } 
     58 
     59        public void publish(LogRecord record) 
     60        { 
    5461            StringBuffer errorBuf = new StringBuffer(); 
    55              
     62 
    5663            errorBuf.append(timeFormat.format(new Date(record.getMillis()))); 
    57             errorBuf.append("  -  " + record.getMessage() + "\n");           
    58              
    59             errorTA.setText(errorTA.getText() + errorBuf.toString());  
    60         }        
    61     } 
    62  
    63     /** Map of FileIOTableModel objects for each reader id. */ 
     64            errorBuf.append("  -  " + record.getMessage() + "\n"); 
     65 
     66            errorTA.setText(errorTA.getText() + errorBuf.toString()); 
     67        } 
     68    } 
     69    /** 
     70     * Map of FileIOTableModel objects for each reader id. 
     71     */ 
    6472    protected TreeMap<String, FileIOTableModel> readerTables; 
    65  
    66     /** Map of FileIOTableModel objects for each writer id. */ 
     73    /** 
     74     * Map of FileIOTableModel objects for each writer id. 
     75     */ 
    6776    protected TreeMap<String, FileIOTableModel> writerTables; 
    68      
    69     /** 
    70      * Constructor.  Initialize local lists, set up the logging handler and 
     77 
     78    /** 
     79     * Constructor. Initialize local lists, set up the logging handler and 
    7180     * initialize the GUI. 
    7281     */ 
    73     public ParamicsCommunicatorGUI() {       
     82    public ParamicsCommunicatorGUI() 
     83    { 
    7484        super("Paramics Communicator"); 
    75          
     85 
    7686        readerTables = new TreeMap<String, FileIOTableModel>(); 
    7787        writerTables = new TreeMap<String, FileIOTableModel>(); 
    78          
     88 
    7989        Logger.getLogger("tmcsim.paramicscommunicator").addHandler(new ParamicsLoggerHandler()); 
    80          
     90 
    8191        initializeGUI(); 
    82     }    
    83      
    84     /** 
    85      * Observer update method.  If the update object is a FileIOUpdate object, 
    86      * update the TableModel corresponding to the unique I/O id.  If the 
    87      * update object is a FileRegUpdate object, add a new tab if the  
    88      * registration type is REGISTER, or update an existing tab if the 
    89      * registration type is UNREGISTER. 
    90      */ 
    91     public void update(Observable o, Object arg) { 
    92          
    93         if(arg instanceof FileIOUpdate) { 
    94  
    95             try { 
    96                 FileIOUpdate update = (FileIOUpdate)arg; 
    97                  
    98                 switch(update.ioType) { 
     92    } 
     93 
     94    /** 
     95     * Observer update method. If the update object is a FileIOUpdate object, 
     96     * update the TableModel corresponding to the unique I/O id. If the update 
     97     * object is a FileRegUpdate object, add a new tab if the registration type 
     98     * is REGISTER, or update an existing tab if the registration type is 
     99     * UNREGISTER. 
     100     */ 
     101    public void update(Observable o, Object arg) 
     102    { 
     103 
     104        if (arg instanceof FileIOUpdate) 
     105        { 
     106 
     107            try 
     108            { 
     109                FileIOUpdate update = (FileIOUpdate) arg; 
     110 
     111                switch (update.ioType) 
     112                { 
    99113                    case READ: 
    100114                        readerTables.get(update.ioID).addIOUpdate(update); 
     
    104118                        break; 
    105119                } 
    106             } 
    107             catch (Exception e) { 
     120            } catch (Exception e) 
     121            { 
    108122                Logger.getLogger("tmcsim.paramicscommunicator.gui").logp( 
    109                         Level.SEVERE, "ParamicsCommunicatorGUI", "update",  
     123                        Level.SEVERE, "ParamicsCommunicatorGUI", "update", 
    110124                        "Exception in receiving FileIOUpdate object.", e); 
    111125            } 
    112         } 
    113         else if(arg instanceof FileRegUpdate) { 
    114             try { 
    115                 FileRegUpdate update = (FileRegUpdate)arg; 
    116                  
    117                 switch(update.ioType) { 
     126        } else if (arg instanceof FileRegUpdate) 
     127        { 
     128            try 
     129            { 
     130                FileRegUpdate update = (FileRegUpdate) arg; 
     131 
     132                switch (update.ioType) 
     133                { 
    118134                    case READ: 
    119                         switch(update.regType) { 
     135                        switch (update.regType) 
     136                        { 
    120137                            case REGISTER: 
    121138                                FileIOTableModel model = new FileIOTableModel(); 
    122139                                readerTables.put(update.ioID, model); 
    123      
     140 
    124141                                addTab(update, model); 
    125142                                break; 
     
    130147                        break; 
    131148                    case WRITE: 
    132                         switch(update.regType) { 
     149                        switch (update.regType) 
     150                        { 
    133151                            case REGISTER: 
    134152                                FileIOTableModel model = new FileIOTableModel(); 
    135153                                writerTables.put(update.ioID, model); 
    136                                  
     154 
    137155                                addTab(update, model); 
    138156                                break; 
     
    140158                                //unregister 
    141159                                break; 
    142                         }                    
     160                        } 
    143161                        break; 
    144162                } 
    145163 
    146             } 
    147             catch (Exception e) { 
     164            } catch (Exception e) 
     165            { 
    148166                Logger.getLogger("tmcsim.paramicscommunicator.gui").logp( 
    149                         Level.SEVERE, "ParamicsCommunicatorGUI", "update",  
     167                        Level.SEVERE, "ParamicsCommunicatorGUI", "update", 
    150168                        "Exception in receiving FileRegUpdate object.", e); 
    151169            } 
    152         }        
    153     } 
    154      
    155     private void initializeGUI() { 
    156          
    157         /* Added by Nathaniel Lehrer */ 
    158         this.setJMenuBar(new javax.swing.JMenuBar() { 
    159             { 
    160                 javax.swing.JMenu fileMenu = new javax.swing.JMenu("File"); 
    161                 javax.swing.JMenuItem logItem = new javax.swing.JMenuItem("Show Log"); 
    162                  
    163                 logItem.addActionListener(new java.awt.event.ActionListener() { 
    164                     public void actionPerformed(java.awt.event.ActionEvent evt) { 
    165                         tmcsim.paramicslog.gui.ParamicsLogGUI.getInstance().display();  
    166                     } 
    167                 }); 
    168                  
    169                 fileMenu.add(logItem); 
    170                 this.add(fileMenu); 
     170        } 
     171    } 
     172 
     173    private void initializeGUI() 
     174    { 
     175 
     176        JMenuBar menuBar = new JMenuBar(); 
     177 
     178        javax.swing.JMenu fileMenu = new javax.swing.JMenu("File"); 
     179        javax.swing.JMenuItem logItem = new javax.swing.JMenuItem("Show Log"); 
     180 
     181        logItem.addActionListener(new java.awt.event.ActionListener() 
     182        { 
     183            public void actionPerformed(java.awt.event.ActionEvent evt) 
     184            { 
     185                tmcsim.paramicslog.gui.ParamicsLogGUI.getInstance().display(); 
    171186            } 
    172187        }); 
    173         /* End Add by Nathaniel Lehrer */ 
    174          
     188 
     189        fileMenu.add(logItem); 
     190        menuBar.add(fileMenu); 
     191 
     192        javax.swing.JMenu helpMenu = new javax.swing.JMenu("Help"); 
     193        javax.swing.JMenuItem aboutItem = new javax.swing.JMenuItem("About"); 
     194 
     195        aboutItem.addActionListener(new java.awt.event.ActionListener() 
     196        { 
     197            public void actionPerformed(java.awt.event.ActionEvent evt) 
     198            { 
     199                String ver = RevisionNumber.getString(); 
     200                JOptionPane.showMessageDialog(rootPane, "Version: " + ver, "About", JOptionPane.INFORMATION_MESSAGE); 
     201            } 
     202        }); 
     203 
     204        helpMenu.add(aboutItem); 
     205        menuBar.add(helpMenu); 
     206 
     207        this.setJMenuBar(menuBar); 
     208 
    175209        fileIOTabs = new JTabbedPane(); 
    176210        fileIOTabs.setAlignmentX(Box.CENTER_ALIGNMENT); 
     
    180214        fileIOTabs.setBorder(BorderFactory.createCompoundBorder( 
    181215                BorderFactory.createTitledBorder( 
    182                     BorderFactory.createRaisedBevelBorder(), "Registered I/O"), 
    183                     BorderFactory.createEmptyBorder(5,5,5,5))); 
    184      
     216                BorderFactory.createRaisedBevelBorder(), "Registered I/O"), 
     217                BorderFactory.createEmptyBorder(5, 5, 5, 5))); 
     218 
    185219        errorTA = new JTextArea(); 
    186220        errorTA.setLineWrap(true); 
    187          
     221 
    188222        errorPane = new JScrollPane(); 
    189223        errorPane.setViewportView(errorTA); 
     
    191225        errorPane.setBorder(BorderFactory.createCompoundBorder( 
    192226                BorderFactory.createTitledBorder( 
    193                     BorderFactory.createRaisedBevelBorder(), "Errors"), 
    194                     BorderFactory.createEmptyBorder(5,5,5,5))); 
    195          
    196          
     227                BorderFactory.createRaisedBevelBorder(), "Errors"), 
     228                BorderFactory.createEmptyBorder(5, 5, 5, 5))); 
     229 
     230 
    197231        Box guiBox = new Box(BoxLayout.Y_AXIS); 
    198232        guiBox.add(fileIOTabs); 
    199233        guiBox.add(Box.createVerticalStrut(10)); 
    200234        guiBox.add(errorPane); 
    201          
     235 
    202236        add(guiBox); 
    203          
     237 
    204238        setMinimumSize(new Dimension(420, 680)); 
    205239        setPreferredSize(new Dimension(420, 680)); 
     
    208242        setVisible(true); 
    209243    } 
    210      
    211     /** 
    212      * Method creates a new tab for the new I/O object.  The tab is labeled 
     244 
     245    /** 
     246     * Method creates a new tab for the new I/O object. The tab is labeled 
    213247     * "Reader #" or "Writer #", where '#' is the I/O object's ID. 
     248     * 
    214249     * @param update Initial update object. 
    215      * @param model TableModel for reader/writer that will display I/O operations. 
    216      */ 
    217     private void addTab(FileRegUpdate update, FileIOTableModel model) { 
    218          
     250     * @param model TableModel for reader/writer that will display I/O 
     251     * operations. 
     252     */ 
     253    private void addTab(FileRegUpdate update, FileIOTableModel model) 
     254    { 
     255 
    219256        String tabName = null; 
    220          
    221         switch(update.ioType) { 
     257 
     258        switch (update.ioType) 
     259        { 
    222260            case READ: 
    223261                tabName = "Reader " + update.ioID; 
     
    227265                break; 
    228266        } 
    229          
     267 
    230268        fileIOTabs.add(tabName, new ParamicsIOInfoPanel(update, model)); 
    231269    } 
    232      
    233270    private JTabbedPane fileIOTabs; 
    234  
    235271    private JScrollPane errorPane; 
    236      
    237272    private JTextArea errorTA; 
    238  
    239273} 
Note: See TracChangeset for help on using the changeset viewer.