Example usage for java.awt.event MouseEvent getY

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

Introduction

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

Prototype

public int getY() 

Source Link

Document

Returns the vertical y position of the event relative to the source component.

Usage

From source file:de.tor.tribes.ui.panels.MinimapPanel.java

/**
 * Creates new form MinimapPanel/*w  w  w .ja v a2  s  . co  m*/
 */
MinimapPanel() {
    initComponents();
    setSize(300, 300);
    mMinimapListeners = new LinkedList<>();
    mToolChangeListeners = new LinkedList<>();
    setCursor(ImageManager.getCursor(iCurrentCursor));
    mScreenshotPanel = new ScreenshotPanel();
    minimapButtons.put(ID_MINIMAP, new Rectangle(2, 2, 26, 26));
    minimapButtons.put(ID_ALLY_CHART, new Rectangle(30, 2, 26, 26));
    minimapButtons.put(ID_TRIBE_CHART, new Rectangle(60, 2, 26, 26));
    try {
        minimapIcons.put(ID_MINIMAP, ImageIO.read(new File("./graphics/icons/minimap.png")));
        minimapIcons.put(ID_ALLY_CHART, ImageIO.read(new File("./graphics/icons/ally_chart.png")));
        minimapIcons.put(ID_TRIBE_CHART, ImageIO.read(new File("./graphics/icons/tribe_chart.png")));
    } catch (Exception ignored) {
    }
    jPanel1.add(mScreenshotPanel);
    rVisiblePart = new Rectangle(ServerSettings.getSingleton().getMapDimension());
    zoomed = false;
    MarkerManager.getSingleton().addManagerListener(this);
    TagManager.getSingleton().addManagerListener(this);
    MinimapRepaintThread.getSingleton().setVisiblePart(rVisiblePart);
    if (!GlobalOptions.isMinimal()) {
        MinimapRepaintThread.getSingleton().start();
    }
    addMouseListener(new MouseListener() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (!showControls && e.getButton() != MouseEvent.BUTTON1) {
                //show controls
                Point p = e.getPoint();
                p.translate(-5, -5);
                showControls(p);
                return;
            }
            if (!showControls && iCurrentView == ID_MINIMAP) {
                Point p = mousePosToMapPosition(e.getX(), e.getY());
                DSWorkbenchMainFrame.getSingleton().centerPosition(p.getX(), p.getY());
                MapPanel.getSingleton().getMapRenderer().initiateRedraw(MapRenderer.ALL_LAYERS);
                if (MinimapZoomFrame.getSingleton().isVisible()) {
                    MinimapZoomFrame.getSingleton().toFront();
                }
            } else {
                if (minimapButtons.get(ID_MINIMAP).contains(e.getPoint())) {
                    iCurrentView = ID_MINIMAP;
                    mBuffer = null;
                    showControls = false;
                    MinimapRepaintThread.getSingleton().update();
                } else if (minimapButtons.get(ID_ALLY_CHART).contains(e.getPoint())) {
                    iCurrentView = ID_ALLY_CHART;
                    lastHash = 0;
                    showControls = false;
                    updateComplete();
                } else if (minimapButtons.get(ID_TRIBE_CHART).contains(e.getPoint())) {
                    iCurrentView = ID_TRIBE_CHART;
                    lastHash = 0;
                    showControls = false;
                    updateComplete();
                }
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
            if (iCurrentView != ID_MINIMAP) {
                return;
            }
            if (iCurrentCursor == ImageManager.CURSOR_SHOT || iCurrentCursor == ImageManager.CURSOR_ZOOM) {
                iXDown = e.getX();
                iYDown = e.getY();
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            if (iCurrentView != ID_MINIMAP) {
                return;
            }
            if (rDrag == null) {
                return;
            }
            if (iCurrentCursor == ImageManager.CURSOR_SHOT) {
                try {
                    BufferedImage i = MinimapRepaintThread.getSingleton().getImage();
                    double widthFactor = ((double) ServerSettings.getSingleton().getMapDimension().width)
                            / getWidth();
                    double heightFactor = ((double) ServerSettings.getSingleton().getMapDimension().height)
                            / getHeight();

                    int x = (int) Math.rint(widthFactor * rDrag.getX());
                    int y = (int) Math.rint(heightFactor * rDrag.getY());
                    int w = (int) Math.rint(widthFactor * (rDrag.getWidth() - rDrag.getX()));
                    int h = (int) Math.rint(heightFactor * (rDrag.getHeight() - rDrag.getY()));
                    BufferedImage sub = i.getSubimage(x, y, w, h);
                    mScreenshotPanel.setBuffer(sub);
                    jPanel1.setSize(mScreenshotPanel.getSize());
                    jPanel1.setPreferredSize(mScreenshotPanel.getSize());
                    jPanel1.setMinimumSize(mScreenshotPanel.getSize());
                    jPanel1.setMaximumSize(mScreenshotPanel.getSize());
                    jScreenshotPreview.pack();
                    jScreenshotControl.pack();
                    jScreenshotPreview.setVisible(true);
                    jScreenshotControl.setVisible(true);
                } catch (Exception ie) {
                    logger.error("Failed to initialize mapshot", ie);
                }
            } else if (iCurrentCursor == ImageManager.CURSOR_ZOOM) {
                if (!zoomed) {
                    Rectangle mapDim = ServerSettings.getSingleton().getMapDimension();
                    double widthFactor = ((double) mapDim.width) / getWidth();
                    double heightFactor = ((double) mapDim.height) / getHeight();

                    int x = (int) Math.rint(widthFactor * rDrag.getX() + mapDim.getMinX());
                    int y = (int) Math.rint(heightFactor * rDrag.getY() + mapDim.getMinY());
                    int w = (int) Math.rint(widthFactor * (rDrag.getWidth() - rDrag.getX()));

                    if (w >= 10) {
                        rVisiblePart = new Rectangle(x, y, w, w);
                        MinimapRepaintThread.getSingleton().setVisiblePart(rVisiblePart);
                        redraw();
                        zoomed = true;
                    }
                } else {
                    rVisiblePart = new Rectangle(ServerSettings.getSingleton().getMapDimension());
                    MinimapRepaintThread.getSingleton().setVisiblePart(rVisiblePart);
                    redraw();
                    zoomed = false;
                }
                MinimapZoomFrame.getSingleton().setVisible(false);
            }
            iXDown = 0;
            iYDown = 0;
            rDrag = null;
        }

        @Override
        public void mouseEntered(MouseEvent e) {
            if (iCurrentView != ID_MINIMAP) {
                return;
            }
            switch (iCurrentCursor) {
            case ImageManager.CURSOR_ZOOM: {
                MinimapZoomFrame.getSingleton().setVisible(true);
            }
            }
        }

        @Override
        public void mouseExited(MouseEvent e) {
            if (MinimapZoomFrame.getSingleton().isVisible()) {
                MinimapZoomFrame.getSingleton().setVisible(false);
            }
            iXDown = 0;
            iYDown = 0;
            rDrag = null;
        }
    });

    addMouseMotionListener(new MouseMotionListener() {

        @Override
        public void mouseDragged(MouseEvent e) {
            if (iCurrentView != ID_MINIMAP) {
                return;
            }
            switch (iCurrentCursor) {
            case ImageManager.CURSOR_MOVE: {
                Point p = mousePosToMapPosition(e.getX(), e.getY());
                DSWorkbenchMainFrame.getSingleton().centerPosition(p.x, p.y);
                rDrag = null;
                break;
            }
            case ImageManager.CURSOR_SHOT: {
                rDrag = new Rectangle2D.Double(iXDown, iYDown, e.getX(), e.getY());
                break;
            }
            case ImageManager.CURSOR_ZOOM: {
                rDrag = new Rectangle2D.Double(iXDown, iYDown, e.getX(), e.getY());
                break;
            }
            }
        }

        @Override
        public void mouseMoved(MouseEvent e) {
            if (iCurrentView == ID_MINIMAP) {
                switch (iCurrentCursor) {
                case ImageManager.CURSOR_ZOOM: {
                    if (!MinimapZoomFrame.getSingleton().isVisible()) {
                        MinimapZoomFrame.getSingleton().setVisible(true);
                    }
                    int mapWidth = (int) ServerSettings.getSingleton().getMapDimension().getWidth();
                    int mapHeight = (int) ServerSettings.getSingleton().getMapDimension().getHeight();

                    int x = (int) Math.rint((double) mapWidth / (double) getWidth() * (double) e.getX());
                    int y = (int) Math.rint((double) mapHeight / (double) getHeight() * (double) e.getY());
                    MinimapZoomFrame.getSingleton().updatePosition(x, y);
                    break;
                }
                default: {
                    if (MinimapZoomFrame.getSingleton().isVisible()) {
                        MinimapZoomFrame.getSingleton().setVisible(false);
                    }
                }
                }
            }
            Point location = minimapButtons.get(ID_MINIMAP).getLocation();
            location.translate(-2, -2);
            if (!new Rectangle(location.x, location.y, 88, 30).contains(e.getPoint())) {
                //hide controls
                showControls = false;
                repaint();
            }
        }
    });

    addMouseWheelListener(new MouseWheelListener() {

        @Override
        public void mouseWheelMoved(MouseWheelEvent e) {

            if (iCurrentView != ID_MINIMAP) {
                return;
            }
            iCurrentCursor += e.getWheelRotation();
            if (iCurrentCursor == ImageManager.CURSOR_DEFAULT + e.getWheelRotation()) {
                if (e.getWheelRotation() < 0) {
                    iCurrentCursor = ImageManager.CURSOR_SHOT;
                } else {
                    iCurrentCursor = ImageManager.CURSOR_MOVE;
                }
            } else if (iCurrentCursor < ImageManager.CURSOR_MOVE) {
                iCurrentCursor = ImageManager.CURSOR_DEFAULT;
            } else if (iCurrentCursor > ImageManager.CURSOR_SHOT) {
                iCurrentCursor = ImageManager.CURSOR_DEFAULT;
            }
            if (iCurrentCursor != ImageManager.CURSOR_ZOOM) {
                if (MinimapZoomFrame.getSingleton().isVisible()) {
                    MinimapZoomFrame.getSingleton().setVisible(false);
                }
            } else {
                MinimapZoomFrame.getSingleton().setVisible(true);
            }
            setCurrentCursor(iCurrentCursor);
        }
    });

}

From source file:com.t3.client.ui.T3Frame.java

private JComponent createTokenTreePanel() {
    final JTree tree = new JTree();
    tokenPanelTreeModel = new TokenPanelTreeModel(tree);
    tree.setModel(tokenPanelTreeModel);/* w  w w  .  j  a v  a 2  s .c  o  m*/
    tree.setCellRenderer(new TokenPanelTreeCellRenderer());
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    tree.addMouseListener(new MouseAdapter() {
        // TODO: Make this a handler class, not an aic
        @Override
        public void mousePressed(MouseEvent e) {
            // tree.setSelectionPath(tree.getPathForLocation(e.getX(), e.getY()));
            TreePath path = tree.getPathForLocation(e.getX(), e.getY());
            if (path == null) {
                return;
            }
            Object row = path.getLastPathComponent();
            int rowIndex = tree.getRowForLocation(e.getX(), e.getY());
            if (SwingUtilities.isLeftMouseButton(e)) {
                if (!SwingUtil.isShiftDown(e)) {
                    tree.clearSelection();
                }
                tree.addSelectionInterval(rowIndex, rowIndex);

                if (row instanceof Token) {
                    if (e.getClickCount() == 2) {
                        Token token = (Token) row;
                        getCurrentZoneRenderer().clearSelectedTokens();
                        getCurrentZoneRenderer().centerOn(new ZonePoint(token.getX(), token.getY()));

                        // Pick an appropriate tool
                        getToolbox().setSelectedTool(token.isToken() ? PointerTool.class : StampTool.class);
                        getCurrentZoneRenderer().setActiveLayer(token.getLayer());
                        getCurrentZoneRenderer().selectToken(token.getId());
                        getCurrentZoneRenderer().requestFocusInWindow();
                    }
                }
            }
            if (SwingUtilities.isRightMouseButton(e)) {
                if (!isRowSelected(tree.getSelectionRows(), rowIndex) && !SwingUtil.isShiftDown(e)) {
                    tree.clearSelection();
                    tree.addSelectionInterval(rowIndex, rowIndex);
                }
                final int x = e.getX();
                final int y = e.getY();
                EventQueue.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        Token firstToken = null;
                        Set<GUID> selectedTokenSet = new HashSet<GUID>();
                        for (TreePath path : tree.getSelectionPaths()) {
                            if (path.getLastPathComponent() instanceof Token) {
                                Token token = (Token) path.getLastPathComponent();
                                if (firstToken == null) {
                                    firstToken = token;
                                }
                                if (AppUtil.playerOwns(token)) {
                                    selectedTokenSet.add(token.getId());
                                }
                            }
                        }
                        if (!selectedTokenSet.isEmpty()) {
                            try {
                                if (firstToken.isStamp()) {
                                    new StampPopupMenu(selectedTokenSet, x, y, getCurrentZoneRenderer(),
                                            firstToken).showPopup(tree);
                                } else {
                                    new TokenPopupMenu(selectedTokenSet, x, y, getCurrentZoneRenderer(),
                                            firstToken).showPopup(tree);
                                }
                            } catch (IllegalComponentStateException icse) {
                                log.info(tree.toString(), icse);
                            }
                        }
                    }
                });
            }
        }
    });
    TabletopTool.getEventDispatcher().addListener(new AppEventListener() {
        @Override
        public void handleAppEvent(AppEvent event) {
            tokenPanelTreeModel.setZone((Zone) event.getNewValue());
        }
    }, TabletopTool.ZoneEvent.Activated);
    return tree;
}

From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java

private double userY(MouseEvent event) {
    Rectangle2D rectangle = getScaledDataArea();
    double minY = rectangle.getMinY();
    double maxY = rectangle.getMaxY();
    Plot plot = chart.getPlot();/* w  w w.j  av a 2  s  .com*/
    int yc = event.getY();

    ValueAxis ya = this.getVerticalValueAxis(plot);
    double ymin = ya.getLowerBound();
    double ymax = ya.getUpperBound();
    double v = (yc - minY) / (maxY - minY);
    v = 1 - v;
    return (v * (ymax - ymin) + ymin);
}

From source file:org.gumtree.vis.hist2d.Hist2DPanel.java

@Override
public void mousePressed(MouseEvent e) {
    //        int mods = e.getModifiers();
    //        if (isMaskingEnabled() && (mods & maskingKeyMask) != 0) {
    if (isMaskingEnabled()) {
        // Prepare masking service.
        int cursorType = findCursorOnSelectedItem(e.getX(), e.getY());
        if (cursorType == Cursor.DEFAULT_CURSOR) {
            Rectangle2D screenDataArea = getScreenDataArea(e.getX(), e.getY());
            if (screenDataArea != null) {
                this.maskPoint = getPointInRectangle(e.getX(), e.getY(), screenDataArea);
            } else {
                this.maskPoint = null;
            }/*from w w w  .  ja v  a2  s .c  om*/
        } else {
            if (cursorType == Cursor.MOVE_CURSOR) {
                Point2D point = translateScreenToChart(translateScreenToJava2D(e.getPoint()));
                if (point != null) {
                    this.maskMovePoint = point;
                }
            }
            setMaskDragIndicator(cursorType);
        }
    }
    if (getMaskDragIndicator() == Cursor.DEFAULT_CURSOR) {
        if (e.getX() < getScreenDataArea().getMaxX()) {
            super.mousePressed(e);
        }
    }
}

From source file:gda.gui.mca.McaGUI.java

private SimplePlot getSimplePlot() {
    if (simplePlot == null) {
        simplePlot = new SimplePlot();
        simplePlot.setYAxisLabel("Values");
        simplePlot.setTitle("MCA");
        /*// w ww. j  a v  a2s.c o m
         * do not attempt to get calibration until the analyser is available getEnergyCalibration();
         */

        simplePlot.setXAxisLabel("Channel Number");

        simplePlot.setTrackPointer(true);
        JPopupMenu menu = simplePlot.getPopupMenu();
        JMenuItem item = new JMenuItem("Add Region Of Interest");
        menu.add(item);
        item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(null, "To add a region of interest, please click on region low"
                        + " and region high channels\n" + "in the graph and set the index\n");
                regionClickCount = 0;
            }
        });

        JMenuItem calibitem = new JMenuItem("Calibrate Energy");
        /*
         * Comment out as calibration is to come from the analyser directly menu.add(calibitem);
         */
        calibitem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    // regionClickCount = 0;
                    int[] data = (int[]) analyser.getData();
                    double[] dData = new double[data.length];
                    for (int i = 0; i < dData.length; i++) {
                        dData[i] = data[i];
                    }
                    if (energyCalibrationDialog == null) {
                        energyCalibrationDialog = new McaCalibrationPanel(
                                (EpicsMCARegionOfInterest[]) analyser.getRegionsOfInterest(), dData, mcaName);
                        energyCalibrationDialog.addIObserver(McaGUI.this);
                    }
                    energyCalibrationDialog.setVisible(true);
                } catch (DeviceException e1) {
                    logger.error("Exception: " + e1.getMessage());
                } catch (Exception ex) {
                    JOptionPane.showMessageDialog(null, ex.getMessage());
                    ex.printStackTrace();
                }
            }

        });

        simplePlot.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent me) {
                // /////////System.out.println("Mouse clicked " +
                // me.getX() + " "
                // /////// + me.getY());
                SimpleDataCoordinate coordinates = simplePlot.convertMouseEvent(me);
                if (simplePlot.getScreenDataArea().contains(me.getX(), me.getY()) && regionClickCount == 0) {
                    regionLow = coordinates.toArray();
                    regionClickCount++;
                } else if (simplePlot.getScreenDataArea().contains(me.getX(), me.getY())
                        && regionClickCount == 1) {
                    regionHigh = coordinates.toArray();
                    regionClickCount++;

                    if (regionValid(regionLow[0], regionHigh[0])) {

                        final String s = (String) JOptionPane.showInputDialog(null,
                                "Please select the Region Index:\n", "Region Of Interest",
                                JOptionPane.PLAIN_MESSAGE, null, null, String.valueOf(getNextRegion()));
                        Thread t1 = uk.ac.gda.util.ThreadManager.getThread(new Runnable() {
                            @Override
                            public void run() {

                                try {

                                    if (s != null) {
                                        int rIndex = Integer.parseInt(s);
                                        EpicsMCARegionOfInterest[] epc = { new EpicsMCARegionOfInterest() };
                                        epc[0].setRegionLow(regionLow[0]);
                                        epc[0].setRegionHigh(regionHigh[0]);
                                        epc[0].setRegionIndex(rIndex);
                                        epc[0].setRegionName("region " + rIndex);
                                        analyser.setRegionsOfInterest(epc);

                                        addRegionMarkers(rIndex, regionLow[0], regionHigh[0]);
                                    }

                                } catch (DeviceException e) {
                                    logger.error("Unable to set the table values");
                                }

                            }

                        });
                        t1.start();
                    }
                }
            }

        });

        // TODO note that selectePlot cannot be changed runtime
        simplePlot.initializeLine(selectedPlot);
        simplePlot.setLineName(selectedPlot, getSelectedPlotString());
        simplePlot.setLineColor(selectedPlot, getSelectedPlotColor());
        simplePlot.setLineType(selectedPlot, "LineOnly");

    }
    return simplePlot;
}

From source file:org.gvsig.remotesensing.scatterplot.chart.ScatterPlotDiagram.java

/**
 * Handles a 'mouse released' event.  On Windows, we need to check if this 
 * is a popup trigger, but only if we haven't already been tracking a zoom
 * rectangle./*from w w w .j a v  a  2s  . com*/
 *
 * @param e  information about the event.
 */
public void mouseReleased(MouseEvent e) {

    if (this.zoomRectangle != null) {
        boolean hZoom = false;
        boolean vZoom = false;
        if (this.orientation == PlotOrientation.HORIZONTAL) {
            hZoom = this.rangeZoomable;
            vZoom = this.domainZoomable;
        } else {
            hZoom = this.domainZoomable;
            vZoom = this.rangeZoomable;
        }

        boolean zoomTrigger1 = hZoom && Math.abs(e.getX() - this.zoomPoint.getX()) >= this.zoomTriggerDistance;
        boolean zoomTrigger2 = vZoom && Math.abs(e.getY() - this.zoomPoint.getY()) >= this.zoomTriggerDistance;
        if (zoomTrigger1 || zoomTrigger2) {
            if ((hZoom && (e.getX() < this.zoomPoint.getX()))
                    || (vZoom && (e.getY() < this.zoomPoint.getY()))) {
                // restoreAutoBounds();
            } else {
                double x, y, w, h;
                Rectangle2D screenDataArea = getScreenDataArea((int) this.zoomPoint.getX(),
                        (int) this.zoomPoint.getY());
                // for mouseReleased event, (horizontalZoom || verticalZoom)
                // will be true, so we can just test for either being false;
                // otherwise both are true
                if (!vZoom) {
                    x = this.zoomPoint.getX();
                    y = screenDataArea.getMinY();
                    w = Math.min(this.zoomRectangle.getWidth(),
                            screenDataArea.getMaxX() - this.zoomPoint.getX());
                    h = screenDataArea.getHeight();
                } else if (!hZoom) {
                    x = screenDataArea.getMinX();
                    y = this.zoomPoint.getY();
                    w = screenDataArea.getWidth();
                    h = Math.min(this.zoomRectangle.getHeight(),
                            screenDataArea.getMaxY() - this.zoomPoint.getY());
                } else {
                    x = this.zoomPoint.getX();
                    y = this.zoomPoint.getY();
                    w = Math.min(this.zoomRectangle.getWidth(),
                            screenDataArea.getMaxX() - this.zoomPoint.getX());
                    h = Math.min(this.zoomRectangle.getHeight(),
                            screenDataArea.getMaxY() - this.zoomPoint.getY());
                }
                if (activeROI != null) {
                    Rectangle2D rectangleArea = new Rectangle2D.Double(x, y, w, h);
                    g2 = (Graphics2D) getGraphics();
                    g2.setPaint(activeROI.getColor());
                    g2.draw(rectangleArea);
                    activeROI.add(rectangleArea, getRange(rectangleArea));
                    RoiFromChartProcess process = new RoiFromChartProcess();
                    process.addParam("roi", activeROI);
                    process.addParam("raster", (FLyrRasterSE) rasterSE);
                    process.setActions(this);
                    process.start();
                    if (gestorRois != null) {
                        // Cargar la nueva ROI en el destor
                        gestorRois.clearRoiGraphics();
                    }
                }

            }
            this.zoomPoint = null;
            this.zoomRectangle = null;
            updateUI();
        } else {
            // Erase the zoom rectangle
            Graphics2D g2 = (Graphics2D) getGraphics();
            drawRectangle(g2);
            g2.dispose();
            this.zoomPoint = null;
            this.zoomRectangle = null;
        }

    }

    else if (e.isPopupTrigger()) {
        if (this.popup != null) {
            displayPopupMenu(e.getX(), e.getY());
        }
    }
}

From source file:net.rptools.maptool.client.ui.MapToolFrame.java

private JComponent createDrawTreePanel() {
    final JTree tree = new JTree();
    drawablesPanel = new DrawablesPanel();
    drawPanelTreeModel = new DrawPanelTreeModel(tree);
    tree.setModel(drawPanelTreeModel);/* w  ww . j  a v  a 2s.  c  o  m*/
    tree.setCellRenderer(new DrawPanelTreeCellRenderer());
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);

    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitPane.setContinuousLayout(true);

    splitPane.setTopComponent(new JScrollPane(tree));
    splitPane.setBottomComponent(drawablesPanel);
    splitPane.setDividerLocation(100);
    // Add mouse Event for right click menu
    tree.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            TreePath path = tree.getPathForLocation(e.getX(), e.getY());
            if (path == null) {
                return;
            }
            Object row = path.getLastPathComponent();
            int rowIndex = tree.getRowForLocation(e.getX(), e.getY());
            if (SwingUtilities.isLeftMouseButton(e)) {
                if (!SwingUtil.isShiftDown(e) && !SwingUtil.isControlDown(e)) {
                    tree.clearSelection();
                }
                tree.addSelectionInterval(rowIndex, rowIndex);
                if (row instanceof DrawnElement) {
                    if (e.getClickCount() == 2) {
                        DrawnElement de = (DrawnElement) row;
                        getCurrentZoneRenderer()
                                .centerOn(new ZonePoint((int) de.getDrawable().getBounds().getCenterX(),
                                        (int) de.getDrawable().getBounds().getCenterY()));
                    }
                }

                int[] treeRows = tree.getSelectionRows();
                java.util.Arrays.sort(treeRows);
                drawablesPanel.clearSelectedIds();
                for (int i = 0; i < treeRows.length; i++) {
                    TreePath p = tree.getPathForRow(treeRows[i]);
                    if (p.getLastPathComponent() instanceof DrawnElement) {
                        DrawnElement de = (DrawnElement) p.getLastPathComponent();
                        drawablesPanel.addSelectedId(de.getDrawable().getId());
                    }
                }
            }
            if (SwingUtilities.isRightMouseButton(e)) {
                if (!isRowSelected(tree.getSelectionRows(), rowIndex) && !SwingUtil.isShiftDown(e)) {
                    tree.clearSelection();
                    tree.addSelectionInterval(rowIndex, rowIndex);
                    drawablesPanel.clearSelectedIds();
                }
                final int x = e.getX();
                final int y = e.getY();
                EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        DrawnElement firstElement = null;
                        Set<GUID> selectedDrawSet = new HashSet<GUID>();
                        for (TreePath path : tree.getSelectionPaths()) {
                            if (path.getLastPathComponent() instanceof DrawnElement) {
                                DrawnElement de = (DrawnElement) path.getLastPathComponent();
                                if (firstElement == null) {
                                    firstElement = de;
                                }
                                selectedDrawSet.add(de.getDrawable().getId());
                            }
                        }
                        if (!selectedDrawSet.isEmpty()) {
                            try {
                                new DrawPanelPopupMenu(selectedDrawSet, x, y, getCurrentZoneRenderer(),
                                        firstElement).showPopup(tree);
                            } catch (IllegalComponentStateException icse) {
                                log.info(tree.toString(), icse);
                            }
                        }
                    }
                });
            }
        }

    });
    // Add Zone Change event
    MapTool.getEventDispatcher().addListener(new AppEventListener() {
        public void handleAppEvent(AppEvent event) {
            drawPanelTreeModel.setZone((Zone) event.getNewValue());
        }
    }, MapTool.ZoneEvent.Activated);
    return splitPane;
}

From source file:edu.ku.brc.specify.tasks.SystemSetupTask.java

/**
 * Adds the Context PopupMenu for the RecordSet.
 * @param roc the RolloverCommand btn to add the pop to
 *///from  ww  w.j  a v  a  2s .  c  o m
public void addPopMenu(final RolloverCommand roc, final PickList pickList) {
    if (roc.getLabelText() != null) {
        final JPopupMenu popupMenu = new JPopupMenu();

        JMenuItem delMenuItem = new JMenuItem(getResourceString("Delete"));
        if (!pickList.getIsSystem()) {
            delMenuItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent actionEvent) {
                    CommandDispatcher.dispatch(new CommandAction(SYSTEMSETUPTASK, DELETE_CMD_ACT, roc));
                }
            });
        } else {
            delMenuItem.setEnabled(false);
        }
        popupMenu.add(delMenuItem);

        JMenuItem viewMenuItem = new JMenuItem(getResourceString("EDIT"));
        viewMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent actionEvent) {
                startEditor(edu.ku.brc.specify.datamodel.PickList.class, "name", roc.getName(), roc.getName(),
                        PICKLIST);
            }
        });
        popupMenu.add(viewMenuItem);

        MouseListener mouseListener = new MouseAdapter() {
            private boolean showIfPopupTrigger(MouseEvent mouseEvent) {
                if (roc.isEnabled() && mouseEvent.isPopupTrigger() && popupMenu.getComponentCount() > 0) {
                    popupMenu.show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY());
                    return true;
                }
                return false;
            }

            @Override
            public void mousePressed(MouseEvent mouseEvent) {
                if (roc.isEnabled()) {
                    showIfPopupTrigger(mouseEvent);
                }
            }

            @Override
            public void mouseReleased(MouseEvent mouseEvent) {
                if (roc.isEnabled()) {
                    showIfPopupTrigger(mouseEvent);
                }
            }
        };
        roc.addMouseListener(mouseListener);
    }
}

From source file:ucar.unidata.idv.control.chart.TimeSeriesChartWrapper.java

/**
 * Callback method for receiving notification of a mouse click on a chart.
 *
 * @param event  information about the event.
 *
 * @return Did we handle this event/*from w w  w.  j a  va  2 s.c  o m*/
 */
public boolean chartPanelMouseClicked(MouseEvent event) {
    if (SwingUtilities.isRightMouseButton(event)) {
        closestAnnotation = findClosestAnnotation(getAllAnnotations(), event.getX(), event.getY(), false,
                false);
        return EVENT_PASSON;
    }

    if (event.getClickCount() <= 1) {
        ChartAnnotation annotation = findClosestAnnotation(getAllAnnotations(), event.getX(), event.getY(),
                true, event.isShiftDown());
        if (annotation == null) {
            return false;
        }
        signalChartChanged();
        return EVENT_DONTPASSON;
    }

    try {
        if (isOnBottomDomainAxis(event)) {
            WayPoint waypoint = new WayPoint(getDomainValue(event.getX()), this);
            waypoint.addPropertyChangeListener(this);
            if (!waypoint.showProperties(chartPanel, event.getX(), event.getY())) {
                return EVENT_DONTPASSON;
            }
            wayPoints.add(waypoint);
            setSelectedAnnotation(waypoint, wayPoints, event.isShiftDown());
            setLocationPositions();
            plot.addAnnotation(waypoint);
        } else if (isOnLeftRangeAxis(event)) {
            //                System.err.println("new x/y:" + event.getX() +"/" +event.getY());
            RangeFilter rangeFilter = new RangeFilter(getRangeValue(event.getY()), this);
            if (!rangeFilter.showProperties(chartPanel, event.getX(), event.getY())) {
                return EVENT_DONTPASSON;
            }
            rangeFilters.add(rangeFilter);

            setSelectedAnnotation(rangeFilter, rangeFilters, event.isShiftDown());
            plot.addAnnotation(rangeFilter);

            if (true || event.isShiftDown()) {
                RangeFilter attached = rangeFilter.doMakeAttached(event);
                rangeFilters.add(attached);
                plot.addAnnotation(attached);
            }
            rangeFiltersChanged();
        } else {
            return EVENT_PASSON;
        }
    } catch (Exception exc) {
        LogUtil.logException("Error creating wayPoints", exc);
    }
    return EVENT_DONTPASSON;
}

From source file:edu.ku.brc.specify.tasks.subpane.images.ImagesPane.java

/**
 * Shows the Reset menu./* w  w w . j a  va  2 s  . com*/
 * @param e the mouse event
 */
private void showContextMenu(final MouseEvent e) {
    if (e.isPopupTrigger()) {
        JPopupMenu popup = new JPopupMenu();
        JMenuItem menuItem = new JMenuItem(UIRegistry.getResourceString("ES_TEXT_RESET"));
        menuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ex) {
                searchText.setEnabled(true);
                searchText.setBackground(textBGColor);
                searchText.setText("");
            }
        });
        popup.add(menuItem);
        popup.show(e.getComponent(), e.getX(), e.getY());

    }
}