List of usage examples for java.awt.event MouseEvent getSource
public Object getSource()
From source file:lu.lippmann.cdb.graph.mouse.CadralEditingGraphMousePlugin.java
/** * {@inheritDoc}/*w ww . jav a 2 s .c om*/ */ @Override public void mousePressed(MouseEvent e) { if (e.getButton() != 3) { //not with left click @SuppressWarnings("unchecked") final VisualizationViewer<CNode, CEdge> vv = (VisualizationViewer<CNode, CEdge>) e.getSource(); final Point2D p = e.getPoint(); final Layout<CNode, CEdge> layout = vv.getModel().getGraphLayout(); final GraphElementAccessor<CNode, CEdge> pickSupport = vv.getPickSupport(); if (pickSupport != null) { final CNode vertex = pickSupport.getVertex(layout, p.getX(), p.getY()); if (vertex == null) { return; } else { //set fields for mouseReleased startVertex = vertex; down = e.getPoint(); vv.addPostRenderPaintable(edgePaintable); vv.addPostRenderPaintable(arrowPaintable); edgeIsDirected = EdgeType.DIRECTED; } } } }
From source file:com.xtructure.xevolution.gui.XEvolutionGui.java
/** * Adds the graph./*from w ww . j a v a 2s . c o m*/ * * @param valueId * the value id * @return the graph */ private Graph addGraph(final XValId<?> valueId) { final Graph g = new Graph(valueId.getBase(), bufferSize, bufferCount); graphsMap.put(valueId, g); g.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getSource() instanceof Graph) { Graph g = (Graph) e.getSource(); int index = g.getHighlightIndex(); if (index >= 0) { tabbedPane.setSelectedIndex(GENERATIONS_INDEX); populationPanel.getComboBox().setSelectedIndex(index); genomePanel.sortBy(valueId); } } } }); // just show the first graph menuBar.addGraphCheckbox(g, graphPanel, graphsMap.size() == 1); genomePanel.addSortByAttributeId(valueId); return g; }
From source file:lu.lippmann.cdb.graph.mouse.CadralGraphMouse.java
/** * {@inheritDoc}/*from w w w . ja va 2 s . co m*/ */ @Override public void mouseReleased(MouseEvent e) { if (mode.equals(Mode.PICKING)) { @SuppressWarnings("unchecked") final VisualizationViewer<CNode, CEdge> vv = (VisualizationViewer<CNode, CEdge>) e.getSource(); final Point2D p = e.getPoint(); final Layout<CNode, CEdge> layout = vv.getModel().getGraphLayout(); final GraphElementAccessor<CNode, CEdge> pickSupport = vv.getPickSupport(); if (pickSupport != null) { final CNode vertex = pickSupport.getVertex(layout, p.getX(), p.getY()); if (vertex != null) { //Check that we moved the selected vertex if (before != null && !layout.transform(vertex).equals(before.get(vertex.getId()))) { boolean needsGroup = (vv.getPickedVertexState().getPicked().size() > 1); if (needsGroup) { graph.startGroupOperation(); } for (CNode picked : vv.getPickedVertexState().getPicked()) { if (before.containsKey(picked.getId())) { graph.moveNodeTo(picked, before.get(picked.getId()), layout.transform(picked)); } } if (needsGroup) { graph.stopGroupOperation(); } } } } } //will call either : // - CadralEditingGraphMousePlugin.mouseReleased(e) // - CadralPickingGraphMousePlugin.mouseReleased(e) //System.out.println("Position : " + e.getPoint()); super.mouseReleased(e); }
From source file:lu.lippmann.cdb.graph.mouse.CadralEditingGraphMousePlugin.java
/** * {@inheritDoc}//from w w w .j av a 2 s .c o m */ @Override public void mouseDragged(MouseEvent e) { if (checkModifiers(e)) { @SuppressWarnings("unchecked") final VisualizationViewer<CNode, CEdge> vv = (VisualizationViewer<CNode, CEdge>) e.getSource(); final Layout<CNode, CEdge> layout = vv.getModel().getGraphLayout(); final GraphElementAccessor<CNode, CEdge> pickSupport = vv.getPickSupport(); if (startVertex != null) { transformEdgeShape(down, e.getPoint()); if (edgeIsDirected == EdgeType.DIRECTED) { transformArrowShape(down, e.getPoint()); final CNode pointedVertex = pickSupport.getVertex(layout, e.getX(), e.getY()); if (pointedVertex != null && pointedVertex != startVertex) { if (!pointedVertices.containsKey(pointedVertex)) { pointedVertices.put(pointedVertex, pointedVertex.getColor()); //save original color } Color prevColor = pointedVertex.getColor(); if (pointedVertex.getColor().equals(pointedVertices.get(pointedVertex))) { if (pointedVertex != this.lastDragVertex && this.lastDragVertex != null) { lastDragVertex.setColor(pointedVertices.get(lastDragVertex)); } //Don't change color if there is an existing edge if (layout.getGraph().findEdge(startVertex, pointedVertex) == null) { if (GraphUtil.isDarkNode(pointedVertex)) { if (prevColor.darker().equals(prevColor)) { pointedVertex.setColor(Color.GRAY); } else { if (prevColor.brighter().equals(prevColor)) { pointedVertex.setColor(Color.GRAY); } else { pointedVertex.setColor(pointedVertices.get(pointedVertex).brighter()); } } } else { pointedVertex.setColor(pointedVertices.get(pointedVertex).darker()); } } } this.lastDragVertex = this.dragVertex; this.dragVertex = pointedVertex; } else if (dragVertex != null) { dragVertex.setColor(pointedVertices.get(dragVertex)); } } } vv.repaint(); } }
From source file:io.github.jeremgamer.editor.panels.Labels.java
public Labels(final JFrame frame, final LabelPanel lp, final PanelSave ps) { this.frame = frame; this.setBorder(BorderFactory.createTitledBorder("")); JButton add = null;/* ww w . ja va 2 s . co m*/ try { add = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("add.png")))); } catch (IOException e) { e.printStackTrace(); } add.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { JOptionPane jop = new JOptionPane(); @SuppressWarnings("static-access") String name = jop.showInputDialog((JFrame) SwingUtilities.windowForComponent(labelList), "Nommez le label :", "Crer un label", JOptionPane.QUESTION_MESSAGE); if (name != null) { for (int i = 0; i < data.getSize(); i++) { if (data.get(i).equals(name)) { name += "1"; } } data.addElement(name); new LabelSave(name); ActionPanel.updateLists(); OtherPanel.updateLists(); PanelsPanel.updateLists(); } } catch (IOException e) { e.printStackTrace(); } } }); JButton remove = null; try { remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); } catch (IOException e) { e.printStackTrace(); } remove.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { if (labelList.getSelectedValue() != null) { File file = new File("projects/" + Editor.getProjectName() + "/labels/" + labelList.getSelectedValue() + ".rbd"); JOptionPane jop = new JOptionPane(); @SuppressWarnings("static-access") int option = jop.showConfirmDialog((JFrame) SwingUtilities.windowForComponent(labelList), "tes-vous sr de vouloir supprimer ce label?", "Avertissement", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (option == JOptionPane.OK_OPTION) { File dir = new File("projects/" + Editor.getProjectName() + "/panels"); for (File f : FileUtils.listFilesAndDirs(dir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) { if (!f.isDirectory()) { try { ps.load(f); } catch (IOException e) { e.printStackTrace(); } for (String section : ps .getSectionsContaining(labelList.getSelectedValue() + " (Label)")) { ps.removeSection(section); try { ps.save(f); } catch (IOException e) { e.printStackTrace(); } } } } if (labelList.getSelectedValue().equals(lp.getFileName())) { lp.setFileName(""); } lp.hide(); file.delete(); data.remove(labelList.getSelectedIndex()); ActionPanel.updateLists(); OtherPanel.updateLists(); PanelsPanel.updateLists(); } } } catch (NullPointerException npe) { npe.printStackTrace(); } } }); JPanel buttons = new JPanel(); buttons.setLayout(new BoxLayout(buttons, BoxLayout.LINE_AXIS)); buttons.add(add); buttons.add(remove); updateList(); labelList.addMouseListener(new MouseAdapter() { @SuppressWarnings("unchecked") public void mouseClicked(MouseEvent evt) { JList<String> list = (JList<String>) evt.getSource(); if (evt.getClickCount() == 2) { int index = list.locationToIndex(evt.getPoint()); if (isOpen == false) { lp.show(); lp.load(new File("projects/" + Editor.getProjectName() + "/labels/" + list.getModel().getElementAt(index) + ".rbd")); previousSelection = list.getSelectedValue(); isOpen = true; } else { try { if (previousSelection.equals(list.getModel().getElementAt(index))) { lp.hide(); previousSelection = list.getSelectedValue(); list.clearSelection(); isOpen = false; } else { lp.hideThenShow(); previousSelection = list.getSelectedValue(); lp.load(new File("projects/" + Editor.getProjectName() + "/labels/" + list.getModel().getElementAt(index) + ".rbd")); } } catch (NullPointerException npe) { lp.hide(); list.clearSelection(); } } } else if (evt.getClickCount() == 3) { int index = list.locationToIndex(evt.getPoint()); if (isOpen == false) { lp.show(); lp.load(new File("projects/" + Editor.getProjectName() + "/labels/" + list.getModel().getElementAt(index) + ".rbd")); previousSelection = list.getSelectedValue(); isOpen = true; } else { try { if (previousSelection.equals(list.getModel().getElementAt(index))) { lp.hide(); previousSelection = list.getSelectedValue(); list.clearSelection(); isOpen = false; } else { lp.hideThenShow(); previousSelection = list.getSelectedValue(); lp.load(new File("projects/" + Editor.getProjectName() + "/labels/" + list.getModel().getElementAt(index) + ".rbd")); } } catch (NullPointerException npe) { lp.hide(); list.clearSelection(); } } } } }); JScrollPane listPane = new JScrollPane(labelList); listPane.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED); this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); this.add(buttons); this.add(listPane); }
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 *///from ww w . j av a 2 s. c o 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:controlador.ControladorReportes.java
@Override public void mouseClicked(MouseEvent e) { if (e.getSource().equals(reportes.getBtnElegir())) { mostrarSelectorReporte();//from w w w.j a va 2 s. c o m } else if (e.getSource().equals(reportes.getBtnActualizar())) { consultarTabla(); } else if (e.getSource().equals(reportes.getBtnPdf())) { generarPdf(); } else if (e.getSource().equals(selectorReporte.getBtnAceptar())) { elegirReporte(); } }
From source file:io.github.jeremgamer.editor.panels.Buttons.java
public Buttons(final JFrame frame, final ButtonPanel be, final PanelSave ps) { this.setBorder(BorderFactory.createTitledBorder("")); this.frame = frame; JButton add = null;// w w w . j av a 2 s . c o m try { add = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("add.png")))); } catch (IOException e) { e.printStackTrace(); } add.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { JOptionPane jop = new JOptionPane(); @SuppressWarnings("static-access") String name = jop.showInputDialog(null, "Nommez le bouton :", "Crer un bouton", JOptionPane.QUESTION_MESSAGE); if (name != null) { for (int i = 0; i < data.getSize(); i++) { if (data.get(i).equals(name)) { name += "1"; } } data.addElement(name); new ButtonSave(name); ActionPanel.updateLists(); OtherPanel.updateLists(); PanelsPanel.updateLists(); } } catch (IOException e) { e.printStackTrace(); } } }); JButton remove = null; try { remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); } catch (IOException e) { e.printStackTrace(); } remove.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { if (buttonList.getSelectedValue() != null) { File file = new File("projects/" + Editor.getProjectName() + "/buttons/" + buttonList.getSelectedValue() + "/" + buttonList.getSelectedValue() + ".rbd"); JOptionPane jop = new JOptionPane(); @SuppressWarnings("static-access") int option = jop.showConfirmDialog(null, "tes-vous sr de vouloir supprimer ce bouton?", "Avertissement", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (option == JOptionPane.OK_OPTION) { File dir = new File("projects/" + Editor.getProjectName() + "/panels"); for (File f : FileUtils.listFilesAndDirs(dir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) { if (!f.isDirectory()) { try { ps.load(f); } catch (IOException e) { e.printStackTrace(); } for (String section : ps .getSectionsContaining(buttonList.getSelectedValue() + " (Bouton)")) { ps.removeSection(section); try { ps.save(f); } catch (IOException e) { e.printStackTrace(); } } } } if (buttonList.getSelectedValue().equals(be.getFileName())) { be.setFileName(""); } be.hide(); file.delete(); File parent = new File(file.getParent()); for (File img : FileUtils.listFiles(parent, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) { img.delete(); } parent.delete(); data.remove(buttonList.getSelectedIndex()); ActionPanel.updateLists(); OtherPanel.updateLists(); PanelsPanel.updateLists(); } } } catch (NullPointerException npe) { npe.printStackTrace(); } } }); JPanel buttons = new JPanel(); buttons.setLayout(new BoxLayout(buttons, BoxLayout.LINE_AXIS)); buttons.add(add); buttons.add(remove); updateList(); buttonList.addMouseListener(new MouseAdapter() { @SuppressWarnings("unchecked") public void mouseClicked(MouseEvent evt) { JList<String> list = (JList<String>) evt.getSource(); if (evt.getClickCount() == 2) { int index = list.locationToIndex(evt.getPoint()); if (isOpen == false) { be.load(new File("projects/" + Editor.getProjectName() + "/buttons/" + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index) + ".rbd")); be.show(); previousSelection = list.getSelectedValue(); isOpen = true; } else { try { if (previousSelection.equals(list.getModel().getElementAt(index))) { be.hide(); previousSelection = list.getSelectedValue(); list.clearSelection(); isOpen = false; } else { be.hideThenShow(); previousSelection = list.getSelectedValue(); be.load(new File("projects/" + Editor.getProjectName() + "/buttons/" + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index) + ".rbd")); } } catch (NullPointerException npe) { be.hide(); list.clearSelection(); } } } else if (evt.getClickCount() == 3) { int index = list.locationToIndex(evt.getPoint()); if (isOpen == false) { be.load(new File("projects/" + Editor.getProjectName() + "/buttons/" + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index) + ".rbd")); be.show(); previousSelection = list.getSelectedValue(); isOpen = true; } else { try { if (previousSelection.equals(list.getModel().getElementAt(index))) { be.hide(); previousSelection = list.getSelectedValue(); list.clearSelection(); isOpen = false; } else { be.hideThenShow(); previousSelection = list.getSelectedValue(); be.load(new File("projects/" + Editor.getProjectName() + "/buttons/" + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index) + ".rbd")); } } catch (NullPointerException npe) { be.hide(); list.clearSelection(); } } } } }); JScrollPane listPane = new JScrollPane(buttonList); listPane.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED); this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); this.add(buttons); this.add(listPane); }
From source file:latexstudio.editor.DropboxRevisionsTopComponent.java
private void jTable1MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MousePressed if (evt.getClickCount() == 2) { // Resolving which row has been double-clicked Point point = evt.getPoint(); JTable table = (JTable) evt.getSource(); int row = table.rowAtPoint(point); // Finding revision using information from the clicked row Object revisionNumber = table.getValueAt(row, REVISION_COLUMN); if (revisionNumber != null) { loadRevision(revisionNumber.toString()); }//from ww w . j ava2 s .c om } }
From source file:fitmon.WorkoutLog.java
private void removeItem(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeItem if (evt.getClickCount() == 1) { JTable target = (JTable) evt.getSource(); int row = target.getSelectedRow(); int column = target.getSelectedColumn(); String selectedwkt = (String) target.getValueAt(row, 0); //int index = selectedwkt.indexOf("--"); // String foodName = selectedFood.substring(0, index); //int calorie = selectedFood.substring(index+2); if (target.getColumnName(target.getSelectedColumn()).equals("Edit")) { DefaultTableModel model = (DefaultTableModel) tab.getModel(); model.removeRow(row);/*from w w w . j av a 2 s . c o m*/ for (int i = 0; i < wkt.size(); i++) { if (wkt.get(i).getWorkout().equals(selectedwkt)) //&& wkt.get(i).getCal().equals(calorie)) { wkt.remove(i); break; } } } // do some action if appropriate column } // TODO add your handling code here: }