Changeset 59 in tmcsimulator for trunk/src/tmcsim/client/cadclientgui/screens/CADMenu.java
- Timestamp:
- 03/15/2017 10:20:21 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/tmcsim/client/cadclientgui/screens/CADMenu.java
r40 r59 13 13 import java.awt.event.MouseListener; 14 14 import java.awt.event.MouseMotionListener; 15 import java.io.File;16 15 import java.io.IOException; 17 16 import java.net.MalformedURLException; … … 23 22 import java.util.logging.Logger; 24 23 import javax.imageio.ImageIO; 25 26 24 import javax.swing.Box; 27 25 import javax.swing.BoxLayout; … … 30 28 import javax.swing.JFrame; 31 29 import javax.swing.JLabel; 32 import static javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE;33 30 34 31 /** … … 39 36 * "CADMenuLayout" can also be found in the same folder showing how this class's 40 37 * looks were made. 41 * 38 * 42 39 * @author Vincent 43 * 40 * 44 41 */ 45 public class CADMenu extends JFrame {46 42 public class CADMenu extends JFrame 43 { 47 44 private final int ONE_SECOND = 1000; 48 49 45 private DateFormat dateFormat; 50 51 46 private Box mainPanel; 52 47 private Box bottomRightIcons; … … 56 51 private JLabel name; 57 52 private JLabel userListName1; 58 59 53 private JButton button1; 60 54 private JButton button2; … … 65 59 private JButton buttonTool; 66 60 private JButton buttonMore; 67 68 61 // the drop down menu when the "more button" is clicked. 69 62 private JFrame moreMenu; 70 71 63 // the drop down menu when the "tool button" is clicked. 72 64 private JFrame toolMenu; 73 74 65 private JButton buttonCheckmark; 75 66 private JButton buttonMinus; 76 77 67 private JLabel position; 78 68 … … 80 70 * Constructor call. Creates the CADMenu. 81 71 */ 82 public CADMenu() { 72 public CADMenu() 73 { 83 74 initialize(); 84 75 createTopPanel(); 85 76 createBottomPanel(); 86 77 createDropDownMenus(); 87 78 88 79 initControllers(); 89 80 90 81 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()); 100 89 } 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 } 109 107 } 110 // Doesn't work: file path problem?111 // ImageIcon myIcon = new ImageIcon(getClass().getClassLoader().getResource("images/CADicon.png"));112 // setIconImage(myIcon.getImage());113 108 setPreferredSize(new Dimension(1195, 178)); 114 109 setResizable(true); … … 125 120 * Initializes variables and connects the CADMenu to the CADMenuListener. 126 121 */ 127 public void initialize() { 122 public void initialize() 123 { 128 124 mainPanel = new Box(BoxLayout.Y_AXIS); 129 125 mainPanel.setAlignmentX(LEFT_ALIGNMENT); … … 131 127 } 132 128 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 { 139 139 closeToolMenu(); 140 140 closeMoreMenu(); … … 142 142 } 143 143 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 { 148 150 } 149 151 }); 150 addMouseListener(new MouseListener() { 151 public void mouseClicked(MouseEvent arg0) { 152 addMouseListener(new MouseListener() 153 { 154 public void mouseClicked(MouseEvent arg0) 155 { 152 156 closeToolMenu(); 153 157 closeMoreMenu(); 154 158 } 155 159 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 { 166 174 } 167 175 }); 168 176 } 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 { 176 188 } 177 189 }); 178 190 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 { 193 211 } 194 212 }); 195 213 } 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 { 203 225 ImageIcon image = new ImageIcon( 204 226 "images/MoreMenuImages/moreMenu.png"); … … 206 228 if (e.getLocationOnScreen().getY() >= moreMenu.getY() 207 229 && e.getLocationOnScreen().getY() <= moreMenu.getY() 208 + moreMenu.getHeight() / 8) { 230 + moreMenu.getHeight() / 8) 231 { 209 232 image = new ImageIcon( 210 233 "images/MoreMenuImages/moreMenuHighlighted1.png"); 211 } else if (e.getLocationOnScreen().getY() >= moreMenu.getY() 234 } 235 else if (e.getLocationOnScreen().getY() >= moreMenu.getY() 212 236 + moreMenu.getHeight() * 2 / 8 213 237 && e.getLocationOnScreen().getY() <= moreMenu.getY() 214 + moreMenu.getHeight() * 3 / 8) { 238 + moreMenu.getHeight() * 3 / 8) 239 { 215 240 image = new ImageIcon( 216 241 "images/MoreMenuImages/moreMenuHighlighted3.png"); … … 223 248 }); 224 249 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 { 239 270 if (e.getLocationOnScreen().getY() >= moreMenu.getY() 240 271 && e.getLocationOnScreen().getY() <= moreMenu.getY() 241 + moreMenu.getHeight() / 8) { 272 + moreMenu.getHeight() / 8) 273 { 242 274 ScreenManager.openIncidentEditor(); 243 275 closeMoreMenu(); 244 } else if (e.getLocationOnScreen().getY() >= moreMenu.getY() 276 } 277 else if (e.getLocationOnScreen().getY() >= moreMenu.getY() 245 278 + moreMenu.getHeight() * 2 / 8 246 279 && e.getLocationOnScreen().getY() <= moreMenu.getY() 247 + moreMenu.getHeight() * 3 / 8) { 280 + moreMenu.getHeight() * 3 / 8) 281 { 248 282 ScreenManager.openCardfile(); 249 283 closeMoreMenu(); … … 252 286 }); 253 287 } 254 255 public void initControllers(){ 288 289 public void initControllers() 290 { 256 291 addListeners(); 257 292 258 293 buttonTool.addActionListener(newToolActionListener()); 259 294 buttonMore.addActionListener(newMoreActionListener()); 260 295 261 296 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 { 269 308 closeMoreMenu(); 270 309 } 271 if (toolMenu.isVisible()) { 310 if (toolMenu.isVisible()) 311 { 272 312 closeToolMenu(); 273 } else { 313 } 314 else 315 { 274 316 toolMenu.setLocation(new Point(getX() + getWidth() 275 317 - toolMenu.getWidth(), getY() + 85)); … … 279 321 }; 280 322 } 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 { 286 332 closeToolMenu(); 287 333 } 288 if (moreMenu.isVisible()) { 334 if (moreMenu.isVisible()) 335 { 289 336 closeMoreMenu(); 290 } else { 337 } 338 else 339 { 291 340 moreMenu.setLocation(new Point(getX() + getWidth() 292 341 - moreMenu.getWidth(), getY() + 85)); … … 296 345 }; 297 346 } 298 347 299 348 /* 300 349 * Creates the topPanel for the CADMenu. 301 350 */ 302 public void createTopPanel() { 351 public void createTopPanel() 352 { 303 353 304 354 Box topPanel = new Box(BoxLayout.X_AXIS); … … 390 440 * Creates the bottomPanel of the CADMenu. 391 441 */ 392 public void createBottomPanel() { 442 public void createBottomPanel() 443 { 393 444 Color grayBackground = new Color(100, 100, 100); 394 445 … … 477 528 * Creates the two bottom right buttons. 478 529 */ 479 public void createBottomRightButtons() { 530 public void createBottomRightButtons() 531 { 480 532 bottomRightButtonsGrayed = new Box(BoxLayout.X_AXIS); 481 533 ImageIcon image = new ImageIcon( … … 502 554 * buttons 503 555 */ 504 public void createDropDownMenus() { 556 public void createDropDownMenus() 557 { 505 558 506 559 ImageIcon image = new ImageIcon("images/ToolMenuImages/toolMenu.png"); … … 524 577 * Takes in the name of the user and displays it. 525 578 */ 526 public void setName(String username) { 579 public void setName(String username) 580 { 527 581 name.setText(username); 528 582 userListName1.setText(username); 529 583 } 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 531 592 /** 532 593 * 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. 538 597 * @return the JButton. 539 598 */ 540 public JButton makeButton(ImageIcon image) { 599 public JButton makeButton(ImageIcon image) 600 { 541 601 JButton button = new JButton(image); 542 602 Dimension size = new Dimension(image.getImage().getWidth(null), image … … 555 615 * highlighted rows). 556 616 */ 557 public void closeToolMenu() { 617 public void closeToolMenu() 618 { 558 619 ImageIcon image; 559 620 JLabel menu; … … 570 631 * highlighted rows). 571 632 */ 572 public void closeMoreMenu() { 633 public void closeMoreMenu() 634 { 573 635 ImageIcon image; 574 636 JLabel menu; … … 585 647 * time every second. 586 648 */ 587 public void handleUpdateTime() { 649 public void handleUpdateTime() 650 { 588 651 Date date = new Date(); 589 652 String dateTime = dateFormat.format(date); … … 594 657 * Makes screen visible. 595 658 */ 596 public void open() { 659 public void open() 660 { 597 661 setVisible(true); 598 662 } … … 601 665 * Hides screen. 602 666 */ 603 public void close() { 667 public void close() 668 { 604 669 setVisible(false); 605 670 } … … 608 673 * Currently not used. 609 674 */ 610 public void setIncomingIncident() { 675 public void setIncomingIncident() 676 { 611 677 bottomRightIcons.remove(bottomRightButtonsGrayed); 612 678 bottomRightIcons.add(bottomRightButtonsColored); … … 618 684 * Currently not used. 619 685 */ 620 public void endIncomingIncident() { 686 public void endIncomingIncident() 687 { 621 688 bottomRightIcons.remove(bottomRightButtonsColored); 622 689 bottomRightIcons.add(bottomRightButtonsGrayed); … … 628 695 * Sets position title to trainee. 629 696 */ 630 public void removeDispatcherStatus() { 697 public void removeDispatcherStatus() 698 { 631 699 position.setText("Trainee"); 632 700 } 633 634 701 }
Note: See TracChangeset
for help on using the changeset viewer.
