Example usage for java.awt.event MouseEvent getButton

List of usage examples for java.awt.event MouseEvent getButton

Introduction

In this page you can find the example usage for java.awt.event MouseEvent getButton.

Prototype

public int getButton() 

Source Link

Document

Returns which, if any, of the mouse buttons has changed state.

Usage

From source file:de.jakop.ngcalsync.application.TrayStarter.java

private MouseAdapter createLogMouseListener(final JFrame logWindow) {
    return new MouseAdapter() {

        @Override// w  ww . java 2 s  . c  o m
        public void mouseClicked(final MouseEvent e) {
            if (e.getClickCount() == 1 && e.getButton() == MouseEvent.BUTTON1) {
                logWindow.setVisible(!logWindow.isVisible());
            }
        }

    };
}

From source file:dbseer.gui.panel.DBSeerExplainChartPanel.java

@Override
public void mouseReleased(MouseEvent e) {
    if (e.getButton() == MouseEvent.BUTTON3) {
        displayPopupMenu(e.getX(), e.getY());
        return;// w ww. j av  a 2s.  com
    }
    repaint();
    int smallX = Math.min(startX, endX);
    int smallY = Math.min(startY, endY);
    int bigX = Math.max(startX, endX);
    int bigY = Math.max(startY, endY);

    XYPlot plot = this.getChart().getXYPlot();
    Rectangle2D plotArea = this.getScreenDataArea();
    double chartSmallX = plot.getDomainAxis().java2DToValue(smallX, plotArea, plot.getDomainAxisEdge());
    double chartBigX = plot.getDomainAxis().java2DToValue(bigX, plotArea, plot.getDomainAxisEdge());
    double chartSmallY = plot.getRangeAxis().java2DToValue(smallY, plotArea, plot.getRangeAxisEdge());
    double chartBigY = plot.getRangeAxis().java2DToValue(bigY, plotArea, plot.getRangeAxisEdge());

    double minXValue = Math.min(chartSmallX, chartBigX);
    double maxXValue = Math.max(chartSmallX, chartBigX);
    double minYValue = Math.min(chartSmallY, chartBigY);
    double maxYValue = Math.max(chartSmallY, chartBigY);

    //testLog.append("Scanning: (" + smallX + ", " + smallY + "), (" + bigX + ", " + bigY + ")\n");
    //testLog.append("Scanning: X = [" + Math.min(chartSmallX, chartBigX) + ", " + Math.max(chartSmallX, chartBigX) + "]\n");
    //testLog.append("Scanning: Y = [" + Math.min(chartSmallY, chartBigY) + ", " + Math.max(chartSmallY, chartBigY) + "]\n");

    Set<XYItemEntity> foundItem = new HashSet<XYItemEntity>();

    XYDataset dataset = this.getChart().getXYPlot().getDataset();
    EntityCollection collection = this.getChartRenderingInfo().getEntityCollection();

    for (Object obj : collection.getEntities()) {
        if (obj instanceof XYItemEntity) {
            XYItemEntity entity = (XYItemEntity) obj;
            int series = entity.getSeriesIndex();
            int idx = entity.getItem();
            if (dataset.getX(series, idx).doubleValue() >= minXValue
                    && dataset.getX(series, idx).doubleValue() <= maxXValue
                    && dataset.getY(series, idx).doubleValue() >= minYValue
                    && dataset.getY(series, idx).doubleValue() <= maxYValue) {
                foundItem.add(entity);
            }
        }
    }

    //      for (int x = smallX; x <= bigX; ++x)
    //      {
    //         for (int y = smallY; y <= bigY; ++y)
    //         {
    //            ChartEntity entity = this.getEntityForPoint(x, y);
    //            if (entity instanceof XYItemEntity)
    //            {
    //               foundItem.add((XYItemEntity)entity);
    //            }
    //         }
    //      }

    selectedItems = foundItem;

    //      outlierRegion.clear();
    //      for (XYItemEntity entity : foundItem)
    //      {
    //         //testLog.append(entity.toString() + "\n");
    //         //testLog.append("Series = " + entity.getSeriesIndex() + ", ");
    //         //testLog.append("X = " + entity.getDataset().getX(entity.getSeriesIndex(), entity.getItem()) + ", ");
    //         //testLog.append("Y = " + entity.getDataset().getY(entity.getSeriesIndex(), entity.getItem()) + "\n");
    //         outlierRegion.add(entity.getDataset().getX(entity.getSeriesIndex(), entity.getItem()).doubleValue());
    //      }
    //
    //      Collections.sort(outlierRegion);
    //      if (!outlierRegion.isEmpty())
    //      {
    //         testLog.setText("");
    //         testLog.append("Outlier time selected = [");
    //         for (int i = 0; i < outlierRegion.size(); ++i)
    //         {
    //            testLog.append(outlierRegion.get(i).toString());
    //            if (i < outlierRegion.size() - 1)
    //            {
    //               testLog.append(" ");
    //            }
    //         }
    //         testLog.append("]\n");
    //      }
}

From source file:com.univocity.app.swing.DataAnalysisWindow.java

private void addPopupMenuToTable(DaoTable daoTable, boolean isSourceTable) {
    String engineName = isSourceTable ? config.getSourceEngineName() : config.getDestinationEngineName();

    if (engineName == null) {
        return;/*  w ww .j  a  va 2  s.  c o m*/
    }

    final JTable table = daoTable.getDataTable();
    final JPopupMenu menu = new JPopupMenu();
    menu.add(newJMenuItem("Disable updates", daoTable, engineName, false, false));
    menu.add(newJMenuItem("Enable updates", daoTable, engineName, true, false));
    menu.add(new JSeparator());
    menu.add(newJMenuItem("Disable updates on all rows", daoTable, engineName, false, true));
    menu.add(newJMenuItem("Enable updates on all rows", daoTable, engineName, true, true));

    table.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON3) {
                int rowNumber = table.rowAtPoint(e.getPoint());
                if (rowNumber != -1) {
                    table.getSelectionModel().setSelectionInterval(rowNumber, rowNumber);
                    menu.show(table, e.getX(), e.getY());
                }
            }
        };
    });
}

From source file:org.openmicroscopy.shoola.agents.util.ui.ChannelButton.java

/**
 * Selects the channel or displays the pop up menu.
 *
 * @param e The mouse event to handle.//  ww  w . jav a 2s .  c  om
 */
private void onClick(MouseEvent e) {
    boolean mask = (e.isControlDown() || e.isMetaDown());
    if (e.getButton() == MouseEvent.BUTTON1 && !(mask))
        setChannelSelected();
    else if ((e.getButton() == MouseEvent.BUTTON2 || mask))
        onReleased(e);
}

From source file:eu.europa.ec.markt.dss.applet.view.validationpolicy.EditView.java

private void registerMouseListener(final JTree tree) {

    MouseListener mouseAdapter = new MouseAdapter() {
        public void mousePressed(MouseEvent mouseEvent) {
            if (mouseEvent.getButton() == MouseEvent.BUTTON3) {
                final int selectedRow = tree.getRowForLocation(mouseEvent.getX(), mouseEvent.getY());
                final TreePath selectedPath = tree.getPathForLocation(mouseEvent.getX(), mouseEvent.getY());
                if (selectedRow != -1) {
                    final XmlDomAdapterNode clickedItem = (XmlDomAdapterNode) selectedPath
                            .getLastPathComponent();
                    final boolean isLeaf = tree.getModel().isLeaf(selectedPath.getLastPathComponent());
                    // Do nothing on root element
                    if (selectedPath.getPathCount() > 1) {
                        // find the allowed actions, to know if a popup menu should be displayed and the content of the popup menu + action handlers
                        if (clickedItem.node instanceof Element) {
                            nodeActionAdd(mouseEvent, selectedRow, selectedPath, clickedItem, tree);
                        } else if (isLeaf) {
                            valueLeafActionEdit(mouseEvent, selectedPath, clickedItem, tree);
                        }/*from   w  w w . j  a  va2 s  .  co  m*/
                    }
                }
            }
        }
    };
    tree.addMouseListener(mouseAdapter);
}

From source file:org.openconcerto.erp.model.FamilleArticleTree.java

public void mousePressed(MouseEvent e) {

    Object o = this.getSelectionPath().getLastPathComponent();

    int id = 1;/*from  www. ja v a 2 s .co  m*/

    if (e.getButton() == MouseEvent.BUTTON3) {
        if (o instanceof FamilleTreeNode) {

            final FamilleTreeNode nodeSelect = (FamilleTreeNode) o;
            id = nodeSelect.getId();
        }

        final int idSelect = id;

        // Ajouter, supprimer, modifier une famille

        JPopupMenu menu = new JPopupMenu();
        menu.add(new AbstractAction("Ajouter une famille") {
            public void actionPerformed(ActionEvent e) {
                EditFrame frameAddFamille = new EditFrame(familleElt, EditFrame.CREATION);
                SQLRowValues rowVals = new SQLRowValues(familleElt.getTable());
                rowVals.put("ID_FAMILLE_ARTICLE_PERE", idSelect);
                frameAddFamille.getSQLComponent().select(rowVals);
                frameAddFamille.setVisible(true);

            }
        });

        if (idSelect > 1) {
            menu.add(new AbstractAction("Modifier") {
                public void actionPerformed(ActionEvent e) {
                    EditFrame frameModFamille = new EditFrame(familleElt, EditFrame.MODIFICATION);
                    frameModFamille.selectionId(idSelect, 1);
                    frameModFamille.setVisible(true);

                }
            });

            menu.add(new AbstractAction("Supprimer") {
                public void actionPerformed(ActionEvent e) {
                    try {
                        familleElt.archive(idSelect);
                    } catch (SQLException e1) {
                        e1.printStackTrace();
                    }
                }
            });
        }
        menu.show(e.getComponent(), e.getPoint().x, e.getPoint().y);
    }

}

From source file:de.tbuchloh.kiskis.gui.widgets.PasswordElement.java

private void initCreatePopup() {
    _pwdCreateMenu = new JPopupMenu();
    final JMenuItem secure = new JMenuItem(M.getString("secure_item")); //$NON-NLS-1$
    secure.addActionListener(new PasswordActionListener(PasswordFactory.SECURE));
    _pwdCreateMenu.add(secure);/*w  ww.j a va 2s.co  m*/

    final JMenuItem human = new JMenuItem(M.getString("human_readable_item")); //$NON-NLS-1$
    human.addActionListener(new PasswordActionListener(PasswordFactory.HUMAN_READABLE));
    _pwdCreateMenu.add(human);

    final JMenuItem template = new JMenuItem(M.createAction(this, "onCreateByTemplate"));
    _pwdCreateMenu.add(template);

    _specialActionsMenu = new JPopupMenu();
    _specialActionsMenu.add(M.createAction(this, "onCopyToClipboard"));

    _pwdField.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(final MouseEvent e) {
            if (e.getButton() != MouseEvent.BUTTON3) {
                return;
            }
            final int x = e.getX(); // _pwdField.getWidth()
            // - _specialActionsMenu.getWidth();
            final int y = e.getY();

            LOG.debug("Show context menu x=" + x + ", y=" + y);
            _specialActionsMenu.show(_pwdField, x, y);
        }
    });
}

From source file:com.clough.android.adbv.view.UpdateTableDialog.java

private void resultTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_resultTableMouseClicked
    // TODO add your handling code here:
    if (evt.getButton() == MouseEvent.BUTTON3) {
        int rowIndex;
        if ((rowIndex = validateRowSelection()) != -1) {
            showTableChangeOptionMenu(evt.getLocationOnScreen().x - getX(),
                    evt.getLocationOnScreen().y - getY(), rowIndex);
        }/*from w  w  w  .jav a 2s. c om*/
    }
}

From source file:eu.europa.esig.dss.applet.view.validationpolicy.EditView.java

private void registerMouseListener(final JTree tree) {

    MouseListener mouseAdapter = new MouseAdapter() {
        @Override/* www . jav a 2  s  .  co  m*/
        public void mousePressed(MouseEvent mouseEvent) {
            if (mouseEvent.getButton() == MouseEvent.BUTTON3) {
                final int selectedRow = tree.getRowForLocation(mouseEvent.getX(), mouseEvent.getY());
                final TreePath selectedPath = tree.getPathForLocation(mouseEvent.getX(), mouseEvent.getY());
                if (selectedRow != -1) {
                    final XmlDomAdapterNode clickedItem = (XmlDomAdapterNode) selectedPath
                            .getLastPathComponent();
                    final boolean isLeaf = tree.getModel().isLeaf(selectedPath.getLastPathComponent());
                    // Do nothing on root element
                    if (selectedPath.getPathCount() > 1) {
                        // find the allowed actions, to know if a popup menu should be displayed and the content of the popup menu + action handlers
                        if (clickedItem.node instanceof Element) {
                            nodeActionAdd(mouseEvent, selectedRow, selectedPath, clickedItem, tree);
                        } else if (isLeaf) {
                            valueLeafActionEdit(mouseEvent, selectedPath, clickedItem, tree);
                        }
                    }
                }
            }
        }
    };
    tree.addMouseListener(mouseAdapter);
}

From source file:edu.harvard.mcz.imagecapture.ImageZoomPanel.java

@Override
public void mouseClicked(MouseEvent e) {
    if (e.getButton() == MouseEvent.BUTTON1) {
        Point clickAt = e.getPoint();
        Dimension size = jLabel.getSize();
        jLabel.zoomIn();//from w  ww . j  a v  a  2 s.c  o  m
        jLabel.repaint();
        jLabel.doLayout();
        jLabel.centerOn(clickAt);
        jLabel.invalidate();
        jScrollPane.revalidate();
        jScrollPane.getParent().validate();
        jScrollPane.setVisible(false);
        jScrollPane.setVisible(true);
        jScrollPane.validate();
        jScrollPane.doLayout();
        zoomIn();
        zoomOut();
    } else if (e.getButton() == MouseEvent.BUTTON3) {
        Point clickAt = e.getPoint();
        zoomOut();
        jLabel.centerOn(clickAt);
    }
}