Example usage for java.awt.event MouseEvent getPoint

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

Introduction

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

Prototype

public Point getPoint() 

Source Link

Document

Returns the x,y position of the event relative to the source component.

Usage

From source file:uk.co.modularaudio.util.swing.dndtable.layeredpane.LayeredPaneDndTableMouseListener.java

@Override
public void mouseReleased(final MouseEvent e) {
    //      log.debug("Mouse released.");
    // Popup test
    if (e.isPopupTrigger()) {
        final Point dragStartPoint = e.getPoint();
        final boolean foundIt = table.getComponentAtWithLocalPoint(dragStartPoint, componentAndLocalPoint);
        Point localPoint = null;/*from   ww w.  j  a v  a 2 s .c  o m*/
        C component = null;
        if (foundIt) {
            localPoint = componentAndLocalPoint.getHead();
            component = componentAndLocalPoint.getTail();
        }

        if (dndPolicy.isMouseOverPopupSource(table, component, localPoint, dragStartPoint)) {
            dndPolicy.doPopup(table, component, localPoint, dragStartPoint);
        }
    } else {
        //      log.debug(e);
        try {
            final State curState = dndState.getCurrentState();
            final Point tablePoint = e.getPoint();
            final boolean foundIt = table.getComponentAtWithLocalPoint(tablePoint, componentAndLocalPoint);
            Point point = null;
            C component = null;
            if (foundIt) {
                point = componentAndLocalPoint.getHead();
                component = componentAndLocalPoint.getTail();
            }
            switch (curState) {
            case DURING_DRAG:
                if (dndPolicy.isValidDragTarget(table, component, point, tablePoint)) {
                    dndPolicy.endDrag(table, component, point, tablePoint);
                    //                  log.debug("Ended drag.");
                } else {
                    dndPolicy.endInvalidDrag(table, component, point, tablePoint);
                    //               log.debug("Is not over valid drag!");
                }
                // Now fall back into the browsing state
            case BROWSING:
            case MOUSE_OVER_DRAGGABLE_AREA:
                // Reset the state
                dndState.changeTo(State.BROWSING);
                break;
            default:
                break;
            }
            //         decorationManager.setMouseLocation( tablePoint );
            //            log.debug("Synthesising mouse move.");
            synthesiseMouseMove(e);
        } catch (final Exception e1) {
            final String msg = "Exception caught during mouse release processing: " + e1.toString();
            log.error(msg, e1);
        }
    }
}

From source file:gda.images.GUI.CmuCameraDisplayPanel.java

@Override
public void configure() {
    //logger.info("Cmu Camera Panel config called");
    samplePanel = new RTPCameraClient();
    samplePanel.setPreferredSize(ImageSize);
    samplePanel.setMinimumSize(ImageSize);
    samplePanel.setMaximumSize(ImageSize);
    samplePanel.getImageModifier().setDisplayCrossHair(true);

    samplePanel.addMouseListener(new MouseListener() {

        @Override//  www .  j  a va 2s  .com
        public void mouseClicked(MouseEvent mevt) {
            //logger.info("mouse clicked at " + mevt.getLocationOnScreen());
            //samplePanel.setCentre(mevt.getLocationOnScreen());
            if (mevt.isControlDown()) {
                Point p = mevt.getPoint();
                x = p.x;
                y = p.y;
                samplePanel.getImageModifier().setCentre(p);
                save();
            }
            //samplePanel.revalidate();

        }

        @Override
        public void mouseEntered(MouseEvent arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void mouseExited(MouseEvent arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void mousePressed(MouseEvent arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void mouseReleased(MouseEvent arg0) {
            // TODO Auto-generated method stub

        }

    });
    try {
        config = LocalParameters.getXMLConfiguration();
    } catch (ConfigurationException e) {
        logger.error("unable to configure beam centre values ", e);

    } catch (IOException e) {
        logger.error("unable to read beam centre values ", e);
    }
    this.load();
    //samplePanel.setDisplayCrossHair(true);
    //samplePanel.setDisplayBeamSize(true);

    //
    samplePanel.getImageModifier().setCentre(new Point(x, y));
    //samplePanel.setBeamSize(new Point(50, 50), new Point(200, 200));

    this.setLayout(new BorderLayout());
    this.add(samplePanel, BorderLayout.CENTER);
    this.add(getButtonPanel(), BorderLayout.SOUTH);

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            CmuCameraDisplayPanel.this.add(samplePanel);
            //samplePanel.setXScale(0.9);
            //samplePanel.setYScale(1.1);
            //samplePanel.setDisplayScale(true);
            //samplePanel.start();
        }
    });

    videoReceiver.addImageListener(this);
}

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();//  ww w. j  av  a2  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);
    }
}

From source file:lu.lippmann.cdb.graph.mouse.CadralEditingGraphMousePlugin.java

/**
 * {@inheritDoc}/*  w w  w  . j a v  a  2s.  com*/
 */
@Override
public void mousePressed(MouseEvent e) {
    if (e.getButton() != 3) { //not with left click
        @SuppressWarnings("unchecked")
        final VisualizationViewer<CNode, CEdge> vv = (VisualizationViewer<CNode, CEdge>) e.getSource();
        final Point2D p = e.getPoint();
        final Layout<CNode, CEdge> layout = vv.getModel().getGraphLayout();
        final GraphElementAccessor<CNode, CEdge> pickSupport = vv.getPickSupport();
        if (pickSupport != null) {
            final CNode vertex = pickSupport.getVertex(layout, p.getX(), p.getY());
            if (vertex == null) {
                return;
            } else {
                //set fields for mouseReleased
                startVertex = vertex;
                down = e.getPoint();
                vv.addPostRenderPaintable(edgePaintable);
                vv.addPostRenderPaintable(arrowPaintable);
                edgeIsDirected = EdgeType.DIRECTED;
            }
        }
    }
}

From source file:lu.lippmann.cdb.graph.mouse.CadralGraphMouse.java

/**
 * {@inheritDoc}//from w w w . j  av  a  2s  .com
 */
@Override
public void mouseReleased(MouseEvent e) {
    if (mode.equals(Mode.PICKING)) {
        @SuppressWarnings("unchecked")
        final VisualizationViewer<CNode, CEdge> vv = (VisualizationViewer<CNode, CEdge>) e.getSource();
        final Point2D p = e.getPoint();
        final Layout<CNode, CEdge> layout = vv.getModel().getGraphLayout();
        final GraphElementAccessor<CNode, CEdge> pickSupport = vv.getPickSupport();
        if (pickSupport != null) {
            final CNode vertex = pickSupport.getVertex(layout, p.getX(), p.getY());
            if (vertex != null) {
                //Check that we moved the selected vertex
                if (before != null && !layout.transform(vertex).equals(before.get(vertex.getId()))) {
                    boolean needsGroup = (vv.getPickedVertexState().getPicked().size() > 1);
                    if (needsGroup) {
                        graph.startGroupOperation();
                    }
                    for (CNode picked : vv.getPickedVertexState().getPicked()) {
                        if (before.containsKey(picked.getId())) {
                            graph.moveNodeTo(picked, before.get(picked.getId()), layout.transform(picked));
                        }
                    }
                    if (needsGroup) {
                        graph.stopGroupOperation();
                    }
                }
            }
        }
    }
    //will call either :
    // - CadralEditingGraphMousePlugin.mouseReleased(e)
    // - CadralPickingGraphMousePlugin.mouseReleased(e)
    //System.out.println("Position : " + e.getPoint());
    super.mouseReleased(e);
}

From source file:org.kalypso.ui.rrm.internal.map.editRelation.EditRelationWidget.java

@Override
public void mouseMoved(final MouseEvent e) {
    final IMapPanel mapPanel = getMapPanel();
    if (mapPanel == null)
        return;/*from  ww w.  j  av  a  2  s  .  c om*/

    final GeoTransform transform = mapPanel.getProjection();
    if (transform == null)
        return;

    final Point p = e.getPoint();
    final GM_Point point = GeometryFactory.createGM_Point(p, transform,
            mapPanel.getMapModell().getCoordinatesSystem());
    final double grabDistance = MapUtilities.calculateWorldDistance(mapPanel, point, GRAB_RADIUS);

    /* Update hover source */
    final FeatureList allowedSourceFeatures = m_data.getAllowedSourceFeatures();
    final Feature newSource = EditRelationUtils.findNearestFeature(point, grabDistance, allowedSourceFeatures);
    m_data.setFeatures(newSource, null);

    repaintMap();

    return;
}

From source file:edu.ku.brc.af.ui.forms.formatters.UIFormatterListEdtDlg.java

/**
 * // www  . ja va  2  s.c  o  m
 */
private void hookFormatListMouseListener() {
    MouseAdapter mAdp = new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                int index = formatList.locationToIndex(e.getPoint());
                formatList.ensureIndexIsVisible(index);
                editFormatter((UIFieldFormatter) formatList.getSelectedValue(), false);
            }
        }
    };

    formatList.addMouseListener(mAdp);
}

From source file:org.colombbus.tangara.ConfigurationWindow.java

/**
 * This method initializes the components to put in this JFrame.
 *
 *//* w w w . ja va 2 s .c o  m*/
private void initialize() {
    //We load the default properties.
    loadDefaultProperties();

    //We load the table contents.
    loadProperties();
    String[] columnNames = { Messages.getString("ConfigurationWindow.propertyColumn"),
            Messages.getString("ConfigurationWindow.valueColumn") };
    SpecialTableModel model = new SpecialTableModel(modelData, columnNames);
    propertiesTable = new JTable(model);
    propertiesTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    //We set the double click listener on the table.
    propertiesTable.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                Point p = e.getPoint();
                int row = propertiesTable.rowAtPoint(p);
                ConfigurationPropertyWindow confPropertyWindow = new ConfigurationPropertyWindow(
                        ConfigurationWindow.this, row, (String) propertiesTable.getValueAt(row, 0),
                        (String) propertiesTable.getValueAt(row, 1));
                confPropertyWindow.setVisible(true);
            }
        }
    });

    //We set the content pane of the window.
    this.setContentPane(getMainPanel());
}

From source file:org.kalypso.ogc.gml.map.widgets.FindElementMapWidget.java

@Override
public void mouseMoved(final MouseEvent e) {
    final IMapPanel mapPanel = getMapPanel();
    if (mapPanel == null)
        return;//from   w  ww  .j  av a  2s  .  c  o m

    final Point p = e.getPoint();

    final GM_Point currentPoint = MapUtilities.transform(mapPanel, p);
    updateTooltip(currentPoint);

    repaintMap();
}

From source file:io.github.jeremgamer.editor.panels.Actions.java

public Actions(final JFrame frame, final ActionPanel ap) {
    this.frame = frame;

    this.setBorder(BorderFactory.createTitledBorder(""));
    JButton add = null;//from ww  w  . j av  a2 s  . c  o  m
    try {
        add = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("add.png"))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    add.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                JOptionPane jop = new JOptionPane();
                @SuppressWarnings("static-access")
                String name = jop.showInputDialog(null, "Nommez l'action :", "Crer une action",
                        JOptionPane.QUESTION_MESSAGE);

                if (name != null) {
                    for (int i = 0; i < data.getSize(); i++) {
                        if (data.get(i).equals(name)) {
                            name += "1";
                        }
                    }
                    data.addElement(name);
                    new ActionSave(name);
                    OtherPanel.updateLists();
                    ButtonPanel.updateLists();
                    ActionPanel.updateLists();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

    });

    JButton remove = null;
    try {
        remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    remove.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                if (actionList.getSelectedValue() != null) {
                    File file = new File("projects/" + Editor.getProjectName() + "/actions/"
                            + actionList.getSelectedValue() + ".rbd");
                    JOptionPane jop = new JOptionPane();
                    @SuppressWarnings("static-access")
                    int option = jop.showConfirmDialog(null,
                            "tes-vous sr de vouloir supprimer cette action?", "Avertissement",
                            JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);

                    if (option == JOptionPane.OK_OPTION) {
                        if (actionList.getSelectedValue().equals(ap.getFileName())) {
                            ap.setFileName("");
                        }
                        ap.hide();
                        file.delete();
                        data.remove(actionList.getSelectedIndex());
                        OtherPanel.updateLists();
                        ButtonPanel.updateLists();
                    }
                }
            } catch (NullPointerException npe) {
                npe.printStackTrace();
            }

        }

    });

    JPanel buttons = new JPanel();
    buttons.setLayout(new BoxLayout(buttons, BoxLayout.LINE_AXIS));
    buttons.add(add);
    buttons.add(remove);

    updateList();
    actionList.addMouseListener(new MouseAdapter() {
        @SuppressWarnings("unchecked")
        public void mouseClicked(MouseEvent evt) {
            JList<String> list = (JList<String>) evt.getSource();
            if (evt.getClickCount() == 2) {
                int index = list.locationToIndex(evt.getPoint());
                if (isOpen == false) {
                    ap.show();
                    ap.load(new File("projects/" + Editor.getProjectName() + "/actions/"
                            + list.getModel().getElementAt(index) + ".rbd"));
                    previousSelection = list.getSelectedValue();
                    isOpen = true;
                } else {
                    try {
                        if (previousSelection.equals(list.getModel().getElementAt(index))) {
                            ap.hide();
                            previousSelection = list.getSelectedValue();
                            list.clearSelection();
                            isOpen = false;
                        } else {
                            ap.hideThenShow();
                            previousSelection = list.getSelectedValue();
                            ap.load(new File("projects/" + Editor.getProjectName() + "/actions/"
                                    + list.getModel().getElementAt(index) + ".rbd"));
                        }
                    } catch (NullPointerException npe) {
                        ap.hide();
                        list.clearSelection();
                    }
                }
            } else if (evt.getClickCount() == 3) {
                int index = list.locationToIndex(evt.getPoint());
                if (isOpen == false) {
                    ap.show();
                    ap.load(new File("projects/" + Editor.getProjectName() + "/actions/"
                            + list.getModel().getElementAt(index) + ".rbd"));
                    previousSelection = list.getSelectedValue();
                    isOpen = true;
                } else {
                    try {
                        if (previousSelection.equals(list.getModel().getElementAt(index))) {
                            ap.hide();
                            previousSelection = list.getSelectedValue();
                            list.clearSelection();
                            isOpen = false;
                        } else {
                            ap.hideThenShow();
                            previousSelection = list.getSelectedValue();
                            ap.load(new File("projects/" + Editor.getProjectName() + "/actions/"
                                    + list.getModel().getElementAt(index) + ".rbd"));
                        }
                    } catch (NullPointerException npe) {
                        ap.hide();
                        list.clearSelection();
                    }
                }
            }
        }
    });
    JScrollPane listPane = new JScrollPane(actionList);
    listPane.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED);
    this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
    this.add(buttons);
    this.add(listPane);
    OtherPanel.updateLists();
}