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

/**
 * This method is called on mouse button events. It begins a new line or tries
 * to select an existing line./*  w  w  w . j av  a 2  s . com*/
 */
public void processMouseEvent(MouseEvent e) {
    if (e.getButton() == MouseEvent.BUTTON1) { // Left mouse button
        if (e.getID() == MouseEvent.MOUSE_PRESSED) { // Pressed down
            if (e.isShiftDown()) { // with Shift key
                // If the shift key is down, try to select a line
                int x = e.getX();
                int y = e.getY();

                // Loop through the lines checking to see if we hit one
                PolyLine selection = null;
                int numlines = lines.size();
                for (int i = 0; i < numlines; i++) {
                    PolyLine line = (PolyLine) lines.get(i);
                    if (line.intersects(x - 2, y - 2, 4, 4)) {
                        selection = line;
                        e.consume();
                        break;
                    }
                }
                // If we found an intersecting line, save it and repaint
                if (selection != selectedLine) { // If selection changed
                    selectedLine = selection; // remember which is selected
                    repaint(); // will make selection dashed
                }
            } else if (!e.isControlDown()) { // no shift key or ctrl key
                // Start a new line on mouse down without shift or ctrl
                currentLine = new PolyLine(e.getX(), e.getY());
                lines.add(currentLine);
                e.consume();
            }
        } else if (e.getID() == MouseEvent.MOUSE_RELEASED) {// Left Button Up
            // End the line on mouse up
            if (currentLine != null) {
                currentLine = null;
                e.consume();
            }
        }
    }

    // The superclass method dispatches to registered event listeners
    super.processMouseEvent(e);
}

From source file:de.tntinteractive.portalsammler.gui.DocumentTable.java

private void showPopup(final MouseEvent ev) {
    final JMenuItem open = new JMenuItem("Anzeigen");
    open.addActionListener(new ActionListener() {
        @Override/*from  w  w  w . jav  a 2 s  .c o  m*/
        public void actionPerformed(final ActionEvent e) {
            DocumentTable.this.openSelectedRows();
        }
    });

    final JMenuItem export = new JMenuItem("Exportieren");
    export.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            DocumentTable.this.exportSelectedRows();
        }
    });

    final JPopupMenu menu = new JPopupMenu();
    menu.add(open);
    menu.add(export);
    menu.show(ev.getComponent(), ev.getX(), ev.getY());
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopTree.java

@Override
public void setItemClickAction(Action action) {
    if (this.doubleClickAction != action) {
        if (action != null) {
            if (itemClickListener == null) {
                itemClickListener = new MouseAdapter() {
                    @Override/*  w  ww .  j  av  a2s .com*/
                    public void mouseClicked(MouseEvent e) {
                        if (isEditable()) {
                            if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2
                                    && doubleClickAction != null) {

                                int rowForLocation = impl.getRowForLocation(e.getX(), e.getY());
                                TreePath pathForLocation = impl.getPathForRow(rowForLocation);

                                if (pathForLocation != null) {
                                    impl.setSelectionPath(pathForLocation);

                                    doubleClickAction.actionPerform(DesktopTree.this);
                                }
                            }
                        }
                    }
                };
                impl.addMouseListener(itemClickListener);
                impl.setToggleClickCount(0);
            }
        } else {
            impl.removeMouseListener(itemClickListener);
            impl.setToggleClickCount(2);
            itemClickListener = null;
        }
        this.doubleClickAction = action;
    }
}

From source file:com.qspin.qtaste.ui.TestCaseTree.java

@Override
public String getToolTipText(MouseEvent e) {
    if (getRowForLocation(e.getX(), e.getY()) == -1)
        return null;
    else {/*from   w  w  w  .j  av a  2  s  . c o  m*/
        TreePath tp = this.getPathForLocation(e.getX(), e.getY());
        TreeNode node = this.getTreeNode(tp);
        if (node != null) {
            TCTreeNode tcTreeNode = (TCTreeNode) node;
            if ((tcTreeNode.getUserObject() != null) && (tcTreeNode.getUserObject() instanceof FileNode)) {
                FileNode fNode = (FileNode) tcTreeNode.getUserObject();
                //node
                if (fNode.isTestcaseDir()) {
                    if (fNode.isTestcaseCheckOk()) {
                        // compute the number of test cases (based on test data)
                        String text = fNode.getTestcaseCount() + " testcase(s) defined.";
                        String testcaseHeader = fNode.getTestcaseHeader();
                        if (!testcaseHeader.isEmpty()) {
                            text += "\n\nDescription:\n" + testcaseHeader;
                        }
                        return text;
                    } else {
                        return "no TestData file found or file is empty.";
                    }
                }
            }
        }
        return null;
    }
}

From source file:DragPictureDemo2.java

public void mouseDragged(MouseEvent e) {
    //Don't bother to drag if the component displays no image.
    if (image == null)
        return;//from   w ww .j  av  a  2 s  . c o  m

    if (firstMouseEvent != null) {
        e.consume();

        //If they are holding down the control key, COPY rather than MOVE
        int ctrlMask = InputEvent.CTRL_DOWN_MASK;
        int action = ((e.getModifiersEx() & ctrlMask) == ctrlMask) ? TransferHandler.COPY
                : TransferHandler.MOVE;

        int dx = Math.abs(e.getX() - firstMouseEvent.getX());
        int dy = Math.abs(e.getY() - firstMouseEvent.getY());
        //Arbitrarily define a 5-pixel shift as the
        //official beginning of a drag.
        if (dx > 5 || dy > 5) {
            //This is a drag, not a click.
            JComponent c = (JComponent) e.getSource();
            TransferHandler handler = c.getTransferHandler();
            //Tell the transfer handler to initiate the drag.
            handler.exportAsDrag(c, firstMouseEvent, action);
            firstMouseEvent = null;
        }
    }
}

From source file:net.sf.jabref.gui.MainTableSelectionListener.java

/**
 * Process general right-click events on the table. Show the table context menu at
 * the position where the user right-clicked.
 * @param e The mouse event defining the popup trigger.
 * @param row The row where the event occured.
 *//*from   w w  w  .  ja v a2  s . c  o  m*/
private void processPopupTrigger(MouseEvent e, int row) {
    int selRow = table.getSelectedRow();
    if ((selRow == -1) || // (getSelectedRowCount() == 0))
            !table.isRowSelected(table.rowAtPoint(e.getPoint()))) {
        table.setRowSelectionInterval(row, row);
        //panel.updateViewToSelected();
    }
    RightClickMenu rightClickMenu = new RightClickMenu(panel, panel.metaData());
    rightClickMenu.show(table, e.getX(), e.getY());
}

From source file:net.sf.mzmine.modules.visualization.msms.MsMsPlot.java

@Override
public void mouseClicked(final MouseEvent event) {

    // Let the parent handle the event (selection etc.)
    super.mouseClicked(event);

    if (event.getX() < 70) { // User clicked on Y-axis
        if (event.getClickCount() == 2) { // Reset zoom on Y-axis
            XYDataset data = ((XYPlot) getChart().getPlot()).getDataset();
            Number maximum = DatasetUtils.findMaximumRangeValue(data);
            getXYPlot().getRangeAxis().setRange(0, 1.05 * maximum.floatValue());
        } else if (event.getClickCount() == 1) {
            // Auto range on Y-axis
            getXYPlot().getRangeAxis().setAutoTickUnitSelection(true);
            getXYPlot().getRangeAxis().setAutoRange(true);
        }/*from   w ww  .  ja v  a 2 s  .c o m*/
    } else if (event.getY() > this.getChartRenderingInfo().getPlotInfo().getPlotArea().getMaxY() - 41
            && event.getClickCount() == 2) {
        // Reset zoom on X-axis
        getXYPlot().getDomainAxis().setAutoTickUnitSelection(true);
        restoreAutoDomainBounds();
    } else if (event.getClickCount() == 2) {
        visualizer.actionPerformed(
                new ActionEvent(event.getSource(), ActionEvent.ACTION_PERFORMED, "SHOW_SPECTRUM"));
    }
}

From source file:net.sf.mzmine.modules.visualization.ida.IDAPlot.java

@Override
public void mouseClicked(final MouseEvent event) {

    // Let the parent handle the event (selection etc.)
    super.mouseClicked(event);

    if (event.getX() < 70) { // User clicked on Y-axis
        if (event.getClickCount() == 2) { // Reset zoom on Y-axis
            XYDataset data = ((XYPlot) getChart().getPlot()).getDataset();
            Number maximum = DatasetUtilities.findMaximumRangeValue(data);
            getXYPlot().getRangeAxis().setRange(0, 1.05 * maximum.floatValue());
        } else if (event.getClickCount() == 1) {
            // Auto range on Y-axis
            getXYPlot().getRangeAxis().setAutoTickUnitSelection(true);
            getXYPlot().getRangeAxis().setAutoRange(true);
        }/*from w  w w. j  av a  2  s.  c  om*/
    } else if (event.getY() > this.getChartRenderingInfo().getPlotInfo().getPlotArea().getMaxY() - 41
            && event.getClickCount() == 2) {
        // Reset zoom on X-axis
        getXYPlot().getDomainAxis().setAutoTickUnitSelection(true);
        restoreAutoDomainBounds();
    } else if (event.getClickCount() == 2) {
        visualizer.actionPerformed(
                new ActionEvent(event.getSource(), ActionEvent.ACTION_PERFORMED, "SHOW_SPECTRUM"));
    }
}

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;
        }/*from  ww  w  . j  a v  a2 s  .c  o 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:com.mycompany.zad1.MainWindow.java

private void imageMoiffayLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_imageMoiffayLabelMouseClicked
    if (regionGrowing) {
        int treschold = Integer.parseInt(JOptionPane.showInputDialog("Treschold value"));
        RegionGrowing growing = new RegionGrowing();
        ArrayList<int[]> mask = growing.findRegion(imageBuff, evt.getX(), evt.getY(), treschold);

        ImageUtlis utlis = new ImageUtlis();
        utlis.repaintImage(imageBuff, colors[currentColor], mask);

        SupportFrame frame = new SupportFrame();

        frame.initRegionMask(imageOrginal.getWidth(), imageOrginal.getHeight(), mask);
        frame.setVisible(true);//from ww  w  .  j  a va2s.co m
        imageMoiffayLabel.setIcon(new ImageIcon(imageBuff.getImage()));

        currentColor++;

        if (currentColor == colors.length) {
            regionGrowingButton.setEnabled(false);
            regionGrowing = false;
            currentColor = 0;
        }
    }
}