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:org.openmicroscopy.shoola.agents.metadata.editor.DocComponent.java

/** Initializes the various buttons. */
private void initButtons() {
    IconManager icons = IconManager.getInstance();
    menuButton = new JButton(icons.getIcon(IconManager.UP_DOWN_9_12));
    UIUtilities.unifiedButtonLookAndFeel(menuButton);
    menuButton.setBackground(UIUtilities.BACKGROUND_COLOR);
    menuButton.addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent e) {
            showMenu(menuButton, e.getPoint());
        }//ww  w  .  ja  v a2  s.co  m
    });
    infoButton = new JMenuItem(icons.getIcon(IconManager.INFO));
    infoButton.setText("Info...");
    infoButton.addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent e) {
            popMenu.setVisible(false);
            displayInformation(label, e.getPoint());
        }
    });
    unlinkButton = new JMenuItem(icons.getIcon(IconManager.MINUS_12));
    unlinkButton.setText("Remove");
    unlinkButton.addActionListener(this);
    unlinkButton.setActionCommand("" + REMOVE);
    if (data instanceof FileAnnotationData) {
        FileAnnotationData fa = (FileAnnotationData) data;
        unlinkButton.setToolTipText("Remove the attachment.");

        if (fa.getId() > 0) {
            unlinkButton.setEnabled(deletable);
            downloadButton = new JMenuItem(icons.getIcon(IconManager.DOWNLOAD_12));
            downloadButton.setText("Download...");
            downloadButton.setToolTipText("Download the selected file.");
            downloadButton.setActionCommand("" + DOWNLOAD);
            downloadButton.addActionListener(this);

            String ns = fa.getNameSpace();
            openButton = new JMenuItem(icons.getIcon(IconManager.VIEW_DOC_12));
            openButton.setText("View");
            openButton.setToolTipText("View the file.");
            openButton.setActionCommand("" + OPEN);
            openButton.addActionListener(this);
            if (FileAnnotationData.COMPANION_FILE_NS.equals(ns) || FileAnnotationData.MEASUREMENT_NS.equals(ns))
                unlinkButton = null;
        }
    } else if (data instanceof TagAnnotationData || data instanceof XMLAnnotationData
            || data instanceof TermAnnotationData || data instanceof LongAnnotationData
            || data instanceof DoubleAnnotationData) {
        unlinkButton.setToolTipText("Remove the annotation.");
        editButton = new JMenuItem(icons.getIcon(IconManager.EDIT_12));
        if (isModulo)
            editButton.setText("View");
        else
            editButton.setText("Edit");
        editButton.setActionCommand("" + EDIT);
        editButton.addActionListener(this);
        editButton.addMouseListener(new MouseAdapter() {

            /** 
             * Sets the location of the mouse click.
             * @see MouseAdapter#mousePressed(MouseEvent)
             */
            public void mousePressed(MouseEvent e) {
                popupPoint = e.getPoint();
            }

        });
    }
}

From source file:org.yccheok.jstock.gui.charting.ChartLayerUI.java

private void processEvent(MouseEvent e, JXLayer layer) {
    if (MouseEvent.MOUSE_DRAGGED == e.getID()) {
        return;/*from w ww .  j av a 2  s. com*/
    }

    final Point mousePoint = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), layer);
    if (this.updateMainTraceInfo(mousePoint)) {
        this.updateIndicatorTraceInfos(this.mainTraceInfo.getDataIndex());
        this.setDirty(true);
    }
}

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

public void mousePressed(MouseEvent e) {

    if (MouseUtils.isPopupTrigger(e)) {
        // open popup
        current_peak = findPeakAt(e.getPoint());
        enforceSelection(current_peak);/*www .j av a 2s.  c  o m*/
        createPopupMenu(current_peak != null).show(theChartPanel, e.getX(), e.getY());
    } else {
        was_moving = is_moving;
        if ((MouseUtils.isPushTrigger(e) || MouseUtils.isMoveTrigger(e))
                && theChartPanel.getScreenDataArea().contains(e.getPoint())) {
            mouse_start_point = e.getPoint();
            if (MouseUtils.isMoveTrigger(e))
                onActivateMoving();
        }
    }
}

From source file:com.projity.pm.graphic.spreadsheet.SpreadSheet.java

public void setModel(SpreadSheetModel spreadSheetModel, SpreadSheetColumnModel spreadSheetColumnModel) {
    makeCustomTableHeader(spreadSheetColumnModel);
    TableModel oldModel = getModel();
    setModel(spreadSheetModel);//from   w  ww .  j  av  a 2  s  .c  o m

    if (spreadSheetColumnModel != null) {
        //System.out.println("creating new ColModel");
        setColumnModel(spreadSheetColumnModel);

        selection = new SpreadSheetSelectionModel(this);
        selection.setRowSelection(new SpreadSheetListSelectionModel(selection, true));
        selection.setColumnSelection(new SpreadSheetListSelectionModel(selection, false));
        setSelectionModel(selection.getRowSelection());
        createDefaultColumnsFromModel(spreadSheetModel.getFieldArray()); //Consume memory
        getColumnModel().setSelectionModel(selection.getColumnSelection());
    }

    registerEditors(); //Consume memory
    initRowHeader(spreadSheetModel);
    initModel();
    initListeners();

    GraphicConfiguration config = GraphicConfiguration.getInstance();
    //fix for substance
    setTableHeader(createDefaultTableHeader());
    JTableHeader header = getTableHeader();
    header.setPreferredSize(
            new Dimension((int) header.getPreferredSize().getWidth(), config.getColumnHeaderHeight()));
    header.addMouseListener(new HeaderMouseListener(this));

    addMouseListener(new MouseAdapter() {
        //         Cursor oldCursor = null;
        //         public void mouseEntered(MouseEvent e) {
        //            Point p = e.getPoint();
        //            int col = columnAtPoint(p);
        //            Field field = ((SpreadSheetModel) getModel()).getFieldInNonTranslatedColumn(col + 1);
        //            System.out.println("mouse entered field " + field);
        //            if (field != null && field.isHyperlink()) {
        //               oldCursor = getCursor();
        //               setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        //               System.out.println("setting new cursor to " + Cursor.getPredefinedCursor(Cursor.HAND_CURSOR) + " old is " + oldCursor);
        //            } else 
        //               super.mouseEntered(e);
        //
        //         }
        //
        //         public void mouseExited(MouseEvent e) {
        //            Point p = e.getPoint();
        //            int col = columnAtPoint(p);
        //            Field field = ((SpreadSheetModel) getModel()).getFieldInNonTranslatedColumn(col + 1);
        //            System.out.println("mouse exited field " + field);
        //            if (field != null && field.isHyperlink()) {
        //               setCursor(oldCursor);
        //               System.out.println("setting old cursor to " + oldCursor);
        //               e.consume();
        //            } else 
        //               super.mouseEntered(e);
        //         }

        public void mousePressed(MouseEvent e) { // changed to mousePressed instead of mouseClicked() for snappier handling 17/5/04 hk
            Point p = e.getPoint();
            int row = rowAtPoint(p);
            int col = columnAtPoint(p);
            SpreadSheetPopupMenu popup = getPopup();
            if (SwingUtilities.isLeftMouseButton(e)) {
                SpreadSheetColumnModel columnModel = (SpreadSheetColumnModel) getColumnModel();
                Field field = ((SpreadSheetModel) getModel()).getFieldInNonTranslatedColumn(col + 1);
                SpreadSheetModel model = (SpreadSheetModel) getModel();
                if (field.isNameField()) {
                    // if (col == columnModel.getNameIndex()) {
                    GraphicNode node = model.getNode(row);
                    if (isOnIcon(e)) {
                        if (model.getCellProperties(node).isCompositeIcon()) {
                            finishCurrentOperations();
                            selection.getRowSelection().clearSelection();
                            boolean change = true;
                            if (!node.isFetched()) // for subprojects
                                change = node.fetch();
                            if (change)
                                model.changeCollapsedState(row);
                            e.consume(); // prevent dbl click treatment below

                            // because editor may have already been
                            // installed we
                            // have to update its collapsed state
                            // updateNameCellEditor(node);

                            // editCellAt(row,model.findGraphicNodeRow(node));
                        }
                    }
                } else if (field != null && field.isHyperlink()) {
                    Hyperlink link = (Hyperlink) model.getValueAt(row, col + 1);
                    if (link != null) {
                        BrowserControl.displayURL(link.getAddress());
                        e.consume(); // prevent dbl click treatment below
                    }

                }
                if (!e.isConsumed()) {
                    if (e.getClickCount() == 2) // if above code didn't treat and is dbl click
                        doDoubleClick(row, col);
                    else
                        doClick(row, col);
                }

            } else if (popup != null && SwingUtilities.isRightMouseButton(e)) { // e.isPopupTrigger() can be used too
                //               selection.getRowSelection().clearSelection();
                //               selection.getRowSelection().addSelectionInterval(row, row);
                popup.setRow(row);
                popup.setCol(col);
                popup.show(SpreadSheet.this, e.getX(), e.getY());
            }
        }
    });

    if (oldModel != spreadSheetModel && oldModel instanceof CommonSpreadSheetModel)
        ((CommonSpreadSheetModel) getModel()).getCache().removeNodeModelListener(this);
    spreadSheetModel.getCache().addNodeModelListener(this);

    //      getColumnModel().addColumnModelListener(new TableColumnModelListener(){
    //         public void columnAdded(TableColumnModelEvent e) {
    //            // TODO Auto-generated method stub
    //            
    //         }
    //         public void columnMarginChanged(ChangeEvent e) {
    //            // TODO Auto-generated method stub
    //            
    //         }
    //         public void columnMoved(TableColumnModelEvent e) {
    //            // TODO Auto-generated method stub
    //            
    //         }
    //         public void columnRemoved(TableColumnModelEvent e) {
    //            // TODO Auto-generated method stub
    //            
    //         }
    //         public void columnSelectionChanged(ListSelectionEvent e) {
    //            System.out.println(((e.getValueIsAdjusting())?"lse=":"LSE=")+e.getFirstIndex()+", "+e.getLastIndex());
    //            SpreadSheet.this.revalidate();
    //            //SpreadSheet.this.paintImmediately(0, 0, getWidth(), GraphicConfiguration.getInstance().getColumnHeaderHeight());
    //         }
    //      });

}

From source file:com.diversityarrays.kdxplore.curate.TraitsAndInstancesPanel2.java

private void showContextMenu(MouseEvent me) {

    Map<SimpleStatistics<?>, TraitInstance> tiByStat = new HashMap<>();

    List<SimpleStatistics<?>> statsList = new ArrayList<>();
    List<TraitInstance> selectedInstances = new ArrayList<>();

    Set<Integer> rowSet = new HashSet<>();

    for (int row : traitInstanceStatsTable.getSelectedRows()) {
        rowSet.add(row);//from w ww . j  a v a  2  s.  c o  m
    }

    // Include the right-click one too
    int row = traitInstanceStatsTable.rowAtPoint(me.getPoint());
    if (row >= 0) {
        rowSet.add(row);
    }

    List<Integer> vrows = new ArrayList<>(rowSet);
    Collections.sort(vrows);
    for (Integer vrow : vrows) {
        collectInfoFromRow(vrow, selectedInstances, tiByStat, statsList);
    }

    List<TraitInstance> checkedInstances = tiStatsModel.getCheckedTraitInstances();

    Action action = null;
    if (!statsList.isEmpty()) {
        String label = statsList.size() == 1 ? "Show Outliers"
                : "Show Outliers for " + statsList.size() + " Traits";
        action = new AbstractAction(label) {
            @Override
            public void actionPerformed(ActionEvent e) {
                StringBuilder html = new StringBuilder();
                html.append("<HTML><TABLE><TR>");

                outlierSelections.clear();

                for (SimpleStatistics<?> stat : statsList) {
                    html.append("<TH>");
                    html.append(StringUtil.htmlEscape(stat.getStatsName()));
                    html.append("</TH>");
                }

                html.append("</TR><TR>");

                for (SimpleStatistics<?> stat : statsList) {
                    TraitInstance ti = tiByStat.get(stat);
                    html.append("<TD valign='top'>");
                    describeStats(stat, html, ti);
                    html.append("</TD>");

                    outlierSelections.add(createOutlierSelection(stat, ti));
                }
                html.append("</TR></TABLE>");

                outlierConsumer.accept(outlierSelections);

                JOptionPane.showMessageDialog(TraitsAndInstancesPanel2.this, html.toString(), "Outliers",
                        JOptionPane.INFORMATION_MESSAGE);

            }
        };
    }

    curationMenuProvider.showTraitInstanceTableToolMenu(me, checkedInstances, selectedInstances, action);
}

From source file:graph.eventhandlers.MyEditingGraphMousePlugin.java

/**
 * If the mouse is pressed in an empty area, create a new vertex there. If
 * the mouse is pressed on an existing vertex, prepare to create an edge
 * from that vertex to another/*from  w w w . j  a v a  2  s . c o  m*/
 */
public void mousePressed(MouseEvent e) {
    pw = graphInstance.getPathway();
    if (checkModifiers(e)) {

        final VisualizationViewer<BiologicalNodeAbstract, BiologicalEdgeAbstract> vv = (VisualizationViewer<BiologicalNodeAbstract, BiologicalEdgeAbstract>) e
                .getSource();
        // final Point2D p = vv.inverseViewTransform(e.getPoint());
        // System.out.println("Points: "+e.getPoint().getX()+", "+e.getPoint().getY());
        final Point2D p = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(e.getPoint());
        // System.out.println(e.getPoint()+ " "+p);
        // System.out.println("Points: "+p.getX()+", "+p.getY());
        // final Point2D p = e.getPoint();
        GraphElementAccessor<BiologicalNodeAbstract, BiologicalEdgeAbstract> pickSupport = vv.getPickSupport();
        // System.out.println("Click: "+p);
        // System.out.println("regul: "+e.getPoint());

        Iterator<BiologicalNodeAbstract> it = pw.getGraph().getAllVertices().iterator();
        // while(it.hasNext()){
        // System.out.println(pw.getGraph().getVertexLocation(it.next()));
        // }
        // System.out.println(pw.getGraph().getAllEdges().size());
        // System.out.println(pickSupport.g);

        BiologicalNodeAbstract vertex = null;

        vertex = (BiologicalNodeAbstract) pickSupport.getVertex(vv.getGraphLayout(), e.getPoint().getX(),
                e.getPoint().getY());
        // System.out.println(vertex);

        if (vertex != null) { // get ready to make an edge
            // System.out.println(vertex);
            startVertex = vertex;
            super.down = e.getPoint();
            transformEdgeShape(down, down);
            vv.addPostRenderPaintable(edgePaintable);
            if ((e.getModifiers() & InputEvent.SHIFT_MASK) != 0) {
                edgeIsDirected = true;
                transformArrowShape(down, e.getPoint());
                vv.addPostRenderPaintable(arrowPaintable);
            }
        } else { // make a new vertex
            Graph<BiologicalNodeAbstract, BiologicalEdgeAbstract> graph = vv.getGraphLayout().getGraph();
            //            BiologicalNodeAbstract newVertex = new BiologicalNodeAbstract(
            //                  "label", "name");
            // vertexLocations.put(newVertex, p);

            Layout<BiologicalNodeAbstract, BiologicalEdgeAbstract> layout = vv.getGraphLayout();

            // System.out.println("size V: "+layout.getGraph().getVertices().size());
            // System.out.println("size E: "+layout.getGraph().getEdges().size());

            // graph.addVertex(newVertex);
            /*
             * Object key = (((AggregateLayout)
             * layout).getDelegate()).getBaseKey(); Object datum = new
             * Coordinates(vv.inverseTransform( e.getPoint()).getX(),
             * vv.inverseTransform( e.getPoint()).getY());
             * newVertex.setUserDatum(key, datum, new CopyAction.Clone());
             */

            for (Iterator<BiologicalNodeAbstract> iterator = graph.getVertices().iterator(); iterator
                    .hasNext();) {
                layout.lock(iterator.next(), true);

            }

            if (con.isPetriView()) {
                // System.out.println("is petri");

                PetriNetVertexDialog dialog = new PetriNetVertexDialog(con.getPetriNetEditingMode());
                BiologicalNodeAbstract bna = dialog.getAnswer(p);
                // System.out.println();
                if (bna != null) {
                    // BiologicalNodeAbstract ba = new
                    // BiologicalNodeAbstract(
                    // answers[0], "", newVertex);
                    // ba.setBiologicalElement(answers[1]);
                    // ba.setCompartment(answers[2]);
                    // graphInstance.getPathway().addElement(ba);
                    // graph.addVertex(newVertex);

                    // vv.getModel().restart();
                    //System.out.println("update");
                    if (pw instanceof BiologicalNodeAbstract) {
                        bna.setParentNode((BiologicalNodeAbstract) pw);
                    }
                    MainWindowSingleton.getInstance().updateElementTree();
                    MainWindowSingleton.getInstance().updatePathwayTree();
                    //MainWindowSingelton.getInstance().updateAllGuiElements();
                    //MainWindowSingelton.getInstance().updateOptionPanel();
                    // MainWindowSingelton.getInstance()
                    // .updateTheoryProperties();

                    // Pathway pw = graphInstance.getPathway();

                }

            } else {
                // System.out.println("not petri");
                VertexDialog dialog = new VertexDialog();
                String[] answers = dialog.getAnswer();
                if (answers != null) {

                    // BiologicalNodeAbstract ba = new
                    // BiologicalNodeAbstract(
                    // answers[0], "");
                    String name = answers[0];
                    String label = answers[0];
                    String element = answers[1];
                    String compartment = answers[2];
                    //                  newVertex.setBiologicalElement(answers[1]);
                    //                  newVertex.setCompartment(answers[2]);
                    // graphInstance.getPathway().addElement(newVertex);
                    // graph.addVertex(newVertex);

                    BiologicalNodeAbstract newVertex = pw.addVertex(name, label, element, compartment, p);
                    if (pw instanceof BiologicalNodeAbstract) {
                        newVertex.setParentNode((BiologicalNodeAbstract) pw);
                    }
                    //pw.addVertex(newVertex, p);
                    if (graph.getVertices().size() > 1) {
                        // System.exit(0);
                    }

                    // pw.getGraph().setVertexLocation(newVertex, p);
                    // layout.setLocation(newVertex, p);
                    // vv.getModel().restart();
                    MainWindowSingleton.getInstance().updateElementTree();
                    // MainWindowSingelton.getInstance()
                    // .updateTheoryProperties();

                    for (Iterator<BiologicalNodeAbstract> iterator = graph.getVertices().iterator(); iterator
                            .hasNext();) {
                        layout.lock(iterator.next(), false);
                    }

                }

            }
            if (pw instanceof BiologicalNodeAbstract) {

            }
        }
        vv.repaint();
    }
}

From source file:pt.lsts.neptus.plugins.sunfish.awareness.SituationAwareness.java

@Override
public void mouseMoved(MouseEvent event, StateRenderer2D source) {

    List<AssetPosition> allPositions = new ArrayList<AssetPosition>();

    for (AssetTrack track : assets.values())
        allPositions.addAll(track.getTrack());

    Collections.sort(allPositions);

    for (AssetPosition p : allPositions) {
        if (p.getTimestamp() < oldestTimestampSelection || p.getTimestamp() > newestTimestampSelection)
            continue;

        double dist = event.getPoint().distance(source.getScreenPosition(p.getLoc()));
        if (dist < 5) {
            intercepted = p;/*from  w  ww.  ja  v  a2 s  .  c  o m*/
            return;
        }
    }

    intercepted = null;
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.EditorControl.java

/**
 * Removes the tags or files.//w w  w .  j  av a 2s  .c o  m
 * @see MouseListener#mouseReleased(MouseEvent)
 */
public void mouseReleased(MouseEvent e) {
    JButton src = (JButton) e.getSource();
    if (!src.isEnabled())
        return;
    int index = Integer.parseInt(src.getActionCommand());
    Point p = e.getPoint();
    switch (index) {
    case REMOVE_TAGS:
        view.removeTags(src, p);
        break;
    case REMOVE_DOCS:
        view.removeAttachedFiles(src, p);
        break;
    case REMOVE_OTHER_ANNOTATIONS:
        view.removeOtherAnnotations(src, p);
    }
}

From source file:org.tellervo.desktop.tridasv2.ui.ComponentViewerOld.java

private void setupTable() {
    tableModel = new ElementListTableModel();
    table = new JXTable(tableModel);

    tableSorter = new ElementListTableSorter(tableModel, table);
    table.getTableHeader().addMouseListener(tableSorter); // add sorter & header renderer
    table.setColumnSelectionAllowed(false);
    table.setRowSelectionAllowed(true);//  ww w.  j  a va 2 s .co  m

    // set our column widths
    ElementListTableModel.setupColumnWidths(table);

    table.setDefaultRenderer(Object.class, new ElementListCellRenderer(this, false));
    table.setDefaultRenderer(Boolean.class, new BooleanCellRenderer(this, false));

    // hide irrelevent columns
    TableColumnModelExt colmodel = (TableColumnModelExt) table.getColumnModel();
    table.setColumnControlVisible(true);
    colmodel.getColumnExt(I18n.getText("hidden.MostRecentVersion")).setVisible(false);
    colmodel.getColumnExt(I18n.getText("dbbrowser.n")).setVisible(false);
    colmodel.getColumnExt(I18n.getText("dbbrowser.rec")).setVisible(false);
    colmodel.getColumnExt(I18n.getText("dbbrowser.hash")).setVisible(false);

    // popup menu
    table.addMouseListener(new PopupListener() {
        @Override
        public void showPopup(MouseEvent e) {
            // only clicks on tables
            if (!(e.getSource() instanceof JTable))
                return;

            JTable table = (JTable) e.getSource();
            ElementListTableModel model = (ElementListTableModel) table.getModel();

            // get the row and sanity check
            int row = table.rowAtPoint(e.getPoint());
            if (row < 0 || row >= model.getRowCount())
                return;

            // select it?
            table.setRowSelectionInterval(row, row);

            // get the element
            Element element = model.getElementAt(row);

            // create and show the menu
            JPopupMenu popup = new ElementListPopupMenu(element, ComponentViewerOld.this);
            popup.show(table, e.getX(), e.getY());
        }
    });
}

From source file:op.care.prescription.DlgRegular.java

private void tblDosisMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblDosisMousePressed
    if (!SwingUtilities.isRightMouseButton(evt)) {
        return;/* ww w.jav a2  s. c  o  m*/
    }

    final TMDose tm = (TMDose) tblDosis.getModel();
    if (tm.getRowCount() == 0) {
        return;
    }
    Point p = evt.getPoint();
    Point p2 = evt.getPoint();
    // Convert a coordinate relative to a component's bounds to screen coordinates
    SwingUtilities.convertPointToScreen(p2, tblDosis);

    //        final Point screenposition = p2;
    final int row = tblDosis.rowAtPoint(p);

    ListSelectionModel lsm = tblDosis.getSelectionModel();
    lsm.setSelectionInterval(row, row);

    // Meneintrge
    SYSTools.unregisterListeners(menu);
    menu = new JPopupMenu();

    //-----------------------------------------
    JMenuItem itemPopupDelete = new JMenuItem(SYSTools.xx("misc.msg.delete"), SYSConst.icon22delete);
    itemPopupDelete.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent evt) {
            PrescriptionSchedule schedule = prescription.getPrescriptionSchedule().get(row);
            prescription.getPrescriptionSchedule().remove(schedule);
            schedules2delete.add(schedule);
            reloadTable();
        }
    });
    menu.add(itemPopupDelete);
    menu.show(evt.getComponent(), (int) p.getX(), (int) p.getY());

}