Ignore:
Timestamp:
03/15/2017 10:20:21 AM (9 years ago)
Author:
jdalbey
Message:

Merge CAD Client updates for multiple incident view windows.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/tmcsim/client/cadclientgui/screens/CADMenu.java

    r40 r59  
    1313import java.awt.event.MouseListener; 
    1414import java.awt.event.MouseMotionListener; 
    15 import java.io.File; 
    1615import java.io.IOException; 
    1716import java.net.MalformedURLException; 
     
    2322import java.util.logging.Logger; 
    2423import javax.imageio.ImageIO; 
    25  
    2624import javax.swing.Box; 
    2725import javax.swing.BoxLayout; 
     
    3028import javax.swing.JFrame; 
    3129import javax.swing.JLabel; 
    32 import static javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE; 
    3330 
    3431/** 
     
    3936 * "CADMenuLayout" can also be found in the same folder showing how this class's 
    4037 * looks were made. 
    41  *  
     38 * 
    4239 * @author Vincent 
    43  *  
     40 * 
    4441 */ 
    45 public class CADMenu extends JFrame { 
    46  
     42public class CADMenu extends JFrame 
     43{ 
    4744    private final int ONE_SECOND = 1000; 
    48  
    4945    private DateFormat dateFormat; 
    50  
    5146    private Box mainPanel; 
    5247    private Box bottomRightIcons; 
     
    5651    private JLabel name; 
    5752    private JLabel userListName1; 
    58  
    5953    private JButton button1; 
    6054    private JButton button2; 
     
    6559    private JButton buttonTool; 
    6660    private JButton buttonMore; 
    67      
    6861    // the drop down menu when the "more button" is clicked. 
    6962    private JFrame moreMenu; 
    70  
    7163    // the drop down menu when the "tool button" is clicked. 
    7264    private JFrame toolMenu; 
    73  
    7465    private JButton buttonCheckmark; 
    7566    private JButton buttonMinus; 
    76  
    7767    private JLabel position; 
    7868 
     
    8070     * Constructor call. Creates the CADMenu. 
    8171     */ 
    82     public CADMenu() { 
     72    public CADMenu() 
     73    { 
    8374        initialize(); 
    8475        createTopPanel(); 
    8576        createBottomPanel(); 
    8677        createDropDownMenus(); 
    87          
     78 
    8879        initControllers(); 
    89          
     80 
    9081        getContentPane().add(mainPanel); 
    91  
    92         setTitle("Inform CAD"); 
    93         URL url = null; 
    94         try 
    95         { 
    96             url = new URL("http://i1030.photobucket.com/albums/y362/sendeva66/antclipart2.jpg"); 
    97         } catch (MalformedURLException ex) 
    98         { 
    99             Logger.getLogger(CADMenu.class.getName()).log(Level.SEVERE, "can't access url", ex); 
     82        setTitle("Inform CAD "); 
     83        // Load an image for the task bar icon --JD 
     84        // First try to get the image from a local file 
     85        ImageIcon coolIcon = new ImageIcon("images/CADMenuImages/US_101_icon.png"); 
     86        if (coolIcon.getIconWidth() >= 0) 
     87        { 
     88            setIconImage(coolIcon.getImage()); 
    10089        } 
    101         Image image = null; 
    102         try 
    103         { 
    104             image = ImageIO.read(url); 
    105             setIconImage(image); 
    106         } catch (IOException ex) 
    107         { 
    108             Logger.getLogger(CADMenu.class.getName()).log(Level.SEVERE, null, ex); 
     90        else // if no local file found, try a URL 
     91        { 
     92            URL url; 
     93            Image img = null; 
     94            try 
     95            { 
     96                String iconURL = "http://www.chicagonow.com/running-with-a-book-cart/files/2012/02/crosswalk1.jpg"; 
     97                url = new URL(iconURL); 
     98                img = ImageIO.read(url); 
     99                setIconImage(img); 
     100            } catch (MalformedURLException ex) 
     101            { 
     102                Logger.getLogger(CADMenu.class.getName()).log(Level.SEVERE, null, ex); 
     103            } catch (IOException ex) 
     104            { 
     105                Logger.getLogger(CADMenu.class.getName()).log(Level.SEVERE, null, ex); 
     106            } 
    109107        } 
    110         // Doesn't work: file path problem? 
    111 //        ImageIcon myIcon = new ImageIcon(getClass().getClassLoader().getResource("images/CADicon.png")); 
    112 //        setIconImage(myIcon.getImage()); 
    113108        setPreferredSize(new Dimension(1195, 178)); 
    114109        setResizable(true); 
     
    125120     * Initializes variables and connects the CADMenu to the CADMenuListener. 
    126121     */ 
    127     public void initialize() { 
     122    public void initialize() 
     123    { 
    128124        mainPanel = new Box(BoxLayout.Y_AXIS); 
    129125        mainPanel.setAlignmentX(LEFT_ALIGNMENT); 
     
    131127    } 
    132128 
    133     public void addListeners() { 
    134         addComponentListener(new ComponentListener() { 
    135             public void componentHidden(ComponentEvent e) { 
    136             } 
    137  
    138             public void componentMoved(ComponentEvent e) { 
     129    public void addListeners() 
     130    { 
     131        addComponentListener(new ComponentListener() 
     132        { 
     133            public void componentHidden(ComponentEvent e) 
     134            { 
     135            } 
     136 
     137            public void componentMoved(ComponentEvent e) 
     138            { 
    139139                closeToolMenu(); 
    140140                closeMoreMenu(); 
     
    142142            } 
    143143 
    144             public void componentResized(ComponentEvent e) { 
    145             } 
    146  
    147             public void componentShown(ComponentEvent e) { 
     144            public void componentResized(ComponentEvent e) 
     145            { 
     146            } 
     147 
     148            public void componentShown(ComponentEvent e) 
     149            { 
    148150            } 
    149151        }); 
    150         addMouseListener(new MouseListener() { 
    151             public void mouseClicked(MouseEvent arg0) { 
     152        addMouseListener(new MouseListener() 
     153        { 
     154            public void mouseClicked(MouseEvent arg0) 
     155            { 
    152156                closeToolMenu(); 
    153157                closeMoreMenu(); 
    154158            } 
    155159 
    156             public void mouseEntered(MouseEvent arg0) { 
    157             } 
    158  
    159             public void mouseExited(MouseEvent arg0) { 
    160             } 
    161  
    162             public void mousePressed(MouseEvent arg0) { 
    163             } 
    164  
    165             public void mouseReleased(MouseEvent arg0) { 
     160            public void mouseEntered(MouseEvent arg0) 
     161            { 
     162            } 
     163 
     164            public void mouseExited(MouseEvent arg0) 
     165            { 
     166            } 
     167 
     168            public void mousePressed(MouseEvent arg0) 
     169            { 
     170            } 
     171 
     172            public void mouseReleased(MouseEvent arg0) 
     173            { 
    166174            } 
    167175        }); 
    168176    } 
    169      
    170     public void initToolMenuListeners(){ 
    171         toolMenu.addMouseMotionListener(new MouseMotionListener() { 
    172             public void mouseDragged(MouseEvent e) { 
    173             } 
    174  
    175             public void mouseMoved(MouseEvent e) { 
     177 
     178    public void initToolMenuListeners() 
     179    { 
     180        toolMenu.addMouseMotionListener(new MouseMotionListener() 
     181        { 
     182            public void mouseDragged(MouseEvent e) 
     183            { 
     184            } 
     185 
     186            public void mouseMoved(MouseEvent e) 
     187            { 
    176188            } 
    177189        }); 
    178190 
    179         toolMenu.addMouseListener(new MouseListener() { 
    180             public void mouseEntered(MouseEvent e) { 
    181             } 
    182  
    183             public void mouseExited(MouseEvent e) { 
    184             } 
    185  
    186             public void mousePressed(MouseEvent e) { 
    187             } 
    188  
    189             public void mouseReleased(MouseEvent e) { 
    190             } 
    191  
    192             public void mouseClicked(MouseEvent e) { 
     191        toolMenu.addMouseListener(new MouseListener() 
     192        { 
     193            public void mouseEntered(MouseEvent e) 
     194            { 
     195            } 
     196 
     197            public void mouseExited(MouseEvent e) 
     198            { 
     199            } 
     200 
     201            public void mousePressed(MouseEvent e) 
     202            { 
     203            } 
     204 
     205            public void mouseReleased(MouseEvent e) 
     206            { 
     207            } 
     208 
     209            public void mouseClicked(MouseEvent e) 
     210            { 
    193211            } 
    194212        }); 
    195213    } 
    196      
    197     public void initMoreMenuListeners(){ 
    198         moreMenu.addMouseMotionListener(new MouseMotionListener() { 
    199             public void mouseDragged(MouseEvent e) { 
    200             } 
    201  
    202             public void mouseMoved(MouseEvent e) { 
     214 
     215    public void initMoreMenuListeners() 
     216    { 
     217        moreMenu.addMouseMotionListener(new MouseMotionListener() 
     218        { 
     219            public void mouseDragged(MouseEvent e) 
     220            { 
     221            } 
     222 
     223            public void mouseMoved(MouseEvent e) 
     224            { 
    203225                ImageIcon image = new ImageIcon( 
    204226                        "images/MoreMenuImages/moreMenu.png"); 
     
    206228                if (e.getLocationOnScreen().getY() >= moreMenu.getY() 
    207229                        && e.getLocationOnScreen().getY() <= moreMenu.getY() 
    208                                 + moreMenu.getHeight() / 8) { 
     230                        + moreMenu.getHeight() / 8) 
     231                { 
    209232                    image = new ImageIcon( 
    210233                            "images/MoreMenuImages/moreMenuHighlighted1.png"); 
    211                 } else if (e.getLocationOnScreen().getY() >= moreMenu.getY() 
     234                } 
     235                else if (e.getLocationOnScreen().getY() >= moreMenu.getY() 
    212236                        + moreMenu.getHeight() * 2 / 8 
    213237                        && e.getLocationOnScreen().getY() <= moreMenu.getY() 
    214                                 + moreMenu.getHeight() * 3 / 8) { 
     238                        + moreMenu.getHeight() * 3 / 8) 
     239                { 
    215240                    image = new ImageIcon( 
    216241                            "images/MoreMenuImages/moreMenuHighlighted3.png"); 
     
    223248        }); 
    224249 
    225         moreMenu.addMouseListener(new MouseListener() { 
    226             public void mouseEntered(MouseEvent e) { 
    227             } 
    228  
    229             public void mouseExited(MouseEvent e) { 
    230             } 
    231  
    232             public void mousePressed(MouseEvent e) { 
    233             } 
    234  
    235             public void mouseReleased(MouseEvent e) { 
    236             } 
    237  
    238             public void mouseClicked(MouseEvent e) { 
     250        moreMenu.addMouseListener(new MouseListener() 
     251        { 
     252            public void mouseEntered(MouseEvent e) 
     253            { 
     254            } 
     255 
     256            public void mouseExited(MouseEvent e) 
     257            { 
     258            } 
     259 
     260            public void mousePressed(MouseEvent e) 
     261            { 
     262            } 
     263 
     264            public void mouseReleased(MouseEvent e) 
     265            { 
     266            } 
     267 
     268            public void mouseClicked(MouseEvent e) 
     269            { 
    239270                if (e.getLocationOnScreen().getY() >= moreMenu.getY() 
    240271                        && e.getLocationOnScreen().getY() <= moreMenu.getY() 
    241                                 + moreMenu.getHeight() / 8) { 
     272                        + moreMenu.getHeight() / 8) 
     273                { 
    242274                    ScreenManager.openIncidentEditor(); 
    243275                    closeMoreMenu(); 
    244                 } else if (e.getLocationOnScreen().getY() >= moreMenu.getY() 
     276                } 
     277                else if (e.getLocationOnScreen().getY() >= moreMenu.getY() 
    245278                        + moreMenu.getHeight() * 2 / 8 
    246279                        && e.getLocationOnScreen().getY() <= moreMenu.getY() 
    247                                 + moreMenu.getHeight() * 3 / 8) { 
     280                        + moreMenu.getHeight() * 3 / 8) 
     281                { 
    248282                    ScreenManager.openCardfile(); 
    249283                    closeMoreMenu(); 
     
    252286        }); 
    253287    } 
    254      
    255     public void initControllers(){ 
     288 
     289    public void initControllers() 
     290    { 
    256291        addListeners(); 
    257292 
    258293        buttonTool.addActionListener(newToolActionListener()); 
    259294        buttonMore.addActionListener(newMoreActionListener()); 
    260          
     295 
    261296        initToolMenuListeners(); 
    262         initMoreMenuListeners();     
    263     } 
    264  
    265     public ActionListener newToolActionListener(){ 
    266         return new ActionListener() { 
    267             public void actionPerformed(ActionEvent arg0) { 
    268                 if (moreMenu.isVisible()) { 
     297        initMoreMenuListeners(); 
     298    } 
     299 
     300    public ActionListener newToolActionListener() 
     301    { 
     302        return new ActionListener() 
     303        { 
     304            public void actionPerformed(ActionEvent arg0) 
     305            { 
     306                if (moreMenu.isVisible()) 
     307                { 
    269308                    closeMoreMenu(); 
    270309                } 
    271                 if (toolMenu.isVisible()) { 
     310                if (toolMenu.isVisible()) 
     311                { 
    272312                    closeToolMenu(); 
    273                 } else { 
     313                } 
     314                else 
     315                { 
    274316                    toolMenu.setLocation(new Point(getX() + getWidth() 
    275317                            - toolMenu.getWidth(), getY() + 85)); 
     
    279321        }; 
    280322    } 
    281      
    282     public ActionListener newMoreActionListener(){ 
    283         return new ActionListener() { 
    284             public void actionPerformed(ActionEvent arg0) { 
    285                 if (toolMenu.isVisible()) { 
     323 
     324    public ActionListener newMoreActionListener() 
     325    { 
     326        return new ActionListener() 
     327        { 
     328            public void actionPerformed(ActionEvent arg0) 
     329            { 
     330                if (toolMenu.isVisible()) 
     331                { 
    286332                    closeToolMenu(); 
    287333                } 
    288                 if (moreMenu.isVisible()) { 
     334                if (moreMenu.isVisible()) 
     335                { 
    289336                    closeMoreMenu(); 
    290                 } else { 
     337                } 
     338                else 
     339                { 
    291340                    moreMenu.setLocation(new Point(getX() + getWidth() 
    292341                            - moreMenu.getWidth(), getY() + 85)); 
     
    296345        }; 
    297346    } 
    298      
     347 
    299348    /* 
    300349     * Creates the topPanel for the CADMenu. 
    301350     */ 
    302     public void createTopPanel() { 
     351    public void createTopPanel() 
     352    { 
    303353 
    304354        Box topPanel = new Box(BoxLayout.X_AXIS); 
     
    390440     * Creates the bottomPanel of the CADMenu. 
    391441     */ 
    392     public void createBottomPanel() { 
     442    public void createBottomPanel() 
     443    { 
    393444        Color grayBackground = new Color(100, 100, 100); 
    394445 
     
    477528     * Creates the two bottom right buttons. 
    478529     */ 
    479     public void createBottomRightButtons() { 
     530    public void createBottomRightButtons() 
     531    { 
    480532        bottomRightButtonsGrayed = new Box(BoxLayout.X_AXIS); 
    481533        ImageIcon image = new ImageIcon( 
     
    502554     * buttons 
    503555     */ 
    504     public void createDropDownMenus() { 
     556    public void createDropDownMenus() 
     557    { 
    505558 
    506559        ImageIcon image = new ImageIcon("images/ToolMenuImages/toolMenu.png"); 
     
    524577     * Takes in the name of the user and displays it. 
    525578     */ 
    526     public void setName(String username) { 
     579    public void setName(String username) 
     580    { 
    527581        name.setText(username); 
    528582        userListName1.setText(username); 
    529583    } 
    530  
     584    /** 
     585     * Accessor to the user's name (for use in IncidentViewer comments 
     586     */ 
     587    public String getName() 
     588    { 
     589        return name.getText(); 
     590    } 
     591     
    531592    /** 
    532593     * Factory method. Makes a JButton with an image and listener. 
    533      *  
    534      * @param image 
    535      *            the image this button will display. 
    536      * @param listener 
    537      *            the action listener for this button. 
     594     * 
     595     * @param image the image this button will display. 
     596     * @param listener the action listener for this button. 
    538597     * @return the JButton. 
    539598     */ 
    540     public JButton makeButton(ImageIcon image) { 
     599    public JButton makeButton(ImageIcon image) 
     600    { 
    541601        JButton button = new JButton(image); 
    542602        Dimension size = new Dimension(image.getImage().getWidth(null), image 
     
    555615     * highlighted rows). 
    556616     */ 
    557     public void closeToolMenu() { 
     617    public void closeToolMenu() 
     618    { 
    558619        ImageIcon image; 
    559620        JLabel menu; 
     
    570631     * highlighted rows). 
    571632     */ 
    572     public void closeMoreMenu() { 
     633    public void closeMoreMenu() 
     634    { 
    573635        ImageIcon image; 
    574636        JLabel menu; 
     
    585647     * time every second. 
    586648     */ 
    587     public void handleUpdateTime() { 
     649    public void handleUpdateTime() 
     650    { 
    588651        Date date = new Date(); 
    589652        String dateTime = dateFormat.format(date); 
     
    594657     * Makes screen visible. 
    595658     */ 
    596     public void open() { 
     659    public void open() 
     660    { 
    597661        setVisible(true); 
    598662    } 
     
    601665     * Hides screen. 
    602666     */ 
    603     public void close() { 
     667    public void close() 
     668    { 
    604669        setVisible(false); 
    605670    } 
     
    608673     * Currently not used. 
    609674     */ 
    610     public void setIncomingIncident() { 
     675    public void setIncomingIncident() 
     676    { 
    611677        bottomRightIcons.remove(bottomRightButtonsGrayed); 
    612678        bottomRightIcons.add(bottomRightButtonsColored); 
     
    618684     * Currently not used. 
    619685     */ 
    620     public void endIncomingIncident() { 
     686    public void endIncomingIncident() 
     687    { 
    621688        bottomRightIcons.remove(bottomRightButtonsColored); 
    622689        bottomRightIcons.add(bottomRightButtonsGrayed); 
     
    628695     * Sets position title to trainee. 
    629696     */ 
    630     public void removeDispatcherStatus() { 
     697    public void removeDispatcherStatus() 
     698    { 
    631699        position.setText("Trainee"); 
    632700    } 
    633  
    634701} 
Note: See TracChangeset for help on using the changeset viewer.