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

/**
 * This method implements the DragGestureListener interface. It will be
 * invoked when the DragGestureRecognizer thinks that the user has initiated
 * a drag. If we're not in drawing mode, then this method will try to figure
 * out which Scribble object is being dragged, and will initiate a drag on
 * that object./* ww  w .  j  av a2  s .  c  o m*/
 */
public void dragGestureRecognized(DragGestureEvent e) {
    // Don't drag if we're not in drag mode
    if (!dragMode)
        return;

    // Figure out where the drag started
    MouseEvent inputEvent = (MouseEvent) e.getTriggerEvent();
    int x = inputEvent.getX();
    int y = inputEvent.getY();

    // Figure out which scribble was clicked on, if any by creating a
    // small rectangle around the point and testing for intersection.
    Rectangle r = new Rectangle(x - LINEWIDTH, y - LINEWIDTH, LINEWIDTH * 2, LINEWIDTH * 2);
    int numScribbles = scribbles.size();
    for (int i = 0; i < numScribbles; i++) { // Loop through the scribbles
        Scribble s = (Scribble) scribbles.get(i);
        if (s.intersects(r)) {
            // The user started the drag on top of this scribble, so
            // start to drag it.

            // First, remember which scribble is being dragged, so we can
            // delete it later (if this is a move rather than a copy)
            beingDragged = s;

            // Next, create a copy that will be the one dragged
            Scribble dragScribble = (Scribble) s.clone();
            // Adjust the origin to the point the user clicked on.
            dragScribble.translate(-x, -y);

            // Choose a cursor based on the type of drag the user initiated
            Cursor cursor;
            switch (e.getDragAction()) {
            case DnDConstants.ACTION_COPY:
                cursor = DragSource.DefaultCopyDrop;
                break;
            case DnDConstants.ACTION_MOVE:
                cursor = DragSource.DefaultMoveDrop;
                break;
            default:
                return; // We only support move and copys
            }

            // Some systems allow us to drag an image along with the
            // cursor. If so, create an image of the scribble to drag
            if (dragSource.isDragImageSupported()) {
                Rectangle scribbleBox = dragScribble.getBounds();
                Image dragImage = this.createImage(scribbleBox.width, scribbleBox.height);
                Graphics2D g = (Graphics2D) dragImage.getGraphics();
                g.setColor(new Color(0, 0, 0, 0)); // transparent background
                g.fillRect(0, 0, scribbleBox.width, scribbleBox.height);
                g.setColor(Color.black);
                g.setStroke(linestyle);
                g.translate(-scribbleBox.x, -scribbleBox.y);
                g.draw(dragScribble);
                Point hotspot = new Point(-scribbleBox.x, -scribbleBox.y);

                // Now start dragging, using the image.
                e.startDrag(cursor, dragImage, hotspot, dragScribble, this);
            } else {
                // Or start the drag without an image
                e.startDrag(cursor, dragScribble, this);
            }
            // After we've started dragging one scribble, stop looking
            return;
        }
    }
}

From source file:com.mirth.connect.client.ui.components.MirthTreeTable.java

public void setMirthColumnControlEnabled(boolean enable) {
    if (enable) {
        if (rightClickMouseAdapter == null) {
            rightClickMouseAdapter = new MouseAdapter() {
                public void mouseClicked(MouseEvent e) {
                    if (SwingUtilities.isRightMouseButton(e)) {
                        getColumnMenu().show(e.getComponent(), e.getX(), e.getY());
                    }/*from  w  w w  .j  a  v  a 2 s  .  c o m*/
                }
            };

            getTableHeader().addMouseListener(rightClickMouseAdapter);
        }
    } else {
        if (rightClickMouseAdapter != null) {
            getTableHeader().removeMouseListener(rightClickMouseAdapter);
            rightClickMouseAdapter = null;
        }
    }

    setColumnControlVisible(enable);
}

From source file:ScribbleDragAndDrop.java

/**
 * This method, and the following four methods are from the MouseListener
 * interface. If we're in drawing mode, this method handles mouse down
 * events and starts a new scribble.//from   w ww . j a  va 2s  .c  o m
 */
public void mousePressed(MouseEvent e) {
    if (dragMode)
        return;
    currentScribble = new Scribble();
    scribbles.add(currentScribble);
    currentScribble.moveto(e.getX(), e.getY());
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.AnnotationReportApplet.java

public void mousePressed(MouseEvent e) {
    if (MouseUtils.isPopupTrigger(e)) {
        theCanvas.enforceSelection(e.getPoint());
        createPopupMenu().show(theCanvas, e.getX(), e.getY());
    }/*from   w w w  .  j  a  v  a 2  s .c om*/
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.AnnotationReportApplet.java

public void mouseReleased(MouseEvent e) {
    if (MouseUtils.isPopupTrigger(e)) {
        theCanvas.enforceSelection(e.getPoint());
        createPopupMenu().show(theCanvas, e.getX(), e.getY());
    }/*from w  ww . j a  va  2s.  c  o  m*/
}

From source file:TransferableScribblePane.java

/**
 * This method is called for mouse motion events. We don't have to detect
 * gestures that initiate a drag in this method. That is the job of the
 * DragGestureRecognizer we created in the constructor: it will notify the
 * DragGestureListener defined below./*from ww w  . jav a  2  s. co m*/
 */
public void processMouseMotionEvent(MouseEvent e) {
    if (e.getID() == MouseEvent.MOUSE_DRAGGED && // If we're dragging
            currentLine != null) { // and a line exists
        currentLine.addSegment(e.getX(), e.getY()); // Add a line segment
        e.consume(); // Eat the event
        repaint(); // Redisplay all lines
    }
    super.processMouseMotionEvent(e); // Invoke any listeners
}

From source file:gda.gui.dv.panels.vispanels.ColourSelector.java

/**
 * The function that performs the histogram Drawing
 * //from www.j a  va2  s . c  o m
 * @param raw
 *            the raw data
 * @return the new data in the appropriate form
 */
@Override
public ImageData cast(DoubleDataset raw) {

    dataLink = raw;

    if (max == null) {
        max = raw.max().doubleValue();
    }
    if (min == null) {
        min = raw.min().doubleValue();
    }

    ImageData result = colourCast(raw, max, min);

    // if old stuff exists then remove it.
    if (chart != null) {
        chart.removeAll();
    }

    // now plot the histogram

    HistogramDataset histData = new HistogramDataset();
    histData.addSeries("h1", raw.getData(), 100, min, max);
    histogram = ChartFactory.createHistogram("Histogram", "Value", "Counts", histData, PlotOrientation.VERTICAL,
            false, false, false);

    if (unconfigured == false) {
        this.remove(chart);
    }
    unconfigured = false;

    chart = new DrawChart(histogram);

    chart.setMouseZoomable(false);

    chart.setPreferredSize(new Dimension(300, 300));
    chart.setMinimumSize(new Dimension(200, 200));

    c.gridx = 0;
    c.gridy = 4;
    c.gridwidth = 2;

    this.add(chart, c);

    chart.addMouseListener(new MouseListener() {
        Double tmin = min;
        Double tmax = max;

        @Override
        public void mouseClicked(MouseEvent e) {

        }

        @Override
        public void mouseEntered(MouseEvent e) {

        }

        @Override
        public void mouseExited(MouseEvent e) {

        }

        @Override
        public void mousePressed(MouseEvent e) {
            SimpleDataCoordinate coordinates = convertMouseEvent(e);
            if (chart.getScreenDataArea().contains(e.getX(), e.getY())) {
                tmin = coordinates.getX();
            } else {
                if (chart.getScreenDataArea().outcode(e.getX(), e.getY()) != Rectangle2D.OUT_RIGHT) {
                    //                  System.out.println("out of bounds");
                    //                  System.out.printf("Mouse: %d\n", e.getX());
                } else {
                    tmin = max;
                }
            }

        }

        @Override
        public void mouseReleased(MouseEvent e) {
            boolean update = false;
            SimpleDataCoordinate coordinates = convertMouseEvent(e);

            if (chart.getScreenDataArea().contains(e.getX(), e.getY())) {
                tmax = coordinates.getX();
                update = true;
            } else {
                if (chart.getScreenDataArea().outcode(e.getX(), e.getY()) != Rectangle2D.OUT_LEFT) {
                    //                  System.out.println("out of bounds");
                    //                  System.out.printf("Mouse: %d\n", e.getX());
                } else {
                    tmax = min;
                    update = true;
                }
            }
            if (update && tmin != tmax) {
                if (tmin > tmax) { // check and correct limits
                    Double t = tmin;
                    tmin = tmax;
                    tmax = t;
                }
                min = tmin;
                max = tmax;

                owner.getDataSetImage().applyColorCast();
                owner.getDataSetPlot3D().applyColorCast();
                owner.getDataSetImage().repaint();
            }
        }

        public SimpleDataCoordinate convertMouseEvent(MouseEvent me) {
            return new SimpleDataCoordinate(

                    histogram.getXYPlot().getDomainAxis().java2DToValue(me.getX(), chart.getScreenDataArea(),
                            histogram.getXYPlot().getDomainAxisEdge()),

                    histogram.getXYPlot().getRangeAxis().java2DToValue(me.getY(), chart.getScreenDataArea(),
                            histogram.getXYPlot().getRangeAxisEdge()));

        }

    });

    lblchart.invalidate();
    lblchart.validate();

    this.invalidate();
    this.validate();

    return result;

}

From source file:EventTestPane.java

/**
 * Display mouse events that don't involve mouse motion. The mousemods()
 * method prints modifiers, and is defined below. The other methods return
 * additional information about the mouse event. showLine() displays a line
 * of text in the window. It is defined at the end of this class, along with
 * the paintComponent() method.//  w w  w  .ja va 2 s.  co  m
 */
public void processMouseEvent(MouseEvent e) {
    String type = null;
    switch (e.getID()) {
    case MouseEvent.MOUSE_PRESSED:
        type = "MOUSE_PRESSED";
        break;
    case MouseEvent.MOUSE_RELEASED:
        type = "MOUSE_RELEASED";
        break;
    case MouseEvent.MOUSE_CLICKED:
        type = "MOUSE_CLICKED";
        break;
    case MouseEvent.MOUSE_ENTERED:
        type = "MOUSE_ENTERED";
        break;
    case MouseEvent.MOUSE_EXITED:
        type = "MOUSE_EXITED";
        break;
    }
    showLine(mousemods(e) + type + ": [" + e.getX() + "," + e.getY() + "] " + "num clicks = "
            + e.getClickCount() + (e.isPopupTrigger() ? "; is popup trigger" : ""));

    // When the mouse enters the component, request keyboard focus so
    // we can receive and respond to keyboard events
    if (e.getID() == MouseEvent.MOUSE_ENTERED)
        requestFocus();
}

From source file:Main.java

/**
 * Display mouse events that don't involve mouse motion. The mousemods()
 * method prints modifiers, and is defined below. The other methods return
 * additional information about the mouse event. showLine() displays a line
 * of text in the window. It is defined at the end of this class, along with
 * the paintComponent() method./*  w w  w . jav  a2 s  .  c om*/
 */
public void processMouseEvent(MouseEvent e) {
    String type = null;
    switch (e.getID()) {
    case MouseEvent.MOUSE_DRAGGED:
        type = "MOUSE_DRAGGED";
        break;
    case MouseEvent.MOUSE_RELEASED:
        type = "MOUSE_RELEASED";
        break;
    case MouseEvent.MOUSE_CLICKED:
        type = "MOUSE_CLICKED";
        break;
    case MouseEvent.MOUSE_ENTERED:
        type = "MOUSE_ENTERED";
        break;
    case MouseEvent.MOUSE_EXITED:
        type = "MOUSE_EXITED";
        break;
    }
    showLine(mousemods(e) + type + ": [" + e.getX() + "," + e.getY() + "] " + "num clicks = "
            + e.getClickCount() + (e.isPopupTrigger() ? "; is popup trigger" : ""));

    // When the mouse enters the component, request keyboard focus so
    // we can receive and respond to keyboard events
    if (e.getID() == MouseEvent.MOUSE_ENTERED)
        requestFocus();
}

From source file:javazoom.jlgui.player.amp.playlist.ui.PlaylistUI.java

/**
 * Handle mouse clicks on playlist./*from ww w . j a  v  a2 s  .co m*/
 * @param evt
 */
protected void handleMouseClick(MouseEvent evt) {
    int x = evt.getX();
    int y = evt.getY();
    ui.getAcPlAddPopup().setVisible(false);
    ui.getAcPlAdd().setVisible(true);
    ui.getAcPlRemovePopup().setVisible(false);
    ui.getAcPlRemove().setVisible(true);
    ui.getAcPlSelectPopup().setVisible(false);
    ui.getAcPlSelect().setVisible(true);
    ui.getAcPlMiscPopup().setVisible(false);
    ui.getAcPlMisc().setVisible(true);
    ui.getAcPlListPopup().setVisible(false);
    ui.getAcPlList().setVisible(true);
    // Check select action
    if (ui.getPlaylistPanel().isInSelectArea(x, y)) {
        int index = getIndex(y);
        if (index != -1) {
            // PopUp
            if (javax.swing.SwingUtilities.isRightMouseButton(evt)) {
                if (fipopup != null)
                    fipopup.show(this, x, y);
            } else {
                PlaylistItem pli = playlist.getItemAt(index);
                if (pli != null) {
                    pli.setSelected(!pli.isSelected());
                    if ((evt.getClickCount() == 2) && (evt.getModifiers() == MouseEvent.BUTTON1_MASK)) {
                        player.pressStop();
                        player.setCurrentSong(pli);
                        playlist.setCursor(index);
                        player.pressStart();
                    }
                }
            }
            repaint();
        }
    }
}