Example usage for java.awt.event MouseEvent BUTTON2

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

Introduction

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

Prototype

int BUTTON2

To view the source code for java.awt.event MouseEvent BUTTON2.

Click Source Link

Document

Indicates mouse button #2; used by #getButton .

Usage

From source file:Main.java

public Main() {
    setLayout(null);/*from  w  w w .j a  v  a  2s.  c  om*/
    add(button);
    button.setSize(button.getPreferredSize());
    button.setLocation(20, 20);
    addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            System.out.println(e.getButton() == MouseEvent.BUTTON2);
        }
    });
}

From source file:Main.java

public Main() {
    setSize(300, 300);/* w ww. jav  a2s  . com*/
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    final JTextArea textArea = new JTextArea();
    textArea.setText("Click Me!");

    textArea.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            if (e.getButton() == MouseEvent.NOBUTTON) {
                textArea.setText("No button clicked...");
            } else if (e.getButton() == MouseEvent.BUTTON1) {
                textArea.setText("Button 1 clicked...");
            } else if (e.getButton() == MouseEvent.BUTTON2) {
                textArea.setText("Button 2 clicked...");
            } else if (e.getButton() == MouseEvent.BUTTON3) {
                textArea.setText("Button 3 clicked...");
            }

            System.out.println("Number of click: " + e.getClickCount());
            System.out.println("Click position (X, Y):  " + e.getX() + ", " + e.getY());
        }
    });

    getContentPane().add(textArea);
}

From source file:org.fhcrc.cpl.viewer.mrm.utilities.MRMerMouseListener.java

public void mouseClicked(MouseEvent e) {
    if (e.getSource() instanceof ChartPanel && ((e.getButton() == MouseEvent.BUTTON2)
            || (e.getButton() == MouseEvent.BUTTON1) && ((e.getModifiers() & InputEvent.CTRL_MASK) != 0))) {
        CenterZoomNumberAxis czna = (CenterZoomNumberAxis) _cp.getChart().getXYPlot().getDomainAxis();
        NumberAxis range = (NumberAxis) _cp.getChart().getXYPlot().getRangeAxis();
        Rectangle2D screenDataArea = _cp.getScreenDataArea(e.getX(), e.getY());
        double y1 = czna.getLowerBound();
        double y2 = czna.getUpperBound();
        double x1 = screenDataArea.getX();
        double x2 = x1 + screenDataArea.getWidth();
        double transformedx = (((y2 - y1) / (x2 - x1)) * (e.getX() - x1)) + y1;
        MRMDialog mrmd = (MRMDialog) MRMAncestor();
        PeaksTableModel model = (PeaksTableModel) mrmd.peaksTable.getModel();
        MRMTransition mrt = mrmd.transitionOnPlot;
        mrt.setCalcXatMaxYAllDaughters(transformedx);
        mrt.setCalcMaxYAllDaughters(//from w  w  w.j  a v a2s  .  c  om
                range.getLowerBound() + 0.95 * (range.getUpperBound() - range.getLowerBound()));
        model.setValueAt(new Float(mrt.getCalcXatMaxYAllDaughters()), mrt.getTableRow(),
                MRMDialog.peaksData.MidTime.colno);
        for (MRMDaughter d : mrt.getDaughters().values()) {
            model.setValueAt(new Float(mrt.getCalcXatMaxYAllDaughters()), d.getElutionDataTableRow(),
                    MRMDialog.peaksData.MidTime.colno);
        }
        mrmd.updateChartsAndFields(false);
    }
    if ((e.isShiftDown() || e.getButton() == MouseEvent.BUTTON3) || shifted) {
        _cp.mouseClicked(e);
    } else {
        _cp.mouseClicked(e);
    }
}

From source file:org.kalypso.ogc.gml.widgets.base.PanToWidget.java

public PanToWidget(final String name, final String toolTip) {
    super(name, toolTip);

    m_mouseButtons = new int[] { MouseEvent.BUTTON1, MouseEvent.BUTTON2 };
}

From source file:org.kalypso.ogc.gml.widgets.base.PanToWidget.java

public PanToWidget() {
    super("pan to", ""); //$NON-NLS-1$ //$NON-NLS-2$
    m_mouseButtons = new int[] { MouseEvent.BUTTON1, MouseEvent.BUTTON2 };
}

From source file:SWTUtils.java

/**
 * Creates an AWT <code>MouseEvent</code> from a swt event.
 * This method helps passing SWT mouse event to awt components.
 * @param event The swt event.//from   w w  w . j  a va  2 s  .c o  m
 * @return A AWT mouse event based on the given SWT event.
 */
public static MouseEvent toAwtMouseEvent(org.eclipse.swt.events.MouseEvent event) {
    int button = MouseEvent.NOBUTTON;
    switch (event.button) {
    case 1:
        button = MouseEvent.BUTTON1;
        break;
    case 2:
        button = MouseEvent.BUTTON2;
        break;
    case 3:
        button = MouseEvent.BUTTON3;
        break;
    }
    int modifiers = 0;
    if ((event.stateMask & SWT.CTRL) != 0) {
        modifiers |= InputEvent.CTRL_DOWN_MASK;
    }
    if ((event.stateMask & SWT.SHIFT) != 0) {
        modifiers |= InputEvent.SHIFT_DOWN_MASK;
    }
    if ((event.stateMask & SWT.ALT) != 0) {
        modifiers |= InputEvent.ALT_DOWN_MASK;
    }
    MouseEvent awtMouseEvent = new MouseEvent(DUMMY_PANEL, event.hashCode(), event.time, modifiers, event.x,
            event.y, 1, false, button);
    return awtMouseEvent;
}

From source file:com.mirth.connect.client.ui.TemplatePanel.java

public TemplatePanel(MirthEditorPane m) {
    this.parent = m;

    initComponents();//from  w  w  w.ja v  a2 s .c o m
    openFileButton.setIcon(UIConstants.ICON_FILE_PICKER);

    if (PlatformUI.MIRTH_FRAME != null) {
        dataTypeComboBox.setModel(new javax.swing.DefaultComboBoxModel(
                PlatformUI.MIRTH_FRAME.dataTypeToDisplayName.values().toArray()));
    }

    hl7Document = new SyntaxDocument();
    hl7Document.setTokenMarker(new HL7TokenMarker());
    pasteBox.setDocument(hl7Document);

    // handles updating the tree
    pasteBox.getDocument().addDocumentListener(new DocumentListener() {
        public void changedUpdate(DocumentEvent e) {
            updateText();
        }

        public void insertUpdate(DocumentEvent e) {
            updateText();
        }

        public void removeUpdate(DocumentEvent e) {
            updateText();
        }
    });
    pasteBox.addMouseListener(new MouseListener() {
        public void mouseClicked(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON2) {
                if (pasteBox.getText().equals(DEFAULT_TEXT)) {
                    pasteBox.setText("");
                }
            }
        }

        public void mouseEntered(MouseEvent e) {
        }

        public void mouseExited(MouseEvent e) {
        }

        public void mousePressed(MouseEvent e) {
        }

        public void mouseReleased(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON2) {
                if (pasteBox.getText().length() == 0) {
                    pasteBox.setText(DEFAULT_TEXT);
                }
            }
        }
    });

    new DropTarget(pasteBox, this);
}

From source file:org.optaplanner.examples.tsp.swingui.TspWorldPanel.java

public TspWorldPanel(TspPanel tspPanel) {
    this.tspPanel = tspPanel;
    addComponentListener(new ComponentAdapter() {
        @Override//  w w  w  . ja  v  a  2s. c om
        public void componentResized(ComponentEvent e) {
            // TODO Not thread-safe during solving
            TravelingSalesmanTour travelingSalesmanTour = TspWorldPanel.this.tspPanel
                    .getTravelingSalesmanTour();
            if (travelingSalesmanTour != null) {
                resetPanel(travelingSalesmanTour);
            }
        }
    });
    MouseAdapter mouseAdapter = new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            if (translator != null) {
                double longitude = translator.translateXToLongitude(e.getX());
                double latitude = translator.translateYToLatitude(e.getY());
                if (e.getButton() == MouseEvent.BUTTON1) {
                    dragSourceStandstill = TspWorldPanel.this.tspPanel
                            .findNearestStandstill(new AirLocation(-1L, latitude, longitude));
                    TravelingSalesmanTour tour = TspWorldPanel.this.tspPanel.getTravelingSalesmanTour();
                    dragTargetStandstill = tour.getDomicile();
                    resetPanel(tour);
                } else if (e.getButton() == MouseEvent.BUTTON2 || e.getButton() == MouseEvent.BUTTON3) {
                    TspWorldPanel.this.tspPanel.insertLocationAndVisit(longitude, latitude);
                }
            }
        }

        @Override
        public void mouseDragged(MouseEvent e) {
            if (translator != null) {
                if (dragSourceStandstill != null) {
                    double longitude = translator.translateXToLongitude(e.getX());
                    double latitude = translator.translateYToLatitude(e.getY());
                    dragTargetStandstill = TspWorldPanel.this.tspPanel
                            .findNearestStandstill(new AirLocation(-1L, latitude, longitude));
                    TravelingSalesmanTour tour = TspWorldPanel.this.tspPanel.getTravelingSalesmanTour();
                    if (dragSourceStandstill == dragTargetStandstill) {
                        dragTargetStandstill = tour.getDomicile();
                    }
                    resetPanel(tour);
                }
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            if (translator != null) {
                if (e.getButton() == MouseEvent.BUTTON1) {
                    double longitude = translator.translateXToLongitude(e.getX());
                    double latitude = translator.translateYToLatitude(e.getY());
                    dragTargetStandstill = TspWorldPanel.this.tspPanel
                            .findNearestStandstill(new AirLocation(-1L, latitude, longitude));
                    TravelingSalesmanTour tour = TspWorldPanel.this.tspPanel.getTravelingSalesmanTour();
                    if (dragSourceStandstill == dragTargetStandstill) {
                        dragTargetStandstill = tour.getDomicile();
                    }
                    Standstill sourceStandstill = TspWorldPanel.this.dragSourceStandstill;
                    Standstill targetStandstill = TspWorldPanel.this.dragTargetStandstill;
                    TspWorldPanel.this.dragSourceStandstill = null;
                    TspWorldPanel.this.dragTargetStandstill = null;
                    // connectStandstills() will call resetPanel()
                    TspWorldPanel.this.tspPanel.connectStandstills(sourceStandstill, targetStandstill);
                }
            }
        }
    };
    addMouseListener(mouseAdapter);
    addMouseMotionListener(mouseAdapter);
    europaBackground = new ImageIcon(getClass().getResource("europaBackground.png"));
}

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.//from   ww w. j  ava  2s  .co m
 */
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:pl.edu.icm.visnow.lib.basic.viewers.Viewer2D.Display2DPanel.java

private void formMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseClicked
    if (evt.getButton() == MouseEvent.BUTTON1) {
        tootltipActive = !tootltipActive;
        formMouseMoved(evt);//from   w ww .  j ava2  s. com
    } else if (evt.getButton() == MouseEvent.BUTTON2) {
        this.reset();
    } else if (evt.getButton() == MouseEvent.BUTTON3) {
        showControlsFrame();
    }

}