List of usage examples for java.awt.event MouseEvent getPoint
public Point getPoint()
From source file:ru.jcorp.smartstreets.gui.map.bundle.GraphEditMousePlugin.java
@SuppressWarnings("unchecked") public void mouseReleased(MouseEvent e) { if (checkModifiers(e)) { editor.clearPath();/* www . j a v a 2 s . c om*/ final VisualizationViewer<GraphNode, GraphLink> vv = (VisualizationViewer<GraphNode, GraphLink>) e .getSource(); final Point2D p = e.getPoint(); Layout<GraphNode, GraphLink> layout = vv.getModel().getGraphLayout(); GraphElementAccessor<GraphNode, GraphLink> pickSupport = vv.getPickSupport(); if (pickSupport != null) { final GraphNode vertex = pickSupport.getVertex(layout, p.getX(), p.getY()); if (vertex != null && startVertex != null) { Graph<GraphNode, GraphLink> graph = vv.getGraphLayout().getGraph(); GraphLink coGraphLink; if (edgeFactory instanceof LinkedLinesFactory) { coGraphLink = ((LinkedLinesFactory) edgeFactory).createLinkedLine(startVertex, vertex); } else { coGraphLink = edgeFactory.create(); } SmartMapLine line = coGraphLink.getMapLine(); if (line.getCodirectionalSign() == null) line.setCodirectionalSign(new RoadSign()); if (line.getOppositelySign() == null) line.setOppositelySign(new RoadSign()); GraphLink opGraphLink = new GraphLink(coGraphLink.getMapLine(), coGraphLink.getMapLine().getOppositelySign()); coGraphLink.setNeighbor(opGraphLink); opGraphLink.setNeighbor(coGraphLink); graph.addEdge(coGraphLink, startVertex, vertex, edgeIsDirected); graph.addEdge(opGraphLink, vertex, startVertex, edgeIsDirected); vv.repaint(); } } startVertex = null; down = null; edgeIsDirected = EdgeType.UNDIRECTED; vv.removePostRenderPaintable(edgePaintable); vv.removePostRenderPaintable(arrowPaintable); } }
From source file:net.panthema.BispanningGame.MyEditingGraphMousePlugin.java
/** * If startVertex is non-null, stretch an edge shape between startVertex and * the mouse pointer to simulate edge creation *//* w w w .j av a 2 s . co m*/ @SuppressWarnings("unchecked") public void mouseDragged(MouseEvent e) { if (checkModifiers(e) || startVertex != null) { if (startVertex != null) { transformEdgeShape(down, e.getPoint()); } VisualizationViewer<V, E> vv = (VisualizationViewer<V, E>) e.getSource(); vv.repaint(); } }
From source file:edu.uci.ics.jung.visualization.VisualizationViewer.java
/** * called by the superclass to display tooltips *//*w w w .j a v a 2s .c o m*/ public String getToolTipText(MouseEvent event) { Layout<V, E> layout = getGraphLayout(); Point2D p = null; if (vertexToolTipTransformer != null) { p = event.getPoint(); //renderContext.getBasicTransformer().inverseViewTransform(event.getPoint()); V vertex = getPickSupport().getVertex(layout, p.getX(), p.getY()); if (vertex != null) { return vertexToolTipTransformer.transform(vertex); } } if (edgeToolTipTransformer != null) { if (p == null) p = renderContext.getMultiLayerTransformer().inverseTransform(Layer.VIEW, event.getPoint()); E edge = getPickSupport().getEdge(layout, p.getX(), p.getY()); if (edge != null) { return edgeToolTipTransformer.transform(edge); } } if (mouseEventToolTipTransformer != null) { return mouseEventToolTipTransformer.transform(event); } return super.getToolTipText(event); }
From source file:SwingGlassExample.java
private void redispatchMouseEvent(MouseEvent e) { boolean inButton = false; boolean inMenuBar = false; Point glassPanePoint = e.getPoint(); Component component = null;// w w w . ja v a2s . c o m Container container = contentPane; Point containerPoint = SwingUtilities.convertPoint(this, glassPanePoint, contentPane); int eventID = e.getID(); if (containerPoint.y < 0) { inMenuBar = true; container = menuBar; containerPoint = SwingUtilities.convertPoint(this, glassPanePoint, menuBar); testForDrag(eventID); } //XXX: If the event is from a component in a popped-up menu, //XXX: then the container should probably be the menu's //XXX: JPopupMenu, and containerPoint should be adjusted //XXX: accordingly. component = SwingUtilities.getDeepestComponentAt(container, containerPoint.x, containerPoint.y); if (component == null) { return; } else { inButton = true; testForDrag(eventID); } if (inMenuBar || inButton || inDrag) { Point componentPoint = SwingUtilities.convertPoint(this, glassPanePoint, component); component.dispatchEvent(new MouseEvent(component, eventID, e.getWhen(), e.getModifiers(), componentPoint.x, componentPoint.y, e.getClickCount(), e.isPopupTrigger())); } }
From source file:org.kalypso.kalypsomodel1d2d.ui.map.channeledit.DrawBanklineWidget.java
@Override public void mouseDragged(final MouseEvent event) { if (m_edit && m_bankline != null) m_lineEditor.dragged(event.getPoint(), getMapPanel()); }
From source file:org.apache.cayenne.swing.components.textpane.JCayenneTextPane.java
public String getToolTipText(MouseEvent e) { if (e.getPoint().y > endYPositionToolTip && e.getPoint().y < startYPositionToolTip && imageError) { setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); String htmlText = getTooltipTextError().replaceAll("\n", "<br> ").replaceAll("\t", " ") .replaceAll("\r", "<br> "); return "<HTML>" + "<body bgcolor='#FFEBCD' text='black'>" + htmlText + "</body>"; } else {/*from w ww.j a v a 2 s .c o m*/ setCursor(Cursor.getDefaultCursor()); return null; } }
From source file:org.pmedv.blackboard.components.PartView.java
private void handlePopupTrigger(MouseEvent e) { if (e.isPopupTrigger() && model.getParts().size() >= 1) { Point p = e.getPoint(); // get the row index that contains that coordinate int rowNumber = partPanel.getPartTable().rowAtPoint(p); // Get the ListSelectionModel of the JTable ListSelectionModel model = partPanel.getPartTable().getSelectionModel(); // set the selected interval of rows. Using the "rowNumber" // variable for the beginning and end selects only that one row. model.setSelectionInterval(rowNumber, rowNumber); tablePopupMenu.show(e.getComponent(), e.getX(), e.getY()); }/*from www . j a v a 2s . c om*/ }
From source file:ToggleSample.java
private void init() { updateUI();//from w w w .j a va 2 s .c o m setRequestFocusEnabled(false); // Borrows heavily from BasicMenuUI MouseInputListener mouseInputListener = new MouseInputListener() { // If mouse released over this menu item, activate it public void mouseReleased(MouseEvent mouseEvent) { MenuSelectionManager menuSelectionManager = MenuSelectionManager.defaultManager(); Point point = mouseEvent.getPoint(); if ((point.x >= 0) && (point.x < getWidth()) && (point.y >= 0) && (point.y < getHeight())) { menuSelectionManager.clearSelectedPath(); // component automatically handles "selection" at this point // doClick(0); // not necessary } else { menuSelectionManager.processMouseEvent(mouseEvent); } } // If mouse moves over menu item, add to selection path, so it // becomes armed public void mouseEntered(MouseEvent mouseEvent) { MenuSelectionManager menuSelectionManager = MenuSelectionManager.defaultManager(); menuSelectionManager.setSelectedPath(getPath()); } // When mouse moves away from menu item, disaarm it and select // something else public void mouseExited(MouseEvent mouseEvent) { MenuSelectionManager menuSelectionManager = MenuSelectionManager.defaultManager(); MenuElement path[] = menuSelectionManager.getSelectedPath(); if (path.length > 1) { MenuElement newPath[] = new MenuElement[path.length - 1]; for (int i = 0, c = path.length - 1; i < c; i++) { newPath[i] = path[i]; } menuSelectionManager.setSelectedPath(newPath); } } // Pass along drag events public void mouseDragged(MouseEvent mouseEvent) { MenuSelectionManager.defaultManager().processMouseEvent(mouseEvent); } public void mouseClicked(MouseEvent mouseEvent) { } public void mousePressed(MouseEvent mouseEvent) { } public void mouseMoved(MouseEvent mouseEvent) { } }; addMouseListener(mouseInputListener); addMouseMotionListener(mouseInputListener); }
From source file:de.tntinteractive.portalsammler.gui.DocumentTable.java
public DocumentTable(final Gui gui, final SecureStore store) { this.gui = gui; this.store = store; this.table = new JTable(); this.table.setRowSelectionAllowed(true); this.refreshContents(); this.table.addMouseListener(new MouseAdapter() { @Override/*from w ww .j a va 2s. com*/ public void mousePressed(final MouseEvent me) { final int r = DocumentTable.this.table.rowAtPoint(me.getPoint()); if (!DocumentTable.this.table.getSelectionModel().isSelectedIndex(r)) { if (r >= 0 && r < DocumentTable.this.table.getRowCount()) { DocumentTable.this.table.setRowSelectionInterval(r, r); } else { DocumentTable.this.table.clearSelection(); } } if (me.isPopupTrigger()) { DocumentTable.this.showPopup(me); } else if (me.getClickCount() == 2) { DocumentTable.this.openSelectedRows(); } } @Override public void mouseReleased(final MouseEvent me) { if (me.isPopupTrigger()) { DocumentTable.this.showPopup(me); } } }); this.table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); this.table.getColumnModel().getColumn(0).setPreferredWidth(120); this.table.getColumnModel().getColumn(1).setPreferredWidth(80); this.table.getColumnModel().getColumn(2).setPreferredWidth(100); this.table.getColumnModel().getColumn(3).setPreferredWidth(500); }
From source file:com.att.aro.ui.model.ImageBPTable.java
/** * Returns a default table header for the DataTable. * //w w w . j a v a 2s.co m * @return A JTableHeader object with default properties. */ @Override public JTableHeader createDefaultTableHeader() { return new JTableHeader(columnModel) { private static final long serialVersionUID = 1L; @Override public String getToolTipText(MouseEvent mEvent) { int column = columnAtPoint(mEvent.getPoint()); // Locate the renderer under the event location if (column != -1) { TableColumn aColumn = columnModel.getColumn(column); Object tip = aColumn.getHeaderValue(); if (tip != null) { return tip.toString(); } } return null; } }; }