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:com.jaspersoft.ireport.designer.data.fieldsproviders.BeanInspectorPanel.java

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

    if (evt.getClickCount() == 2 && evt.getButton() == MouseEvent.BUTTON1) {
        DefaultMutableTreeNode tn = (DefaultMutableTreeNode) jTree1.getSelectionPath().getLastPathComponent();

        if (tn.getChildCount() > 0)
            return;

        /*if (!jTree1.isCollapsed( jTree1.getSelectionPath() ))
        {//w  ww. j av  a2  s  . co m
        jTree1.collapsePath( jTree1.getSelectionPath() );
        return;
        }
         *
         */
        if (tn.getUserObject() instanceof TreeJRField) {
            TreeJRField jrf = (TreeJRField) tn.getUserObject();
            if (!jrf.getObj().isPrimitive() && !jrf.getObj().getName().startsWith("java.lang.")) {
                exploreBean(tn, jrf.getObj().getName(),
                        isPathOnDescription() ? Misc.nvl(jrf.getField().getDescription(), "")
                                : Misc.nvl(jrf.getField().getName(), ""));
            }
        }
    }

}

From source file:org.apache.syncope.ide.netbeans.view.ResourceExplorerTopComponent.java

private void resourceExplorerTreeMouseClicked(final java.awt.event.MouseEvent evt) {
    if (evt.getButton() == MouseEvent.BUTTON1 && evt.getClickCount() == 2) {
        DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) resourceExplorerTree
                .getLastSelectedPathComponent();
        DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) selectedNode.getParent();
        String parentNodeName = parentNode == null ? null : String.valueOf(parentNode.getUserObject());
        if (selectedNode.isLeaf() && StringUtils.isNotBlank(parentNodeName)) {
            String leafNodeName = (String) selectedNode.getUserObject();
            try {
                if (PluginConstants.MAIL_TEMPLATES.equals(parentNodeName)) {
                    openMailEditor(leafNodeName);
                } else if (PluginConstants.REPORT_XSLTS.equals(parentNodeName)) {
                    openReportEditor(leafNodeName);
                }//from  ww  w  . ja v  a2s .  c  om
            } catch (IOException e) {
                Exceptions.printStackTrace(e);
            }
        }
    } else if (evt.getButton() == MouseEvent.BUTTON3 && evt.getClickCount() == 1) {
        DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) resourceExplorerTree
                .getLastSelectedPathComponent();
        String selectedNodeName = (String) selectedNode.getUserObject();
        if (selectedNode.isLeaf() && !PluginConstants.ROOT_NAME.equals(selectedNodeName)
                && !PluginConstants.MAIL_TEMPLATES.equals(selectedNodeName)
                && !PluginConstants.REPORT_XSLTS.equals(selectedNodeName)) {
            leafRightClickAction(evt, selectedNode);
        } else if (PluginConstants.MAIL_TEMPLATES.equals(selectedNodeName)) {
            folderRightClickAction(evt, mailTemplates);
        } else if (PluginConstants.REPORT_XSLTS.equals(selectedNodeName)) {
            folderRightClickAction(evt, reportXslts);
        } else if (PluginConstants.ROOT_NAME.equals(selectedNodeName)) {
            rootRightClickAction(evt);
        }
    }
}

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.//ww  w  .j  ava  2 s.co  m
 */
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:pt.lsts.neptus.plugins.sunfish.IridiumComms.java

@Override
public void mouseClicked(MouseEvent event, StateRenderer2D source) {
    if (event.getButton() != MouseEvent.BUTTON3) {
        super.mouseClicked(event, source);
        return;//w ww.  j a v a 2s . c om
    }

    final LocationType loc = source.getRealWorldLocation(event.getPoint());
    loc.convertToAbsoluteLatLonDepth();

    JPopupMenu popup = new JPopupMenu();

    if (IridiumManager.getManager().isActive()) {
        popup.add(I18n.text("Deactivate Polling")).addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                IridiumManager.getManager().stop();
            }
        });
    } else {
        popup.add(I18n.text("Activate Polling")).addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                IridiumManager.getManager().start();
            }
        });
    }

    popup.add(I18n.text("Select Iridium gateway")).addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            IridiumManager.getManager().selectMessenger(getConsole());
        }
    });

    popup.addSeparator();

    popup.add(I18n.textf("Send %vehicle a command via Iridium", getMainVehicleId()))
            .addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    sendIridiumCommand();
                }
            });

    popup.add(I18n.textf("Command %vehicle a plan via Iridium", getMainVehicleId()))
            .addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    commandPlanExecution();
                }
            });

    popup.add(I18n.textf("Subscribe to iridium device updates", getMainVehicleId()))
            .addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    ActivateSubscription activate = new ActivateSubscription();
                    activate.setDestination(0xFF);
                    activate.setSource(ImcMsgManager.getManager().getLocalId().intValue());
                    try {
                        IridiumManager.getManager().send(activate);
                        getConsole().post(Notification.success("Iridium message sent",
                                "1 Iridium messages were sent using "
                                        + IridiumManager.getManager().getCurrentMessenger().getName()));
                    } catch (Exception ex) {
                        GuiUtils.errorMessage(getConsole(), ex);
                    }
                }
            });

    popup.add(I18n.textf("Unsubscribe to iridium device updates", getMainVehicleId()))
            .addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    DeactivateSubscription deactivate = new DeactivateSubscription();
                    deactivate.setDestination(0xFF);
                    deactivate.setSource(ImcMsgManager.getManager().getLocalId().intValue());
                    try {
                        IridiumManager.getManager().send(deactivate);
                    } catch (Exception ex) {
                        GuiUtils.errorMessage(getConsole(), ex);
                    }
                }
            });

    popup.add("Set this as actual wave glider target").addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setWaveGliderTargetPosition(loc);
        }
    });

    popup.add("Set this as desired wave glider target").addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setWaveGliderDesiredPosition(loc);
        }
    });

    popup.addSeparator();

    popup.add(I18n.text("Send a text note")).addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            sendTextNote();
        }
    });

    popup.add("Add virtual drifter").addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            VirtualDrifter d = new VirtualDrifter(loc, 0, 0.1);
            PropertiesEditor.editProperties(d, true);
            drifters.add(d);
            update();
        }
    });

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

From source file:javazoom.jlgui.player.amp.visual.ui.SpectrumTimeAnalyzer.java

private void prepareDisplayToggleListener() {
    setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent pEvent) {
            if (pEvent.getButton() == MouseEvent.BUTTON1) {
                if (displayMode + 1 > 1) {
                    displayMode = 0;//from   w ww.j  av  a  2  s. c  o  m
                } else {
                    displayMode++;
                }
            }
        }
    });
}

From source file:pts4.googlemaps.Gmaps.java

public void createStage() {

    GeoPosition Utrecht = new GeoPosition(52.0907370, 5.1214200);
    /*// Create a waypoint painter that takes all the waypoints
     WaypointPainter<Waypoint> waypointPainter = new WaypointPainter<Waypoint>();
     waypointPainter.setWaypoints(waypoints);*/
    // Set the focus
    mapViewer.setZoom(10);//  ww w.ja va 2 s .c om
    mapViewer.setAddressLocation(Utrecht);

    // Add interactions
    MouseInputListener mia = new PanMouseInputListener(mapViewer);

    mapViewer.addMouseListener(sa);
    mapViewer.addMouseMotionListener(sa);
    mapViewer.setOverlayPainter(sp);
    mapViewer.addMouseListener(mia);
    mapViewer.addMouseMotionListener(mia);
    //mapViewer.addMouseListener(new CenterMapListener(mapViewer));
    mapViewer.addMouseWheelListener(new ZoomMouseWheelListenerCenter(mapViewer));
    mapViewer.addKeyListener(new PanKeyListener(mapViewer));

    mapViewer.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent me) {

            //Rechter muisknop klik
            if (me.getButton() == MouseEvent.BUTTON3) {
                GeoPosition mousepoint = mapViewer.convertPointToGeoPosition(me.getPoint());
                Double lat1 = mousepoint.getLatitude();
                Double lng1 = mousepoint.getLongitude();
                Double lat2;
                Double lng2;

                for (MyWaypoint u : units) {
                    lat2 = u.getPosition().getLatitude();
                    lng2 = u.getPosition().getLongitude();

                    if (UnitControl.distFrom(lat1.floatValue(), lng1.floatValue(), lat2.floatValue(),
                            lng2.floatValue()) < (mapViewer.getZoom() * mapViewer.getZoom()
                                    * mapViewer.getZoom() * 2)) {
                        Platform.runLater(new Runnable() {

                            @Override
                            public void run() {

                                MessageBox msg = new MessageBox("Send message to unit " + u.getLabel() + "?",
                                        MessageBoxType.YES_NO);
                                msg.showAndWait();

                                if (msg.getMessageBoxResult() == MessageBoxResult.YES) {

                                    try {
                                        if (gui.messageToUnit(u.getLabel()) == false) {
                                            MessageBox msg2 = new MessageBox("Error connecting to unit",
                                                    MessageBoxType.OK_ONLY);
                                            msg2.show();

                                        }
                                    } catch (IOException ex) {
                                        Logger.getLogger(Gmaps.class.getName()).log(Level.SEVERE, null, ex);
                                    }

                                } else {
                                    //msg.close();
                                }
                            }

                        });
                    }
                }

            } else {
                if (createUnit == true) {
                    Color kleur = null;
                    if (type == 1) {
                        kleur = Color.cyan;
                    }
                    if (type == 2) {
                        kleur = Color.YELLOW;
                    }
                    if (type == 3) {
                        kleur = Color.RED;
                    }
                    GeoPosition plek = mapViewer.convertPointToGeoPosition(me.getPoint());
                    Platform.runLater(new Runnable() {
                        @Override
                        public void run() {
                            gui.setUnit(plek.getLongitude(), plek.getLatitude());
                        }
                    });

                    for (MyWaypoint p : orders) {
                        if (p.getLabel().equals(id)) {
                            orders.remove(p);
                        }
                    }
                    orders.add(new MyWaypoint(id, kleur, plek));
                    for (Unit a : EmergencyUnits) {
                        if (a.getName().equals(id)) {
                            GeoPosition plek2 = new GeoPosition(a.getLatidude(), a.getLongitude());
                            ChatMessage chat = new ChatMessage(
                                    gui.getIncidentorder() + "\n" + gui.getUnitDescription(), "Meldkamer", id);
                            server.sendMessage(chat);
                            a.setIncident(incidentstring);
                            new Animation(plek, plek2, id, orders, units, Gmaps.this, waypointPainter3);
                        }
                    }
                    createUnit = false;
                    // Create a waypoint painter that takes all the waypoints
                    waypointPainter3.setWaypoints(orders);
                    waypointPainter3.setRenderer(new FancyWaypointRenderer());
                    draw();
                }

                if (simulation == true) {
                    Color kleur = null;
                    if (type == 1) {
                        kleur = Color.cyan;
                    }
                    if (type == 2) {
                        kleur = Color.YELLOW;
                    }
                    if (type == 3) {
                        kleur = Color.RED;
                    }
                    GeoPosition plek = mapViewer.convertPointToGeoPosition(me.getPoint());
                    Platform.runLater(new Runnable() {
                        @Override
                        public void run() {
                            gui.setUnit(plek.getLongitude(), plek.getLatitude());
                        }
                    });

                    for (MyWaypoint p : orders) {
                        if (p.getLabel().equals(id)) {
                            orders.remove(p);
                        }
                    }
                    orders.add(new MyWaypoint(id, kleur, plek));
                    for (Unit a : EmergencyUnits) {
                        if (a.getName().equals(id)) {
                            GeoPosition plek2 = new GeoPosition(a.getLatidude(), a.getLongitude());
                            ChatMessage chat = new ChatMessage(
                                    gui.getIncidentorder() + "\n" + gui.getUnitDescription(), "Meldkamer", id);
                            server.sendMessage(chat);
                            a.setIncident(incidentstring);
                            Point2D fire = mapViewer.getTileFactory().geoToPixel(plek, mapViewer.getZoom());
                            simulations = new Simulation(plek, plek2, id, orders, units, Gmaps.this,
                                    waypointPainter3);
                            new SimulationAnimation(simulations, plek, plek2, id, orders, units, Gmaps.this,
                                    waypointPainter3);

                        }
                    }
                    createUnit = false;
                    // Create a waypoint painter that takes all the waypoints
                    waypointPainter3.setWaypoints(orders);
                    waypointPainter3.setRenderer(new FancyWaypointRenderer());
                    /*
                     List<Painter<JXMapViewer>> painters = new ArrayList<Painter<JXMapViewer>>();
                     painters.add(simulations);
                     CompoundPainter<JXMapViewer> painter = new CompoundPainter<JXMapViewer>(painters);
                                
                     mapViewer.setOverlayPainter(painter);*/
                    draw();
                    simulation = false;
                }

                if (weather == true) {
                    GeoPosition mousepoint = mapViewer.convertPointToGeoPosition(me.getPoint());
                    Double lat1 = mousepoint.getLatitude();
                    Double lng1 = mousepoint.getLongitude();
                    try {
                        new Weather(lng1, lat1);
                    } catch (IOException ex) {
                        Logger.getLogger(Gmaps.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (JSONException ex) {
                        Logger.getLogger(Gmaps.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        }
    }); // end MouseAdapter

}

From source file:pl.edu.icm.visnow.lib.basic.viewers.Viewer2D.Display2DPanel.java

private void formMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseReleased
    if (evt.getButton() == MouseEvent.BUTTON1) {
        move = false;//from   ww w.  j  a  v  a 2 s .c  o  m
        this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    }
}

From source file:pl.edu.icm.visnow.lib.basic.viewers.Viewer2D.Display2DPanel.java

private void formMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMousePressed
    if (evt.getButton() == MouseEvent.BUTTON1) {
        oldX = evt.getX();//from w  w  w . j  av a 2 s  .  com
        oldY = evt.getY();
        if (!noObjects) {
            move = true;
            this.setCursor(new Cursor(Cursor.MOVE_CURSOR));
        }
    }
}

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);//www  .j a v a2s.  co  m
    } else if (evt.getButton() == MouseEvent.BUTTON2) {
        this.reset();
    } else if (evt.getButton() == MouseEvent.BUTTON3) {
        showControlsFrame();
    }

}

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

@Override
public void setLookupSelectHandler(Runnable selectHandler) {
    impl.addMouseListener(new MouseAdapter() {
        @Override/*w w  w .  ja v a 2s .  com*/
        public void mousePressed(MouseEvent e) {
            if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
                int rowForLocation = impl.getRowForLocation(e.getX(), e.getY());
                TreePath pathForLocation = impl.getPathForRow(rowForLocation);
                if (pathForLocation != null) {
                    CollectionDatasource treeCds = getDatasource();
                    if (treeCds != null) {
                        TreeModelAdapter.Node treeItem = (TreeModelAdapter.Node) pathForLocation
                                .getLastPathComponent();
                        if (treeItem != null) {
                            treeCds.setItem(treeItem.getEntity());
                            selectHandler.run();
                        }
                    }
                }
            }
        }
    });
}