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:UndoableDrawingPanel2.java

public UndoableDrawingPanel2() {
    MouseListener mouseListener = new MouseAdapter() {
        public void mouseReleased(MouseEvent mouseEvent) {
            StateEdit stateEdit = new StateEdit(UndoableDrawingPanel2.this);
            polygon.addPoint(mouseEvent.getX(), mouseEvent.getY());
            stateEdit.end();//from w  w  w . j av  a  2s  . c  om
            undoableEditSupport.postEdit(stateEdit);
            repaint();
        }
    };
    addMouseListener(mouseListener);
}

From source file:UndoDrawing.java

public UndoableDrawingPanel() {
    MouseListener mouseListener = new MouseAdapter() {
        public void mouseReleased(MouseEvent mouseEvent) {
            undoableEditSupport.postEdit(new UndoableDrawEdit(UndoableDrawingPanel.this));
            polygon.addPoint(mouseEvent.getX(), mouseEvent.getY());
            repaint();//from  ww  w.ja  v a2s  . com
        }
    };
    addMouseListener(mouseListener);
}

From source file:Main.java

public GrabAndScrollLabel(ImageIcon i) {
    super(i);/*from www.  j  a  v  a2  s. c om*/

    MouseInputAdapter mia = new MouseInputAdapter() {
        int xDiff, yDiff;
        Container c;

        public void mouseDragged(MouseEvent e) {
            c = GrabAndScrollLabel.this.getParent();
            if (c instanceof JViewport) {
                JViewport jv = (JViewport) c;
                Point p = jv.getViewPosition();
                int newX = p.x - (e.getX() - xDiff);
                int newY = p.y - (e.getY() - yDiff);

                int maxX = GrabAndScrollLabel.this.getWidth() - jv.getWidth();
                int maxY = GrabAndScrollLabel.this.getHeight() - jv.getHeight();
                if (newX < 0)
                    newX = 0;
                if (newX > maxX)
                    newX = maxX;
                if (newY < 0)
                    newY = 0;
                if (newY > maxY)
                    newY = maxY;

                jv.setViewPosition(new Point(newX, newY));
            }
        }

        public void mousePressed(MouseEvent e) {
            setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
            xDiff = e.getX();
            yDiff = e.getY();
        }

        public void mouseReleased(MouseEvent e) {
            setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        }
    };
    addMouseMotionListener(mia);
    addMouseListener(mia);
}

From source file:it.unibas.spicygui.vista.listener.MyMouseEventListener.java

public void mousePressed(MouseEvent e) {
    e.consume();// www  .  j av  a  2 s.c o  m
    Component comS = SwingUtilities.getDeepestComponentAt(pannelloPrincipale, e.getX(), e.getY());
    if ((comS instanceof JScrollBar || !((comS instanceof JPanel) || (comS instanceof JTree)))
            && comS != null) {
        if (tmp12 == null) {
            tmp12 = comS;
        }

    }
    if (!(Costanti.INTERMEDIE.equals(comS.getName()))) {
        dispacciaEvento(null, e, e.getPoint(), false);
    }
    jLayeredPane.moveToFront(component);
    component.updateUI();
}

From source file:GrabAndDragDemo.java

public GrabAndScrollLabel(ImageIcon i) {
    super(i);//ww w  .jav a2 s.c om

    MouseInputAdapter mia = new MouseInputAdapter() {
        int xDiff, yDiff;

        boolean isDragging;

        Container c;

        public void mouseDragged(MouseEvent e) {
            c = GrabAndScrollLabel.this.getParent();
            if (c instanceof JViewport) {
                JViewport jv = (JViewport) c;
                Point p = jv.getViewPosition();
                int newX = p.x - (e.getX() - xDiff);
                int newY = p.y - (e.getY() - yDiff);

                int maxX = GrabAndScrollLabel.this.getWidth() - jv.getWidth();
                int maxY = GrabAndScrollLabel.this.getHeight() - jv.getHeight();
                if (newX < 0)
                    newX = 0;
                if (newX > maxX)
                    newX = maxX;
                if (newY < 0)
                    newY = 0;
                if (newY > maxY)
                    newY = maxY;

                jv.setViewPosition(new Point(newX, newY));
            }
        }

        public void mousePressed(MouseEvent e) {
            setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
            xDiff = e.getX();
            yDiff = e.getY();
        }

        public void mouseReleased(MouseEvent e) {
            setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        }
    };
    addMouseMotionListener(mia);
    addMouseListener(mia);
}

From source file:analisisnumerico.Main.java

private void jPanel2MousePressed(java.awt.event.MouseEvent evt) {
    x = evt.getX();
    y = evt.getY();
}

From source file:org.fhcrc.cpl.viewer.quant.gui.LogRatioHistMouseListener.java

/**
 * Undraw the previous selected region (if it was drawn), calculate the new regions, draw again, save
 * the points, and draw the numeric ratio in its little box
 * @param e//from  ww  w  .j  a v a 2  s  .c  om
 */
public void mouseDragged(MouseEvent e) {

    if (this.selectedRegionStart == null || e.getX() < this.selectedRegionStart.getX()) {
        return;
    }

    if (this.selectedRegion != null)
        drawOrUndrawRegion();

    // Erase the previous zoom rectangle (if any)...
    Rectangle2D scaledDataArea = _chartPanel.getScreenDataArea();

    this.selectedRegion = new Rectangle2D.Double(this.selectedRegionStart.getX(), scaledDataArea.getMinY(),
            Math.min(Math.abs(e.getX() - selectedRegionStart.getX()),
                    _chartPanel.getWidth() - this.selectedRegionStart.getX()),
            scaledDataArea.getHeight());
    transformAndSaveSelectedRegion();

    // Draw the new zoom rectangle...
    drawOrUndrawRegion();

    lastMousedRatio = Rounder.round(Math.exp(transformMouseXValue(e.getX())), 2);
    drawRatioInBox(getChartPanelGraphics());
}

From source file:org.fhcrc.cpl.viewer.quant.gui.LogRatioHistMouseListener.java

/**
 * When mouse moved, draw the ratio under the mouse pointer
 * @param e//from  w w  w  .j  ava2  s  .c  o m
 */
public void mouseMoved(MouseEvent e) {
    lastMousedRatio = Rounder.round(Math.exp(transformMouseXValue(e.getX())), 2);
    drawRatioInBox(getChartPanelGraphics());
}

From source file:org.fhcrc.cpl.viewer.quant.gui.LogRatioHistMouseListener.java

/**
 * Save the initial selection point//from w ww  .  j a  v a2 s.c om
 * @param e
 */
public void mousePressed(MouseEvent e) {
    Rectangle2D screenDataArea = _chartPanel.getScreenDataArea(e.getX(), e.getY());
    if (screenDataArea != null) {
        this.selectedRegionStart = getPointInRectangle(e.getX(), e.getY(), screenDataArea);
    } else {
        this.selectedRegionStart = null;
    }
}

From source file:playground.sergioo.capacitiesChanger2012.gui.NetworkPanel.java

@Override
public void mouseDragged(MouseEvent e) {
    camera.move(iniX - e.getX(), iniY - e.getY());
    iniX = e.getX();
    iniY = e.getY();
    repaint();
}