List of usage examples for java.awt AWTEvent getID
public int getID()
From source file:de.tor.tribes.ui.windows.DSWorkbenchMainFrame.java
/** * Creates new form MapFrame/*from w w w . ja v a 2 s. co m*/ */ DSWorkbenchMainFrame() { initComponents(); setAlwaysOnTop(false); if (!GlobalOptions.isMinimal()) { setTitle("DS Workbench " + Constants.VERSION + Constants.VERSION_ADDITION); } else { setTitle("DS Workbench Mini " + Constants.VERSION + Constants.VERSION_ADDITION); } jExportDialog.pack(); jAddROIDialog.pack(); JOutlookBar outlookBar = new JOutlookBar(); outlookBar.addBar("Navigation", jNavigationPanel); outlookBar.addBar("Information", jInformationPanel); outlookBar.addBar("Karte", jMapPanel); outlookBar.addBar("ROI", jROIPanel); outlookBar.setVisibleBar(1); jSettingsScrollPane.setViewportView(outlookBar); mAbout = new AboutDialog(this, true); mAbout.pack(); chooser.setDialogTitle("Speichern unter..."); chooser.addChoosableFileFilter(new javax.swing.filechooser.FileFilter() { @Override public boolean accept(File f) { return (f != null) && (f.isDirectory() || f.getName().endsWith(".png")); } @Override public String getDescription() { return "PNG Image (*.png)"; } }); chooser.addChoosableFileFilter(new javax.swing.filechooser.FileFilter() { @Override public boolean accept(File f) { return (f != null) && (f.isDirectory() || f.getName().endsWith(".jpeg")); } @Override public String getDescription() { return "JPEG Image (*.jpeg)"; } }); //Schedule Backup new Timer("BackupTimer", true).schedule(new BackupTask(), 60 * 10000, 60 * 10000); //give focus to map panel if mouse enters map jMapPanelHolder.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { jMapPanelHolder.requestFocusInWindow(); } }); getContentPane().setBackground(Constants.DS_BACK); pack(); capabilityInfoPanel1.addActionListener(MapPanel.getSingleton()); // <editor-fold defaultstate="collapsed" desc=" Add global KeyListener "> Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() { @Override public void eventDispatched(AWTEvent event) { if (event.getID() == KeyEvent.KEY_PRESSED) { KeyEvent e = (KeyEvent) event; if (DSWorkbenchMainFrame.getSingleton().isActive()) { //move shortcuts if (e.getKeyCode() == KeyEvent.VK_DOWN) { scroll(0.0, 2.0); } else if (e.getKeyCode() == KeyEvent.VK_UP) { scroll(0.0, -2.0); } else if (e.getKeyCode() == KeyEvent.VK_LEFT) { scroll(-2.0, 0.0); } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) { scroll(2.0, 0.0); } else if ((e.getKeyCode() == KeyEvent.VK_1) && e.isShiftDown() && !e.isControlDown() && !e.isAltDown()) { //shot minimap tool shortcut MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ATTACK_AXE); } else if ((e.getKeyCode() == KeyEvent.VK_2) && e.isShiftDown() && !e.isControlDown() && !e.isAltDown()) { //attack axe tool shortcut MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ATTACK_RAM); } else if ((e.getKeyCode() == KeyEvent.VK_3) && e.isShiftDown() && !e.isControlDown() && !e.isAltDown()) { //attack ram tool shortcut MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ATTACK_SNOB); } else if ((e.getKeyCode() == KeyEvent.VK_4) && e.isShiftDown() && !e.isControlDown() && !e.isAltDown()) { //attack snob tool shortcut MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ATTACK_SPY); } else if ((e.getKeyCode() == KeyEvent.VK_5) && e.isShiftDown() && !e.isControlDown() && !e.isAltDown()) { //attack sword tool shortcut MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ATTACK_LIGHT); } else if ((e.getKeyCode() == KeyEvent.VK_6) && e.isShiftDown() && !e.isControlDown() && !e.isAltDown()) { //attack light tool shortcut MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ATTACK_HEAVY); } else if ((e.getKeyCode() == KeyEvent.VK_7) && e.isShiftDown() && !e.isControlDown() && !e.isAltDown()) { //attack heavy tool shortcut MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ATTACK_SWORD); } else if ((e.getKeyCode() == KeyEvent.VK_S) && e.isControlDown() && !e.isAltDown()) { //search frame shortcut DSWorkbenchSearchFrame.getSingleton() .setVisible(!DSWorkbenchSearchFrame.getSingleton().isVisible()); } } //misc shortcuts if ((e.getKeyCode() == KeyEvent.VK_0) && e.isAltDown()) { //no tool shortcut MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_DEFAULT); } else if ((e.getKeyCode() == KeyEvent.VK_1) && e.isAltDown() && !e.isShiftDown() && !e.isControlDown()) { //measure tool shortcut MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_MEASURE); } else if ((e.getKeyCode() == KeyEvent.VK_2) && e.isAltDown() && !e.isShiftDown() && !e.isControlDown()) { //mark tool shortcut MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_MARK); } else if ((e.getKeyCode() == KeyEvent.VK_3) && e.isAltDown() && !e.isShiftDown() && !e.isControlDown()) { //tag tool shortcut MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_TAG); } else if ((e.getKeyCode() == KeyEvent.VK_4) && e.isAltDown() && !e.isShiftDown() && !e.isControlDown()) { //attack ingame tool shortcut MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_SUPPORT); } else if ((e.getKeyCode() == KeyEvent.VK_5) && e.isAltDown() && !e.isShiftDown() && !e.isControlDown()) { //attack ingame tool shortcut MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_SELECTION); } else if ((e.getKeyCode() == KeyEvent.VK_6) && e.isAltDown() && !e.isShiftDown() && !e.isControlDown()) { //attack ingame tool shortcut MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_RADAR); } else if ((e.getKeyCode() == KeyEvent.VK_7) && e.isAltDown() && !e.isShiftDown() && !e.isControlDown()) { //attack ingame tool shortcut MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ATTACK_INGAME); } else if ((e.getKeyCode() == KeyEvent.VK_8) && e.isAltDown() && !e.isShiftDown() && !e.isControlDown()) { //res ingame tool shortcut MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_SEND_RES_INGAME); } else if ((e.getKeyCode() == KeyEvent.VK_1) && e.isControlDown() && !e.isShiftDown() && !e.isAltDown()) { //move minimap tool shortcut MinimapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_MOVE); } else if ((e.getKeyCode() == KeyEvent.VK_2) && e.isControlDown() && !e.isShiftDown() && !e.isAltDown()) { //zoom minimap tool shortcut MinimapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ZOOM); } else if ((e.getKeyCode() == KeyEvent.VK_3) && e.isControlDown() && !e.isShiftDown() && !e.isAltDown()) { //shot minimap tool shortcut MinimapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_SHOT); } else if ((e.getKeyCode() == KeyEvent.VK_T) && e.isControlDown() && !e.isShiftDown() && !e.isAltDown()) { //search time shortcut ClockFrame.getSingleton().setVisible(!ClockFrame.getSingleton().isVisible()); } else if ((e.getKeyCode() == KeyEvent.VK_S) && e.isAltDown() && !e.isShiftDown() && !e.isControlDown()) { planMapshot(); } else if (e.getKeyCode() == KeyEvent.VK_F2) { DSWorkbenchAttackFrame.getSingleton() .setVisible(!DSWorkbenchAttackFrame.getSingleton().isVisible()); } else if (e.getKeyCode() == KeyEvent.VK_F3) { DSWorkbenchMarkerFrame.getSingleton() .setVisible(!DSWorkbenchMarkerFrame.getSingleton().isVisible()); } else if (e.getKeyCode() == KeyEvent.VK_F4) { DSWorkbenchTroopsFrame.getSingleton() .setVisible(!DSWorkbenchTroopsFrame.getSingleton().isVisible()); } else if (e.getKeyCode() == KeyEvent.VK_F5) { DSWorkbenchRankFrame.getSingleton() .setVisible(!DSWorkbenchRankFrame.getSingleton().isVisible()); } else if (e.getKeyCode() == KeyEvent.VK_F6) { DSWorkbenchFormFrame.getSingleton() .setVisible(!DSWorkbenchFormFrame.getSingleton().isVisible()); } else if (e.getKeyCode() == KeyEvent.VK_F7) { if (ServerSettings.getSingleton().isChurch()) { DSWorkbenchChurchFrame.getSingleton() .setVisible(!DSWorkbenchChurchFrame.getSingleton().isVisible()); } } else if (e.getKeyCode() == KeyEvent.VK_F8) { DSWorkbenchConquersFrame.getSingleton() .setVisible(!DSWorkbenchConquersFrame.getSingleton().isVisible()); } else if (e.getKeyCode() == KeyEvent.VK_F9) { DSWorkbenchNotepad.getSingleton() .setVisible(!DSWorkbenchNotepad.getSingleton().isVisible()); } else if (e.getKeyCode() == KeyEvent.VK_F10) { DSWorkbenchTagFrame.getSingleton() .setVisible(!DSWorkbenchTagFrame.getSingleton().isVisible()); } else if (e.getKeyCode() == KeyEvent.VK_F11) { DSWorkbenchStatsFrame.getSingleton() .setVisible(!DSWorkbenchStatsFrame.getSingleton().isVisible()); } else if (e.getKeyCode() == KeyEvent.VK_F12) { DSWorkbenchSettingsDialog.getSingleton().setVisible(true); } else if ((e.getKeyCode() == KeyEvent.VK_1) && e.isControlDown() && e.isAltDown() && !e.isShiftDown()) { //ROI 1 centerROI(0); } else if ((e.getKeyCode() == KeyEvent.VK_2) && e.isControlDown() && e.isAltDown() && !e.isShiftDown()) { //ROI 2 centerROI(1); } else if ((e.getKeyCode() == KeyEvent.VK_3) && e.isControlDown() && e.isAltDown() && !e.isShiftDown()) { //ROI 3 centerROI(2); } else if ((e.getKeyCode() == KeyEvent.VK_4) && e.isControlDown() && e.isAltDown() && !e.isShiftDown()) { //ROI 4 centerROI(3); } else if ((e.getKeyCode() == KeyEvent.VK_5) && e.isControlDown() && e.isAltDown() && !e.isShiftDown()) { //ROI 5 centerROI(4); } else if ((e.getKeyCode() == KeyEvent.VK_6) && e.isControlDown() && e.isAltDown() && !e.isShiftDown()) { //ROI 6 centerROI(5); } else if ((e.getKeyCode() == KeyEvent.VK_7) && e.isControlDown() && e.isAltDown() && !e.isShiftDown()) { //ROI 7 centerROI(6); } else if ((e.getKeyCode() == KeyEvent.VK_8) && e.isControlDown() && e.isAltDown() && !e.isShiftDown()) { //ROI 8 centerROI(7); } else if ((e.getKeyCode() == KeyEvent.VK_9) && e.isControlDown() && e.isAltDown() && !e.isShiftDown()) { //ROI 9 centerROI(8); } else if ((e.getKeyCode() == KeyEvent.VK_0) && e.isControlDown() && e.isAltDown() && !e.isShiftDown()) { //ROI 10 centerROI(9); } else if (e.getKeyCode() == KeyEvent.VK_SPACE) { jMapPanelHolder.requestFocusInWindow(); MapPanel.getSingleton().setSpaceDown(true); } else if (e.getKeyCode() == KeyEvent.VK_SHIFT) { jMapPanelHolder.requestFocusInWindow(); MapPanel.getSingleton().setShiftDown(true); } } else if (event.getID() == KeyEvent.KEY_RELEASED) { KeyEvent e = (KeyEvent) event; if (e.getKeyCode() == KeyEvent.VK_SPACE) { MapPanel.getSingleton().setSpaceDown(false); } else if (e.getKeyCode() == KeyEvent.VK_SHIFT) { MapPanel.getSingleton().setShiftDown(false); } } } }, AWTEvent.KEY_EVENT_MASK); // </editor-fold> // <editor-fold defaultstate="collapsed" desc=" Load UI Icons "> try { jOnlineLabel.setIcon(new ImageIcon("./graphics/icons/online.png")); jEnableClipboardWatchButton.setIcon(new ImageIcon("./graphics/icons/watch_clipboard.png")); jCenterIngameButton .setIcon(new ImageIcon(DSWorkbenchMainFrame.class.getResource("/res/ui/center_ingame.png"))); jRefreshButton.setIcon(new ImageIcon("./graphics/icons/refresh.png")); jCenterCoordinateIngame.setIcon(new ImageIcon("./graphics/icons/center.png")); } catch (Exception e) { logger.error("Failed to load status icon(s)", e); } // </editor-fold> // <editor-fold defaultstate="collapsed" desc=" Check for desktop support "> if (!Desktop.isDesktopSupported()) { jCenterIngameButton.setEnabled(false); jCenterCoordinateIngame.setEnabled(false); } // </editor-fold> // <editor-fold defaultstate="collapsed" desc=" Restore last map position "> try { String x = GlobalOptions.getSelectedProfile().getProperty("last.x"); String y = GlobalOptions.getSelectedProfile().getProperty("last.y"); centerPosition(Double.parseDouble(x), Double.parseDouble(y)); } catch (Exception e) { centerPosition(ServerSettings.getSingleton().getMapDimension().getCenterX(), ServerSettings.getSingleton().getMapDimension().getCenterY()); } // </editor-fold> // <editor-fold defaultstate="collapsed" desc=" Restore other settings "> jShowMapPopup.setSelected(GlobalOptions.getProperties().getBoolean("show.map.popup")); jShowMouseOverInfo.setSelected(GlobalOptions.getProperties().getBoolean("show.mouseover.info")); jIncludeSupport.setSelected(GlobalOptions.getProperties().getBoolean("include.support")); jHighlightTribeVillages.setSelected(GlobalOptions.getProperties().getBoolean("highlight.tribes.villages")); jShowRuler.setSelected(GlobalOptions.getProperties().getBoolean("show.ruler")); jDisplayChurch.setSelected(GlobalOptions.getProperties().getBoolean("show.church")); jDisplayWatchtower.setSelected(GlobalOptions.getProperties().getBoolean("show.watchtower")); jDisplayChurch.setEnabled(ServerSettings.getSingleton().isChurch()); jDisplayWatchtower.setEnabled(ServerSettings.getSingleton().isWatchtower()); ServerSettings.getSingleton().addListener(new ServerSettingsListener() { @Override public void fireServerSettingsChanged() { jDisplayChurch.setEnabled(ServerSettings.getSingleton().isChurch()); jDisplayWatchtower.setEnabled(ServerSettings.getSingleton().isWatchtower()); } }); int r = GlobalOptions.getProperties().getInt("radar.size"); int hour = r / 60; jHourField.setText(Integer.toString(hour)); jMinuteField.setText(Integer.toString(r - hour * 60)); // </editor-fold> // <editor-fold defaultstate="collapsed" desc="Skin Setup"> DefaultComboBoxModel gpModel = new DefaultComboBoxModel(GlobalOptions.getAvailableSkins()); jGraphicPacks.setModel(gpModel); String skin = GlobalOptions.getProperty("default.skin"); if (gpModel.getIndexOf(skin) != -1) { jGraphicPacks.setSelectedItem(skin); } else { jGraphicPacks.setSelectedItem("default"); } //</editor-fold> minZoom = GlobalOptions.getProperties().getDouble("map.zoom.min"); maxZoom = GlobalOptions.getProperties().getDouble("map.zoom.max"); dZoomInOutFactor = GlobalOptions.getProperties().getDouble("map.zoom.in.out.factor"); mNotificationHideThread = new NotificationHideThread(); mNotificationHideThread.start(); SystrayHelper.installSystrayIcon(); //update online state onlineStateChanged(); restoreProperties(); }