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:base.BasePlayer.BedCanvas.java

public void mouseMoved(MouseEvent event) {
    mouseY = event.getY();//  w w  w.ja  va  2  s.c  om
    this.mouseX = event.getX();
    this.mouseRect.setBounds(event.getX() - Main.sidebarWidth, event.getY(), 1, 1);
    this.sideMouseRect.setBounds(event.getX(), event.getY(), 1, 1);

    if (!sidebar && event.getX() < Main.sidebarWidth) {
        sidebar = true;
    } else {
        if (sidebar && event.getX() >= Main.sidebarWidth) {
            sidebar = false;
        }
    }

    for (int i = 0; i < this.trackDivider.size(); i++) {
        if (this.trackDivider.get(i) * this.getHeight() < mouseY) {
            continue;
        }
        if (this.trackDivider.get(i) * this.getHeight() >= mouseY) {
            if (hoverIndex != i) {
                hoverIndex = i;
            }
            break;
        }
    }
    repaint();

}

From source file:gda.plots.SimplePlot.java

/**
 * Part of the implementation of MouseListener. Overrides the super class (ChartPanel) implementation so that the
 * mouse can be used to select a rectangle as well as for zooming.
 * //w w  w .j a v a 2 s .c om
 * @see #mousePressed(java.awt.event.MouseEvent)
 * @see #mouseDragged(java.awt.event.MouseEvent)
 * @param e
 *            the mouse event which caused the call
 */
@Override
public void mouseReleased(MouseEvent e) {
    // Unless a rectangle is being dragged we just
    // want to call the super class method (which
    // deals with zooming)
    if (rd == null) {
        super.mouseReleased(e);

        if (magnifyingImage || magnifyingData) {
            // If the button released is BUTTON1 then the rectangle for
            // magnification will have been resized.
            if (e.getButton() == MouseEvent.BUTTON1) {
                magnifyWidth = e.getX() - magnifyXPoint;
                magnifyHeight = e.getY() - magnifyYPoint;
                magnifyRectangleIsNew = true;
            }

            // If the button released is BUTTON2 then the rectangle will
            // have been being dragged around. Need to redraw in XOR mode
            // one
            // last time to remove rectangle from plot.
            else if (e.getButton() == MouseEvent.BUTTON2) {
                Graphics2D g2 = (Graphics2D) getGraphics();
                g2.setXORMode(dragColour);
                if (magnifyRectangle != null) {
                    g2.fill(magnifyRectangle);
                }
                g2.dispose();
            }
            recalculateMagnifyRectangle(e);
            magnifier.update(magnifyRectangle);
        }
    } else {
        rd.mouseReleased(e);
    }
}

From source file:base.BasePlayer.BedCanvas.java

@SuppressWarnings("unchecked")
public void mousePressed(MouseEvent event) {
    resize = false;/*from w ww.ja v a 2 s  .co m*/
    pressY = event.getY();
    mouseDrag = true;

    this.requestFocus();
    Main.drawCanvas.pressX = event.getX();

    Main.drawCanvas.tempDrag = Main.drawCanvas.pressX;
    switch (event.getModifiers()) {

    case InputEvent.BUTTON1_MASK: {

        //   if(this.settingsbutton > -1) {
        if (sidebar && this.hoverIndex < bedTrack.size()
                && this.sideMouseRect.intersects(bedTrack.get(this.hoverIndex).settingsButton)) {

            this.bedTrack.get(this.hoverIndex).getPopup().show(this, mouseX, mouseY);
            //settingsbutton = -1;
            break;
        }

        //}
        if (resizer) {
            preresize = mouseY;
            preresizer = this.trackDivider.get(this.resizeDivider) * this.getHeight();
            tempDivider = (ArrayList<Double>) trackDivider.clone();
        }

        break;
    }
    case InputEvent.BUTTON3_MASK: {

        this.zoomDrag = false;
        if (sidebar) {
            this.bedTrack.get(hoverIndex).getPopup().show(this, mouseX, mouseY);
        }

    }
    }

}

From source file:gda.plots.SimplePlot.java

/**
 * Recalculates the rectangle which should be magnified.
 * //  ww  w .ja  va 2  s .com
 * @param e
 *            the MouseEvent which triggered the recalculation
 */
private void recalculateMagnifyRectangle(MouseEvent e) {
    if (magnifyWidth == 0 || magnifyHeight == 0)
        return;

    Rectangle2D scaledDataArea = getScreenDataArea();

    double widthToUse;
    double heightToUse;
    double xToUse;
    double yToUse;

    // If magnifyWidth is positive then e.getX() is
    // the end of the rectangle so the start is (e.getX() - magnifyWidth ).
    // If magnifyWidth is negative then e.getX() is the start of a
    // rectangle with the opposite sign width. Similarly for y.

    if (magnifyWidth > 0) {
        xToUse = e.getX() - magnifyWidth;
        widthToUse = magnifyWidth;
    } else {
        xToUse = e.getX();
        widthToUse = -1.0 * magnifyWidth;
    }

    if (magnifyHeight > 0) {
        yToUse = e.getY() - magnifyHeight;
        heightToUse = magnifyHeight;
    } else {
        yToUse = e.getY();
        heightToUse = -1.0 * magnifyHeight;
    }

    // xToUse and yToUse now specify the top left of the rectangle. In order
    // to keep the magnified rectangle inside the data area the start point
    // must be inside a rectangle which is the scaledDataArea reduced in
    // width
    // and height by the width and height of the magnifyRectangle.

    Point2D revisedStartPoint = ShapeUtilities.getPointInRectangle(xToUse, yToUse,
            new Rectangle2D.Double(scaledDataArea.getMinX(), scaledDataArea.getMinY(),
                    scaledDataArea.getWidth() - magnifyWidth, scaledDataArea.getHeight() - magnifyHeight));
    magnifyRectangle = new Rectangle2D.Double(revisedStartPoint.getX(), revisedStartPoint.getY(), widthToUse,
            heightToUse);
}

From source file:GUI.MainWindow.java

private void VulnReferencesListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_VulnReferencesListMouseClicked

    int clicked = evt.getButton();
    if (clicked == MouseEvent.BUTTON1 && evt.getClickCount() == 2) {
        // A double click. Lets see if there is already a link or if we are creating a new one
        Object obj = VulnReferencesList.getSelectedValue();
        if (obj == null) {
            // We should simply show the 'add reference' prompy
        } else if (obj instanceof Reference) {
            // User probably wants to edit the existing reference
            Reference ref = (Reference) obj;
            addReference(VulnTree, VulnReferencesList, ref);
        }//from   w w  w .  j  a  v  a 2 s  .c om
    } else if (clicked == MouseEvent.BUTTON3) {
        // A right click. Show the context menu
        //int selected = VulnReferencesList.getSelectedIndex();
        List l = VulnReferencesList.getSelectedValuesList();
        int selected = l.size();

        System.out.println("selected: " + selected);
        // None are selected enable insert and disable all the rest
        InsertReference.setEnabled(true);
        EditReferenceOption.setEnabled(false);
        LaunchInBrowser.setEnabled(false);
        DeleteReferenceOption.setEnabled(false);

        if (selected == 1) {
            // One was selected to enable the right options
            InsertReference.setEnabled(true);
            EditReferenceOption.setEnabled(true);
            LaunchInBrowser.setEnabled(true);
            DeleteReferenceOption.setEnabled(true);
        } else if (selected >= 2) {
            // One was selected to enable the right options
            InsertReference.setEnabled(true);
            EditReferenceOption.setEnabled(false);
            LaunchInBrowser.setEnabled(true);
            DeleteReferenceOption.setEnabled(true);
        }

        VulnReferencesContextMenu.show((Component) evt.getSource(), evt.getX(), evt.getY());
    }
}

From source file:base.BasePlayer.BedCanvas.java

@SuppressWarnings("unchecked")
public void mouseDragged(MouseEvent event) {
    switch (event.getModifiers()) {

    case InputEvent.BUTTON1_MASK: {
        if (sidebar) {
            return;
        }//from   ww w .ja  v a  2s  .  co  m
        this.mouseX = event.getX();
        this.mouseY = event.getY();

        if (resizer && this.getHeight() > this.trackDivider.size() * 20) {

            this.trackDivider.set(this.resizeDivider, mouseY / (double) this.getHeight());

            if ((positivelock || negative)
                    && this.trackDivider.get(this.resizeDivider) * this.getHeight() - preresizer >= 0) {
                positivelock = false;
                negative = false;
                preresize = mouseY;
                tempDivider = (ArrayList<Double>) trackDivider.clone();

            } else if ((!negative || negativelock)
                    && this.trackDivider.get(this.resizeDivider) * this.getHeight() - preresizer < 0) {
                negativelock = false;
                preresize = mouseY;
                tempDivider = (ArrayList<Double>) trackDivider.clone();
                negative = true;
            }

            if (negativelock) { // || (this.trackDivider.get(this.resizeDivider+1)*this.getHeight()) -(this.trackDivider.get(this.resizeDivider)*this.getHeight()) < 20) {
                this.trackDivider.set(this.resizeDivider,
                        (this.trackDivider.get(this.resizeDivider + 1) * this.getHeight() - 19)
                                / (double) this.getHeight());
            }
            if (positivelock) { // || (this.trackDivider.get(this.resizeDivider+1)*this.getHeight()) -(this.trackDivider.get(this.resizeDivider)*this.getHeight()) < 20) {
                this.trackDivider.set(this.resizeDivider, 19 / (double) this.getHeight());
            }
            if (this.trackDivider.get(this.resizeDivider) * this.getHeight() - preresizer < 0) {

                negative = true;
                positivelock = true;
                if (this.resizeDivider > 0) {

                    for (int i = 1; i < this.resizeDivider + 1; i++) {
                        if ((this.trackDivider.get(i) * this.getHeight())
                                - (this.trackDivider.get(i - 1) * this.getHeight()) < 20) {

                            this.trackDivider.set(i, ((this.trackDivider.get(i - 1) * this.getHeight()) + 19)
                                    / (double) this.getHeight());
                        } else {
                            positivelock = false;
                            if (i != this.resizeDivider) {
                                this.trackDivider.set(i, (this.tempDivider.get(i) / preresize) * mouseY);
                            }
                        }
                    }
                }
                if ((this.trackDivider.get(0) * this.getHeight()) >= 20) {
                    this.trackDivider.set(0, (this.tempDivider.get(0) / preresize) * mouseY);
                    positivelock = false;
                } else {
                    this.trackDivider.set(0, 19 / (double) this.getHeight());
                }

            } else {

                negative = false;
                negativelock = true;
                if (this.resizeDivider < this.trackDivider.size() - 1) {

                    for (int i = this.resizeDivider; i < this.trackDivider.size() - 1; i++) {

                        if ((this.trackDivider.get(i + 1) * this.getHeight())
                                - (this.trackDivider.get(i) * this.getHeight()) < 20) {

                            this.trackDivider.set(i, ((this.trackDivider.get(i + 1) * this.getHeight()) - 19)
                                    / (double) this.getHeight());
                        } else {

                            negativelock = false;
                            if (i != this.resizeDivider) {
                                try {
                                    this.trackDivider.set(i,
                                            1 - ((1 - this.tempDivider.get(i)) / (this.getHeight() - preresize))
                                                    * (this.getHeight() - mouseY));
                                } catch (Exception e) {

                                    //   e.printStackTrace();
                                }
                            }
                        }
                    }
                    if (this.getHeight()
                            - (this.trackDivider.get(this.trackDivider.size() - 2) * this.getHeight()) >= 20) {
                        negativelock = false;
                    } else {
                        this.trackDivider.set(this.trackDivider.size() - 2,
                                (this.getHeight() - 19) / (double) this.getHeight());
                    }

                }
            }

            preresizer = this.trackDivider.get(this.resizeDivider) * this.getHeight();
            repaint();

        } else if (lineZoomer) {

            if (Main.drawCanvas.selectedSplit.start > 1
                    || Main.drawCanvas.selectedSplit.end < Main.drawCanvas.selectedSplit.chromEnd) {
                Main.drawCanvas.gotoPos(
                        Main.drawCanvas.selectedSplit.start
                                - (Main.drawCanvas.tempDrag - mouseX) / Main.drawCanvas.selectedSplit.pixel * 2,
                        Main.drawCanvas.selectedSplit.end + (Main.drawCanvas.tempDrag - mouseX)
                                / Main.drawCanvas.selectedSplit.pixel * 2);
            }

            Main.drawCanvas.tempDrag = mouseX;
            Main.chromDraw.updateExons = true;
            repaint();
            Main.chromDraw.repaint();
            Draw.updatevars = true;
            Main.drawCanvas.repaint();

        } else {
            if (getCursor().getType() != Cursor.N_RESIZE_CURSOR) {
                zoomDrag = true;

                repaint();
            }
            return;
        }
        break;
    }
    case InputEvent.BUTTON3_MASK: {
        if (sidebar) {
            return;
        }
        if ((int) Main.drawCanvas.selectedSplit.start == 1
                && (int) Main.drawCanvas.selectedSplit.end == Main.drawCanvas.selectedSplit.chromEnd) {
            break;
        }

        Main.drawCanvas.mouseDrag = true;
        Main.drawCanvas.moveX = event.getX();
        Main.drawCanvas.drag(Main.drawCanvas.moveX);
        break;
    }
    case 17: {
        if (sidebar) {
            return;
        }
        if ((int) Main.drawCanvas.selectedSplit.start == 1
                && (int) Main.drawCanvas.selectedSplit.end == Main.drawCanvas.selectedSplit.chromEnd) {
            break;
        }

        Main.drawCanvas.mouseDrag = true;
        Main.drawCanvas.moveX = event.getX();
        Main.drawCanvas.drag(Main.drawCanvas.moveX);
        break;
    }
    }
}

From source file:FourByFour.java

public void mousePressed(MouseEvent e) {
    board.checkSelection2D(e.getX(), e.getY(), 1);
    repaint();
}

From source file:org.forester.archaeopteryx.TreePanel.java

final boolean inOv(final MouseEvent e) {
    return ((e.getX() > getVisibleRect().x + getOvXPosition() + 1)
            && (e.getX() < getVisibleRect().x + getOvXPosition() + getOvMaxWidth() - 1)
            && (e.getY() > getVisibleRect().y + getOvYPosition() + 1)
            && (e.getY() < getVisibleRect().y + getOvYPosition() + getOvMaxHeight() - 1));
}

From source file:org.forester.archaeopteryx.TreePanel.java

final boolean inOvRectangle(final MouseEvent e) {
    return ((e.getX() >= getOvRectangle().getX() - 1)
            && (e.getX() <= getOvRectangle().getX() + getOvRectangle().getWidth() + 1)
            && (e.getY() >= getOvRectangle().getY() - 1)
            && (e.getY() <= getOvRectangle().getY() + getOvRectangle().getHeight() + 1));
}

From source file:org.forester.archaeopteryx.TreePanel.java

final private boolean inOvVirtualRectangle(final MouseEvent e) {
    return (inOvVirtualRectangle(e.getX(), e.getY()));
}