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:org.fhcrc.cpl.viewer.mrm.utilities.MRMerMouseListener.java

public void mouseDragged(MouseEvent e) {
    if ((e.isShiftDown() || e.getButton() == MouseEvent.BUTTON3) || shifted) {
        if (this.coElutionStart == null) {
            return;
        }//w w w .  j a  v  a 2 s  .co  m
        Graphics2D g2 = (Graphics2D) _cp.getGraphics();
        if (this.coElutionRegion != null)
            drawCoElutionRegion(g2);
        if (e.getX() < this.coElutionStart.getX())
            return;
        // Erase the previous zoom rectangle (if any)...
        Rectangle2D scaledDataArea = _cp.getScreenDataArea((int) this.coElutionStart.getX(),
                (int) this.coElutionStart.getY());

        // selected rectangle shouldn't extend outside the data area...
        double xmax = Math.min(e.getX(), scaledDataArea.getMaxX());
        double ymax = Math.min(e.getY(), scaledDataArea.getMaxY());
        /*
                    this.coElutionRegion = new Rectangle2D.Double(
                this.coElutionStart.getX(), this.coElutionStart.getY(),
                xmax - this.coElutionStart.getX(), ymax - this.coElutionStart.getY());
        */
        this.coElutionRegion = new Rectangle2D.Double(this.coElutionStart.getX(), scaledDataArea.getMinY(),
                Math.abs(e.getX() - coElutionStart.getX()), scaledDataArea.getHeight());

        // Draw the new zoom rectangle...
        drawCoElutionRegion(g2);

        g2.dispose();

    } else {
        _cp.mouseDragged(e);
    }
}

From source file:org.adempiere.apps.graph.PerformanceIndicator.java

/**
*    Init Graph Display/*from   ww w .  j  a  va2  s .com*/
*  Kinamo (pelgrim)
*/
private void init() {
    chartPanel = new ChartPanel(createChart(), //chart
            false, //boolean properties
            false, // boolean save
            false, //boolean print
            false, //boolean zoom
            true //boolean tooltips
    );
    chartPanel.setPreferredSize(indicatordimension);

    chartPanel.addChartMouseListener(new org.jfree.chart.ChartMouseListener() {
        public void chartMouseClicked(org.jfree.chart.ChartMouseEvent e) {
            //plot p = (MeterPlot) e.getSource();
            MouseEvent me = e.getTrigger();
            if (SwingUtilities.isLeftMouseButton(me) && me.getClickCount() > 1)
                fireActionPerformed(me);
            if (SwingUtilities.isRightMouseButton(me))
                popupMenu.show((Component) me.getSource(), me.getX(), me.getY());
        }

        public void chartMouseMoved(org.jfree.chart.ChartMouseEvent e) {

        }
    });

    this.add(chartPanel, BorderLayout.NORTH);
    this.setMinimumSize(paneldimension);
    this.setMaximumSize(paneldimension);
    //---------------------------------------------

    invalidate();
}

From source file:com.projity.pm.graphic.graph.GraphInteractor.java

public void mousePressed(MouseEvent e) {
    if (isReadOnly())
        return;/*from   w ww .  jav  a  2s.  c  o  m*/
    if (SwingUtilities.isRightMouseButton(e)) {
        if (popup != null)
            popup.show(getGraph(), e.getX(), e.getY());
    } else {
        if (selected == null)
            return;
        if (isMove()) {
            selection = false;
            x0 = e.getX();
            y0 = e.getY();
            drawBarShadow(x0, y0, true);
        } else if (isDirectAction()) {
            executeAction(e.getX(), e.getY());
            state = NOTHING_SELECTED;
            //select(e.getX(),e.getY()); //TODO commented to avoid second action when spliting
        }
    }
}

From source file:edu.purdue.cc.bionet.ui.HeatMap.java

/**
 * The mouseClicked method of the MouseListener interface.
 * //from ww w. j  a  v  a  2s.  c  o  m
 * @param event The MouseEvent which triggered this action.
 */
public void mouseClicked(MouseEvent event) {
    if (mapPosition.contains(event.getPoint())) {
        Correlation clicked = this.getCorrelationFromPoint(new Point(event.getX(), event.getY()));
        if (clicked != null && this.range.contains(Math.abs(clicked.getValue(this.correlationMethod)))) {
            this.fireGraphMouseEvent(clicked, event);
        }
    }

}

From source file:dotaSoundEditor.Controls.EditorPanel.java

protected void attachDoubleClickListenerToTree() {
    MouseListener ml = new MouseAdapter() {
        @Override/*from   w ww.  ja v a  2  s  .co m*/
        public void mousePressed(MouseEvent e) {
            int selRow = currentTree.getRowForLocation(e.getX(), e.getY());
            TreePath selPath = currentTree.getPathForLocation(e.getX(), e.getY());
            if (selRow != -1 && ((DefaultMutableTreeNode) selPath.getLastPathComponent()).isLeaf()) {
                if (e.getClickCount() == 2) {
                    playSelectedTreeSound(selPath, Paths.get(vpkPath));
                }
            }
        }
    };
    currentTree.addMouseListener(ml);
}

From source file:com.ivli.roim.controls.ChartControl.java

private ChartEntity findEntity(MouseEvent e) {
    if (null != getChart()) {
        final Insets insets = getInsets();
        final int x = (int) ((e.getX() - insets.left) / this.getScaleX());
        final int y = (int) ((e.getY() - insets.top) / this.getScaleY());

        if (this.getChartRenderingInfo() != null) {
            EntityCollection entities = this.getChartRenderingInfo().getEntityCollection();

            if (entities != null)
                return entities.getEntity(x, y);
        }/*from   ww w  .ja  v  a  2  s .c o  m*/
    }
    return null;
}

From source file:Main.java

public Main() {
    setSize(300, 300);/*from  w  ww . j  a  va 2 s .  c om*/
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    final JTextArea textArea = new JTextArea();
    textArea.setText("Click Me!");

    textArea.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            if (e.getButton() == MouseEvent.NOBUTTON) {
                textArea.setText("No button clicked...");
            } else if (e.getButton() == MouseEvent.BUTTON1) {
                textArea.setText("Button 1 clicked...");
            } else if (e.getButton() == MouseEvent.BUTTON2) {
                textArea.setText("Button 2 clicked...");
            } else if (e.getButton() == MouseEvent.BUTTON3) {
                textArea.setText("Button 3 clicked...");
            }

            System.out.println("Number of click: " + e.getClickCount());
            System.out.println("Click position (X, Y):  " + e.getX() + ", " + e.getY());
        }
    });

    getContentPane().add(textArea);
}

From source file:JavaXWin.java

public void mouseDragged(MouseEvent e) {
    if (m_resizeComponent.getWidth() + e.getX() >= MIN_WIDTH)
        m_resizeComponent.setBounds(m_resizeComponent.getX(), m_resizeComponent.getY(),
                m_resizeComponent.getWidth() + e.getX(), m_resizeComponent.getHeight());
    else/*from  w  w w.j  av  a  2s  .c o  m*/
        m_resizeComponent.setBounds(m_resizeComponent.getX(), m_resizeComponent.getY(), MIN_WIDTH,
                m_resizeComponent.getHeight());
    m_resizeComponent.validate();
}

From source file:com.tradedesksoftware.ets.client.charting.ChartShiftController.java

public void mouseDragged(MouseEvent mouseEvent) {
    if (!mouseEvent.isControlDown())
        return;/*from   w  ww . j av a2s.  c  om*/

    if (oldx > -1 && oldy > -1) {
        ValueAxis domAxis = getPlotAxis(chartPanel.getChart(), !axesSwaped);
        ValueAxis rngAxis = getPlotAxis(chartPanel.getChart(), axesSwaped);

        int xdif = mouseEvent.getX() - oldx;
        int ydif = mouseEvent.getY() - oldy;

        final Rectangle scaledDataArea = chartPanel.getScreenDataArea();

        double xdelta = (double) xdif * domAxis.getRange().getLength() / (scaledDataArea.width);
        double ydelta = (double) ydif * rngAxis.getRange().getLength() / (scaledDataArea.height);

        domAxis.setRange(domAxis.getLowerBound() - xdelta, domAxis.getUpperBound() - xdelta);
        rngAxis.setRange(rngAxis.getLowerBound() + ydelta, rngAxis.getUpperBound() + ydelta);
    }

    oldx = mouseEvent.getX();
    oldy = mouseEvent.getY();
}

From source file:JavaXWin.java

public void mouseMoved(MouseEvent e) {
    if (!m_dragging) {
        if (e.getX() < CORNER) {
            setCursor(Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR));
        } else if (e.getX() > getWidth() - CORNER) {
            setCursor(Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR));
        } else {//  w ww.ja v a  2  s  .  c o m
            setCursor(Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR));
        }
    }
}