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:graph.eventhandlers.MyEditingGraphMousePlugin.java

/**
 * If startVertex is non-null, and the mouse is released over an existing
 * vertex, create an undirected edge from startVertex to the vertex under
 * the mouse pointer. If shift was also pressed, create a directed edge
 * instead./*from  w  ww.ja v  a 2  s  . com*/
 */
public void mouseReleased(MouseEvent e) {
    pw = graphInstance.getPathway();
    if (checkModifiers(e)) {
        final VisualizationViewer<BiologicalNodeAbstract, BiologicalEdgeAbstract> vv = (VisualizationViewer) e
                .getSource();
        //final Point2D p = vv.getRenderContext().getMultiLayerTransformer()
        //      .inverseTransform(e.getPoint());
        //int v = vv.getPickedVertexState().getPicked().size();
        //int edge = vv.getPickedEdgeState().getPicked().size();
        GraphElementAccessor<BiologicalNodeAbstract, BiologicalEdgeAbstract> pickSupport = vv.getPickSupport();
        // if (v > 0) {
        // System.out.println("release");
        final BiologicalNodeAbstract vertex = (BiologicalNodeAbstract) pickSupport
                .getVertex(vv.getGraphLayout(), e.getPoint().getX(), e.getPoint().getY());
        if (vertex != null && startVertex != null) {

            // Pathway pw = graphInstance.getPathway();

            BiologicalNodeAbstract start = startVertex;// (BiologicalNodeAbstract)
            // pw
            // .getNodeByVertexID(startVertex.toString());
            BiologicalNodeAbstract end = vertex;// (BiologicalNodeAbstract)
            // pw
            // .getNodeByVertexID(vertex.toString());

            if (pw.isPetriNet() && !((start instanceof Place && end instanceof Transition)
                    || (start instanceof Transition && end instanceof Place)))
                JOptionPane.showMessageDialog(MainWindowSingleton.getInstance(),
                        "In a petri net only Transition->Place and Place->Transition Relations are allowed!",
                        "Unallowed Operation...", JOptionPane.ERROR_MESSAGE);

            else if ((start instanceof ContinuousTransition && end instanceof Place
                    && ((Place) end).isDiscrete())
                    || (end instanceof ContinuousTransition && start instanceof Place
                            && ((Place) start).isDiscrete()))
                JOptionPane.showMessageDialog(MainWindowSingleton.getInstance(),
                        "Relations between discrete Places and Continoues Transitions are not possible!",
                        "Unallowed Operation...", JOptionPane.ERROR_MESSAGE);
            else {
                // Graph graph = vv.getGraphLayout().getGraph();
                EdgeDialog dialog = new EdgeDialog(startVertex, vertex);
                Pair<String[], BiologicalNodeAbstract[]> answer = dialog.getAnswer();
                String[] answers = answer.getLeft();
                BiologicalNodeAbstract[] nodes = answer.getRight();

                if (answers != null) {
                    if (answers[2] != null && answers[2].toLowerCase().contains("inhibi")
                            && !(startVertex instanceof Place && vertex instanceof Transition))
                        JOptionPane.showMessageDialog(MainWindowSingleton.getInstance(),
                                "Inhibitory Edges are only possible from Place to Transition!",
                                "Unallowed Operation...", JOptionPane.ERROR_MESSAGE);
                    else {
                        String name = answers[0];
                        String label = answers[0];
                        String element = answers[2];
                        if (answers[2].toLowerCase().contains("inhibi")) {
                            element = Elementdeclerations.pnInhibitionEdge;
                        }
                        boolean directed = false;
                        if (answers[1].equals("directed_edge")) {
                            directed = true;
                        }

                        Set<BiologicalNodeAbstract> parentBNAs = new HashSet<BiologicalNodeAbstract>();
                        parentBNAs.addAll(nodes[0].getAllParentNodes());
                        parentBNAs.addAll(nodes[1].getAllParentNodes());
                        BiologicalEdgeAbstract bea = pw.addEdge(label, name, nodes[0], nodes[1], element,
                                directed);
                        if (nodes[0] == startVertex && nodes[1] == vertex) {
                            pw.addEdgeToView(bea, false);
                        } else {
                            BiologicalEdgeAbstract clone = bea.clone();
                            clone.setFrom(startVertex);
                            clone.setTo(vertex);
                            pw.addEdgeToView(clone, false);
                        }
                    }
                }
            }
        }
        vv.repaint();
        startVertex = null;
        down = null;
        edgeIsDirected = false;
        vv.removePostRenderPaintable(edgePaintable);
        vv.removePostRenderPaintable(arrowPaintable);
    }
}

From source file:VASSAL.build.module.map.PieceMover.java

/** Place the clicked-on piece into the {@link DragBuffer} */
protected void selectMovablePieces(MouseEvent e) {
    final GamePiece p = map.findPiece(e.getPoint(), dragTargetSelector);
    dragBegin = e.getPoint();//from   w  ww .  j a  v  a 2 s  . co m
    if (p != null) {
        final EventFilter filter = (EventFilter) p.getProperty(Properties.MOVE_EVENT_FILTER);
        if (filter == null || !filter.rejectEvent(e)) {
            selectionProcessor.accept(p);
        } else {
            DragBuffer.getBuffer().clear();
        }
    } else {
        DragBuffer.getBuffer().clear();
    }
    // show/hide selection boxes
    map.repaint();
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java

public void mousePressed(MouseEvent e) {
    if (MouseUtils.isPushTrigger(e) || MouseUtils.isCtrlPushTrigger(e)) {
        start_position = getAnnotationAtPoint(e.getPoint());
        mouse_start_point = e.getPoint();
        mouse_end_point = null;//from   www  . ja v  a 2s .  c  o m

        if (start_position != null) {
            if (isInResizeCorner(start_position, mouse_start_point)) {
                // start resizing
                setSelection(start_position);
                is_resizing = true;
            } else {
                // start DnD
                if (!isSelected(start_position))
                    setSelection(start_position);
                is_dragndrop = true;
            }
        } else {
            start_position = getCPAtPoint(e.getPoint());
            if (start_position != null) {
                // start moving cp
                setSelection(start_position);
                is_movingcp = true;
            } else {
                // start selection
                is_dragndrop = false;
            }
        }
    }
    was_dragged = false;
}

From source file:VASSAL.build.module.map.PieceMover.java

public void mouseReleased(MouseEvent e) {
    if (canHandleEvent(e)) {
        if (!isClick(e.getPoint())) {
            performDrop(e.getPoint());/*from   w w  w  . ja va2  s  .c  o  m*/
        }
    }
    dragBegin = null;
    map.getView().setCursor(null);
}

From source file:org.openconcerto.task.TodoListPanel.java

private void initTable(int mode) {
    this.t.setBlockRepaint(true);

    this.t.setBlockEventOnColumn(true);
    this.model.setMode(mode);

    this.t.getColumnModel().getColumn(0).setCellRenderer(this.a);
    this.t.getColumnModel().getColumn(0).setCellEditor(this.a);
    this.t.setBlockEventOnColumn(true);
    setIconForColumn(0, this.iconTache);
    setIconForColumn(1, this.iconPriorite);
    this.t.setBlockEventOnColumn(true);

    this.t.getColumnModel().getColumn(1).setCellEditor(this.iconEditor);
    final JTextField textField = new JTextField() {
        @Override/*from w w w  .  j av a 2 s  .com*/
        public void paint(Graphics g) {
            super.paint(g);
            g.setColor(TodoListPanel.this.t.getGridColor());
            g.fillRect(getWidth() - 19, 0, 1, getHeight());
            g.setColor(new Color(250, 250, 250));
            g.fillRect(getWidth() - 18, 0, 18, getHeight());
            g.setColor(Color.BLACK);
            for (int i = 0; i < 3; i++) {
                int x = getWidth() - 14 + i * 4;
                int y = getHeight() - 5;
                g.fillRect(x, y, 1, 2);
            }
        }
    };
    textField.setBorder(BorderFactory.createEmptyBorder());
    final DefaultCellEditor defaultCellEditor = new DefaultCellEditor(textField);
    textField.addMouseListener(new MouseListener() {

        public void mouseClicked(MouseEvent e) {

        }

        public void mouseEntered(MouseEvent e) {
            // TODO Auto-generated method stub

        }

        public void mouseExited(MouseEvent e) {
            // TODO Auto-generated method stub

        }

        public void mousePressed(MouseEvent e) {

        }

        public void mouseReleased(MouseEvent e) {
            if (e.getX() > textField.getWidth() - 19) {
                TodoListElement l = getTaskAt(
                        SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), TodoListPanel.this.t));
                TodoListPanel.this.t.editingCanceled(new ChangeEvent(this));
                JFrame f = new JFrame(TM.tr("details"));
                f.setContentPane(new TodoListElementEditorPanel(l));
                f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                f.setSize(500, 200);
                f.setLocation(50, e.getYOnScreen() + TodoListPanel.this.t.getRowHeight());
                f.setVisible(true);
            }

        }
    });
    this.t.getColumnModel().getColumn(2).setCellEditor(defaultCellEditor);
    this.t.getColumnModel().getColumn(3).setMaxWidth(300);
    this.t.getColumnModel().getColumn(3).setMinWidth(100);

    this.timestampTableCellEditorCreated.stopCellEditing();
    this.timestampTableCellEditorDone.stopCellEditing();
    this.timestampTableCellEditorDeadLine.stopCellEditing();

    if (this.model.getMode() == TodoListModel.EXTENDED_MODE) {
        this.t.getColumnModel().getColumn(3).setCellRenderer(this.timestampTableCellRendererCreated);
        this.t.getColumnModel().getColumn(3).setCellEditor(this.timestampTableCellEditorCreated);

        this.t.getColumnModel().getColumn(4).setCellRenderer(this.timestampTableCellRendererDone);
        this.t.getColumnModel().getColumn(4).setCellEditor(this.timestampTableCellEditorDone);

        this.t.getColumnModel().getColumn(5).setCellRenderer(this.timestampTableCellRendererDeadLine);
        this.t.getColumnModel().getColumn(5).setCellEditor(this.timestampTableCellEditorDeadLine);
    } else {
        this.t.getColumnModel().getColumn(3).setCellRenderer(this.timestampTableCellRendererDeadLine);
        this.t.getColumnModel().getColumn(3).setCellEditor(this.timestampTableCellEditorDeadLine);
    }

    final TableColumn userColumn = this.t.getColumnModel()
            .getColumn(this.t.getColumnModel().getColumnCount() - 1);
    userColumn.setCellRenderer(this.userTableCellRenderer);
    userColumn.setMaxWidth(150);
    userColumn.setMinWidth(100);
    t.setEnabled(false);
    initUserCellEditor(userColumn);

    this.t.setBlockEventOnColumn(false);
    this.t.setBlockRepaint(false);
    this.t.getColumnModel().getColumn(1).setCellRenderer(this.iconRenderer);
    // Better look
    this.t.setShowHorizontalLines(false);
    this.t.setGridColor(new Color(230, 230, 230));
    this.t.setRowHeight(new JTextField(" ").getPreferredSize().height + 4);
    AlternateTableCellRenderer.UTILS.setAllColumns(this.t);
    this.t.repaint();

}

From source file:client.ui.FilePane.java

private void fileInfoScrollMouseClicked(MouseEvent evt) {//GEN-FIRST:event_fileInfoScrollMouseClicked
    Point p = evt.getPoint();
    if (!fileInfoTable.contains(p)) { //???
        fileInfoTable.clearSelection();//from   w  w w.j  av  a 2s .  c  om
        fileInfoTable.getRowSorter().setSortKeys(null);
        fileInfoTable.repaint();
        clearNoteAndText();
    }
}

From source file:client.ui.FilePane.java

private void noteDisplayScrollMouseClicked(MouseEvent evt) {//GEN-FIRST:event_noteDisplayScrollMouseClicked
    Point p = evt.getPoint();
    if (!noteTable.contains(p)) { //???
        noteTable.clearSelection();//from  w  ww  .java  2 s  . c om
        noteTable.getRowSorter().setSortKeys(null);
        noteTable.repaint();
    }
}

From source file:de.codesourcery.eve.skills.ui.components.impl.MarketPriceEditorComponent.java

/**
 * Checks whether a mouse-click event should trigger a context-sensitive
 * popup menu and renders the menu if so.
 * /*from   www  .j  a  v a2s.  com*/
 * @param e
 */
private void maybeShowPopup(MouseEvent e) {

    if (!e.isPopupTrigger()) {
        return;
    }

    final int[] selectedRows = table.getSelectedRows();

    if (ArrayUtils.isEmpty(selectedRows)) {

        final int row = table.rowAtPoint(e.getPoint());
        if (row < 0) {
            if (log.isDebugEnabled()) {
                log.debug("maybeShowPopup(): Outside of table.");
            }
            return;
        }

        table.getSelectionModel().setSelectionInterval(row, row);
    }

    // translate row indices
    for (int i = 0; i < selectedRows.length; i++) {
        selectedRows[i] = table.getRowSorter().convertRowIndexToModel(selectedRows[i]);
    }
    if (populatePopupMenu(e, selectedRows)) {
        popupMenu.show(e.getComponent(), e.getX(), e.getY());
    }
}

From source file:net.sf.jabref.gui.groups.GroupSelector.java

private void showPopup(MouseEvent e) {
    final TreePath path = groupsTree.getPathForLocation(e.getPoint().x, e.getPoint().y);
    addGroupPopupAction.setEnabled(true);
    addSubgroupPopupAction.setEnabled(path != null);
    editGroupPopupAction.setEnabled(path != null);
    removeGroupAndSubgroupsPopupAction.setEnabled(path != null);
    removeGroupKeepSubgroupsPopupAction.setEnabled(path != null);
    moveSubmenu.setEnabled(path != null);
    expandSubtreePopupAction.setEnabled(path != null);
    collapseSubtreePopupAction.setEnabled(path != null);
    removeSubgroupsPopupAction.setEnabled(path != null);
    sortSubmenu.setEnabled(path != null);
    addToGroup.setEnabled(false);//from   w w  w.  j a va 2  s. co  m
    moveToGroup.setEnabled(false);
    removeFromGroup.setEnabled(false);
    if (path != null) { // some path dependent enabling/disabling
        GroupTreeNodeViewModel node = (GroupTreeNodeViewModel) path.getLastPathComponent();
        editGroupPopupAction.setNode(node);
        addSubgroupPopupAction.setNode(node);
        removeGroupAndSubgroupsPopupAction.setNode(node);
        removeSubgroupsPopupAction.setNode(node);
        removeGroupKeepSubgroupsPopupAction.setNode(node);
        expandSubtreePopupAction.setNode(node);
        collapseSubtreePopupAction.setNode(node);
        sortDirectSubgroupsPopupAction.setNode(node);
        sortAllSubgroupsPopupAction.setNode(node);
        groupsTree.setHighlightBorderCell(node);
        if (node.canBeEdited()) {
            editGroupPopupAction.setEnabled(false);
            addGroupPopupAction.setEnabled(false);
            removeGroupAndSubgroupsPopupAction.setEnabled(false);
            removeGroupKeepSubgroupsPopupAction.setEnabled(false);
        } else {
            editGroupPopupAction.setEnabled(true);
            addGroupPopupAction.setEnabled(true);
            addGroupPopupAction.setNode(node);
            removeGroupAndSubgroupsPopupAction.setEnabled(true);
            removeGroupKeepSubgroupsPopupAction.setEnabled(true);
        }
        expandSubtreePopupAction
                .setEnabled(groupsTree.isCollapsed(path) || groupsTree.hasCollapsedDescendant(path));
        collapseSubtreePopupAction
                .setEnabled(groupsTree.isExpanded(path) || groupsTree.hasExpandedDescendant(path));
        sortSubmenu.setEnabled(!node.isLeaf());
        removeSubgroupsPopupAction.setEnabled(!node.isLeaf());
        moveNodeUpPopupAction.setEnabled(node.canMoveUp());
        moveNodeDownPopupAction.setEnabled(node.canMoveDown());
        moveNodeLeftPopupAction.setEnabled(node.canMoveLeft());
        moveNodeRightPopupAction.setEnabled(node.canMoveRight());
        moveSubmenu.setEnabled(moveNodeUpPopupAction.isEnabled() || moveNodeDownPopupAction.isEnabled()
                || moveNodeLeftPopupAction.isEnabled() || moveNodeRightPopupAction.isEnabled());
        moveNodeUpPopupAction.setNode(node);
        moveNodeDownPopupAction.setNode(node);
        moveNodeLeftPopupAction.setNode(node);
        moveNodeRightPopupAction.setNode(node);
        // add/remove entries to/from group
        List<BibEntry> selection = frame.getCurrentBasePanel().getSelectedEntries();
        if (!selection.isEmpty()) {
            if (node.canAddEntries(selection)) {
                addToGroup.setNode(node);
                addToGroup.setBasePanel(panel);
                addToGroup.setEnabled(true);
                moveToGroup.setNode(node);
                moveToGroup.setBasePanel(panel);
                moveToGroup.setEnabled(true);
            }
            if (node.canRemoveEntries(selection)) {
                removeFromGroup.setNode(node);
                removeFromGroup.setBasePanel(panel);
                removeFromGroup.setEnabled(true);
            }
        }
    } else {
        editGroupPopupAction.setNode(null);
        addGroupPopupAction.setNode(null);
        addSubgroupPopupAction.setNode(null);
        removeGroupAndSubgroupsPopupAction.setNode(null);
        removeSubgroupsPopupAction.setNode(null);
        removeGroupKeepSubgroupsPopupAction.setNode(null);
        moveNodeUpPopupAction.setNode(null);
        moveNodeDownPopupAction.setNode(null);
        moveNodeLeftPopupAction.setNode(null);
        moveNodeRightPopupAction.setNode(null);
        expandSubtreePopupAction.setNode(null);
        collapseSubtreePopupAction.setNode(null);
        sortDirectSubgroupsPopupAction.setNode(null);
        sortAllSubgroupsPopupAction.setNode(null);
    }
    groupsContextMenu.show(groupsTree, e.getPoint().x, e.getPoint().y);
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.SpectraPanel.java

public void mouseDragged(MouseEvent e) {
    if (mouse_start_point != null && theDocument.getNoScans() > 0) {
        if (is_moving) {
            // moving
            double mz_delta = screenToDataX(mouse_start_point.getX() - e.getPoint().getX());
            if (mz_delta > 0.) {
                double old_upper_bound = thePlot.getDomainAxis().getUpperBound();
                double old_lower_bound = thePlot.getDomainAxis().getLowerBound();
                double new_upper_bound = Math.min(old_upper_bound + mz_delta,
                        theDocument.getPeakDataAt(current_ind).getMaxMZ());
                double new_lower_bound = old_lower_bound + new_upper_bound - old_upper_bound;

                thePlot.getDomainAxis().setRange(new Range(new_lower_bound, new_upper_bound));
            } else {
                double old_upper_bound = thePlot.getDomainAxis().getUpperBound();
                double old_lower_bound = thePlot.getDomainAxis().getLowerBound();
                double new_lower_bound = Math.max(old_lower_bound + mz_delta,
                        theDocument.getPeakDataAt(current_ind).getMinMZ());
                double new_upper_bound = old_upper_bound + new_lower_bound - old_lower_bound;

                thePlot.getDomainAxis().setRange(new Range(new_lower_bound, new_upper_bound));
            }/*w w w.  j  av a  2 s.c o m*/

            mouse_start_point = e.getPoint();
        } else {
            // zooming                
            Graphics2D g2 = (Graphics2D) theChartPanel.getGraphics();
            g2.setXORMode(java.awt.Color.gray);

            // delete old rectangle
            if (zoom_rectangle != null)
                g2.draw(zoom_rectangle);

            // create new rectangle
            double start_x = Math.min(e.getX(), mouse_start_point.getX());
            double end_x = Math.max(e.getX(), mouse_start_point.getX());

            Rectangle2D data_area = theChartPanel.getScreenDataArea((int) start_x,
                    (int) mouse_start_point.getY());
            double xmax = Math.min(end_x, data_area.getMaxX());
            zoom_rectangle = new Rectangle2D.Double(start_x, data_area.getMinY(), xmax - start_x,
                    data_area.getHeight());

            // draw new rectangle
            g2.draw(zoom_rectangle);
            g2.dispose();
        }
    }
}