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:pt.lsts.neptus.console.plugins.ImageLayers.java

@Override
public void mouseClicked(MouseEvent event, StateRenderer2D source) {
    if (event.getButton() == MouseEvent.BUTTON3) {
        JPopupMenu popup = new JPopupMenu();
        popup.add("Add layer from file").addActionListener(new ActionListener() {

            @Override//  w w w  .  j  a v a2s.c om
            public void actionPerformed(ActionEvent e) {
                JFileChooser chooser = GuiUtils.getFileChooser(lastDir, I18n.text("Neptus image layers"),
                        "layer");
                int op = chooser.showOpenDialog(getConsole());
                if (op != JFileChooser.APPROVE_OPTION)
                    return;
                lastDir = chooser.getSelectedFile().getParent();
                Future<ImageLayer> il = addLayer(chooser.getSelectedFile());
                try {
                    il.get();
                } catch (Exception ex) {
                    GuiUtils.errorMessage(getConsole(), ex);
                }
            }
        });

        if (!layers.isEmpty()) {
            JMenu menu = new JMenu("Remove");
            JMenu menu2 = new JMenu("Opacity");
            for (final ImageLayer l : layers) {
                menu.add(l.getName()).addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        layers.remove(l);
                        layerFiles = StringUtils.join(layers, ",");
                        rebuildControls();
                    }
                });

                menu2.add(l.getName() + "(" + l.getTransparency() + ")")
                        .addActionListener(new ActionListener() {
                            @Override
                            public void actionPerformed(ActionEvent e) {
                                String s = JOptionPane.showInputDialog(getConsole(),
                                        "Enter opacity (1 for opaque, 0 for invisible)", l.getTransparency());
                                if (s == null)
                                    return;
                                try {
                                    double val = Double.parseDouble(s);
                                    if (val < 0)
                                        throw new Exception("Value must be greater or equal to 0");
                                    if (val > 1)
                                        throw new Exception("Value must be less or equal to 1");
                                    l.setTransparency(val);

                                } catch (Exception ex) {
                                    GuiUtils.errorMessage(getConsole(), ex);
                                }
                            }
                        });

            }
            popup.add(menu);
            popup.add(menu2);
        }

        popup.show(source, event.getX(), event.getY());
    }
}

From source file:org.kalypso.kalypsomodel1d2d.ui.map.channeledit.DrawBanklineWidget.java

@Override
public void mousePressed(final MouseEvent event) {
    if (event.getButton() != MouseEvent.BUTTON1)
        return;//ww  w . j  a  va2  s .c  o  m

    event.consume();

    final IMapPanel mapPanel = getMapPanel();
    if (mapPanel == null)
        return;

    final Point p = event.getPoint();

    m_currentPos = MapUtilities.transform(mapPanel, p);

    /* If we have a node, take this position, else take the current one */
    // final GM_Point currentPos = MapUtilities.transform( mapPanel, p );

    if (!m_edit) {
        try {
            final GM_Curve curve = (GM_Curve) m_lineBuilder.addPoint(m_currentPos);
            if (curve != null)
                finishLine(curve);
        } catch (final Exception e) {
            e.printStackTrace();
            reinit();
        }
    }
}

From source file:Simulator.java

private void AddMouseListeners() {
    map().addMouseListener(new MouseAdapter() {
        @Override//from   w w w  .ja  v  a  2s . c om
        public void mouseClicked(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON1) {
                map().getAttribution().handleAttribution(e.getPoint(), true);
            }
        }
    });

    map().addMouseMotionListener(new MouseAdapter() {
        @Override
        public void mouseMoved(MouseEvent e) {
            Point p = e.getPoint();
            boolean cursorHand = map().getAttribution().handleAttributionCursor(p);
            if (cursorHand) {
                map().setCursor(new Cursor(Cursor.HAND_CURSOR));
            } else {
                map().setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
            }
        }
    });
}

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(// w w w . j ava2s  .  c  o  m
                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:playground.sergioo.workplaceCapacities2012.gui.ClustersPanel.java

@Override
public void mouseClicked(MouseEvent e) {
    this.requestFocus();
    double[] p = getWorld(e.getX(), e.getY());
    if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON3)
        camera.centerCamera(p);/*from  w w w . ja v a 2s.  c o  m*/
    else {
        if (window.getOption().equals(Option.ZOOM) && e.getButton() == MouseEvent.BUTTON1)
            camera.zoomIn(p[0], p[1]);
        else if (window.getOption().equals(Option.ZOOM) && e.getButton() == MouseEvent.BUTTON3)
            camera.zoomOut(p[0], p[1]);
    }
    repaint();
}

From source file:org.interreg.docexplore.management.manage.ManageComponent.java

@SuppressWarnings("serial")
public ManageComponent(MainWindow win, final ManageHandler handler, boolean editable, boolean showPages) {
    super(new BorderLayout());

    this.win = win;
    this.handler = handler;
    this.bookList = new JList(new CollectionNode(this));
    setBorder(BorderFactory.createLineBorder(Color.black, 1));

    bookList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    bookList.setCellRenderer(new ManageCellRenderer());
    //tree.setRowHeight(52);
    add(new JScrollPane(bookList), BorderLayout.CENTER);

    if (editable) {
        bookList.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
                    int index = bookList.locationToIndex(e.getPoint());
                    if (index < 0 || !bookList.getCellBounds(index, index).contains(e.getPoint()))
                        return;
                    handler.bookOpened((Book) bookList.getModel().getElementAt(index));
                }//from w  w w  .ja  v a2  s. com
            }
        });
        this.toolbar = new ManageToolbar(this);
        add(toolbar, BorderLayout.NORTH);

        bookList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                if (e.getValueIsAdjusting())
                    return;
                int count = bookList.getSelectedIndices().length;
                toolbar.deleteButton.setEnabled(count > 0);
                toolbar.editButton.setEnabled(count == 1);
                //            toolbar.processButton.setEnabled(count == 1);
                toolbar.exportButton.setEnabled(count == 1);
            }
        });
    }
    bookList.setBackground(new JPanel().getBackground());

    getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
            .put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "DEL");
    getActionMap().put("DEL", new AbstractAction() {
        public void actionPerformed(ActionEvent arg0) {
            @SuppressWarnings({ "unchecked", "rawtypes" })
            Vector<Book> books = new Vector(Arrays.asList(bookList.getSelectedValues()));
            if (books.size() > 0 && handler.booksDeleted(books)) {
                ((CollectionNode) bookList.getModel()).reload();
                bookList.clearSelection();
                bookList.repaint();
            }
        }
    });
}

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

public void mouseReleased(MouseEvent e) {
    try {/*from ww  w.  j  a  v  a 2 s  .co m*/
        if ((e.isShiftDown() || e.getButton() == MouseEvent.BUTTON3) || shifted) {
            //            Rectangle2D scaledDataArea = _chartPanel.getScreenDataArea(
            //                    (int) this.coElutionStart.getX(), (int) this.coElutionStart.getY());
            JFreeChart jfc = _cp.getChart();
            XYPlot p = jfc.getXYPlot();
            CenterZoomNumberAxis czna = (CenterZoomNumberAxis) p.getDomainAxis();
            Rectangle2D screenDataArea = _cp.getScreenDataArea(e.getX(), e.getY());
            Rectangle2D plotboundaries = _cp.getChartRenderingInfo().getPlotInfo().getPlotArea();

            double leftmostOnAxis = czna.getLowerBound();
            double rightmostOnAxis = czna.getUpperBound();
            double leftmostOnRange = this.coElutionRegion.getX();
            double rightmostOnRange = this.coElutionRegion.getX() + this.coElutionRegion.getWidth();
            double leftmostonscreen = screenDataArea.getX();
            double rightmostonscreen = leftmostonscreen + screenDataArea.getWidth();
            double slope = (rightmostOnAxis - leftmostOnAxis) / (rightmostonscreen - leftmostonscreen);
            double transformedLeftRange = (slope * (leftmostOnRange - leftmostonscreen)) + leftmostOnAxis;
            double transformedRightRange = (slope * (rightmostOnRange - leftmostonscreen)) + leftmostOnAxis;
            shifted = false;
            MRMDialog ultimateParent = (MRMDialog) MRMAncestor();
            if (ultimateParent != null) {
                MRMTransition transition = ultimateParent.transitionOnPlot;
                MRMTransition mrmt = transition;
                if (mrmt != null) {
                    int row = mrmt.getTableRow();
                    _ptm.data[row][MRMDialog.peaksData.CoStart.colno] = new Float(0f);
                    _ptm.data[row][MRMDialog.peaksData.CoEnd.colno] = new Float(10000000f);
                    _ptm.setValueAt(new Float(transformedRightRange), row, MRMDialog.peaksData.CoEnd.colno);
                    _ptm.setValueAt(new Float(transformedLeftRange), row, MRMDialog.peaksData.CoStart.colno);
                }
            }
            Graphics2D g2 = (Graphics2D) _cp.getGraphics();
            if (this.coElutionRegion != null)
                drawCoElutionRegion(g2);
            this.coElutionRegion = null;
            this.coElutionStart = null;
        } else {
            _cp.mouseReleased(e);
        }
    } catch (Exception ee) {
    }
}

From source file:org.kootox.episodesmanager.ui.systray.EpisodesTrayIcon.java

public void create() {

    //Check the SystemTray support
    if (!SystemTray.isSupported()) {
        if (log.isInfoEnabled()) {
            log.info("SystemTray is not supported");
        }// w  ww . j  ava  2 s. c om
        return;
    }

    if (loaded) {
        return;
    }

    final PopupMenu popup = new PopupMenu();
    final TrayIcon trayIcon = new TrayIcon(createImage("systray.png", "tray icon"));
    final SystemTray tray = SystemTray.getSystemTray();

    // Create a popup menu components
    MenuItem display = new MenuItem("Display");
    MenuItem exit = new MenuItem("Exit");

    //Add components to popup menu
    popup.add(display);
    popup.addSeparator();
    popup.add(exit);

    trayIcon.setPopupMenu(popup);

    try {
        tray.add(trayIcon);
    } catch (AWTException e) {
        if (log.isDebugEnabled()) {
            log.debug("TrayIcon could not be added.");
        }
        return;
    }

    trayIcon.addMouseListener(new MouseListener() {
        @Override
        public void mouseClicked(MouseEvent mouseEvent) {
            if (mouseEvent.getButton() == MouseEvent.BUTTON1) {
                showHide();
            }
        }

        @Override
        public void mousePressed(MouseEvent mouseEvent) {
            //Do nothing
        }

        @Override
        public void mouseReleased(MouseEvent mouseEvent) {
            //Do nothing
        }

        @Override
        public void mouseEntered(MouseEvent mouseEvent) {
            //Do nothing
        }

        @Override
        public void mouseExited(MouseEvent mouseEvent) {
            //Do nothing
        }
    });

    display.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            showHide();
        }
    });

    exit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            EpisodesManagerMainUI mainUI = EpisodesManagerContext.MAIN_UI_ENTRY_DEF.getContextValue(context);
            mainUI.close();
        }
    });

    loaded = true;
    if (log.isDebugEnabled()) {
        log.debug("Systray loaded");
    }
}

From source file:org.eevolution.form.VCRPDetail.java

private void handleTreeEvent(MouseEvent e) {

    if (e.getButton() == MouseEvent.BUTTON3) {

        model.getTree().setSelectionPath(model.getTree().getPathForLocation(e.getX(), e.getY()));

        DefaultMutableTreeNode node = (DefaultMutableTreeNode) model.getTree().getSelectionPath()
                .getLastPathComponent();

        if (!(node.getUserObject() instanceof Date) && !(node.getUserObject() instanceof MPPOrderNode)) {

            popup.show(e.getComponent(), e.getX(), e.getY());
        }/*from ww w. j av  a2 s.  com*/
    }

    SwingTool.setCursorsFromChild(e.getComponent(), false);
}

From source file:at.ac.tuwien.ibk.biqini.pep.gui.PEPGUI.java

public PEPGUI(String arg0, Vector<IBandwidthTracer> qosRules) {
    super(arg0);//from w  ww .j av  a2s. co m

    // initiate all collections
    tsc = new TimeSeriesCollection[MAXCHARTS];
    charts = new JFreeChart[MAXCHARTS];
    positions = new Vector<Integer>();
    chartPosition = new Hashtable<String, Integer>();
    for (int i = 0; i < MAXCHARTS; i++)
        positions.add(i);
    allSessions = new Hashtable<String, IBandwidthTracer>();

    // fill the BandwidthGenerator with the ongoing QoSRules
    bandwidthGenerator = new BandwidthGenerator();
    Enumeration<IBandwidthTracer> enbandwidth = qosRules.elements();
    while (enbandwidth.hasMoreElements()) {
        IBandwidthTracer b = enbandwidth.nextElement();
        allSessions.put(b.getName(), b);
        bandwidthGenerator.add(b);
    }

    gridBagLayout = new GridBagLayout();

    //insert the list with all QoS rules
    GridBagConstraints c = new GridBagConstraints();
    c.weighty = 9;
    c.weightx = 2.0;
    c.gridheight = MAXCHARTS;
    c.fill = GridBagConstraints.BOTH;
    content = new JPanel(gridBagLayout);
    qoSRuleList = new JList(allSessions.keySet().toArray());
    qoSRuleList.setPreferredSize(new java.awt.Dimension(200, 600));
    qoSRuleList.setBorder(BorderFactory.createRaisedBevelBorder());

    // set a MouseListner on the List
    MouseListener mouseListener = new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {

            if (e.getButton() == MouseEvent.BUTTON1) {
                int index = qoSRuleList.locationToIndex(e.getPoint());
                addStream(allSessions.get(allSessions.keySet().toArray()[index]));
            }
            if (e.getButton() == MouseEvent.BUTTON3) {
                int index = qoSRuleList.locationToIndex(e.getPoint());
                removeStream(allSessions.get(allSessions.keySet().toArray()[index]));
            }
        }
    };
    qoSRuleList.addMouseListener(mouseListener);

    // place all parts at the content pane
    gridBagLayout.setConstraints(qoSRuleList, c);
    content.add(qoSRuleList);
    setContentPane(content);
    content.setSize(1000, 800);

    //create all GUI aspects for our Charts
    insertAllCharts();

    //Start the thread that fills up our time series
    periodicBandwidthReader = new Thread(bandwidthGenerator);
    periodicBandwidthReader.setName("data-collector");
    periodicBandwidthReader.start();
}