Changeset 24 in tmcsimulator for trunk/src


Ignore:
Timestamp:
04/26/2016 07:26:04 AM (10 years ago)
Author:
jdalbey
Message:

CADSimulatorViewer - Add accelerator key to Exit menu item, and remove confirmation prompting when Exit chosen.

Location:
trunk/src/tmcsim/cadsimulator/viewer
Files:
2 edited

Legend:

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

    r8 r24  
    33import java.awt.AWTEvent; 
    44import java.awt.Dimension; 
     5import java.awt.event.ActionEvent; 
     6import java.awt.event.KeyEvent; 
    57import java.awt.event.WindowEvent; 
    6  
    78import javax.swing.JFrame; 
    89import javax.swing.JMenu; 
     
    1112import javax.swing.JOptionPane; 
    1213import javax.swing.JTabbedPane; 
    13  
     14import javax.swing.KeyStroke; 
    1415import tmcsim.cadsimulator.videocontrol.DVDStatusUpdate; 
    1516import tmcsim.cadsimulator.videocontrol.DVDTitleUpdate; 
     
    2021 
    2122/** 
    22  * This class provides a GUI to view current status information for the 
    23  * CAD Simulator. 
     23 * This class provides a GUI to view current status information for the CAD 
     24 * Simulator. 
    2425 * 
    2526 * @see SimulationStatusPanel 
    2627 * @see MediaStatusPanel 
    27  * @author Matthew Cechini  
     28 * @author Matthew Cechini 
    2829 * @version $Revision: 1.3 $ $Date: 2006/06/06 20:46:41 $ 
    2930 */ 
    3031@SuppressWarnings("serial") 
    31 public class CADSimulatorViewer extends JFrame { 
    32  
    33     /** Panel to display simulation information. */ 
     32public class CADSimulatorViewer extends JFrame 
     33{ 
     34 
     35    /** 
     36     * Panel to display simulation information. 
     37     */ 
    3438    private SimulationStatusPanel simulationPanel; 
    35      
    36     /** Panel to display media control information. */ 
     39    /** 
     40     * Panel to display media control information. 
     41     */ 
    3742    private MediaStatusPanel mediaPanel; 
    38      
    39     /** Constructor. */ 
    40     public CADSimulatorViewer() { 
     43 
     44    /** 
     45     * Constructor. 
     46     */ 
     47    public CADSimulatorViewer() 
     48    { 
    4149        super("CAD Simulator"); 
    42          
     50 
    4351        initComponents(); 
    44     }     
    45      
    46     /**  
    47      * @see SimulationStatusPanel 
    48      */ 
    49     public void connectClient() { 
     52    } 
     53 
     54    /** 
     55     * @see SimulationStatusPanel 
     56     */ 
     57    public void connectClient() 
     58    { 
    5059        simulationPanel.connectClient(); 
    5160    } 
    52      
    53     /**  
    54      * @see SimulationStatusPanel 
    55      */ 
    56     public void disconnectClient() { 
     61 
     62    /** 
     63     * @see SimulationStatusPanel 
     64     */ 
     65    public void disconnectClient() 
     66    { 
    5767        simulationPanel.disconnectClient(); 
    5868    } 
    59      
    60     /**  
    61      * @see SimulationStatusPanel 
    62      */ 
    63     public void setSimManagerStatus(boolean connection) { 
    64         simulationPanel.setSimManagerStatus(connection);         
    65     } 
    66      
    67     /**  
    68      * @see SimulationStatusPanel 
    69      */ 
    70     public void setTime(long seconds) { 
     69 
     70    /** 
     71     * @see SimulationStatusPanel 
     72     */ 
     73    public void setSimManagerStatus(boolean connection) 
     74    { 
     75        simulationPanel.setSimManagerStatus(connection); 
     76    } 
     77 
     78    /** 
     79     * @see SimulationStatusPanel 
     80     */ 
     81    public void setTime(long seconds) 
     82    { 
    7183        simulationPanel.setTime(seconds); 
    7284    } 
    7385 
    74     /**  
    75      * @see SimulationStatusPanel 
    76      */ 
    77     public void setScriptStatus(SCRIPT_STATUS newStatus) { 
    78         simulationPanel.setScriptStatus(newStatus);          
    79     } 
    80      
    81     /**  
    82      * @see SimulationStatusPanel 
    83      */ 
    84     public void setParamicsStatus(PARAMICS_STATUS newStatus) { 
    85         simulationPanel.setParamicsStatus(newStatus);        
    86     } 
    87      
    88     /**  
    89      * @see SimulationStatusPanel 
    90      */ 
    91     public void setParamicsNetworkLoaded(String networkID) { 
    92         simulationPanel.setParamicsNetworkLoaded(networkID);         
    93     } 
    94  
    95     /**  
     86    /** 
     87     * @see SimulationStatusPanel 
     88     */ 
     89    public void setScriptStatus(SCRIPT_STATUS newStatus) 
     90    { 
     91        simulationPanel.setScriptStatus(newStatus); 
     92    } 
     93 
     94    /** 
     95     * @see SimulationStatusPanel 
     96     */ 
     97    public void setParamicsStatus(PARAMICS_STATUS newStatus) 
     98    { 
     99        simulationPanel.setParamicsStatus(newStatus); 
     100    } 
     101 
     102    /** 
     103     * @see SimulationStatusPanel 
     104     */ 
     105    public void setParamicsNetworkLoaded(String networkID) 
     106    { 
     107        simulationPanel.setParamicsNetworkLoaded(networkID); 
     108    } 
     109 
     110    /** 
    96111     * @see MediaStatusPanel 
    97112     */ 
    98     public void updateDVDStatus(DVDStatusUpdate update) { 
     113    public void updateDVDStatus(DVDStatusUpdate update) 
     114    { 
    99115        mediaPanel.updateDVDStatus(update); 
    100116    } 
    101117 
    102     /**  
     118    /** 
    103119     * @see MediaStatusPanel 
    104120     */ 
    105     public void updateDVDTitle(DVDTitleUpdate update) { 
     121    public void updateDVDTitle(DVDTitleUpdate update) 
     122    { 
    106123        mediaPanel.updateDVDTitle(update); 
    107124    } 
    108      
    109     /** 
    110      * Method calls the processEvent() method with a WINDOW_CLOSING 
    111      * WindowEvent to start the application closing process. 
    112      */ 
    113     public void closeViewer() { 
     125 
     126    /** 
     127     * Method calls the processEvent() method with a WINDOW_CLOSING WindowEvent 
     128     * to start the application closing process. 
     129     */ 
     130    public void closeViewer() 
     131    { 
    114132        processEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)); 
    115133    } 
    116134 
    117135    /** 
    118      * Overloads the processEvent method.  If the AWTEvent is a  
    119      * WINDOW_CLOSING event, prompt the user to confirm the action. 
    120      * If confirmed, close the application. 
    121      */ 
    122     protected void processEvent(AWTEvent evt) { 
    123          
    124         if(evt.getID() == WindowEvent.WINDOW_CLOSING) { 
     136     * Overloads the processEvent method. If the AWTEvent is a WINDOW_CLOSING 
     137     * event, prompt the user to confirm the action. If confirmed, close the 
     138     * application. 
     139     */ 
     140    protected void processEvent(AWTEvent evt) 
     141    { 
     142 
     143        if (evt.getID() == WindowEvent.WINDOW_CLOSING) 
     144        { 
    125145            int option = JOptionPane.showConfirmDialog(null, 
    126                     "Closing the CAD Simulator will stop the current " + 
    127                     "simulation.  Do you wish to continue exiting?", 
     146                    "Closing the CAD Simulator will stop the current " 
     147                    + "simulation.  Do you wish to continue exiting?", 
    128148                    "Confirm Exit", 
    129149                    JOptionPane.YES_NO_OPTION); 
    130              
    131             if(option != JOptionPane.NO_OPTION) { 
     150 
     151            if (option != JOptionPane.NO_OPTION) 
     152            { 
    132153                System.exit(0); 
    133             }        
     154            } 
    134155        } 
    135      } 
    136      
    137     /** Initialize GUI Components */ 
    138     private void initComponents() { 
    139  
    140          
     156    } 
     157 
     158    /** 
     159     * Initialize GUI Components 
     160     */ 
     161    private void initComponents() 
     162    { 
     163 
     164 
    141165        simulationPanel = new SimulationStatusPanel(); 
    142         mediaPanel      = new MediaStatusPanel(); 
    143          
     166        mediaPanel = new MediaStatusPanel(); 
     167 
    144168        cadSimTabbedPane = new JTabbedPane(); 
    145169        cadSimTabbedPane.addTab("Status", simulationPanel); 
    146170        cadSimTabbedPane.addTab("Media", mediaPanel); 
    147          
    148         add(cadSimTabbedPane);       
     171 
     172        add(cadSimTabbedPane); 
    149173 
    150174        menubar = new JMenuBar(); 
    151          
     175 
    152176        fileMenu = new JMenu("File"); 
     177        fileMenu.setMnemonic(KeyEvent.VK_F); 
    153178        menubar.add(fileMenu); 
    154          
     179 
    155180        exitMenuItem = new JMenuItem(new ExitAction(this)); 
     181        exitMenuItem.setAccelerator(KeyStroke.getKeyStroke( 
     182                KeyEvent.VK_X, ActionEvent.ALT_MASK)); 
    156183        fileMenu.add(exitMenuItem); 
    157          
     184 
    158185        javax.swing.JMenu helpMenu = new javax.swing.JMenu("Help"); 
    159186        javax.swing.JMenuItem aboutItem = new javax.swing.JMenuItem("About"); 
     
    169196        helpMenu.add(aboutItem); 
    170197        menubar.add(helpMenu); 
    171          
     198 
    172199        setJMenuBar(menubar); 
    173          
    174         setPreferredSize(new Dimension(500, 575));   
     200 
     201        setPreferredSize(new Dimension(500, 575)); 
    175202        pack(); 
    176203        setResizable(false); 
    177204    } 
    178      
    179      
    180205    private JTabbedPane cadSimTabbedPane; 
    181      
    182206    private JMenuBar menubar; 
    183      
    184207    private JMenu fileMenu; 
    185      
    186208    private JMenuItem exitMenuItem; 
    187      
    188209} 
  • trunk/src/tmcsim/cadsimulator/viewer/actions/ExitAction.java

    r2 r24  
    22 
    33import java.awt.event.ActionEvent; 
    4  
    54import javax.swing.AbstractAction; 
    6  
    75import tmcsim.cadsimulator.viewer.CADSimulatorViewer; 
    86 
    97/** 
    10  * Abstract action to exit the CADSimulator. When the action is performed 
    11  * the CADSimulatorView.closeViewer() method is called. 
    12  *   
     8 * Abstract action to exit the CADSimulator. When the action is performed the 
     9 * CADSimulatorView.closeViewer() method is called. 
     10 * 
    1311 * @author Matthew Cechini 
    14  * @version  
     12 * @version 
    1513 */ 
    1614@SuppressWarnings("serial") 
    17 public class ExitAction extends AbstractAction { 
     15public class ExitAction extends AbstractAction 
     16{ 
    1817 
    19     /** Reference to the CADSimulatorViewer. */ 
     18    /** 
     19     * Reference to the CADSimulatorViewer. 
     20     */ 
    2021    private CADSimulatorViewer theViewer; 
    2122 
    22     public ExitAction(CADSimulatorViewer viewer) { 
     23    public ExitAction(CADSimulatorViewer viewer) 
     24    { 
    2325        super("Exit"); 
    24          
     26 
    2527        theViewer = viewer; 
    2628    } 
    27      
    28     public void actionPerformed(ActionEvent arg0) {      
    29         theViewer.closeViewer(); 
     29 
     30    public void actionPerformed(ActionEvent arg0) 
     31    { 
     32        //theViewer.closeViewer(); 
     33        /* closeViewer() will prompt the user for confirmation. 
     34         * 26 Apr 2016 I'm tired of seeing the confirmation message, 
     35         * so if the user chooses File>Exit, assume they intend to exit 
     36         * and don't ask for confirmation.  If they click window close 
     37         * button, they will still get the confirmation prompt. jdalbey 
     38         */ 
     39        System.exit(0); 
    3040    } 
    31  
    3241} 
Note: See TracChangeset for help on using the changeset viewer.