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:dbseer.gui.panel.DBSeerSelectableChartPanel.java

@Override
public void mousePressed(MouseEvent e) {
    super.mousePressed(e);

    Rectangle2D origArea = this.getScreenDataArea();
    Plot plot = chart.getPlot();/*w  w w.  ja  va  2s. co  m*/

    if (!(plot instanceof XYPlot)) {
        return;
    }

    XYPlot xyPlot = chart.getXYPlot();
    String origDomainAxisLabel = xyPlot.getDomainAxis().getLabel();

    if (SwingUtilities.isRightMouseButton(e)) {
        return;
    }
    for (DBSeerSelectableChartPanel panel : DBSeerPlotPresetFrame.chartPanels) {
        if (panel != this) {
            Plot otherPlot = panel.getChart().getPlot();
            if (!(otherPlot instanceof XYPlot)) {
                continue;
            }
            Rectangle2D otherArea = panel.getScreenDataArea();
            XYPlot otherXYPlot = panel.getChart().getXYPlot();
            String otherDomainAxisLabel = otherXYPlot.getDomainAxis().getLabel();

            if (origDomainAxisLabel.equalsIgnoreCase(otherDomainAxisLabel)) {
                double origRangeX = origArea.getMaxX() - origArea.getMinX();
                double origRangeY = origArea.getMaxY() - origArea.getMinY();
                double otherRangeX = otherArea.getMaxX() - otherArea.getMinX();
                double otherRangeY = otherArea.getMaxY() - otherArea.getMinY();

                double syncX = otherArea.getMinX() + (e.getX() - origArea.getMinX()) / origRangeX * otherRangeX;
                double syncY = otherArea.getMinY() + (e.getY() - origArea.getMinY()) / origRangeY * otherRangeY;
                MouseEvent syncEvent = new MouseEvent(this, 0, 0, 0, (int) syncX, (int) syncY, 1, false);
                panel.syncMousePressed(syncEvent);
            }
        }
    }
}

From source file:dbseer.gui.panel.DBSeerSelectableChartPanel.java

@Override
public void mouseDragged(MouseEvent e) {
    super.mouseDragged(e);

    Rectangle2D origArea = this.getScreenDataArea();
    Plot plot = chart.getPlot();//from w w  w.ja  v a  2  s.  c om

    if (!(plot instanceof XYPlot)) {
        return;
    }

    XYPlot xyPlot = chart.getXYPlot();
    String origDomainAxisLabel = xyPlot.getDomainAxis().getLabel();

    if (SwingUtilities.isRightMouseButton(e)) {
        return;
    }
    for (DBSeerSelectableChartPanel panel : DBSeerPlotPresetFrame.chartPanels) {
        if (panel != this) {
            Plot otherPlot = panel.getChart().getPlot();
            if (!(otherPlot instanceof XYPlot)) {
                continue;
            }
            Rectangle2D otherArea = panel.getScreenDataArea();
            XYPlot otherXYPlot = panel.getChart().getXYPlot();
            String otherDomainAxisLabel = otherXYPlot.getDomainAxis().getLabel();

            if (origDomainAxisLabel.equalsIgnoreCase(otherDomainAxisLabel)) {
                double origRangeX = origArea.getMaxX() - origArea.getMinX();
                double origRangeY = origArea.getMaxY() - origArea.getMinY();
                double otherRangeX = otherArea.getMaxX() - otherArea.getMinX();
                double otherRangeY = otherArea.getMaxY() - otherArea.getMinY();

                double syncX = otherArea.getMinX() + (e.getX() - origArea.getMinX()) / origRangeX * otherRangeX;
                double syncY = otherArea.getMinY() + (e.getY() - origArea.getMinY()) / origRangeY * otherRangeY;
                MouseEvent syncEvent = new MouseEvent(this, 0, 0, 0, (int) syncX, (int) syncY, 1, false);
                panel.syncMouseDragged(syncEvent);
            }
        }
    }
}

From source file:dbseer.gui.panel.DBSeerSelectableChartPanel.java

@Override
public void mouseReleased(MouseEvent e) {
    super.mouseReleased(e);

    Rectangle2D origArea = this.getScreenDataArea();
    Plot plot = chart.getPlot();//from w  w  w. j  a v  a 2  s.c o  m

    if (!(plot instanceof XYPlot)) {
        return;
    }

    XYPlot xyPlot = chart.getXYPlot();
    String origDomainAxisLabel = xyPlot.getDomainAxis().getLabel();

    if (SwingUtilities.isRightMouseButton(e)) {
        return;
    }
    for (DBSeerSelectableChartPanel panel : DBSeerPlotPresetFrame.chartPanels) {
        if (panel != this) {
            Plot otherPlot = panel.getChart().getPlot();
            if (!(otherPlot instanceof XYPlot)) {
                continue;
            }
            Rectangle2D otherArea = panel.getScreenDataArea();
            XYPlot otherXYPlot = panel.getChart().getXYPlot();
            String otherDomainAxisLabel = otherXYPlot.getDomainAxis().getLabel();

            if (origDomainAxisLabel.equalsIgnoreCase(otherDomainAxisLabel)) {
                double origRangeX = origArea.getMaxX() - origArea.getMinX();
                double origRangeY = origArea.getMaxY() - origArea.getMinY();
                double otherRangeX = otherArea.getMaxX() - otherArea.getMinX();
                double otherRangeY = otherArea.getMaxY() - otherArea.getMinY();

                double syncX = otherArea.getMinX() + (e.getX() - origArea.getMinX()) / origRangeX * otherRangeX;
                double syncY = otherArea.getMinY() + (e.getY() - origArea.getMinY()) / origRangeY * otherRangeY;
                MouseEvent syncEvent = new MouseEvent(this, 0, 0, 0, (int) syncX, (int) syncY, 1, false);
                panel.syncMouseReleased(syncEvent);
            }
        }
    }
}

From source file:edu.ku.brc.specify.ui.containers.ContainerTreePanel.java

/**
 * @param actionTree//from   w w  w  .  j a  v  a  2 s. co m
 */
private void registerPrintContextMenu(final JTree actionTree) {
    actionTree.addMouseListener(new MouseAdapter() {
        private void displayMenu(MouseEvent e) {
            if (e.isPopupTrigger()) {
                JPopupMenu menu = new JPopupMenu();
                JMenuItem printMenu = new JMenuItem(UIRegistry.getResourceString("Print"));
                menu.add(printMenu);
                menu.show(e.getComponent(), e.getX(), e.getY());
                printMenu.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent ev) {
                        print(actionTree);
                    }
                });
            }
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            super.mouseClicked(e);
            displayMenu(e);
        }

        @Override
        public void mousePressed(MouseEvent e) {
            super.mousePressed(e);
            displayMenu(e);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            super.mouseReleased(e);
            displayMenu(e);
        }

    });
}

From source file:org.archiviststoolkit.mydomain.DomainTableWorkSurface.java

/**
 * called when the mouse is pressed./*from  w  w  w  .  j  a v a2s.co m*/
 *
 * @param evt the mouse event
 */
public final void mousePressed(final MouseEvent evt) {
    if (evt.isPopupTrigger()) {
        pm.show(evt.getComponent(), evt.getX(), evt.getY());
    }

}

From source file:com.sshtools.sshterm.SshTerminalPanel.java

public void mouseMoved(MouseEvent e) {
    if (isAutoHideTools()) {
        if (!isToolsVisible() && (e.getY() < 4)) {
            setToolsVisible(true);//from   w ww.j  av a2 s.c o  m
        } else if (isToolsVisible() && (e.getY() > 12)) {
            setToolsVisible(false);
        }

        if (!scrollBar.isVisible() && (e.getX() > (getWidth() - 4))) {
            setScrollBarVisible(true);
        } else if (scrollBar.isVisible() && (e.getX() < (getWidth() - 12))) {
            setScrollBarVisible(false);
        }
    }
}

From source file:org.archiviststoolkit.mydomain.DomainTableWorkSurface.java

/**
 * called when the mouse is released.//from   www .  j  ava 2s. com
 *
 * @param evt the mouse event
 */

public final void mouseReleased(final MouseEvent evt) {
    if (evt.isPopupTrigger()) {
        pm.show(evt.getComponent(), evt.getX(), evt.getY());
    }

}

From source file:org.gumtree.vis.plot1d.Plot1DPanel.java

/**
 * Receives notification of mouse clicks on the panel. These are
 * translated and passed on to any registered {@link ChartMouseListener}s.
 *
 * @param event  Information about the mouse event.
 *//*  w w  w  .  j  a v a 2 s .com*/
@Override
public void mouseClicked(MouseEvent event) {

    Insets insets = getInsets();
    int x = (int) ((event.getX() - insets.left) / getScaleX());
    int y = (int) ((event.getY() - insets.top) / getScaleY());

    setAnchor(new Point2D.Double(x, y));
    if (getChart() == null) {
        return;
    }
    //        getChart().setNotify(true);  // force a redraw
    // new entity code...
    //        if (listeners.length == 0) {
    //            return;
    //        }

    //        if ((event.getModifiers() & maskingSelectionMask) != 0) {
    if (isInternalLegendEnabled) {
        Rectangle2D screenArea = getScreenDataArea();
        Rectangle2D legendArea = new Rectangle2D.Double(screenArea.getMaxX() - internalLegendSetup.getMinX(),
                screenArea.getMinY() + internalLegendSetup.getMinY(), internalLegendSetup.getWidth(),
                internalLegendSetup.getHeight());
        if (legendArea.contains(event.getPoint())) {
            selectInternalLegend(true);
            selectMask(Double.NaN, Double.NaN);
            repaint();
            return;
        } else {
            selectInternalLegend(false);
        }
    }
    if (!isTextInputEnabled() && (event.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) {
        selectMask(ChartMaskingUtilities.translateScreenX(x, getScreenDataArea(), getChart()), Double.NaN);
        repaint();
    }
    if ((event.getModifiers() & seriesSelectionEventMask) == 0) {
        if (getSelectedMask() != null && (event.getModifiers() & MouseEvent.BUTTON1_MASK) != 0
                && !getSelectedMask().getRange()
                        .contains(ChartMaskingUtilities.translateScreenX(x, getScreenDataArea(), getChart()))) {
            selectMask(Double.NaN, Double.NaN);
        }
        repaint();
    } else if (!isTextInputEnabled()) {
        selectMask(ChartMaskingUtilities.translateScreenX(x, getScreenDataArea(), getChart()), Double.NaN);
        repaint();
    }

    ChartEntity entity = null;
    if (getChartRenderingInfo() != null) {
        EntityCollection entities = getChartRenderingInfo().getEntityCollection();
        if (entities != null) {
            entity = entities.getEntity(x, y);
            if (entity instanceof XYItemEntity) {
                XYItemEntity xyEntity = (XYItemEntity) entity;
                //                   XYDataset dataset = xyEntity.getDataset();
                //                   int item = ((XYItemEntity) entity).getItem();
                //                   chartX = dataset.getXValue(xyEntity.getSeriesIndex(), item);
                //                   chartY = dataset.getYValue(xyEntity.getSeriesIndex(), item);
                //                   Point2D screenPoint = ChartMaskingUtilities.translateChartPoint(
                //                         new Point2D.Double(chartX, chartY), getScreenDataArea(), getChart());
                //                   if (getHorizontalAxisTrace()) {
                //                      horizontalTraceLocation = (int) screenPoint.getX();
                //                   }
                //                   if (getVerticalAxisTrace()) {
                //                      verticalTraceLocation = (int) screenPoint.getY();
                //                   }
                if ((event.getModifiers() & seriesSelectionEventMask) != 0
                        && (event.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) {
                    selectSeries(xyEntity.getSeriesIndex());
                    return;
                } else if ((event.getModifiers() & maskingSelectionMask) == 0
                        && (event.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) {
                    if (selectedSeriesIndex != xyEntity.getSeriesIndex()) {
                        selectSeries(-1);
                        return;
                    }
                }
            } else {
                if (selectedSeriesIndex >= 0) {
                    if ((event.getModifiers() & seriesSelectionEventMask) != 0
                            && (event.getModifiers() & maskingSelectionMask) == 0
                            && (event.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) {
                        selectSeries(-1);
                        return;
                    }
                }
            }
        }
    }
    XYChartMouseEvent chartEvent = new XYChartMouseEvent(getChart(), event, entity);
    chartEvent.setXY(getChartX(), getChartY());
    Object[] listeners = getListeners(ChartMouseListener.class);
    for (int i = listeners.length - 1; i >= 0; i -= 1) {
        ((ChartMouseListener) listeners[i]).chartMouseClicked(chartEvent);
    }
    super.mouseClicked(event);
}

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

private JComponent createTokenTreePanel() {
    final JTree tree = new JTree();
    tokenPanelTreeModel = new TokenPanelTreeModel(tree);
    tree.setModel(tokenPanelTreeModel);// w w  w .  jav a 2 s  . co 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) && !SwingUtil.isControlDown(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() {
                    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);
                            }
                        }
                    }
                });
            }
        }
    });
    MapTool.getEventDispatcher().addListener(new AppEventListener() {
        public void handleAppEvent(AppEvent event) {
            tokenPanelTreeModel.setZone((Zone) event.getNewValue());
        }
    }, MapTool.ZoneEvent.Activated);
    return tree;
}

From source file:org.gumtree.vis.plot1d.Plot1DPanel.java

@Override
public void mouseDragged(MouseEvent e) {
    Insets insets = getInsets();/*from   ww w  . jav  a 2 s  .co m*/
    int x = (int) ((e.getX() - insets.left) / getScaleX());
    int y = (int) ((e.getY() - insets.top) / getScaleY());

    ChartEntity entity = null;
    EntityCollection entities = null;
    if (getChartRenderingInfo() != null) {
        entities = getChartRenderingInfo().getEntityCollection();
        if (entities != null) {
            entity = entities.getEntity(x, y);
            //                boolean isDirty = false;
            int seriesIndex = -1;
            if (selectedSeriesIndex >= 0) {
                //                   double xInChart = ChartMaskingUtilities.translateScreenX(x, 
                //                         getScreenDataArea(), getChart());
                //                   XYDataset dataset = getChart().getXYPlot().getDataset();
                //                   PatternDataset patternDataset = (PatternDataset) dataset;
                //                   int itemIndex = patternDataset.getItemFromX(selectedSeriesIndex, xInChart);
                //                   if (itemIndex < patternDataset.getItemCount(selectedSeriesIndex)) {
                //                      chartX = patternDataset.getXValue(selectedSeriesIndex, itemIndex);
                //                      chartY = patternDataset.getYValue(selectedSeriesIndex, itemIndex);
                //                      Point2D axisTrace = ChartMaskingUtilities.translateChartPoint(
                //                            new Point2D.Double(chartX, chartY), getScreenDataArea(), getChart());
                //                      horizontalTraceLocation = (int) axisTrace.getX();
                //                      verticalTraceLocation = (int) axisTrace.getY();
                //                      seriesIndex = selectedSeriesIndex;
                //                      isDirty = true;
                //                   }
                seriesIndex = followDomainTrace(selectedSeriesIndex, x);
            } else if (getChart().getXYPlot().getSeriesCount() == 1) {
                //                   int seriesIndex0 = 0;
                //                   double xInChart = ChartMaskingUtilities.translateScreenX(x, 
                //                         getScreenDataArea(), getChart());
                //                   XYDataset dataset = getChart().getXYPlot().getDataset();
                //                   PatternDataset patternDataset = (PatternDataset) dataset;
                //                   int itemIndex = patternDataset.getItemFromX(seriesIndex0, xInChart);
                //                   if (itemIndex < patternDataset.getItemCount(seriesIndex0)) {
                //                      chartX = patternDataset.getXValue(seriesIndex0, itemIndex);
                //                      chartY = patternDataset.getYValue(seriesIndex0, itemIndex);
                //                      Point2D axisTrace = ChartMaskingUtilities.translateChartPoint(
                //                            new Point2D.Double(chartX, chartY), getScreenDataArea(), getChart());
                //                      horizontalTraceLocation = (int) axisTrace.getX();
                //                      verticalTraceLocation = (int) axisTrace.getY();
                //                      seriesIndex = seriesIndex0;
                //                      isDirty = true;
                //                   }
                seriesIndex = followDomainTrace(0, x);
            } else if (entity instanceof XYItemEntity) {
                XYItemEntity xyEntity = (XYItemEntity) entity;
                XYDataset dataset = xyEntity.getDataset();
                int item = ((XYItemEntity) entity).getItem();
                seriesIndex = xyEntity.getSeriesIndex();
                double chartX = dataset.getXValue(seriesIndex, item);
                double chartY = dataset.getYValue(seriesIndex, item);
                Point2D screenPoint = ChartMaskingUtilities.translateChartPoint(
                        new Point2D.Double(chartX, chartY), getScreenDataArea(), getChart());
                setChartX(chartX);
                setChartY(chartY);
                setSeriesIndex(seriesIndex);
                setItemIndex(item);
                if (dataset instanceof IXYErrorDataset) {
                    setChartError(((IXYErrorDataset) dataset).getYError(seriesIndex, item));

                }
                if (getHorizontalAxisTrace()) {
                    setHorizontalTraceLocation((int) screenPoint.getX());
                }
                if (getVerticalAxisTrace()) {
                    setVerticalTraceLocation((int) screenPoint.getY());
                }
                //                   isDirty = true;
            }
            if (seriesIndex >= 0) {
                Object[] listeners = getListeners(ChartMouseListener.class);
                if (getChart() != null) {
                    XYChartMouseEvent event = new XYChartMouseEvent(getChart(), e, entity);
                    event.setXY(getChartX(), getChartY());
                    event.setSeriesIndex(seriesIndex);
                    for (int i = listeners.length - 1; i >= 0; i -= 1) {
                        ((ChartMouseListener) listeners[i]).chartMouseMoved(event);
                    }
                }
            }

        }
    }

    //        if (isMaskingEnabled() && (e.getModifiers() & maskingKeyMask) != 0) {
    if (isInternalLegendEnabled && isInternalLegendSelected) {
        int cursorType = findCursorOnSelectedItem(e.getX(), e.getY());
        setCursor(Cursor.getPredefinedCursor(cursorType));
    } else if (isMaskingEnabled() && (e.getModifiers() & maskingKeyMask) == 0) {
        int cursorType = findCursorOnSelectedItem(e.getX(), e.getY());
        setCursor(Cursor.getPredefinedCursor(cursorType));
    } else if (getCursor() != defaultCursor) {
        setCursor(defaultCursor);
    }

    if (isInternalLegendEnabled && isInternalLegendSelected
            && findCursorOnSelectedItem(e.getX(), e.getY()) != Cursor.DEFAULT_CURSOR
            && (e.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) {
        changeInternalLegend(e);
    } else if (getMaskDragIndicator() != Cursor.DEFAULT_CURSOR && this.getSelectedMask() != null
            && (e.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) {
        changeSelectedMask(e);
    } else if (isMaskingEnabled() && (e.getModifiers() & maskingKeyMask) != 0) {
        // Do masking service
        // if no initial masking point was set, ignore dragging...
        makeNewMask(e);
    } else {
        super.mouseDragged(e);
    }
}