Example usage for java.awt.event MouseEvent getX

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

Introduction

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

Prototype

public int getX() 

Source Link

Document

Returns the horizontal x position of the event relative to the source component.

Usage

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   w  ww .  j  ava2 s. 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:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java

/**
 * Handles a 'mouse released' event./*from  w  ww . ja v a2  s . c  o m*/
 * <P>
 * On Windows, we need to check if this is a popup trigger, but only if we
 * haven't already been tracking a zoom rectangle.
 *
 * @param e  Information about the event.
 */
public void mouseReleased(MouseEvent e) {

    if (zoomRectangle != null) {

        //            if (Math.abs(e.getX() - zoomPoint.getX()) >= MINIMUM_DRAG_ZOOM_SIZE) {
        if (Math.abs(e.getX() - zoomPoint.getX()) >= 7) {
            if (e.getX() < zoomPoint.getX() || e.getY() < zoomPoint.getY()) {
                autoRangeBoth();
            } else {
                double x, y, w, h;
                Rectangle2D scaledDataArea = getScaledDataArea();
                //for a mouseReleased event, (horizontalZoom || verticalZoom)
                //will be true, so we can just test for either being false;
                //otherwise both are true
                if (!verticalZoom) {
                    x = zoomPoint.getX();
                    y = scaledDataArea.getMinY();
                    w = Math.min(zoomRectangle.getWidth(), scaledDataArea.getMaxX() - zoomPoint.getX());
                    h = scaledDataArea.getHeight();
                } else if (!horizontalZoom) {
                    x = scaledDataArea.getMinX();
                    y = zoomPoint.getY();
                    w = scaledDataArea.getWidth();
                    h = Math.min(zoomRectangle.getHeight(), scaledDataArea.getMaxY() - zoomPoint.getY());
                } else {
                    x = zoomPoint.getX();
                    y = zoomPoint.getY();
                    w = Math.min(zoomRectangle.getWidth(), scaledDataArea.getMaxX() - zoomPoint.getX());
                    h = Math.min(zoomRectangle.getHeight(), scaledDataArea.getMaxY() - zoomPoint.getY());
                }
                Rectangle2D zoomArea = new Rectangle2D.Double(x, y, w, h);
                zoom(zoomArea);

            }
            this.zoomPoint = null;
            this.zoomRectangle = null;
        } else {
            Graphics2D g2 = (Graphics2D) getGraphics();
            g2.setXORMode(java.awt.Color.gray);
            if (fillZoomRectangle) {
                g2.fill(zoomRectangle);
            } else {
                g2.draw(zoomRectangle);
            }
            g2.dispose();
            this.zoomRectangle = null;
        }

        // notify a redraw event
        CoreStatusEvent ev = new CoreStatusEvent(this);
        ev.setType(CoreStatusEvent.REDRAW);
        ((AbstractDmcPlot) chart.getPlot()).notifyCoreStatusListeners(ev);
    }

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

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/*w w w  .  j av a  2  s . co  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: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 .  jav a2s . c o  m
@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:edu.ku.brc.specify.tasks.subpane.images.ImagesPane.java

/**
 * Shows the Reset menu./*from   w  ww .jav  a2 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());

    }
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.link_and_brush.LinkAndBrushChartPanel.java

@Override
public void mouseReleased(MouseEvent e) {

    // if we've been panning, we need to reset now that the mouse is
    // released...
    Rectangle2D zoomRectangle = (Rectangle2D) getChartFieldValueByName("zoomRectangle");
    Point2D zoomPoint = (Point2D) getChartFieldValueByName("zoomPoint");
    if (getChartFieldValueByName("panLast") != null) {
        setChartFieldValue((getChartFieldByName("panLast")), null);
        setCursor(Cursor.getDefaultCursor());
    } else if (zoomRectangle != null) {
        boolean hZoom = false;
        boolean vZoom = false;
        if ((PlotOrientation) getChartFieldValueByName("orientation") == PlotOrientation.HORIZONTAL) {
            hZoom = (Boolean) getChartFieldValueByName("rangeZoomable");
            vZoom = (Boolean) getChartFieldValueByName("domainZoomable");
        } else {//w  w  w .jav a 2  s  .c  o m
            hZoom = (Boolean) getChartFieldValueByName("domainZoomable");
            vZoom = (Boolean) getChartFieldValueByName("rangeZoomable");
        }

        boolean zoomTrigger1 = hZoom && Math
                .abs(e.getX() - zoomPoint.getX()) >= (Integer) getChartFieldValueByName("zoomTriggerDistance");
        boolean zoomTrigger2 = vZoom && Math
                .abs(e.getY() - zoomPoint.getY()) >= (Integer) getChartFieldValueByName("zoomTriggerDistance");
        if (zoomTrigger1 || zoomTrigger2) {
            if ((hZoom && (e.getX() < zoomPoint.getX())) || (vZoom && (e.getY() < zoomPoint.getY()))) {
                restoreAutoBounds();
            } else {
                double x, y, w, h;
                Rectangle2D screenDataArea = getScreenDataArea((int) zoomPoint.getX(), (int) zoomPoint.getY());
                double maxX = screenDataArea.getMaxX();
                double maxY = screenDataArea.getMaxY();
                // for mouseReleased event, (horizontalZoom || verticalZoom)
                // will be true, so we can just test for either being false;
                // otherwise both are true
                if (!vZoom) {
                    x = zoomPoint.getX();
                    y = screenDataArea.getMinY();
                    w = Math.min(zoomRectangle.getWidth(), maxX - zoomPoint.getX());
                    h = screenDataArea.getHeight();
                } else if (!hZoom) {
                    x = screenDataArea.getMinX();
                    y = zoomPoint.getY();
                    w = screenDataArea.getWidth();
                    h = Math.min(zoomRectangle.getHeight(), maxY - zoomPoint.getY());
                } else {
                    x = zoomPoint.getX();
                    y = zoomPoint.getY();
                    w = Math.min(zoomRectangle.getWidth(), maxX - zoomPoint.getX());
                    h = Math.min(zoomRectangle.getHeight(), maxY - zoomPoint.getY());
                }
                Rectangle2D zoomArea = new Rectangle2D.Double(x, y, w, h);
                zoom(zoomArea);
            }
            setChartFieldValue(getChartFieldByName("zoomPoint"), null);
            setChartFieldValue(getChartFieldByName("zoomRectangle"), null);
        } else {
            // erase the zoom rectangle
            Graphics2D g2 = (Graphics2D) getGraphics();
            if ((Boolean) getChartFieldValueByName("useBuffer")) {
                repaint();
            } else {
                drawZoomRectangle(g2, true);
            }
            g2.dispose();
            setChartFieldValue(getChartFieldByName("zoomPoint"), null);
            setChartFieldValue(getChartFieldByName("zoomRectangle"), null);
        }

    }

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

}

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

@Override
public void mouseDragged(MouseEvent e) {
    Insets insets = getInsets();/*from   www  .j a v a 2s .com*/
    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);
    }
}

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

@Override
public void mouseMoved(MouseEvent e) {
    Insets insets = getInsets();/*w  w w. j a  va 2 s  . c  o m*/
    int x = (int) ((e.getX() - insets.left) / getScaleX());
    int y = (int) ((e.getY() - insets.top) / getScaleY());

    ChartEntity entity = null;
    if (getChartRenderingInfo() != null) {
        EntityCollection 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();
                //                         if (getHorizontalAxisTrace() || getVerticalAxisTrace() || isToolTipFollowerEnabled) {
                //                            repaint();
                //                         }
                //                         seriesIndex = selectedSeriesIndex;
                //                         isDirty = true;
                //                      }
                seriesIndex = followDomainTrace(selectedSeriesIndex, x);
                if (seriesIndex >= 0
                        && (getHorizontalAxisTrace() || getVerticalAxisTrace() || isToolTipFollowerEnabled())) {
                    repaint();
                }
            } 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());
                ////                         if (getScreenDataArea().contains(axisTrace)) {
                //                         horizontalTraceLocation = (int) axisTrace.getX();
                //                         verticalTraceLocation = (int) axisTrace.getY();
                //                         if (getHorizontalAxisTrace() || getVerticalAxisTrace() || isToolTipFollowerEnabled) {
                //                            repaint();
                //                         }
                //                         seriesIndex = seriesIndex0;
                //                         isDirty = true;
                ////                         }
                //                      }
                seriesIndex = followDomainTrace(0, x);
                if (seriesIndex >= 0
                        && (getHorizontalAxisTrace() || getVerticalAxisTrace() || isToolTipFollowerEnabled())) {
                    repaint();
                }
            } 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());
                }
                if (getHorizontalAxisTrace() || getVerticalAxisTrace() || isToolTipFollowerEnabled()) {
                    repaint();
                }
                //                      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);
                    }
                }
            }

        }
        //              getChart().handleClick(x, y, getChartRenderingInfo());
    }

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

    super.mouseMoved(e);
    // we can only generate events if the panel's chart is not null
    // (see bug report 1556951)
}

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

/**
 * @param actionTree/* w w w .ja  v  a  2 s  .c o 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: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  .j  a va2  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;
}