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

Revision 3, 19.1 KB checked in by jdalbey, 10 years ago (diff)

Initial Import of project files - cadclientgui

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