Example usage for java.awt.event MouseEvent isAltDown

List of usage examples for java.awt.event MouseEvent isAltDown

Introduction

In this page you can find the example usage for java.awt.event MouseEvent isAltDown.

Prototype

public boolean isAltDown() 

Source Link

Document

Returns whether or not the Alt modifier is down on this event.

Usage

From source file:eu.esdihumboldt.hale.ui.views.styledmap.tool.InstanceTool.java

/**
 * @see AbstractMapTool#click(MouseEvent, GeoPosition)
 *//*w ww  .  j av a2s  .c o  m*/
@Override
public void click(MouseEvent me, GeoPosition pos) {
    if (me.getClickCount() == 2) {
        mapKit.setCenterPosition(pos);
        mapKit.setZoom(mapKit.getMainMap().getZoom() - 1);
    } else if (me.getClickCount() == 1) {
        if (me.isAltDown() && getPositions().size() < 1) {
            // add pos
            addPosition(pos);
        } else if (getPositions().size() == 1) {
            // finish box selection
            // action & reset
            addPosition(pos);

            // action
            try {
                List<Point2D> points = getPoints();
                Rectangle rect = new Rectangle((int) points.get(0).getX(), (int) points.get(0).getY(), 0, 0);
                rect.add(points.get(1));

                updateSelection(rect, me.isControlDown() || me.isMetaDown(), true);
            } catch (IllegalGeoPositionException e) {
                log.error("Error calculating selection box", e); //$NON-NLS-1$
            }

            reset();
        } else {
            // click selection
            reset();

            updateSelection(me.getPoint(), me.isControlDown() || me.isMetaDown(), true);
        }
    }
}

From source file:unikn.dbis.univis.visualization.graph.plaf.VGraphUI.java

/**
 * Creates the listener responsible for calling the correct handlers based
 * on mouse events, and to select invidual cells.
 *//*from w  w  w.  ja va  2s.c  om*/
protected MouseListener createMouseListener() {

    return new MouseHandler() {

        /**
         * Invoked when a mouse button has been pressed on a component.
         *
         //@Override
         public void mousePressed(MouseEvent e) {
                
         Object o = graph.getFirstCellForLocation(e.getX(), e.getY());
                
         if (o instanceof VGraphCell) {
                
         VGraphCell cell = (VGraphCell) o;
                
         JPopupMenu menu = new JPopupMenu();
                
         VChartPanel chartPanel = (VChartPanel) cell.getUserObject();
                
         if (chartPanel.isShowPopUp()) {
                
         LegendItemCollection collect = chartPanel.getChart().getPlot().getLegendItems();
         JMenu first = new JMenu("1-39");
         int checker = 0;
                
         for (Iterator iter = collect.iterator(); iter.hasNext();) {
         LegendItem item = (LegendItem) iter.next();
         checker++;
         first.add(new JMenuItem(item.getLabel()));
         if ((checker % 40) == 0) {
         menu.add(first);
                
         first = new JMenu("" + checker + "-" + (checker + 39));
         }
         if (!iter.hasNext()) {
         menu.add(first);
         }
         }
                
         menu.show(graph, e.getX(), e.getY());
         }
         }
                
         super.mousePressed(e);
         }
         */

        /**
         * Invoked when a mouse button has been pressed on a component.
         */
        @Override
        public void mousePressed(MouseEvent e) {

            Object o = graph.getFirstCellForLocation(e.getX(), e.getY());

            if (SwingUtilities.isLeftMouseButton(e) && e.isAltDown()) {
                if (o instanceof VGraphCell) {

                    VGraphCell cell = (VGraphCell) o;

                    JPopupMenu menu = new JPopupMenu();

                    VChartPanel chartPanel = (VChartPanel) cell.getUserObject();

                    LegendItemCollection collect = chartPanel.getChart().getPlot().getLegendItems();
                    JMenu first = new JMenu("1-39");
                    int checker = 0;

                    for (Iterator iter = collect.iterator(); iter.hasNext();) {
                        LegendItem item = (LegendItem) iter.next();
                        checker++;
                        first.add(new JMenuItem(item.getLabel()));
                        if ((checker % 40) == 0) {
                            menu.add(first);

                            first = new JMenu("" + checker + "-" + (checker + 39));
                        }
                        if (!iter.hasNext()) {
                            menu.add(first);
                        }
                    }

                    menu.show(graph, e.getX(), e.getY());
                }
            }

            super.mousePressed(e);

            if (o != null && o instanceof VGraphCell) {

                VGraphCell cell = (VGraphCell) o;

                o = cell.getUserObject();

                if (o != null && o instanceof VChartPanel) {
                    VChartPanel chart = (VChartPanel) o;

                    for (MouseListener l : chart.getMouseListeners()) {
                        l.mousePressed(e);
                    }
                }
            }
        }

        // Event may be null when called to cancel the current operation.
        @Override
        public void mouseReleased(MouseEvent e) {
            super.mouseReleased(e);

            Object o = graph.getFirstCellForLocation(e.getX(), e.getY());

            if (o != null && o instanceof VGraphCell) {

                VGraphCell cell = (VGraphCell) o;

                o = cell.getUserObject();

                if (o != null && o instanceof VChartPanel) {
                    VChartPanel chart = (VChartPanel) o;

                    for (MouseListener l : chart.getMouseListeners()) {
                        l.mouseReleased(e);
                    }
                }
            }
        }

        /**
         * Invoked when the mouse has been clicked on a component.
         */
        @Override
        public void mouseClicked(MouseEvent e) {
            super.mouseClicked(e);

            Object o = graph.getFirstCellForLocation(e.getX(), e.getY());

            if (o != null && o instanceof VGraphCell) {

                VGraphCell cell = (VGraphCell) o;

                o = cell.getUserObject();

                if (o != null && o instanceof VChartPanel) {
                    VChartPanel chart = (VChartPanel) o;

                    if (SwingUtilities.isRightMouseButton(e)) {
                        JPopupMenu menu = chart.createPopupMenu(true, true, true, true);

                        menu.show(graph, e.getX(), e.getY());
                    }

                    /*
                    for (MouseListener l : chart.getMouseListeners()) {
                    System.out.println("LISTENS CLI");
                    l.mouseClicked(e);
                    }
                    */
                }
            }
        }

        /*
        // Event may be null when called to cancel the current operation.
        @Override
        public void mouseReleased(MouseEvent e) {
        super.mouseReleased(e);
                
        Object[] cells = graphSelectionModel.getSelectionCells();
                
        Rectangle2D bounds = graph.getCellBounds(cells);
                
        if (bounds != null) {
            Rectangle2D b2 = graph.toScreen((Rectangle2D) bounds.clone());
            graph.scrollRectToVisible(new Rectangle((int) b2.getX(), (int) b2.getY(), (int) b2.getWidth(), (int) b2.getHeight()));
        }
        }
        */

        /**
         * Invoked when the mouse pointer has been moved on a component (with no
         * buttons down).
         */
        @Override
        public void mouseMoved(MouseEvent e) {

            if (graph.isMoveable()) {
                super.mouseMoved(e);
            }

            Object o = graph.getFirstCellForLocation(e.getX(), e.getY());

            if (o != null && o instanceof VGraphCell) {

                selectedCell = (VGraphCell) o;

                Rectangle2D bounds = graph.getCellBounds(selectedCell);

                menu.show(graph, (int) (bounds.getX() + bounds.getWidth()),
                        (int) bounds.getY() + (int) (bounds.getHeight() - menu.getHeight()));
            }
        }
    };
}

From source file:MouseNavigateTest.java

protected boolean isStartBehaviorEvent(java.awt.event.MouseEvent evt) {
    int nId = evt.getID();
    return ((nId == MouseEvent.MOUSE_DRAGGED) && (evt.isAltDown() == false) && (evt.isMetaDown() == false));
}

From source file:MouseNavigateTest.java

protected boolean isStartBehaviorEvent(java.awt.event.MouseEvent evt) {
    int nId = evt.getID();
    return ((nId == MouseEvent.MOUSE_DRAGGED) && (evt.isAltDown() != false) && (evt.isMetaDown() == false));
}

From source file:MouseNavigateTest.java

protected boolean isStartBehaviorEvent(java.awt.event.MouseEvent evt) {
    int nId = evt.getID();
    return ((nId == MouseEvent.MOUSE_DRAGGED) && (evt.isAltDown() == false) && (evt.isMetaDown() != false));
}

From source file:corelyzer.ui.CorelyzerGLCanvas.java

public void mouseClicked(final MouseEvent e) {
    Point prePos = e.getPoint();//  ww  w  .j a v a 2s . com
    float sp[] = { 0.0f, 0.0f };
    this.convertMousePointToSceneSpace(prePos, scenePos);

    switch (e.getButton()) {
    case MouseEvent.BUTTON1:
        if (e.getClickCount() > 1) { // doubleclick zoom in/out
            Point mousePos = e.getPoint();

            float[] cp = { 0.0f, 0.0f };
            float[] sc = { 0.0f, 0.0f };

            canvasLock.lock();

            convertMousePointToSceneSpace(mousePos, cp);

            sc[0] = SceneGraph.getSceneCenterX();
            sc[1] = SceneGraph.getSceneCenterY();

            // alt down for zoom out?!
            float base;
            if (e.isAltDown()) { // zoom out
                base = 1.05f;
            } else { // zoom out
                base = 0.95f;
            }

            float scale = (float) Math.pow(base, 3);

            SceneGraph.scaleScene(scale);

            float ncp[] = { 0.0f, 0.0f };

            this.convertMousePointToSceneSpace(mousePos, ncp);
            ncp[0] = ncp[0] - cp[0];
            ncp[1] = ncp[1] - cp[1];

            SceneGraph.panScene(-ncp[0], -ncp[1]);
            canvasLock.unlock();

            CorelyzerApp.getApp().updateGLWindows();
            return;
        }

        // measuring mode
        if (canvasMode == CorelyzerApp.APP_MEASURE_MODE) {
            int nPoint = SceneGraph.addMeasurePoint(scenePos[0], scenePos[1]);
            this.convertScenePointToAbsolute(scenePos, sp);
            if (nPoint == 1) {
                CorelyzerApp.getApp().getToolFrame().addMeasure(sp, 1);
            } else if (nPoint == 2) {
                CorelyzerApp.getApp().getToolFrame().addMeasure(sp, 2);
            }

            PAN_MODE = 0;
            return;
        }

        if (selectedFreeDraw > -1) {
            CorelyzerApp.getApp().getPluginManager().broadcastEventToPlugin(
                    SceneGraph.getFreeDrawPluginID(selectedFreeDraw), CorelyzerPluginEvent.FREE_DRAW_SELECTED,
                    "" + selectedFreeDraw);
            return;
        }

        selectedMarker = SceneGraph.accessPickedMarker();

        if (selectedMarker < 0) {
            if (canvasMode == CorelyzerApp.APP_MARKER_MODE) {
                SceneGraph.setCoreSectionMarkerFocus(false);
                CorelyzerApp.getApp().updateGLWindows();
            }
            return;
        } else {
            if (canvasMode == CorelyzerApp.APP_NORMAL_MODE) {
                AnnotationUtils.openAnnotation(getCanvas(), selectedTrack, selectedTrackSection,
                        selectedMarker);
            } else { // marker mode
                // TODO do something if want to allow user adjust the
                // selected
                // TODO block, like sync to ClastInfo hash...
                if (selectedMarker != SceneGraph.focusedMarker
                        || selectedTrackSection != SceneGraph.focusedTrackSection
                        || selectedTrack != SceneGraph.focusedTrack) {
                    SceneGraph.setCoreSectionMarkerFocus(false);

                    SceneGraph.focusedTrack = selectedTrack;
                    SceneGraph.focusedTrackSection = selectedTrackSection;
                    SceneGraph.focusedMarker = selectedMarker;
                    SceneGraph.setCoreSectionMarkerFocus(true);
                }
            }
        }

        break;

    case MouseEvent.BUTTON2:
        /*
         * System.out.println("---- Middle button clicked at: " +
         * prePos.x + ", " + prePos.y);
         * System.out.println("Converted to Scene Space: " + scenePos[0]
         * + ", " + scenePos[1]);
         */
        break;

    case MouseEvent.BUTTON3:
        /*
         * System.out.println("---- Right button clicked at: " +
         * prePos.x + ", " + prePos.y);
         * System.out.println("Converted to Scene Space: " + scenePos[0]
         * + ", " + scenePos[1]);
         */
        this.handleRightMouseClick(e);
        break;
    default:
        if (e.isPopupTrigger()) {
            this.handleRightMouseClick(e);
        }
    }
}

From source file:corelyzer.ui.CorelyzerGLCanvas.java

/**
 * Handles mouse dragging events: panning, sliding sections, sliding tracks,
 * and trackpad based zooming.//from ww  w.j  av a 2 s.co  m
 */
public void mouseDragged(final MouseEvent e) {

    Point currentPos = e.getPoint();
    int dX = currentPos.x - prePos.x;
    int dY = currentPos.y - prePos.y;

    float sx, sy;
    float w, h;

    canvasLock.lock();

    w = SceneGraph.getCanvasWidth(canvasId);
    h = SceneGraph.getCanvasHeight(canvasId);

    sx = w / canvas.getWidth();
    sy = h / canvas.getHeight();

    this.convertMousePointToSceneSpace(currentPos, scenePos);

    // play a bit measuring test
    if (canvasMode == CorelyzerApp.APP_MEASURE_MODE) {
        SceneGraph.positionMouse(scenePos[0], scenePos[1]);

        // some work for panning
        // automatically pan mode
        canvas.setCursor(new Cursor(Cursor.MOVE_CURSOR));
        SceneGraph.panScene(-dX * sx, -dY * sy);

        canvasLock.unlock();
        prePos = currentPos;
        CorelyzerApp.getApp().updateGLWindows();
        return;
    } else if (canvasMode == CorelyzerApp.APP_CLAST_MODE || canvasMode == CorelyzerApp.APP_CUT_MODE) {
        SceneGraph.positionMouse(scenePos[0], scenePos[1]);

        // Don't have a selected section, just pan
        if (selectedTrackSection == -1) {
            canvas.setCursor(new Cursor(Cursor.MOVE_CURSOR));
            SceneGraph.panScene(-dX * sx, -dY * sy);
        }

        canvasLock.unlock();
        prePos = currentPos;

        CorelyzerApp.getApp().updateGLWindows();
        return;
    }

    // check focused marker manipulation
    if (MANIPULATE_MODE == 1) {
        float dx, dy;
        dx = scenePos[0] - prescenePos[0];
        dy = scenePos[1] - prescenePos[1];
        prescenePos[0] = scenePos[0];
        prescenePos[1] = scenePos[1];
        SceneGraph.manipulateMarker(canvasId, dx, dy);
        SceneGraph.positionMouse(scenePos[0], scenePos[1]);
        canvasLock.unlock();
        prePos = currentPos;
        CorelyzerApp.getApp().updateGLWindows();
        return;
    } else {
        if (e.isAltDown()) // slide track section
        {
            // TODO consider separate move of section image and graph
            // moveSectionImage & moveSectionGraph
            if (selectedTrack >= 0 && selectedTrackSection >= 0) {
                if (canvas.getCursor().getType() != Cursor.HAND_CURSOR) {
                    canvas.setCursor(new Cursor(Cursor.HAND_CURSOR));
                }

                // depth orientation
                float tX = SceneGraph.getDepthOrientation() ? dX * sx : dY * sy;

                // allow vertical movements?
                float tY = 0;
                // float tY = SceneGraph.getDepthOrientation() ?
                // (dY * sy) : (-dX * sx);

                if (selectedGraph >= 0) {
                    // moving graph instead of whole section
                    SceneGraph.moveSectionGraph(selectedTrack, selectedTrackSection, tX, tY);
                } else {
                    Object[] sections = CorelyzerApp.getApp().getSectionList().getSelectedValues();
                    int[] secids = new int[sections.length];
                    for (int i = 0; i < sections.length; i++) {
                        CoreSection cs = (CoreSection) sections[i];
                        secids[i] = (cs != null ? cs.getId() : -1);
                    }
                    SceneGraph.moveSections(selectedTrack, secids, tX, tY);
                }

                // broadcast event to plugins
                String msg = "";
                msg = msg + selectedTrack + "\t" + selectedTrackSection;
                msg = msg + "\t" + dX * sx / SceneGraph.getCanvasDPIX(canvasId) + "\t0";

                CorelyzerApp.getApp().getPluginManager()
                        .broadcastEventToPlugins(CorelyzerPluginEvent.SECTION_MOVED, msg);
            }
        } else if (e.isShiftDown()) { // slide track
            if (selectedTrack >= 0) {
                if (canvas.getCursor().getType() != Cursor.HAND_CURSOR) {
                    canvas.setCursor(new Cursor(Cursor.HAND_CURSOR));
                }

                // fine tune allows depth movements
                if (isFineTune() && finetuneDialog != null) {
                    // depth orientation
                    if (SceneGraph.getDepthOrientation()) { // landscape
                        SceneGraph.moveTrack(selectedTrack, dX * sx, dY * sy);
                    } else { // Portrait
                        SceneGraph.moveTrack(selectedTrack, dY * sy, -dX * sx);
                    }

                    float currentTrackPosX = SceneGraph.getTrackXPos(selectedTrack);
                    float canvasDPIX = SceneGraph.getCanvasDPIX(0);

                    JTextField fineTuneCoreADepthStatus = finetuneDialog.getCoreAAdjustedDepthTextField();
                    JTextField fineTuneCoreBDepthStatus = finetuneDialog.getCoreBAdjustedDepthTextField();
                    int coreANativeID = finetuneDialog.getCoreANativeID();
                    int coreBNativeID = finetuneDialog.getCoreBNativeID();
                    float coreAOrigDepth = finetuneDialog.getCoreAOrigDepth();
                    float coreBOrigDepth = finetuneDialog.getCoreBOrigDepth();

                    if (fineTuneCoreADepthStatus != null && coreANativeID == selectedTrack) {
                        float depth = coreAOrigDepth + 2.54f * currentTrackPosX / (100 * canvasDPIX);
                        fineTuneCoreADepthStatus.setText(String.valueOf(depth));
                    }

                    if (fineTuneCoreBDepthStatus != null && coreBNativeID == selectedTrack) {
                        float depth = coreBOrigDepth + 2.54f * currentTrackPosX / (100 * canvasDPIX);
                        fineTuneCoreBDepthStatus.setText(String.valueOf(depth));
                    }
                } else { // normal
                    // depth orientation
                    if (SceneGraph.getDepthOrientation()) {
                        SceneGraph.moveTrack(selectedTrack, 0.0f, dY * sy);
                    } else {
                        SceneGraph.moveTrack(selectedTrack, 0.0f, -dX * sx);
                    }
                }

                // broadcast message to plugins
                String msg = "";
                msg = msg + selectedTrack;
                msg = msg + "\t0\t" + dY * sx / SceneGraph.getCanvasDPIY(canvasId);
                CorelyzerApp.getApp().getPluginManager()
                        .broadcastEventToPlugins(CorelyzerPluginEvent.TRACK_MOVED, msg);
            }
        } else if (e.isControlDown()) // zooming
        {
            sy = (float) dY / (float) canvas.getHeight();
            SceneGraph.scaleScene(1.0f + sy);
        } else if (PAN_MODE == 1) {
            // automatically pan mode
            canvas.setCursor(new Cursor(Cursor.MOVE_CURSOR));
            SceneGraph.panScene(-dX * sx, -dY * sy);
        }
    } // end of else (manipulation mode)

    SceneGraph.positionMouse(scenePos[0], scenePos[1]);
    canvasLock.unlock();
    prePos = currentPos;
    CorelyzerApp.getApp().updateGLWindows();

}

From source file:com.actelion.research.table.view.JVisualization.java

public void mousePressed(MouseEvent e) {
    mMouseX1 = mMouseX2 = e.getX();//from   ww w .j  a v  a 2 s  . co m
    mMouseY1 = mMouseY2 = e.getY();
    mMouseIsDown = true;

    if (System.getProperty("touch") != null) {
        new Thread() {
            public void run() {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException ie) {
                }

                if (Math.abs(mMouseX2 - mMouseX1) < 5 && Math.abs(mMouseY2 - mMouseY1) < 5 && mMouseIsDown) {
                    SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
                            activateTouchFunction();
                        }
                    });
                }
            }
        }.start();
    }

    mRectangleSelecting = false;
    mLassoSelecting = false;
    if (!handlePopupTrigger(e) && (e.getModifiers() & InputEvent.BUTTON3_MASK) == 0) {
        mAddingToSelection = e.isShiftDown();
        if (e.isAltDown())
            mRectangleSelecting = true;
        else {
            mLassoSelecting = true;
            mLassoRegion = new Polygon();
            mLassoRegion.addPoint(mMouseX1, mMouseY1);
            mLassoRegion.addPoint(mMouseX1, mMouseY1);
        }
    }
}

From source file:de.tor.tribes.ui.windows.DSWorkbenchMainFrame.java

/**
 * Creates new form MapFrame/* w  w w  .  j  a  va2  s .  c o  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();
}

From source file:corelyzer.ui.CorelyzerGLCanvas.java

private void updateMainFrameListSelection(final int track, final int section, final MouseEvent event) {
    CorelyzerApp app = CorelyzerApp.getApp();
    if (app == null) {
        return;//w w  w . jav  a2 s.co m
    }

    if (track >= 0) {
        // Now, we need to traverse app's list model
        // to find match of native id
        // index conversion (native to java list)

        CRDefaultListModel sessionModel = app.getSessionListModel();
        int sessionIndex = -1;
        TrackSceneNode trackNode = null;
        for (int i = 0; i < sessionModel.size(); i++) {
            Session session = (Session) sessionModel.elementAt(i);
            trackNode = session.getTrackSceneNodeWithTrackId(track);

            if (trackNode != null) {
                sessionIndex = i;
            }
        }

        if (sessionIndex < 0) {
            return;
        }

        // Set selected session
        app.getSessionList().setSelectedIndex(sessionIndex);

        // Track
        int ssize;
        boolean found = false;
        CRDefaultListModel tmodel = app.getTrackListModel();
        // tsize = tmodel.getSize();
        TrackSceneNode tt;
        CoreSection cs = null;

        for (int i = 0; i < tmodel.size() && !found; i++) {
            tt = (TrackSceneNode) tmodel.elementAt(i);

            if (track == tt.getId()) {
                selectedTrackIndex = i;
                ssize = tt.getNumCores();

                for (int j = 0; j < ssize; j++) {
                    cs = tt.getCoreSection(j);
                    if (section == cs.getId()) {
                        selectedTrackSectionIndex = j;
                        found = true;
                        break;
                    }
                }
            }
        }

        if (!found || cs == null) {
            return;
        }

        // update ui
        CorelyzerApp.getApp().getTrackList().setSelectedIndex(selectedTrackIndex);
        JList secList = CorelyzerApp.getApp().getSectionList();
        boolean selected = secList.isSelectedIndex(selectedTrackSectionIndex);
        List<Integer> indices = new ArrayList<Integer>();
        indices.addAll(Arrays.asList(ArrayUtils.toObject(secList.getSelectedIndices())));
        if (event.isControlDown() || (event.isMetaDown() && CorelyzerApp.MAC_OS_X)) { // toggle selection
            if (indices.contains(selectedTrackSectionIndex))
                indices.remove(new Integer(selectedTrackSectionIndex));
            else
                indices.add(selectedTrackSectionIndex);

            int[] newSelArray = ArrayUtils.toPrimitive(indices.toArray(new Integer[0]));
            secList.setSelectedIndices(newSelArray);
        } else if (event.isShiftDown()) { // select range
            int[] toSel = null;
            if (indices.size() == 0) {
                toSel = makeRangeArray(0, selectedTrackSectionIndex);
            } else {
                final int minSel = Collections.min(indices);
                final int maxSel = Collections.max(indices);
                if (selectedTrackSectionIndex < minSel) {
                    toSel = makeRangeArray(selectedTrackSectionIndex, minSel);
                } else if (selectedTrackSectionIndex > maxSel) {
                    toSel = makeRangeArray(maxSel, selectedTrackSectionIndex);
                }
            }
            secList.setSelectedIndices(toSel);
        } else if (!(event.isAltDown() && selected)) {
            // don't modify selection if Alt is down and section was already
            // selected...user is presumably trying to move it
            secList.setSelectedIndex(selectedTrackSectionIndex);
        }

        CRDefaultListModel lm = CorelyzerApp.getApp().getSectionListModel();
        String secName = null;
        if (lm != null) {
            Object selSec = lm.getElementAt(selectedTrackSectionIndex);
            if (selSec != null) {
                secName = selSec.toString();
            } else {
                System.out.println("no object at index");
            }
        } else {
            System.out.println("no list model");
        }

        JMenuItem title = (JMenuItem) this.scenePopupMenu.getComponent(0);
        String trackName = CorelyzerApp.getApp().getTrackListModel().getElementAt(selectedTrackIndex)
                .toString();
        title.setText("Track: " + trackName);
        JMenuItem stitle = (JMenuItem) this.scenePopupMenu.getComponent(1);
        stitle.setText("Section: " + secName);

        // Enable section-based popupMenu options
        this.setEnableSectionBasedPopupMenuOptions(true);

        // 2/5/2012 brg: check Stagger Sections menu item if necessary
        final boolean trackIsStaggered = SceneGraph.trackIsStaggered(selectedTrack);
        AbstractButton ab = (AbstractButton) this.scenePopupMenu.getComponent(14);
        ab.getModel().setSelected(trackIsStaggered);

        // check section and graph lock menu items
        final boolean sectionIsLocked = !SceneGraph.isSectionMovable(selectedTrack, selectedTrackSection);
        ab = (AbstractButton) this.scenePopupMenu.getComponent(7);
        ab.getModel().setSelected(sectionIsLocked);
        final boolean sectionGraphIsLocked = !SceneGraph.isSectionGraphMovable(selectedTrack,
                selectedTrackSection);
        ab = (AbstractButton) this.scenePopupMenu.getComponent(8);
        ab.getModel().setSelected(sectionGraphIsLocked);

        CoreSectionImage csImg = cs.getCoreSectionImage();
        if (csImg != null && csImg.getId() != -1) {
            this.propertyMenuItem.setEnabled(true);
            this.splitMenuItem.setEnabled(true);
        } else {
            this.propertyMenuItem.setEnabled(false);
            this.splitMenuItem.setEnabled(false);
        }

        // System.out.println("---> [in Java DS] Picked Track " + track +
        // " and Track Section " + section);
        // String secname = CorelyzerApp.getApp().getSectionListModel().
        // getElementAt(section).toString();
        // System.out.println("---> [INFO] Section " + secname +
        // " is selected");
    } else {
        JMenuItem title = (JMenuItem) this.scenePopupMenu.getComponent(0);
        title.setText("Track: N/A");
        JMenuItem stitle = (JMenuItem) this.scenePopupMenu.getComponent(1);
        stitle.setText("Section: N/A");

        // disable section based items
        this.setEnableSectionBasedPopupMenuOptions(false);
    }
}