source: tmcsimulator/trunk/src/tmcsim/client/cadclientgui/screens/CADMenu.java @ 38

Revision 38, 19.4 KB checked in by jdalbey, 10 years ago (diff)

CADMenu.java: changed default window close operation to EXIT.

Line 
1package tmcsim.client.cadclientgui.screens;
2
3import java.awt.Color;
4import java.awt.Dimension;
5import java.awt.Font;
6import java.awt.Point;
7import java.awt.event.ActionEvent;
8import java.awt.event.ActionListener;
9import java.awt.event.ComponentEvent;
10import java.awt.event.ComponentListener;
11import java.awt.event.MouseEvent;
12import java.awt.event.MouseListener;
13import java.awt.event.MouseMotionListener;
14import java.text.DateFormat;
15import java.text.SimpleDateFormat;
16import java.util.Date;
17
18import javax.swing.Box;
19import javax.swing.BoxLayout;
20import javax.swing.ImageIcon;
21import javax.swing.JButton;
22import javax.swing.JFrame;
23import javax.swing.JLabel;
24import static javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE;
25
26/**
27 * The main CADMenu with buttons to open up other screens. This class uses
28 * mostly images to build from, and java gui does not allow those images to be
29 * editable here, so all the images' pixels are predefined in the images
30 * themselves. The images can be found in the images folder. An image called
31 * "CADMenuLayout" can also be found in the same folder showing how this class's
32 * looks were made.
33 *
34 * @author Vincent
35 *
36 */
37public class CADMenu extends JFrame {
38
39    private final int ONE_SECOND = 1000;
40
41    private DateFormat dateFormat;
42
43    private Box mainPanel;
44    private Box bottomRightIcons;
45    private Box bottomRightButtonsGrayed;
46    private Box bottomRightButtonsColored;
47    private JLabel dateAndTime;
48    private JLabel name;
49    private JLabel userListName1;
50
51    private JButton button1;
52    private JButton button2;
53    private JButton button3;
54    private JButton button4;
55    private JButton button5;
56    private JButton button6;
57    private JButton buttonTool;
58    private JButton buttonMore;
59   
60    // the drop down menu when the "more button" is clicked.
61    private JFrame moreMenu;
62
63    // the drop down menu when the "tool button" is clicked.
64    private JFrame toolMenu;
65
66    private JButton buttonCheckmark;
67    private JButton buttonMinus;
68
69    private JLabel position;
70
71    /**
72     * Constructor call. Creates the CADMenu.
73     */
74    public CADMenu() {
75        initialize();
76        createTopPanel();
77        createBottomPanel();
78        createDropDownMenus();
79       
80        initControllers();
81       
82        getContentPane().add(mainPanel);
83
84        setTitle("Inform CAD");
85        setPreferredSize(new Dimension(1195, 178));
86        setResizable(true);
87        setFocusable(true);
88        pack();
89        //  Unsure why this was "do nothing" because it prevents the Menu frame
90        //  from closing so the user can't terminate the application.
91        //        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
92        setDefaultCloseOperation(EXIT_ON_CLOSE);
93        setVisible(false);
94    }
95
96    /**
97     * Initializes variables and connects the CADMenu to the CADMenuListener.
98     */
99    public void initialize() {
100        mainPanel = new Box(BoxLayout.Y_AXIS);
101        mainPanel.setAlignmentX(LEFT_ALIGNMENT);
102        dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
103    }
104
105    public void addListeners() {
106        addComponentListener(new ComponentListener() {
107            public void componentHidden(ComponentEvent e) {
108            }
109
110            public void componentMoved(ComponentEvent e) {
111                closeToolMenu();
112                closeMoreMenu();
113                setLocation(getLocation());
114            }
115
116            public void componentResized(ComponentEvent e) {
117            }
118
119            public void componentShown(ComponentEvent e) {
120            }
121        });
122        addMouseListener(new MouseListener() {
123            public void mouseClicked(MouseEvent arg0) {
124                closeToolMenu();
125                closeMoreMenu();
126            }
127
128            public void mouseEntered(MouseEvent arg0) {
129            }
130
131            public void mouseExited(MouseEvent arg0) {
132            }
133
134            public void mousePressed(MouseEvent arg0) {
135            }
136
137            public void mouseReleased(MouseEvent arg0) {
138            }
139        });
140    }
141   
142    public void initToolMenuListeners(){
143        toolMenu.addMouseMotionListener(new MouseMotionListener() {
144            public void mouseDragged(MouseEvent e) {
145            }
146
147            public void mouseMoved(MouseEvent e) {
148            }
149        });
150
151        toolMenu.addMouseListener(new MouseListener() {
152            public void mouseEntered(MouseEvent e) {
153            }
154
155            public void mouseExited(MouseEvent e) {
156            }
157
158            public void mousePressed(MouseEvent e) {
159            }
160
161            public void mouseReleased(MouseEvent e) {
162            }
163
164            public void mouseClicked(MouseEvent e) {
165            }
166        });
167    }
168   
169    public void initMoreMenuListeners(){
170        moreMenu.addMouseMotionListener(new MouseMotionListener() {
171            public void mouseDragged(MouseEvent e) {
172            }
173
174            public void mouseMoved(MouseEvent e) {
175                ImageIcon image = new ImageIcon(
176                        "images/MoreMenuImages/moreMenu.png");
177                JLabel menu;
178                if (e.getLocationOnScreen().getY() >= moreMenu.getY()
179                        && e.getLocationOnScreen().getY() <= moreMenu.getY()
180                                + moreMenu.getHeight() / 8) {
181                    image = new ImageIcon(
182                            "images/MoreMenuImages/moreMenuHighlighted1.png");
183                } else if (e.getLocationOnScreen().getY() >= moreMenu.getY()
184                        + moreMenu.getHeight() * 2 / 8
185                        && e.getLocationOnScreen().getY() <= moreMenu.getY()
186                                + moreMenu.getHeight() * 3 / 8) {
187                    image = new ImageIcon(
188                            "images/MoreMenuImages/moreMenuHighlighted3.png");
189                }
190                menu = new JLabel(image);
191                moreMenu.getContentPane().removeAll();
192                moreMenu.getContentPane().add(menu);
193                moreMenu.validate();
194            }
195        });
196
197        moreMenu.addMouseListener(new MouseListener() {
198            public void mouseEntered(MouseEvent e) {
199            }
200
201            public void mouseExited(MouseEvent e) {
202            }
203
204            public void mousePressed(MouseEvent e) {
205            }
206
207            public void mouseReleased(MouseEvent e) {
208            }
209
210            public void mouseClicked(MouseEvent e) {
211                if (e.getLocationOnScreen().getY() >= moreMenu.getY()
212                        && e.getLocationOnScreen().getY() <= moreMenu.getY()
213                                + moreMenu.getHeight() / 8) {
214                    ScreenManager.openIncidentEditor();
215                    closeMoreMenu();
216                } else if (e.getLocationOnScreen().getY() >= moreMenu.getY()
217                        + moreMenu.getHeight() * 2 / 8
218                        && e.getLocationOnScreen().getY() <= moreMenu.getY()
219                                + moreMenu.getHeight() * 3 / 8) {
220                    ScreenManager.openCardfile();
221                    closeMoreMenu();
222                }
223            }
224        });
225    }
226   
227    public void initControllers(){
228        addListeners();
229
230        buttonTool.addActionListener(newToolActionListener());
231        buttonMore.addActionListener(newMoreActionListener());
232       
233        initToolMenuListeners();
234        initMoreMenuListeners();   
235    }
236
237    public ActionListener newToolActionListener(){
238        return new ActionListener() {
239            public void actionPerformed(ActionEvent arg0) {
240                if (moreMenu.isVisible()) {
241                    closeMoreMenu();
242                }
243                if (toolMenu.isVisible()) {
244                    closeToolMenu();
245                } else {
246                    toolMenu.setLocation(new Point(getX() + getWidth()
247                            - toolMenu.getWidth(), getY() + 85));
248                    toolMenu.setVisible(true);
249                }
250            }
251        };
252    }
253   
254    public ActionListener newMoreActionListener(){
255        return new ActionListener() {
256            public void actionPerformed(ActionEvent arg0) {
257                if (toolMenu.isVisible()) {
258                    closeToolMenu();
259                }
260                if (moreMenu.isVisible()) {
261                    closeMoreMenu();
262                } else {
263                    moreMenu.setLocation(new Point(getX() + getWidth()
264                            - moreMenu.getWidth(), getY() + 85));
265                    moreMenu.setVisible(true);
266                }
267            }
268        };
269    }
270   
271    /*
272     * Creates the topPanel for the CADMenu.
273     */
274    public void createTopPanel() {
275
276        Box topPanel = new Box(BoxLayout.X_AXIS);
277        topPanel.setAlignmentX(LEFT_ALIGNMENT);
278
279        ImageIcon image = new ImageIcon("images/CADMenuImages/tritech.png");
280        JLabel tritech = new JLabel(image);
281        topPanel.add(tritech);
282
283        image = new ImageIcon("images/CADMenuImages/empty.png");
284        JLabel empty = new JLabel(image);
285        topPanel.add(empty);
286
287        // center holds the User's Name, user's position, and date/time
288        Box center = new Box(BoxLayout.Y_AXIS);
289        image = new ImageIcon("images/CADMenuImages/top.png");
290
291        name = new JLabel(image);
292        name.setText("User");
293        name.setFont(new Font("SanSerif", Font.BOLD, 16));
294        name.setForeground(Color.WHITE);
295        name.setHorizontalTextPosition(JLabel.CENTER);
296        center.add(name);
297
298        Box centerBottom = new Box(BoxLayout.X_AXIS);
299        centerBottom.setAlignmentX(Box.LEFT_ALIGNMENT);
300
301        image = new ImageIcon("images/CADMenuImages/bottom.png");
302        position = new JLabel(image);
303        position.setText("Public Safety Dispatch Sup");
304        position.setFont(new Font("Arial", Font.PLAIN, 12));
305        position.setForeground(new Color(190, 210, 255));
306        position.setHorizontalTextPosition(JLabel.CENTER);
307        centerBottom.add(position);
308
309        image = new ImageIcon("images/CADMenuImages/bottom.png");
310        Date date = new Date();
311        DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
312        String dateTime = dateFormat.format(date);
313        dateAndTime = new JLabel(image);
314        dateAndTime.setText(dateTime);
315        dateAndTime.setForeground(Color.WHITE);
316        dateAndTime.setHorizontalTextPosition(JLabel.CENTER);
317        centerBottom.add(dateAndTime);
318        center.add(centerBottom);
319
320        topPanel.add(center);
321
322        image = new ImageIcon("images/CADMenuImages/empty2.png");
323        JLabel empty2 = new JLabel(image);
324        topPanel.add(empty2);
325
326        image = new ImageIcon("images/CADMenuImages/button1.png");
327        button1 = makeButton(image);
328        topPanel.add(button1);
329
330        image = new ImageIcon("images/CADMenuImages/button2.png");
331        button2 = makeButton(image);
332        topPanel.add(button2);
333
334        image = new ImageIcon("images/CADMenuImages/button3.png");
335        button3 = makeButton(image);
336        topPanel.add(button3);
337
338        image = new ImageIcon("images/CADMenuImages/button4.png");
339        button4 = makeButton(image);
340        topPanel.add(button4);
341
342        image = new ImageIcon("images/CADMenuImages/button5.png");
343        button5 = makeButton(image);
344        topPanel.add(button5);
345
346        image = new ImageIcon("images/CADMenuImages/button6.png");
347        button6 = makeButton(image);
348        topPanel.add(button6);
349
350        image = new ImageIcon("images/CADMenuImages/button7.png");
351        buttonTool = makeButton(image);
352        topPanel.add(buttonTool);
353
354        image = new ImageIcon("images/CADMenuImages/button8.png");
355        buttonMore = makeButton(image);
356        topPanel.add(buttonMore);
357
358        mainPanel.add(topPanel);
359    }
360
361    /**
362     * Creates the bottomPanel of the CADMenu.
363     */
364    public void createBottomPanel() {
365        Color grayBackground = new Color(100, 100, 100);
366
367        Box userList = new Box(BoxLayout.Y_AXIS);
368        userList.setAlignmentX(LEFT_ALIGNMENT);
369
370        Dimension size = new Dimension(400, 85);
371        userList.setPreferredSize(size);
372        userList.setMaximumSize(size);
373        userList.setMinimumSize(size);
374        userList.setBackground(grayBackground);
375        userList.setOpaque(true);
376
377        Box user1 = new Box(BoxLayout.X_AXIS);
378        user1.setAlignmentX(LEFT_ALIGNMENT);
379
380        ImageIcon image = new ImageIcon("images/CADMenuImages/mailClose.png");
381        JLabel userListIcon1 = new JLabel(image);
382        userListName1 = new JLabel("User");
383        userListName1.setForeground(Color.WHITE);
384        userListName1.setBackground(grayBackground);
385        userListName1.setOpaque(true);
386        JLabel userListNumbers = new JLabel(
387                "<html><font color=white>(</font><font color=red>0</font><font color=white>,0,0)</font></html>");
388        userListNumbers.setBackground(grayBackground);
389        userListNumbers.setOpaque(true);
390
391        user1.add(userListIcon1);
392        user1.add(userListName1);
393        user1.add(userListNumbers);
394        userList.add(user1);
395
396        Box user2 = new Box(BoxLayout.X_AXIS);
397        user2.setAlignmentX(LEFT_ALIGNMENT);
398
399        image = new ImageIcon("images/CADMenuImages/mailClose.png");
400        JLabel userListIcon2 = new JLabel(image);
401        JLabel userListName2 = new JLabel("  SL007  ");
402        userListName2.setForeground(Color.WHITE);
403        userListName2.setBackground(grayBackground);
404        userListName2.setOpaque(true);
405        userListNumbers = new JLabel(
406                "<html><font color=white>(</font><font color=red>0</font><font color=white>,0,0)</font></html>");
407        userListNumbers.setBackground(grayBackground);
408        userListNumbers.setOpaque(true);
409
410        user2.add(userListIcon2);
411        user2.add(userListName2);
412        user2.add(userListNumbers);
413        userList.add(user2);
414
415        JLabel currentAgency = new JLabel("  Current Agency is CHP");
416        currentAgency.setForeground(Color.WHITE);
417        currentAgency.setBackground(grayBackground);
418        currentAgency.setOpaque(true);
419        currentAgency.setHorizontalTextPosition(JLabel.LEFT);
420        userList.add(currentAgency);
421
422        Box bottomPanel = new Box(BoxLayout.X_AXIS);
423        bottomPanel.setAlignmentX(LEFT_ALIGNMENT);
424        bottomPanel.add(userList);
425        bottomPanel.add(Box.createHorizontalStrut(5));
426
427        Box bottomRight = new Box(BoxLayout.Y_AXIS);
428        size = new Dimension(775, 85);
429        bottomRight.setPreferredSize(size);
430        bottomRight.setMaximumSize(size);
431        bottomRight.setMinimumSize(size);
432        image = new ImageIcon("images/CADMenuImages/grayFillerTop.png");
433        bottomRight.add(new JLabel(image));
434
435        bottomRightIcons = new Box(BoxLayout.X_AXIS);
436        bottomRightIcons.setAlignmentX(LEFT_ALIGNMENT);
437        image = new ImageIcon("images/CADMenuImages/grayFillerBottom.png");
438        bottomRightIcons.add(new JLabel(image));
439
440        createBottomRightButtons();
441        bottomRightIcons.add(bottomRightButtonsGrayed);
442        bottomRight.add(bottomRightIcons);
443        bottomPanel.add(bottomRight);
444
445        mainPanel.add(bottomPanel);
446    }
447
448    /**
449     * Creates the two bottom right buttons.
450     */
451    public void createBottomRightButtons() {
452        bottomRightButtonsGrayed = new Box(BoxLayout.X_AXIS);
453        ImageIcon image = new ImageIcon(
454                "images/CADMenuImages/checkmarkGrey.png");
455        buttonCheckmark = makeButton(image);
456        bottomRightButtonsGrayed.add(buttonCheckmark);
457        image = new ImageIcon("images/CADMenuImages/minusGrey.png");
458
459        buttonMinus = makeButton(image);
460        bottomRightButtonsGrayed.add(buttonMinus);
461
462        bottomRightButtonsColored = new Box(BoxLayout.X_AXIS);
463        image = new ImageIcon("images/CADMenuImages/checkmarkGreen.png");
464        buttonCheckmark = makeButton(image);
465        bottomRightButtonsColored.add(buttonCheckmark);
466        image = new ImageIcon("images/CADMenuImages/minusRed.png");
467
468        buttonMinus = makeButton(image);
469        bottomRightButtonsColored.add(buttonMinus);
470    }
471
472    /**
473     * This method creates the drop down menus for both the tool and more
474     * buttons
475     */
476    public void createDropDownMenus() {
477
478        ImageIcon image = new ImageIcon("images/ToolMenuImages/toolMenu.png");
479        JLabel menu = new JLabel(image);
480        toolMenu = new JFrame();
481        toolMenu.getContentPane().add(menu);
482        toolMenu.setUndecorated(true);
483        toolMenu.pack();
484        toolMenu.setVisible(false);
485
486        image = new ImageIcon("images/MoreMenuImages/moreMenu.png");
487        menu = new JLabel(image);
488        moreMenu = new JFrame();
489        moreMenu.getContentPane().add(menu);
490        moreMenu.setUndecorated(true);
491        moreMenu.pack();
492        moreMenu.setVisible(false);
493    }
494
495    /**
496     * Takes in the name of the user and displays it.
497     */
498    public void setName(String username) {
499        name.setText(username);
500        userListName1.setText(username);
501    }
502
503    /**
504     * Factory method. Makes a JButton with an image and listener.
505     *
506     * @param image
507     *            the image this button will display.
508     * @param listener
509     *            the action listener for this button.
510     * @return the JButton.
511     */
512    public JButton makeButton(ImageIcon image) {
513        JButton button = new JButton(image);
514        Dimension size = new Dimension(image.getImage().getWidth(null), image
515                .getImage().getHeight(null));
516        button.setPreferredSize(size);
517        button.setMinimumSize(size);
518        button.setMaximumSize(size);
519        button.setBorderPainted(false);
520        button.setFocusable(false);
521
522        return button;
523    }
524
525    /**
526     * Hides the tool drop down menu. Also resets the image to the default(no
527     * highlighted rows).
528     */
529    public void closeToolMenu() {
530        ImageIcon image;
531        JLabel menu;
532        image = new ImageIcon("images/ToolMenuImages/toolMenu.png");
533        menu = new JLabel(image);
534        toolMenu.getContentPane().removeAll();
535        toolMenu.getContentPane().add(menu);
536        toolMenu.validate();
537        toolMenu.setVisible(false);
538    }
539
540    /**
541     * Hides the more drop down menu. Also resets the image to the default(no
542     * highlighted rows).
543     */
544    public void closeMoreMenu() {
545        ImageIcon image;
546        JLabel menu;
547        image = new ImageIcon("images/MoreMenuImages/moreMenu.png");
548        menu = new JLabel(image);
549        moreMenu.getContentPane().removeAll();
550        moreMenu.getContentPane().add(menu);
551        moreMenu.validate();
552        moreMenu.setVisible(false);
553    }
554
555    /**
556     * This method is called every second in ScreenManger to update the display
557     * time every second.
558     */
559    public void handleUpdateTime() {
560        Date date = new Date();
561        String dateTime = dateFormat.format(date);
562        dateAndTime.setText(dateTime);
563    }
564
565    /**
566     * Makes screen visible.
567     */
568    public void open() {
569        setVisible(true);
570    }
571
572    /**
573     * Hides screen.
574     */
575    public void close() {
576        setVisible(false);
577    }
578
579    /**
580     * Currently not used.
581     */
582    public void setIncomingIncident() {
583        bottomRightIcons.remove(bottomRightButtonsGrayed);
584        bottomRightIcons.add(bottomRightButtonsColored);
585        revalidate();
586        repaint();
587    }
588
589    /**
590     * Currently not used.
591     */
592    public void endIncomingIncident() {
593        bottomRightIcons.remove(bottomRightButtonsColored);
594        bottomRightIcons.add(bottomRightButtonsGrayed);
595        revalidate();
596        repaint();
597    }
598
599    /**
600     * Sets position title to trainee.
601     */
602    public void removeDispatcherStatus() {
603        position.setText("Trainee");
604    }
605
606}
Note: See TracBrowser for help on using the repository browser.