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:playground.sergioo.networkBusLaneAdder2012.gui.BusLaneAdderPanel.java

@Override
public void mouseClicked(MouseEvent e) {
    double[] p = getWorld(e.getX(), e.getY());
    if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON3)
        camera.centerCamera(p);/*from w w  w  .j  a  v  a 2  s  .  c o m*/
    else {
        if (busLaneAdderWindow.getOption().equals(Options.SELECT_NODES)
                && e.getButton() == MouseEvent.BUTTON1) {
            ((NetworkTwoNodesPainterManager) ((NetworkPainter) getActiveLayer().getPainter())
                    .getNetworkPainterManager()).selectNearestNode(p[0], p[1]);
            busLaneAdderWindow.refreshLabel(Labels.NODES);
        } else if (busLaneAdderWindow.getOption().equals(Options.SELECT_NODES)
                && e.getButton() == MouseEvent.BUTTON3) {
            ((NetworkTwoNodesPainterManager) ((NetworkPainter) getActiveLayer().getPainter())
                    .getNetworkPainterManager()).unselectNearestNode(p[0], p[1]);
            busLaneAdderWindow.refreshLabel(Labels.NODES);
        } else if (busLaneAdderWindow.getOption().equals(Options.ZOOM) && e.getButton() == MouseEvent.BUTTON1) {
            camera.zoomIn(p[0], p[1]);
        } else if (busLaneAdderWindow.getOption().equals(Options.ZOOM) && e.getButton() == MouseEvent.BUTTON3) {
            camera.zoomOut(p[0], p[1]);
        }
    }
    repaint();
}

From source file:org.pentaho.reporting.libraries.designtime.swing.date.DateCellEditor.java

/**
 * Asks the editor if it can start editing using <code>anEvent</code>. <code>anEvent</code> is in the invoking
 * component coordinate system. The editor can not assume the Component returned by
 * <code>getCellEditorComponent</code> is installed.  This method is intended for the use of client to avoid the cost
 * of setting up and installing the editor component if editing is not possible. If editing can be started this method
 * returns true./*w  ww  .j ava  2  s.co  m*/
 *
 * @param anEvent the event the editor should use to consider whether to begin editing or not
 * @return true if editing can be started
 * @see #shouldSelectCell
 */
public boolean isCellEditable(final EventObject anEvent) {
    if (anEvent instanceof MouseEvent) {
        final MouseEvent mouseEvent = (MouseEvent) anEvent;
        return mouseEvent.getClickCount() >= 2 && mouseEvent.getButton() == MouseEvent.BUTTON1;
    }
    return true;
}

From source file:de.tbuchloh.kiskis.gui.treeview.TreeView.java

/**
 * @param treeContext/*from   w  ww. java  2s .c  om*/
 */
public TreeView(final JPopupMenu treeContext) {
    final GroupNode root = new GroupNode();
    root.setModelNode(new Group());
    _treeModel = new DefaultTreeModel(root);
    setModel(_treeModel);

    this.setEditable(true);
    this.setCellRenderer(new SpecialNodeCellRenderer());
    this.setCellEditor(new NameCellEditor());
    this.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(final MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON3) {
                LOG.debug("Context Menu invoked!"); //$NON-NLS-1$
                treeContext.show(TreeView.this, e.getX(), e.getY());
            }
        }
    });
    setDragEnabled(true);
    setAutoscrolls(true);
}

From source file:com.github.alexfalappa.nbspringboot.projects.customizer.CfgPropsDialog.java

private void lCfgPropsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lCfgPropsMouseClicked
    if (evt.getButton() == BUTTON1 && evt.getClickCount() > 1) {
        bOkActionPerformed(null);//from w w w.  java 2s. co  m
    }
}

From source file:richtercloud.document.scanner.gui.OCRPanel.java

private void oCRResultTextAreaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_oCRResultTextAreaMouseClicked
    if (evt.getButton() == MouseEvent.BUTTON3) {
        //right click
        this.oCRResultPopup.show(this.oCRResultTextArea, evt.getX(), evt.getY());
    }/* w w w.j a va2 s .co m*/
}

From source file:net.sf.mzmine.desktop.impl.projecttree.ProjectTreeMouseHandler.java

public void mouseClicked(MouseEvent e) {

    if (e.isPopupTrigger())
        handlePopupTriggerEvent(e);/*from  w  ww  .j  a  va  2s .  c o m*/

    if ((e.getClickCount() == 2) && (e.getButton() == MouseEvent.BUTTON1))
        handleDoubleClickEvent(e);

}

From source file:es.udc.fic.medregatas.view.MainAppjFrame.java

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

    if (evt.getButton() == MouseEvent.BUTTON1) {
        selectedRegata = (Regata) regatasList.getSelectedValue();
        jLabelTitle.setText(selectedRegata.toString());
        loadTabs();//from   w w  w .  ja va 2s.com
    }
}

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

@Override
public void mouseClicked(MouseEvent e) {
    double[] p = getWorld(e.getX(), e.getY());
    if (e.getClickCount() == 2) {
        if (window.getOption().equals(Options.SELECT_LINK) && e.getButton() == MouseEvent.BUTTON1) {
            ((NetworkPainter) getActiveLayer().getPainter()).getNetworkPainterManager().selectLink(p[0], p[1]);
            Link link = ((NetworkPainter) getActiveLayer().getPainter()).getNetworkPainterManager()
                    .getSelectedLink();/*from www  . j  a va2  s . c o  m*/
            try {
                link.setCapacity(
                        Double.parseDouble(JOptionPane.showInputDialog("New capacity", link.getCapacity())));
            } catch (Exception e2) {

            }
            ((SimpleSelectionNetworkPainter) getActiveLayer().getPainter()).calculateMinMax();
            window.refreshLabel(Labels.LINK);
        } else if (e.getButton() == MouseEvent.BUTTON3) {
            ((NetworkPainter) getActiveLayer().getPainter()).getNetworkPainterManager().selectLink(p[0], p[1]);
            Link link = ((NetworkPainter) getActiveLayer().getPainter()).getNetworkPainterManager()
                    .getSelectedLink();
            try {
                link.setFreespeed(
                        Double.parseDouble(JOptionPane.showInputDialog("New free speed", link.getFreespeed())));
            } catch (Exception e2) {

            }
            ((SimpleSelectionNetworkPainter) getActiveLayer().getPainter()).calculateMinMax();
            window.refreshLabel(Labels.LINK);
        }
    } else {
        if (window.getOption().equals(Options.SELECT_LINK) && e.getButton() == MouseEvent.BUTTON1) {
            ((NetworkPainter) getActiveLayer().getPainter()).getNetworkPainterManager().selectLink(p[0], p[1]);
            window.refreshLabel(Labels.LINK);
        } else if (window.getOption().equals(Options.SELECT_LINK) && e.getButton() == MouseEvent.BUTTON3) {
            ((NetworkPainter) getActiveLayer().getPainter()).getNetworkPainterManager().unselectLink();
            window.refreshLabel(Labels.LINK);
        } else if (window.getOption().equals(Options.SELECT_NODE) && e.getButton() == MouseEvent.BUTTON1) {
            ((NetworkPainter) getActiveLayer().getPainter()).getNetworkPainterManager().selectNode(p[0], p[1]);
            window.refreshLabel(Labels.NODE);
        } else if (window.getOption().equals(Options.SELECT_NODE) && e.getButton() == MouseEvent.BUTTON3) {
            ((NetworkPainter) getActiveLayer().getPainter()).getNetworkPainterManager().unselectNode();
            window.refreshLabel(Labels.NODE);
        } else if (window.getOption().equals(Options.ZOOM) && e.getButton() == MouseEvent.BUTTON1)
            camera.zoomIn(p[0], p[1]);
        else if (window.getOption().equals(Options.ZOOM) && e.getButton() == MouseEvent.BUTTON3)
            camera.zoomOut(p[0], p[1]);
    }
    repaint();
}

From source file:org.openconcerto.erp.core.finance.accounting.ui.GrandLivrePanel.java

/**
 * Cree un JTable contenant les ecritures du compte pass en argument
 * /*  w ww  .  j  a  v a  2  s  .  c  o  m*/
 * @param compte
 * @return null si aucune ecriture
 */
private JTable createJTableCompte(Compte compte) {

    // on cree la JTable
    final JTable tableTmp = creerJTable(compte);

    if (tableTmp != null) {

        // On met en place le renderer
        EcritureGrandLivreRenderer ecritureRenderer = new EcritureGrandLivreRenderer(
                ((TableSorter) tableTmp.getModel()));

        for (int j = 0; j < tableTmp.getColumnCount(); j++) {
            tableTmp.getColumnModel().getColumn(j).setCellRenderer(ecritureRenderer);
        }

        // Gestion de la souris sur la JTable
        tableTmp.addMouseListener(new MouseAdapter() {

            public void mousePressed(final MouseEvent mE) {

                if (mE.getButton() == MouseEvent.BUTTON3) {
                    JPopupMenu menuDroit = new JPopupMenu();

                    menuDroit.add(new AbstractAction("Voir la source") {

                        public void actionPerformed(ActionEvent e) {
                            int row = tableTmp.rowAtPoint(mE.getPoint());

                            TableSorter s = (TableSorter) tableTmp.getModel();

                            int modelIndex = s.modelIndex(row);
                            ConsultCompteModel consultCompteModel = ((ConsultCompteModel) s.getTableModel());
                            Ecriture ecriture = consultCompteModel.getEcritures().get(modelIndex);

                            MouvementSQLElement.showSource(ecriture.getIdMvt());

                        }
                    });
                    menuDroit.show(mE.getComponent(), mE.getX(), mE.getY());
                }
            }
        });

    }
    return tableTmp;
}

From source file:gg.pistol.sweeper.gui.component.DecoratedPanel.java

/**
 * Helper method to add a contextual menu on a text component that will allow for Copy & Select All text actions.
 *//*w w  w  .  j  a  va2 s. co  m*/
protected void addCopyMenu(final JTextComponent component) {
    Preconditions.checkNotNull(component);

    if (!component.isEditable()) {
        component.setCursor(new Cursor(Cursor.TEXT_CURSOR));
    }

    final JPopupMenu contextMenu = new JPopupMenu();
    JMenuItem copy = new JMenuItem(component.getActionMap().get(DefaultEditorKit.copyAction));
    copy.setText(i18n.getString(I18n.TEXT_COPY_ID));
    contextMenu.add(copy);
    contextMenu.addSeparator();

    JMenuItem selectAll = new JMenuItem(component.getActionMap().get(DefaultEditorKit.selectAllAction));
    selectAll.setText(i18n.getString(I18n.TEXT_SELECT_ALL_ID));
    contextMenu.add(selectAll);

    component.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON3) {
                contextMenu.show(component, e.getX(), e.getY());
            }
        }
    });
}