Warning: Can't use blame annotator:
svn blame failed on trunk/src/tmcsim/client/cadclientgui/screens/CADMenu.java: ("Can't find a temporary directory: Internal error", 20014)

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

Revision 475, 21.3 KB checked in by jdalbey, 7 years ago (diff)

Coordinator.java, AssignedIncidents?.java, UnitStatus?.java, CADMenu.java: Add comments and error messages. Add revision number to CAD Menu.

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