List of usage examples for java.awt.event MouseEvent getSource
public Object getSource()
From source file:ru.jcorp.smartstreets.gui.map.bundle.GraphEditMousePlugin.java
@SuppressWarnings("unchecked") public void mouseReleased(MouseEvent e) { if (checkModifiers(e)) { editor.clearPath();/* w ww .j a v a2 s. c o m*/ 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:org.fhcrc.cpl.viewer.mrm.utilities.MRMerMouseListener.java
public void mouseClicked(MouseEvent e) { if (e.getSource() instanceof ChartPanel && ((e.getButton() == MouseEvent.BUTTON2) || (e.getButton() == MouseEvent.BUTTON1) && ((e.getModifiers() & InputEvent.CTRL_MASK) != 0))) { CenterZoomNumberAxis czna = (CenterZoomNumberAxis) _cp.getChart().getXYPlot().getDomainAxis(); NumberAxis range = (NumberAxis) _cp.getChart().getXYPlot().getRangeAxis(); Rectangle2D screenDataArea = _cp.getScreenDataArea(e.getX(), e.getY()); double y1 = czna.getLowerBound(); double y2 = czna.getUpperBound(); double x1 = screenDataArea.getX(); double x2 = x1 + screenDataArea.getWidth(); double transformedx = (((y2 - y1) / (x2 - x1)) * (e.getX() - x1)) + y1; MRMDialog mrmd = (MRMDialog) MRMAncestor(); PeaksTableModel model = (PeaksTableModel) mrmd.peaksTable.getModel(); MRMTransition mrt = mrmd.transitionOnPlot; mrt.setCalcXatMaxYAllDaughters(transformedx); mrt.setCalcMaxYAllDaughters(// ww w . j av a 2 s. c o m range.getLowerBound() + 0.95 * (range.getUpperBound() - range.getLowerBound())); model.setValueAt(new Float(mrt.getCalcXatMaxYAllDaughters()), mrt.getTableRow(), MRMDialog.peaksData.MidTime.colno); for (MRMDaughter d : mrt.getDaughters().values()) { model.setValueAt(new Float(mrt.getCalcXatMaxYAllDaughters()), d.getElutionDataTableRow(), MRMDialog.peaksData.MidTime.colno); } mrmd.updateChartsAndFields(false); } if ((e.isShiftDown() || e.getButton() == MouseEvent.BUTTON3) || shifted) { _cp.mouseClicked(e); } else { _cp.mouseClicked(e); } }
From source file:com.intel.stl.ui.common.view.ComponentFactory.java
public static SafeNumberField<Integer> createNumericTextField(Integer max, DocumentListener... docListeners) { final SafeNumberField<Integer> field = new SafeNumberField<Integer>(new DecimalFormat("###"), 0, false, max, false);//from w ww . j av a 2 s .c om // only positive integer field.setValidChars(UIConstants.DIGITS); if (docListeners != null) { for (DocumentListener docListener : docListeners) { field.getDocument().addDocumentListener(docListener); } } // Add a mouse listener to clear out the field before the user types field.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { try { JTextComponent tc = (JTextComponent) e.getSource(); String txt = tc.getText(); if (!txt.isEmpty()) { field.getFormatter().stringToValue(txt); } } catch (Exception ex) { field.setText(""); } } }); return field; }
From source file:edu.uci.ics.jung.visualization.control.LabelEditingGraphMousePlugin.java
/** * For primary modifiers (default, MouseButton1): * pick a single Vertex or Edge that// w ww .jav a 2s .c o m * is under the mouse pointer. If no Vertex or edge is under * the pointer, unselect all picked Vertices and edges, and * set up to draw a rectangle for multiple selection * of contained Vertices. * For additional selection (default Shift+MouseButton1): * Add to the selection, a single Vertex or Edge that is * under the mouse pointer. If a previously picked Vertex * or Edge is under the pointer, it is un-picked. * If no vertex or Edge is under the pointer, set up * to draw a multiple selection rectangle (as above) * but do not unpick previously picked elements. * * @param e the event */ @SuppressWarnings("unchecked") public void mouseClicked(MouseEvent e) { if (e.getModifiers() == modifiers && e.getClickCount() == 2) { VisualizationViewer<V, E> vv = (VisualizationViewer) e.getSource(); GraphElementAccessor<V, E> pickSupport = vv.getPickSupport(); if (pickSupport != null) { Transformer<V, String> vs = vv.getRenderContext().getVertexLabelTransformer(); if (vs instanceof MapTransformer) { Map<V, String> map = ((MapTransformer) vs).getMap(); Layout<V, E> layout = vv.getGraphLayout(); // p is the screen point for the mouse event Point2D p = e.getPoint(); V vertex = pickSupport.getVertex(layout, p.getX(), p.getY()); if (vertex != null) { String newLabel = vs.transform(vertex); newLabel = JOptionPane.showInputDialog("New Vertex Label for " + vertex); if (newLabel != null) { map.put(vertex, newLabel); vv.repaint(); } return; } } Transformer<E, String> es = vv.getRenderContext().getEdgeLabelTransformer(); if (es instanceof MapTransformer) { Map<E, String> map = ((MapTransformer) es).getMap(); Layout<V, E> layout = vv.getGraphLayout(); // p is the screen point for the mouse event Point2D p = e.getPoint(); // take away the view transform Point2D ip = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(Layer.VIEW, p); E edge = pickSupport.getEdge(layout, ip.getX(), ip.getY()); if (edge != null) { String newLabel = JOptionPane.showInputDialog("New Edge Label for " + edge); if (newLabel != null) { map.put(edge, newLabel); vv.repaint(); } return; } } } e.consume(); } }
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 ww. j a v a2s . co m } table.setColumnSelectionInterval(index, index); } }); }
From source file:gdt.jgui.tool.JIconSelector.java
/** * Create the context./*from w ww . j a va 2s. c om*/ * @param console the main console. * @param locator$ the locator string. * @return the procedure context. */ @Override public JContext instantiate(JMainConsole console, String locator$) { this.console = console; try { panel.removeAll(); Properties locator = Locator.toProperties(locator$); entihome$ = locator.getProperty(Entigrator.ENTIHOME); entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY); entityLabel$ = locator.getProperty(EntityHandler.ENTITY_LABEL); requesterResponseLocator$ = locator.getProperty(JRequester.REQUESTER_RESPONSE_LOCATOR); // System.out.println("IconSelector:instantiate:locator="+locator$); Entigrator entigrator = console.getEntigrator(entihome$); String icons$ = entigrator.ent_getHome(Entigrator.ICONS); File icons = new File(icons$); File[] fa = icons.listFiles(); if (fa == null) return this; ImageIcon icon; JLabel label; Image img; for (File aFa : fa) { icon = new ImageIcon(aFa.getPath()); img = icon.getImage(); img = img.getScaledInstance(smallIcon, smallIcon, java.awt.Image.SCALE_SMOOTH); icon = new ImageIcon(img); label = new JLabel(); label.setIcon(icon); label.setName(aFa.getName()); label.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent me) { try { JLabel label = (JLabel) me.getSource(); icon$ = label.getName(); byte[] ba = Base64.decodeBase64(requesterResponseLocator$); String responseLocator$ = new String(ba, "UTF-8"); responseLocator$ = Locator.append(responseLocator$, ICON, icon$); JConsoleHandler.execute(JIconSelector.this.console, responseLocator$); } catch (Exception ee) { LOGGER.severe(ee.toString()); } } }); panel.add(label); } } catch (Exception e) { LOGGER.severe(e.toString()); } return this; }
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.// w ww .j a v a2 s. c om */ @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: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/*from ww w.ja v a2s .co m*/ */ @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:picocash.components.mode.buttons.ModeButton.java
private void init() { setLayout(new MigLayout("fill")); add(iconLabel);/*from w w w. j ava 2 s . c om*/ add(nameLabel, "push"); add(minimizeLabel); minimizeLabel.setIcon(PicocashIcons.getSystemIcon("minimize-dark")); addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { JPopupMenu popupMenu = new JPopupMenu(); fillPopupMenu(popupMenu); Dimension dimension = getSize(); popupMenu.setSize(dimension.width, popupMenu.getHeight()); popupMenu.show((Component) arg0.getSource(), -1, dimension.height + 3); } }); }
From source file:de.ep3.ftpc.controller.portal.CrawlerDownloadController.java
@Override public void mouseClicked(MouseEvent e) { CrawlerResultsItem.PreviewPanel previewPanel = (CrawlerResultsItem.PreviewPanel) e.getSource(); CrawlerResult crawlerResult = previewPanel.getCrawlerResult(); CrawlerFile crawlerFile = crawlerResult.getFile(); FTPClient ftpClient = crawlerResult.getFtpClient(); if (ftpClient.isConnected()) { JOptionPane.showMessageDialog(portalFrame, i18n.translate("crawlerDownloadWhileConnected"), null, JOptionPane.ERROR_MESSAGE); return;//from www. j av a 2s . com } String fileExtension = crawlerFile.getExtension(); JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter chooserFilter = new FileNameExtensionFilter( i18n.translate("fileType", fileExtension.toUpperCase()), crawlerFile.getExtension()); chooser.setApproveButtonText(i18n.translate("buttonSave")); chooser.setDialogTitle(i18n.translate("fileDownloadTo")); chooser.setDialogType(JFileChooser.SAVE_DIALOG); chooser.setFileFilter(chooserFilter); chooser.setSelectedFile(new File(crawlerFile.getName())); int selection = chooser.showSaveDialog(portalFrame); if (selection == JFileChooser.APPROVE_OPTION) { File fileToSave = chooser.getSelectedFile(); Server relatedServer = crawlerResult.getServer(); try { ftpClient.connect(relatedServer.need("server.ip"), Integer.parseInt(relatedServer.need("server.port"))); int replyCode = ftpClient.getReplyCode(); if (!FTPReply.isPositiveCompletion(replyCode)) { throw new IOException(i18n.translate("crawlerServerRefused")); } if (relatedServer.has("user.name")) { String userName = relatedServer.get("user.name"); String userPassword = ""; if (relatedServer.hasTemporary("user.password")) { userPassword = relatedServer.getTemporary("user.password"); } boolean loggedIn = ftpClient.login(userName, userPassword); if (!loggedIn) { throw new IOException(i18n.translate("crawlerServerAuthFail")); } } ftpClient.setFileType(FTP.BINARY_FILE_TYPE); /* Download file */ InputStream is = ftpClient.retrieveFileStream(crawlerFile.getFullName()); if (is != null) { byte[] rawFile = new byte[(int) crawlerFile.getSize()]; int i = 0; while (true) { int b = is.read(); if (b == -1) { break; } rawFile[i] = (byte) b; i++; /* Occasionally update the download progress */ if (i % 1024 == 0) { int progress = Math.round((((float) i) / crawlerFile.getSize()) * 100); status.add(i18n.translate("crawlerDownloadProgress", progress)); } } is.close(); is = null; if (!ftpClient.completePendingCommand()) { throw new IOException(); } Files.write(fileToSave.toPath(), rawFile); } /* Logout and disconnect */ ftpClient.logout(); tryDisconnect(ftpClient); status.add(i18n.translate("crawlerDownloadDone")); } catch (IOException ex) { tryDisconnect(ftpClient); JOptionPane.showMessageDialog(portalFrame, i18n.translate("crawlerDownloadFailed", ex.getMessage()), null, JOptionPane.ERROR_MESSAGE); } } }