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:com.diversityarrays.kdxplore.chartcommon.KDXploreChartPanel.java

@Override
public void mouseReleased(MouseEvent e) {
    if (e.isShiftDown() || shiftDownatStart) {
        super.mouseReleased(e);
        shiftDownatStart = false;/*w  ww. j  a v  a  2 s.  co  m*/

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

        ChartEntity entity = null;
        if (this.getChartRenderingInfo() != null) {
            EntityCollection entities = this.getChartRenderingInfo().getEntityCollection();
            if (entities != null) {
                entity = entities.getEntity(x, y);
            }
        }

        Object[] listeners = this.getListeners(ChartMouseListener.class);

        if (this.getChart() != null) {
            ChartMouseEvent event = new ChartMouseEvent(getChart(), e, entity);
            for (int i = listeners.length - 1; i >= 0; i -= 1) {
                if (listeners[i] instanceof KDXChartMouseListener) {
                    ((KDXChartMouseListener) listeners[i]).chartMouseZoomingReleased(event);
                }
            }
        }

    } else {
        super.mouseReleased(e);

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

        ChartEntity entity = null;
        if (this.getChartRenderingInfo() != null) {
            EntityCollection entities = this.getChartRenderingInfo().getEntityCollection();
            if (entities != null) {
                entity = entities.getEntity(x, y);
            }
        }

        Object[] listeners = this.getListeners(ChartMouseListener.class);

        if (this.getChart() != null) {
            ChartMouseEvent event = new ChartMouseEvent(getChart(), e, entity);
            for (int i = listeners.length - 1; i >= 0; i -= 1) {
                if (listeners[i] instanceof KDXChartMouseListener) {
                    ((KDXChartMouseListener) listeners[i]).chartMouseSelectedReleased(event);
                }
            }
        }
    }
}

From source file:org.jax.maanova.plot.MaanovaChartPanel.java

private void myMousePressed(MouseEvent e) {
    this.dragRectangle = new Rectangle(e.getX(), e.getY(), 0, 0);
}

From source file:AncestorTree.java

public boolean isCellEditable(EventObject evt) {
    if (evt instanceof MouseEvent) {
        MouseEvent mEvt = (MouseEvent) evt;
        if (mEvt.getClickCount() == 1) {
            int row = m_tree.getRowForLocation(mEvt.getX(), mEvt.getY());
            if (row != m_lastRow) {
                m_lastRow = row;/*from  ww w.  j a v  a2 s .c o m*/
                m_lastClick = System.currentTimeMillis();
                return false;
            } else if (System.currentTimeMillis() - m_lastClick > 1000) {
                m_lastRow = -1;
                m_lastClick = 0;
                prepareEditor();
                mEvt.consume();
                return true;
            } else
                return false;
        }
    }
    return false;
}

From source file:net.bioclipse.model.ScatterPlotMouseHandler.java

@Override
public void mousePressed(MouseEvent e) {
    super.mousePressed(e);
    ChartPanel chartPanel = getChartPanel(e);
    startX = e.getX();
    startY = e.getY();/* w w  w . j av a  2  s .c  o m*/

    if (!e.isShiftDown()) {
        ((ScatterPlotRenderer) ((XYPlot) chartPanel.getChart().getPlot()).getRenderer()).clearMarkedPoints();
        currentSelection = new ChartSelection();
        chartPanel.getChart().plotChanged(new PlotChangeEvent(chartPanel.getChart().getPlot()));
    } else {
        ((ScatterPlotRenderer) ((XYPlot) chartPanel.getChart().getPlot()).getRenderer())
                .removeMarkedPoint(null);
    }
    if (currentSelection == null) {
        currentSelection = new ChartSelection();
    }

    mouseDragSelection = new ChartSelection();
    currentSelection.setDescriptor(ChartUtils.getChartDescriptor(chartPanel.getChart()));
}

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

/**
 * Set the position from the mouse// www  .  j  a v  a 2s .c  o  m
 *
 * @param event mouse event
 */
public void setPosition(MouseEvent event) {
    int diff = event.getY() - y;
    setPosition(event.getX(), event.getY());
    if ((attached != null) && event.isShiftDown()) {
        attached.setPosition(event.getX(), attached.y + diff);
    }
}

From source file:de.dakror.villagedefense.game.entity.Entity.java

public boolean mouseMoved(MouseEvent e) {
    if (alpha == 0)
        return false;

    return hovered = contains(e.getX(), e.getY());
}

From source file:br.univali.ps.ui.telas.TelaPrincipal.java

/**
/**// w  ww. j ava2  s . c o m
 * Creates new form TelaInicial
 */
public TelaPrincipal() {
    initComponents();
    criaAbas();
    configurarCores();
    instalarObservadores();
    addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent me) {
            // Get x,y and store them
            pX = me.getX();
            pY = me.getY();

        }

        public void mouseDragged(MouseEvent me) {

            Lancador.getJFrame().setLocation(Lancador.getJFrame().getLocation().x + me.getX() - pX,
                    Lancador.getJFrame().getLocation().y + me.getY() - pY);
        }
    });

    addMouseMotionListener(new MouseMotionAdapter() {
        public void mouseDragged(MouseEvent me) {

            Lancador.getJFrame().setLocation(Lancador.getJFrame().getLocation().x + me.getX() - pX,
                    Lancador.getJFrame().getLocation().y + me.getY() - pY);
        }
    });
}

From source file:net.rptools.tokentool.ui.TokenCompositionPanel.java

public void mousePressed(MouseEvent e) {

    dragStartX = e.getX();
    dragStartY = e.getY();

}

From source file:AppletMenuBarDemo.java

/** Called when a mouse event happens over the menubar */
protected void processMouseEvent(MouseEvent e) {
    int type = e.getID(); // What type of event?
    int item = findItemAt(e.getX()); // Over which menu label?

    if (type == MouseEvent.MOUSE_PRESSED) {
        // If it was a mouse down event, then pop up the menu
        if (item == -1)
            return;
        Dimension size = getSize();
        PopupMenu pm = (PopupMenu) menus.elementAt(item);
        if (pm != null)
            pm.show(this, startPositions[item] - 3, size.height);

    } else if (type == MouseEvent.MOUSE_EXITED) {
        // If the mouse left the menubar, then unhighlight
        if (highlightedItem != -1) {
            highlightedItem = -1;//from   w  ww .  ja  v  a 2  s  .  c  om
            if (highlightColor != null)
                repaint();
        }
    } else if ((type == MouseEvent.MOUSE_MOVED) || (type == MouseEvent.MOUSE_ENTERED)) {
        // If the mouse moved, change the highlighted item, if necessary
        if (item != highlightedItem) {
            highlightedItem = item;
            if (highlightColor != null)
                repaint();
        }
    }
}

From source file:lu.lippmann.cdb.common.gui.DragAndDroppablePieChartPanel.java

/**
 * {@inheritDoc}/*from   w  w  w  .j  a v a  2  s  .  co  m*/
 */
@Override
public void mouseDragged(MouseEvent e) {
    if (source != null) {
        final ChartRenderingInfo info = getChartRenderingInfo();
        final Rectangle2D dataArea = info.getPlotInfo().getPlotArea();
        final double xx = dataArea.getCenterX();
        final double yy = dataArea.getCenterY();
        tx = e.getX() - xx;
        ty = e.getY() - yy;
        repaint();
    }
}