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:savant.view.dialog.PluginRepositoryDialog.java

public final Component getCenterPanel(List<TreeBrowserEntry> roots) {
    table = new TreeTable(new TreeBrowserModel(roots) {
        @Override/*from w w  w  . j  a v  a 2s  . c  om*/
        public String[] getColumnNames() {
            return new String[] { "Name", "Description", "Web Site" };
        }

        @Override
        public CellStyle getCellStyleAt(int rowIndex, int columnIndex) {
            return null;
        }
    });
    table.setSortable(true);
    table.setRespectRenderPreferredHeight(true);

    // configure the TreeTable
    table.setExpandAllAllowed(true);
    table.setShowTreeLines(false);
    table.setSortingEnabled(false);
    table.setRowHeight(18);
    table.setShowGrid(false);
    table.setIntercellSpacing(new Dimension(0, 0));
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    //table.expandAll();
    table.expandFirstLevel();
    table.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            int col = table.columnAtPoint(e.getPoint());
            if (col == 2) {
                Object o = table.getModel().getValueAt(table.rowAtPoint(e.getPoint()), col);
                if (o != null && (o instanceof URL)) {
                    System.out.println(o.toString());
                    try {
                        Desktop.getDesktop().browse(((URL) o).toURI());
                    } catch (Exception x) {
                        LOG.error("Unable to open link for " + o, x);
                    }
                    return;
                }
            }
            if (e.getClickCount() == 2) {
                downloadSelectedItem(true);
            }
        }
    });

    // do not select row when expanding a row.
    table.setSelectRowWhenToggling(false);

    table.getColumnModel().getColumn(0).setPreferredWidth(200);
    table.getColumnModel().getColumn(1).setPreferredWidth(520);
    table.getColumnModel().getColumn(2).setPreferredWidth(80);

    table.getColumnModel().getColumn(0).setCellRenderer(new FileRowCellRenderer());
    table.getColumnModel().getColumn(2).setCellRenderer(new WebLinkRenderer());

    // add searchable feature
    TableSearchable searchable = new TableSearchable(table) {

        @Override
        protected String convertElementToString(Object item) {
            if (item instanceof TreeBrowserEntry) {
                return ((TreeBrowserEntry) item).getType();
            }
            return super.convertElementToString(item);
        }
    };
    searchable.setMainIndex(0); // only search for name column

    JScrollPane scrollPane = new JScrollPane(table);

    JPanel panel = new JPanel(new BorderLayout(6, 6));
    panel.add(scrollPane, BorderLayout.CENTER);
    panel.setPreferredSize(new Dimension(800, 500));
    return panel;
}

From source file:net.panthema.BispanningGame.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  www. j  a v  a2s .  c o  m
 */
@SuppressWarnings("unchecked")
public void mouseReleased(MouseEvent e) {
    if (checkModifiers(e)) {
        final VisualizationViewer<V, E> vv = (VisualizationViewer<V, E>) e.getSource();
        final Point2D p = e.getPoint();
        Layout<V, E> layout = vv.getModel().getGraphLayout();
        GraphElementAccessor<V, E> pickSupport = vv.getPickSupport();
        if (pickSupport != null) {
            final V vertex = pickSupport.getVertex(layout, p.getX(), p.getY());
            if (vertex != null && startVertex != null && startVertex != vertex) {
                Graph<V, E> graph = vv.getGraphLayout().getGraph();
                graph.addEdge(edgeFactory.create(), startVertex, vertex, EdgeType.UNDIRECTED);
                vv.getRenderContext().getParallelEdgeIndexFunction().reset();

                if (graph instanceof MyGraph)
                    ((MyGraph) graph).graphChanged();

                vv.repaint();
            }
        }
        startVertex = null;
        down = null;
        vv.removePostRenderPaintable(edgePaintable);
    }
}

From source file:org.kalypso.ogc.gml.widgets.base.PanToWidget.java

@Override
public void mousePressed(final MouseEvent e) {
    if (!ArrayUtils.contains(m_mouseButtons, e.getButton()))
        return;//from   ww  w  .j  av a2  s.  c  o  m

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

    final Point point = e.getPoint();

    m_world2screen = mapPanel.getProjection();
    if (m_world2screen == null)
        return;

    final GM_Position pixelPos = GeometryFactory.createGM_Position(point.getX(), point.getY());
    m_startPoint = m_world2screen.getSourcePoint(pixelPos);

    m_endPoint = null;
}

From source file:net.panthema.BispanningGame.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//ww w  .j a  v  a  2  s  .  c  om
 */
@SuppressWarnings("unchecked")
public void mousePressed(MouseEvent e) {
    if (checkModifiers(e)) {
        final VisualizationViewer<V, E> vv = (VisualizationViewer<V, E>) e.getSource();
        final Point2D p = e.getPoint();
        GraphElementAccessor<V, E> pickSupport = vv.getPickSupport();
        if (pickSupport != null) {
            Graph<V, E> graph = vv.getModel().getGraphLayout().getGraph();

            final V vertex = pickSupport.getVertex(vv.getModel().getGraphLayout(), p.getX(), p.getY());
            if (vertex != null) { // get ready to make an edge
                startVertex = vertex;
                down = e.getPoint();
                transformEdgeShape(down, down);
                vv.addPostRenderPaintable(edgePaintable);
            } else { // make a new vertex
                V newVertex = vertexFactory.create();
                Layout<V, E> layout = vv.getModel().getGraphLayout();
                graph.addVertex(newVertex);
                layout.setLocation(newVertex,
                        vv.getRenderContext().getMultiLayerTransformer().inverseTransform(e.getPoint()));

                if (graph instanceof MyGraph)
                    ((MyGraph) graph).graphChanged();
            }
        }
        vv.repaint();
    }
}

From source file:SortedTableModel.java

public void addHeaderListener() {
    table.getTableHeader().addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent event) {
            JTableHeader header = (JTableHeader) (event.getSource());
            int index = header.columnAtPoint(event.getPoint());
            Class dataType = table.getModel().getColumnClass(index);
            Class[] interfaces = dataType.getInterfaces();
            for (int i = 0; i < interfaces.length; i++) {
                if (interfaces[i].equals(java.lang.Comparable.class)) {
                    renderer.columnSelected(index);
                    break;
                }// w w w.j av a 2 s.  co  m
            }
            table.setColumnSelectionInterval(index, index);
        }
    });
}

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

@Override
public void mouseDragged(final MouseEvent e) {
    final Feature sourceFeature = m_data.getSourceFeature();
    if (sourceFeature == null)
        return;/*from   w w w  . j  a  v  a 2 s  .  c om*/

    final Point p = e.getPoint();

    final IMapPanel mapPanel = getMapPanel();
    final GeoTransform transform = mapPanel.getProjection();
    final GM_Point point = GeometryFactory.createGM_Point(p, transform,
            mapPanel.getMapModell().getCoordinatesSystem());
    final double grabDistance = MapUtilities.calculateWorldDistance(mapPanel, point, GRAB_RADIUS);

    final FeatureList allowedFeatures = m_data.getAllowedTargetFeatures();
    final Feature target = EditRelationUtils.findNearestFeature(point, grabDistance, allowedFeatures);
    /* Never allow self reference */
    final Feature newTarget = target == sourceFeature ? null : target;

    m_data.setFeatures(sourceFeature, newTarget);

    repaintMap();
}

From source file:gui.ReEditingPopupGraphMousePlugin.java

@SuppressWarnings({ "unchecked", "serial" })
protected void handlePopup(MouseEvent e) {
    final VisualizationViewer<V, E> vv = (VisualizationViewer<V, E>) e.getSource();
    final Layout<V, E> layout = vv.getGraphLayout();
    final Graph<V, E> graph = layout.getGraph();
    final Point2D p = e.getPoint();
    final Point2D ivp = p;
    GraphElementAccessor<V, E> pickSupport = vv.getPickSupport();

    if (pickSupport != null) {
        final V vertex = pickSupport.getVertex(layout, ivp.getX(), ivp.getY());
        final E edge = pickSupport.getEdge(layout, ivp.getX(), ivp.getY());
        final PickedState<V> pickedVertexState = vv.getPickedVertexState();
        final PickedState<E> pickedEdgeState = vv.getPickedEdgeState();

        if (vertex != null) {
            Set<V> picked = pickedVertexState.getPicked();
            if (picked.size() > 0) {
                if (graph instanceof UndirectedGraph == false) {
                    JMenu directedMenu = new JMenu("Create Directed Edge");
                    popup.add(directedMenu);
                    for (final V other : picked) {
                        directedMenu.add(new AbstractAction("[" + other + "," + vertex + "]") {
                            public void actionPerformed(ActionEvent e) {
                                graph.addEdge(edgeFactory.create(), other, vertex, EdgeType.DIRECTED);
                                vv.repaint();
                            }/* w w  w  . j  a  va 2  s.  c  o m*/
                        });
                    }
                }
                if (graph instanceof DirectedGraph == false) {
                    JMenu undirectedMenu = new JMenu("Create Undirected Edge");
                    popup.add(undirectedMenu);
                    for (final V other : picked) {
                        undirectedMenu.add(new AbstractAction("[" + other + "," + vertex + "]") {
                            public void actionPerformed(ActionEvent e) {
                                graph.addEdge(edgeFactory.create(), other, vertex);
                                vv.repaint();
                            }
                        });
                    }
                }
            }
            popup.add(new AbstractAction("Delete TETRA Vertex") {
                public void actionPerformed(ActionEvent e) {
                    pickedVertexState.pick(vertex, false);
                    graph.removeVertex(vertex);
                    vv.repaint();
                }
            });
        } else if (edge != null) {
            popup.add(new AbstractAction("Delete Edge") {
                public void actionPerformed(ActionEvent e) {
                    pickedEdgeState.pick(edge, false);
                    graph.removeEdge(edge);
                    vv.repaint();
                }
            });
        } else {
            popup.add(new AbstractAction("Create TETRA Vertex") {
                public void actionPerformed(ActionEvent e) {
                    V newVertex = vertexFactory.create();
                    graph.addVertex(newVertex);
                    layout.setLocation(newVertex,
                            vv.getRenderContext().getMultiLayerTransformer().inverseTransform(p));
                    vv.repaint();
                }
            });
        }
        if (popup.getComponentCount() > 0) {
            popup.show(vv, e.getX(), e.getY());
        }
    }
}

From source file:nz.govt.natlib.ndha.manualdeposit.bulkupload.BulkUploadPresenter.java

private void tblJobListMouseReleased(final java.awt.event.MouseEvent evt) {
    if (evt.isPopupTrigger()) {
        if (theJobListTable.getSelectedRowCount() == 0) {
            final int row = theJobListTable.rowAtPoint(evt.getPoint());
            if (row > -1) {
                theJobListTable.setRowSelectionInterval(row, row);
            }/*from ww  w . j av a2  s  .  c om*/
        }
        final JPopupMenu menu = bulkUploadManager.getBulkUploadMenu();
        if (menu != null) {
            menu.show(evt.getComponent(), evt.getX(), evt.getY());
        }

    }
}

From source file:nz.govt.natlib.ndha.manualdeposit.bulkupload.BulkUploadPresenter.java

private void tableMouseClicked(final java.awt.event.MouseEvent evt) {
    if (evt.isPopupTrigger()) {
        if (theJobListTable.getSelectedRowCount() == 0) {
            final int row = theJobListTable.rowAtPoint(evt.getPoint());
            if (row > -1) {
                theJobListTable.setRowSelectionInterval(row, row);
            }/*from  w  w  w.  j  a  v a  2  s .c  o  m*/
        }
        final JPopupMenu menu = bulkUploadManager.getBulkUploadMenu();
        if (menu != null) {
            menu.show(evt.getComponent(), evt.getX(), evt.getY());
        }

    }
}

From source file:VGL.SummaryChartUI.java

private void updateDisplay() {
    //find out which buttons have been selected
    ArrayList<Integer> selectedTraits = new ArrayList<Integer>();
    for (int i = 0; i < manager.getTraitSet().length; i++) {
        if (traitCheckBoxes[i].isSelected()) {
            selectedTraits.add(i);//from  w  w  w  . j  av a  2s.  com
        }
    }

    PhenotypeCount[] result = manager.calculateTotals(selectedTraits, sexCheckBox.isSelected());

    String[] columnHeadings = { Messages.getInstance().getString("VGLII.Phenotype"),
            Messages.getInstance().getString("VGLII.Observed"),
            Messages.getInstance().getString("VGLII.Expected") };

    data = new Object[result.length][3];
    for (int i = 0; i < result.length; i++) {
        data[i][0] = Messages.getInstance().translateLongPhenotypeName(result[i].getPhenotype());
        data[i][1] = result[i].getCount();
        data[i][2] = "";
    }

    //if none selected, the "phenotype" is "organism"
    if ((selectedTraits.size() == 0) && !sexCheckBox.isSelected())
        data[0][0] = Messages.getInstance().getString("VGLII.Organism");

    // set width of columns sensibly - find longest one
    int maxPhenoStringLength = 0;
    for (int i = 0; i < result.length; i++) {
        if (data[i][0].toString().length() > maxPhenoStringLength)
            maxPhenoStringLength = data[i][0].toString().length();
    }
    int phenoStringWidth = maxPhenoStringLength * 8;

    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    JTable table = new JTable(new SummaryDataTableModel(data, columnHeadings)) {
        //Implement table header tool tips.
        protected JTableHeader createDefaultTableHeader() {
            return new JTableHeader(columnModel) {
                public String getToolTipText(MouseEvent e) {
                    String tip = null;
                    java.awt.Point p = e.getPoint();
                    int index = columnModel.getColumnIndexAtX(p.x);
                    int realIndex = columnModel.getColumn(index).getModelIndex();
                    return columnToolTips[realIndex];
                }
            };
        }
    };
    table.setGridColor(Color.BLACK);
    table.setShowGrid(true);
    table.getColumnModel().getColumn(0).setPreferredWidth(phenoStringWidth);
    table.getModel().addTableModelListener(this);
    panel.add(table.getTableHeader());
    panel.add(table);
    resultPanel.removeAll();
    resultPanel.add(panel);
    resultPanel.revalidate();
    repaint();
}