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

Revision 59, 21.2 KB checked in by jdalbey, 9 years ago (diff)

Merge CAD Client updates for multiple incident view windows.

Line 
1package tmcsim.client.cadclientgui.screens;
2
3import java.awt.Color;
4import java.awt.Dimension;
5import java.awt.Font;
6import java.awt.Image;
7import java.awt.Point;
8import java.awt.event.ActionEvent;
9import java.awt.event.ActionListener;
10import java.awt.event.ComponentEvent;
11import java.awt.event.ComponentListener;
12import java.awt.event.MouseEvent;
13import java.awt.event.MouseListener;
14import java.awt.event.MouseMotionListener;
15import java.io.IOException;
16import java.net.MalformedURLException;
17import java.net.URL;
18import java.text.DateFormat;
19import java.text.SimpleDateFormat;
20import java.util.Date;
21import java.util.logging.Level;
22import java.util.logging.Logger;
23import javax.imageio.ImageIO;
24import javax.swing.Box;
25import javax.swing.BoxLayout;
26import javax.swing.ImageIcon;
27import javax.swing.JButton;
28import javax.swing.JFrame;
29import javax.swing.JLabel;
30
31/**
32 * The main CADMenu with buttons to open up other screens. This class uses
33 * mostly images to build from, and java gui does not allow those images to be
34 * editable here, so all the images' pixels are predefined in the images
35 * themselves. The images can be found in the images folder. An image called
36 * "CADMenuLayout" can also be found in the same folder showing how this class's
37 * looks were made.
38 *
39 * @author Vincent
40 *
41 */
42public class CADMenu extends JFrame
43{
44    private final int ONE_SECOND = 1000;
45    private DateFormat dateFormat;
46    private Box mainPanel;
47    private Box bottomRightIcons;
48    private Box bottomRightButtonsGrayed;
49    private Box bottomRightButtonsColored;
50    private JLabel dateAndTime;
51    private JLabel name;
52    private JLabel userListName1;
53    private JButton button1;
54    private JButton button2;
55    private JButton button3;
56    private JButton button4;
57    private JButton button5;
58    private JButton button6;
59    private JButton buttonTool;
60    private JButton buttonMore;
61    // the drop down menu when the "more button" is clicked.
62    private JFrame moreMenu;
63    // the drop down menu when the "tool button" is clicked.
64    private JFrame toolMenu;
65    private JButton buttonCheckmark;
66    private JButton buttonMinus;
67    private JLabel position;
68
69    /**
70     * Constructor call. Creates the CADMenu.
71     */
72    public CADMenu()
73    {
74        initialize();
75        createTopPanel();
76        createBottomPanel();
77        createDropDownMenus();
78
79        initControllers();
80
81        getContentPane().add(mainPanel);
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());
89        }
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            }
107        }
108        setPreferredSize(new Dimension(1195, 178));
109        setResizable(true);
110        setFocusable(true);
111        pack();
112        //  Unsure why this was "do nothing" because it prevents the Menu frame
113        //  from closing so the user can't terminate the application.
114        //        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
115        setDefaultCloseOperation(EXIT_ON_CLOSE);
116        setVisible(false);
117    }
118
119    /**
120     * Initializes variables and connects the CADMenu to the CADMenuListener.
121     */
122    public void initialize()
123    {
124        mainPanel = new Box(BoxLayout.Y_AXIS);
125        mainPanel.setAlignmentX(LEFT_ALIGNMENT);
126        dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
127    }
128
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            {
139                closeToolMenu();
140                closeMoreMenu();
141                setLocation(getLocation());
142            }
143
144            public void componentResized(ComponentEvent e)
145            {
146            }
147
148            public void componentShown(ComponentEvent e)
149            {
150            }
151        });
152        addMouseListener(new MouseListener()
153        {
154            public void mouseClicked(MouseEvent arg0)
155            {
156                closeToolMenu();
157                closeMoreMenu();
158            }
159
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            {
174            }
175        });
176    }
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            {
188            }
189        });
190
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            {
211            }
212        });
213    }
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            {
225                ImageIcon image = new ImageIcon(
226                        "images/MoreMenuImages/moreMenu.png");
227                JLabel menu;
228                if (e.getLocationOnScreen().getY() >= moreMenu.getY()
229                        && e.getLocationOnScreen().getY() <= moreMenu.getY()
230                        + moreMenu.getHeight() / 8)
231                {
232                    image = new ImageIcon(
233                            "images/MoreMenuImages/moreMenuHighlighted1.png");
234                }
235                else if (e.getLocationOnScreen().getY() >= moreMenu.getY()
236                        + moreMenu.getHeight() * 2 / 8
237                        && e.getLocationOnScreen().getY() <= moreMenu.getY()
238                        + moreMenu.getHeight() * 3 / 8)
239                {
240                    image = new ImageIcon(
241                            "images/MoreMenuImages/moreMenuHighlighted3.png");
242                }
243                menu = new JLabel(image);
244                moreMenu.getContentPane().removeAll();
245                moreMenu.getContentPane().add(menu);
246                moreMenu.validate();
247            }
248        });
249
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            {
270                if (e.getLocationOnScreen().getY() >= moreMenu.getY()
271                        && e.getLocationOnScreen().getY() <= moreMenu.getY()
272                        + moreMenu.getHeight() / 8)
273                {
274                    ScreenManager.openIncidentEditor();
275                    closeMoreMenu();
276                }
277                else if (e.getLocationOnScreen().getY() >= moreMenu.getY()
278                        + moreMenu.getHeight() * 2 / 8
279                        && e.getLocationOnScreen().getY() <= moreMenu.getY()
280                        + moreMenu.getHeight() * 3 / 8)
281                {
282                    ScreenManager.openCardfile();
283                    closeMoreMenu();
284                }
285            }
286        });
287    }
288
289    public void initControllers()
290    {
291        addListeners();
292
293        buttonTool.addActionListener(newToolActionListener());
294        buttonMore.addActionListener(newMoreActionListener());
295
296        initToolMenuListeners();
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                {
308                    closeMoreMenu();
309                }
310                if (toolMenu.isVisible())
311                {
312                    closeToolMenu();
313                }
314                else
315                {
316                    toolMenu.setLocation(new Point(getX() + getWidth()
317                            - toolMenu.getWidth(), getY() + 85));
318                    toolMenu.setVisible(true);
319                }
320            }
321        };
322    }
323
324    public ActionListener newMoreActionListener()
325    {
326        return new ActionListener()
327        {
328            public void actionPerformed(ActionEvent arg0)
329            {
330                if (toolMenu.isVisible())
331                {
332                    closeToolMenu();
333                }
334                if (moreMenu.isVisible())
335                {
336                    closeMoreMenu();
337                }
338                else
339                {
340                    moreMenu.setLocation(new Point(getX() + getWidth()
341                            - moreMenu.getWidth(), getY() + 85));
342                    moreMenu.setVisible(true);
343                }
344            }
345        };
346    }
347
348    /*
349     * Creates the topPanel for the CADMenu.
350     */
351    public void createTopPanel()
352    {
353
354        Box topPanel = new Box(BoxLayout.X_AXIS);
355        topPanel.setAlignmentX(LEFT_ALIGNMENT);
356
357        ImageIcon image = new ImageIcon("images/CADMenuImages/tritech.png");
358        JLabel tritech = new JLabel(image);
359        topPanel.add(tritech);
360
361        image = new ImageIcon("images/CADMenuImages/empty.png");
362        JLabel empty = new JLabel(image);
363        topPanel.add(empty);
364
365        // center holds the User's Name, user's position, and date/time
366        Box center = new Box(BoxLayout.Y_AXIS);
367        image = new ImageIcon("images/CADMenuImages/top.png");
368
369        name = new JLabel(image);
370        name.setText("User");
371        name.setFont(new Font("SanSerif", Font.BOLD, 16));
372        name.setForeground(Color.WHITE);
373        name.setHorizontalTextPosition(JLabel.CENTER);
374        center.add(name);
375
376        Box centerBottom = new Box(BoxLayout.X_AXIS);
377        centerBottom.setAlignmentX(Box.LEFT_ALIGNMENT);
378
379        image = new ImageIcon("images/CADMenuImages/bottom.png");
380        position = new JLabel(image);
381        position.setText("Public Safety Dispatch Sup");
382        position.setFont(new Font("Arial", Font.PLAIN, 12));
383        position.setForeground(new Color(190, 210, 255));
384        position.setHorizontalTextPosition(JLabel.CENTER);
385        centerBottom.add(position);
386
387        image = new ImageIcon("images/CADMenuImages/bottom.png");
388        Date date = new Date();
389        DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
390        String dateTime = dateFormat.format(date);
391        dateAndTime = new JLabel(image);
392        dateAndTime.setText(dateTime);
393        dateAndTime.setForeground(Color.WHITE);
394        dateAndTime.setHorizontalTextPosition(JLabel.CENTER);
395        centerBottom.add(dateAndTime);
396        center.add(centerBottom);
397
398        topPanel.add(center);
399
400        image = new ImageIcon("images/CADMenuImages/empty2.png");
401        JLabel empty2 = new JLabel(image);
402        topPanel.add(empty2);
403
404        image = new ImageIcon("images/CADMenuImages/button1.png");
405        button1 = makeButton(image);
406        topPanel.add(button1);
407
408        image = new ImageIcon("images/CADMenuImages/button2.png");
409        button2 = makeButton(image);
410        topPanel.add(button2);
411
412        image = new ImageIcon("images/CADMenuImages/button3.png");
413        button3 = makeButton(image);
414        topPanel.add(button3);
415
416        image = new ImageIcon("images/CADMenuImages/button4.png");
417        button4 = makeButton(image);
418        topPanel.add(button4);
419
420        image = new ImageIcon("images/CADMenuImages/button5.png");
421        button5 = makeButton(image);
422        topPanel.add(button5);
423
424        image = new ImageIcon("images/CADMenuImages/button6.png");
425        button6 = makeButton(image);
426        topPanel.add(button6);
427
428        image = new ImageIcon("images/CADMenuImages/button7.png");
429        buttonTool = makeButton(image);
430        topPanel.add(buttonTool);
431
432        image = new ImageIcon("images/CADMenuImages/button8.png");
433        buttonMore = makeButton(image);
434        topPanel.add(buttonMore);
435
436        mainPanel.add(topPanel);
437    }
438
439    /**
440     * Creates the bottomPanel of the CADMenu.
441     */
442    public void createBottomPanel()
443    {
444        Color grayBackground = new Color(100, 100, 100);
445
446        Box userList = new Box(BoxLayout.Y_AXIS);
447        userList.setAlignmentX(LEFT_ALIGNMENT);
448
449        Dimension size = new Dimension(400, 85);
450        userList.setPreferredSize(size);
451        userList.setMaximumSize(size);
452        userList.setMinimumSize(size);
453        userList.setBackground(grayBackground);
454        userList.setOpaque(true);
455
456        Box user1 = new Box(BoxLayout.X_AXIS);
457        user1.setAlignmentX(LEFT_ALIGNMENT);
458
459        ImageIcon image = new ImageIcon("images/CADMenuImages/mailClose.png");
460        JLabel userListIcon1 = new JLabel(image);
461        userListName1 = new JLabel("User");
462        userListName1.setForeground(Color.WHITE);
463        userListName1.setBackground(grayBackground);
464        userListName1.setOpaque(true);
465        JLabel userListNumbers = new JLabel(
466                "<html><font color=white>(</font><font color=red>0</font><font color=white>,0,0)</font></html>");
467        userListNumbers.setBackground(grayBackground);
468        userListNumbers.setOpaque(true);
469
470        user1.add(userListIcon1);
471        user1.add(userListName1);
472        user1.add(userListNumbers);
473        userList.add(user1);
474
475        Box user2 = new Box(BoxLayout.X_AXIS);
476        user2.setAlignmentX(LEFT_ALIGNMENT);
477
478        image = new ImageIcon("images/CADMenuImages/mailClose.png");
479        JLabel userListIcon2 = new JLabel(image);
480        JLabel userListName2 = new JLabel("  SL007  ");
481        userListName2.setForeground(Color.WHITE);
482        userListName2.setBackground(grayBackground);
483        userListName2.setOpaque(true);
484        userListNumbers = new JLabel(
485                "<html><font color=white>(</font><font color=red>0</font><font color=white>,0,0)</font></html>");
486        userListNumbers.setBackground(grayBackground);
487        userListNumbers.setOpaque(true);
488
489        user2.add(userListIcon2);
490        user2.add(userListName2);
491        user2.add(userListNumbers);
492        userList.add(user2);
493
494        JLabel currentAgency = new JLabel("  Current Agency is CHP");
495        currentAgency.setForeground(Color.WHITE);
496        currentAgency.setBackground(grayBackground);
497        currentAgency.setOpaque(true);
498        currentAgency.setHorizontalTextPosition(JLabel.LEFT);
499        userList.add(currentAgency);
500
501        Box bottomPanel = new Box(BoxLayout.X_AXIS);
502        bottomPanel.setAlignmentX(LEFT_ALIGNMENT);
503        bottomPanel.add(userList);
504        bottomPanel.add(Box.createHorizontalStrut(5));
505
506        Box bottomRight = new Box(BoxLayout.Y_AXIS);
507        size = new Dimension(775, 85);
508        bottomRight.setPreferredSize(size);
509        bottomRight.setMaximumSize(size);
510        bottomRight.setMinimumSize(size);
511        image = new ImageIcon("images/CADMenuImages/grayFillerTop.png");
512        bottomRight.add(new JLabel(image));
513
514        bottomRightIcons = new Box(BoxLayout.X_AXIS);
515        bottomRightIcons.setAlignmentX(LEFT_ALIGNMENT);
516        image = new ImageIcon("images/CADMenuImages/grayFillerBottom.png");
517        bottomRightIcons.add(new JLabel(image));
518
519        createBottomRightButtons();
520        bottomRightIcons.add(bottomRightButtonsGrayed);
521        bottomRight.add(bottomRightIcons);
522        bottomPanel.add(bottomRight);
523
524        mainPanel.add(bottomPanel);
525    }
526
527    /**
528     * Creates the two bottom right buttons.
529     */
530    public void createBottomRightButtons()
531    {
532        bottomRightButtonsGrayed = new Box(BoxLayout.X_AXIS);
533        ImageIcon image = new ImageIcon(
534                "images/CADMenuImages/checkmarkGrey.png");
535        buttonCheckmark = makeButton(image);
536        bottomRightButtonsGrayed.add(buttonCheckmark);
537        image = new ImageIcon("images/CADMenuImages/minusGrey.png");
538
539        buttonMinus = makeButton(image);
540        bottomRightButtonsGrayed.add(buttonMinus);
541
542        bottomRightButtonsColored = new Box(BoxLayout.X_AXIS);
543        image = new ImageIcon("images/CADMenuImages/checkmarkGreen.png");
544        buttonCheckmark = makeButton(image);
545        bottomRightButtonsColored.add(buttonCheckmark);
546        image = new ImageIcon("images/CADMenuImages/minusRed.png");
547
548        buttonMinus = makeButton(image);
549        bottomRightButtonsColored.add(buttonMinus);
550    }
551
552    /**
553     * This method creates the drop down menus for both the tool and more
554     * buttons
555     */
556    public void createDropDownMenus()
557    {
558
559        ImageIcon image = new ImageIcon("images/ToolMenuImages/toolMenu.png");
560        JLabel menu = new JLabel(image);
561        toolMenu = new JFrame();
562        toolMenu.getContentPane().add(menu);
563        toolMenu.setUndecorated(true);
564        toolMenu.pack();
565        toolMenu.setVisible(false);
566
567        image = new ImageIcon("images/MoreMenuImages/moreMenu.png");
568        menu = new JLabel(image);
569        moreMenu = new JFrame();
570        moreMenu.getContentPane().add(menu);
571        moreMenu.setUndecorated(true);
572        moreMenu.pack();
573        moreMenu.setVisible(false);
574    }
575
576    /**
577     * Takes in the name of the user and displays it.
578     */
579    public void setName(String username)
580    {
581        name.setText(username);
582        userListName1.setText(username);
583    }
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   
592    /**
593     * Factory method. Makes a JButton with an image and listener.
594     *
595     * @param image the image this button will display.
596     * @param listener the action listener for this button.
597     * @return the JButton.
598     */
599    public JButton makeButton(ImageIcon image)
600    {
601        JButton button = new JButton(image);
602        Dimension size = new Dimension(image.getImage().getWidth(null), image
603                .getImage().getHeight(null));
604        button.setPreferredSize(size);
605        button.setMinimumSize(size);
606        button.setMaximumSize(size);
607        button.setBorderPainted(false);
608        button.setFocusable(false);
609
610        return button;
611    }
612
613    /**
614     * Hides the tool drop down menu. Also resets the image to the default(no
615     * highlighted rows).
616     */
617    public void closeToolMenu()
618    {
619        ImageIcon image;
620        JLabel menu;
621        image = new ImageIcon("images/ToolMenuImages/toolMenu.png");
622        menu = new JLabel(image);
623        toolMenu.getContentPane().removeAll();
624        toolMenu.getContentPane().add(menu);
625        toolMenu.validate();
626        toolMenu.setVisible(false);
627    }
628
629    /**
630     * Hides the more drop down menu. Also resets the image to the default(no
631     * highlighted rows).
632     */
633    public void closeMoreMenu()
634    {
635        ImageIcon image;
636        JLabel menu;
637        image = new ImageIcon("images/MoreMenuImages/moreMenu.png");
638        menu = new JLabel(image);
639        moreMenu.getContentPane().removeAll();
640        moreMenu.getContentPane().add(menu);
641        moreMenu.validate();
642        moreMenu.setVisible(false);
643    }
644
645    /**
646     * This method is called every second in ScreenManger to update the display
647     * time every second.
648     */
649    public void handleUpdateTime()
650    {
651        Date date = new Date();
652        String dateTime = dateFormat.format(date);
653        dateAndTime.setText(dateTime);
654    }
655
656    /**
657     * Makes screen visible.
658     */
659    public void open()
660    {
661        setVisible(true);
662    }
663
664    /**
665     * Hides screen.
666     */
667    public void close()
668    {
669        setVisible(false);
670    }
671
672    /**
673     * Currently not used.
674     */
675    public void setIncomingIncident()
676    {
677        bottomRightIcons.remove(bottomRightButtonsGrayed);
678        bottomRightIcons.add(bottomRightButtonsColored);
679        revalidate();
680        repaint();
681    }
682
683    /**
684     * Currently not used.
685     */
686    public void endIncomingIncident()
687    {
688        bottomRightIcons.remove(bottomRightButtonsColored);
689        bottomRightIcons.add(bottomRightButtonsGrayed);
690        revalidate();
691        repaint();
692    }
693
694    /**
695     * Sets position title to trainee.
696     */
697    public void removeDispatcherStatus()
698    {
699        position.setText("Trainee");
700    }
701}
Note: See TracBrowser for help on using the repository browser.