List of usage examples for java.awt.event MouseEvent getSource
public Object getSource()
From source file:com.choicemaker.cm.modelmaker.gui.panels.HoldVsAccuracyPlotPanel.java
private void buildPanel() { XYSeriesCollection dataset = new XYSeriesCollection(); String title = ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.holdvsacc.title"); data = new XYSeries(title); dataset.addSeries(data);//from w w w . j a v a 2 s .c o m final PlotOrientation orientation = PlotOrientation.VERTICAL; chart = ChartFactory.createXYLineChart(title, ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.holdvsacc.cm.accuracy"), ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.holdvsacc.holdpercentage"), dataset, orientation, true, true, true); MouseListener tableMouseListener = new MouseAdapter() { public void mousePressed(MouseEvent e) { Point origin = e.getPoint(); JTable src = (JTable) e.getSource(); int row = src.rowAtPoint(origin); int col = src.columnAtPoint(origin); ModelMaker mm = parent.getModelMaker(); if (src == accuracyTable) { if (col < 2) { if (!Float.isNaN(accuracyData[row][2]) && !Float.isNaN(accuracyData[row][3])) mm.setThresholds(new Thresholds(accuracyData[row][2], accuracyData[row][3])); } else if (col == 2) { if (!Float.isNaN(accuracyData[row][2])) mm.setDifferThreshold(accuracyData[row][2]); } else { if (!Float.isNaN(accuracyData[row][3])) mm.setMatchThreshold(accuracyData[row][3]); } } else { if (col < 2) { if (!Float.isNaN(hrData[row][2]) && !Float.isNaN(hrData[row][3])) mm.setThresholds(new Thresholds(hrData[row][2], hrData[row][3])); } else if (col == 2) { if (!Float.isNaN(hrData[row][2])) mm.setDifferThreshold(hrData[row][2]); } else { if (!Float.isNaN(hrData[row][3])) mm.setMatchThreshold(hrData[row][3]); } } } }; chart.setBackgroundPaint(getBackground()); accuracyTable = new AccuracyTable(true, accuracies); accuracyTable.addMouseListener(tableMouseListener); accuracyPanel = getPanel(accuracyTable, ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.holdvsacc.table.hrvsacc")); hrTable = new AccuracyTable(false, hrs); hrTable.addMouseListener(tableMouseListener); hrPanel = getPanel(hrTable, ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.holdvsacc.table.accvshr")); accuracyTable.setEnabled(false); hrTable.setEnabled(false); }
From source file:ru.jcorp.smartstreets.gui.map.bundle.GraphPopupMousePlugin.java
@Override protected void handlePopup(MouseEvent e) { // noinspection unchecked final VisualizationViewer<GraphNode, GraphLink> viewer = (VisualizationViewer<GraphNode, GraphLink>) e .getSource();/*ww w . ja va 2 s . co m*/ final Layout<GraphNode, GraphLink> layout = viewer.getGraphLayout(); final Graph<GraphNode, GraphLink> graph = layout.getGraph(); final Point2D p = e.getPoint(); final SmartStreetsApp app = SmartStreetsApp.getInstance(); GraphElementAccessor<GraphNode, GraphLink> pickSupport = viewer.getPickSupport(); if (pickSupport != null) { popup.removeAll(); final GraphNode vertex = pickSupport.getVertex(layout, p.getX(), p.getY()); final GraphLink edge = pickSupport.getEdge(layout, p.getX(), p.getY()); final PickedState<GraphNode> pickedVertexState = viewer.getPickedVertexState(); final PickedState<GraphLink> pickedEdgeState = viewer.getPickedEdgeState(); if (vertex != null) { popup.add(new JMenuItem(new AbstractAction(app.getMessage("edit.setSource")) { @Override public void actionPerformed(ActionEvent e) { SmartMapNode mapNode = vertex.getMapNode(); editor.setSourceNode(mapNode); } })); popup.add(new JMenuItem(new AbstractAction(app.getMessage("edit.setDest")) { @Override public void actionPerformed(ActionEvent e) { SmartMapNode mapNode = vertex.getMapNode(); editor.setDestNode(mapNode); } })); popup.add(new JMenuItem(new AbstractAction(app.getMessage("edit.properties")) { @Override public void actionPerformed(ActionEvent e) { SmartMapNode mapNode = vertex.getMapNode(); NodeEditor nodeEditor = new NodeEditor(mapNode); nodeEditor.setLocationRelativeTo(editor); nodeEditor.setVisible(true); editor.clearPathSheduled(); viewer.repaint(); } })); popup.add(new AbstractAction(app.getMessage("graph.deleteVertex")) { @Override public void actionPerformed(ActionEvent e) { editor.clearPathSheduled(); pickedVertexState.pick(vertex, false); graph.removeVertex(vertex); editor.getMapContext().removeNode(vertex.getMapNode()); viewer.repaint(); } }); } else if (edge != null) { popup.add(new JMenuItem(new AbstractAction(app.getMessage("edit.properties")) { @Override public void actionPerformed(ActionEvent e) { SmartMapLine mapLine = edge.getMapLine(); LineEditor lineEditor = new LineEditor(mapLine, edge.getRoadSign()); lineEditor.setLocationRelativeTo(editor); lineEditor.setVisible(true); editor.clearPathSheduled(); viewer.repaint(); } })); popup.add(new AbstractAction(app.getMessage("graph.deleteEdge")) { @Override public void actionPerformed(ActionEvent e) { editor.clearPathSheduled(); pickedEdgeState.pick(edge, false); graph.removeEdge(edge); graph.removeEdge(edge.getNeighbor()); editor.getMapContext().removeLine(edge.getMapLine()); viewer.repaint(); } }); } else { popup.add(new AbstractAction(app.getMessage("graph.createVertex")) { @Override public void actionPerformed(ActionEvent e) { editor.clearPathSheduled(); GraphNode newVertex = vertexFactory.create(); graph.addVertex(newVertex); layout.setLocation(newVertex, viewer.getRenderContext().getMultiLayerTransformer().inverseTransform(p)); viewer.repaint(); } }); } if (popup.getComponentCount() > 0) { popup.show(viewer, e.getX(), e.getY()); } } }
From source file:lu.lippmann.cdb.graph.mouse.CadralEditingGraphMousePlugin.java
/** * When we are editing the graph : publish an event to select the node if * we right click on an existing node (to edit its properties) *///from w w w . ja v a 2 s . com @SuppressWarnings("unchecked") @Override public void mouseClicked(MouseEvent e) { if (e.getButton() == 3) { //right click 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) { commandDispatcher.dispatch(new SelectNodeCommand(vertex, 2)); } else { final CEdge edge = pickSupport.getEdge(layout, p.getX(), p.getY()); if (edge != null) { commandDispatcher.dispatch(new SelectEdgeCommand(edge, 2)); } } } } }
From source file:org.broad.igv.ui.panel.PanTool.java
public void mouseReleased(final MouseEvent e) { if (isDragging) { isDragging = false;/*from w w w . j ava 2 s. co m*/ lastDragEventTime = 0; getReferenceFame().dragStopped(); } Component panel = (Component) e.getSource(); panel.setCursor(getCursor()); }
From source file:gui.SpamPanel.java
public void generate() { Message[] arrMsg = GmailAPI.Spam.toArray(new Message[GmailAPI.Spam.size()]); SpamList = new JList(arrMsg); SpamList.setCellRenderer(new DefaultListCellRenderer() { // Setting the DefaultListCellRenderer public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Message message = (Message) value; // Using value we are getting the object in JList Map<String, String> map = null; try { map = GmailAPI.getMessageDetails(message.getId()); } catch (MessagingException ex) { Logger.getLogger(SpamPanel.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(SpamPanel.class.getName()).log(Level.SEVERE, null, ex); }/*from w w w .ja v a 2 s . c o m*/ String sub = map.get("subject"); if (map.get("subject").length() > 22) { sub = map.get("subject").substring(0, 20) + "..."; } setText(sub); // Setting the text //setIcon( shape.getImage() ); // Setting the Image Icon return this; } }); SpamList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); SpamList.setLayoutOrientation(JList.VERTICAL); SpamList.setVisibleRowCount(-1); jScrollPane1.setViewportView(SpamList); SpamList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { try { JList list = (JList) evt.getSource(); int index = list.locationToIndex(evt.getPoint()); String id = arrMsg[index].getId(); Map<String, String> map = GmailAPI.getMessageDetails(id); jTextField1.setText(map.get("from")); jTextField2.setText(map.get("subject")); dateTextField.setText(map.get("senddate")); BodyTextPane.setText(map.get("body")); BodyTextPane.setContentType("text/html"); //BodyTextArea.setCo } catch (IOException ex) { Logger.getLogger(SpamPanel.class.getName()).log(Level.SEVERE, null, ex); } catch (MessagingException ex) { Logger.getLogger(SpamPanel.class.getName()).log(Level.SEVERE, null, ex); } } }); }
From source file:net.bioclipse.model.ScatterPlotMouseHandler.java
private ChartPanel getChartPanel(MouseEvent me) { Point2D p = null;/*from www . j av a 2 s . c om*/ Frame sourceFrame; ChartPanel selectedPanel = null; if (me.getSource() instanceof Frame) { sourceFrame = (Frame) me.getSource(); Component[] components = sourceFrame.getComponents(); boolean foundChartPanel = false; for (Component component : components) { if (component instanceof ChartPanel) { selectedPanel = (ChartPanel) component; // selectedChart = chartPanel.getChart(); foundChartPanel = true; break; } } assert foundChartPanel : "The source Frame of the event does not contain a ChartPanel"; } else if (me.getSource() instanceof ChartPanel) { selectedPanel = (ChartPanel) me.getSource(); } else { //Can't throw checked exception because the methods that use getChart doesn't throw Exception in their signatures throw new RuntimeException("The source of any mouse event on ScatterPlotMouseHandler should" + " be either Frame or ChartPanel"); } return selectedPanel; }
From source file:edu.scripps.fl.pubchem.xmltool.gui.PubChemXMLCreatorGUI.java
public void mouseClicked(MouseEvent e) { try {/*from w ww .java2 s .c o m*/ if (e.getClickCount() > 0) { setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); if (e.getSource() == jtpExample) { URL url = getClass().getClassLoader().getResource("ExampleExcel.xlsx"); File tmpFile = File.createTempFile("example", ".xlsx"); FileUtils.copyURLToFile(url, tmpFile); tmpFile.deleteOnExit(); Desktop.getDesktop().open(tmpFile); } else if (e.getSource() == jtpExcelTemplate) { File saveFile = gc.fileChooser(jtfFileExcel, ".xlsx", "save"); if (saveFile != null) { URL url = getClass().getClassLoader().getResource("ExcelTemplate_withBAO.xlsx"); OutputStream out = new FileOutputStream(saveFile, true); IOUtils.copy(url.openStream(), out); String output = FilenameUtils.concat(FilenameUtils.getFullPath(saveFile.toString()), FilenameUtils.getBaseName(saveFile.toString())); Desktop.getDesktop().open(new File(saveFile.toString())); } } else if (e.getSource() == jtfFileTemplate && jtfFileTemplate.getText().equals(template)) { jtfFileTemplate.setText(""); } else if (e.getSource() == this) { if (jtfFileTemplate.getText().equals("")) { jtfFileTemplate.setText(template); } } } setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } catch (Throwable throwable) { SwingGUI.handleError(this, throwable); } }
From source file:de.tor.tribes.ui.components.DatePicker.java
private void dayClicked(MouseEvent mvt) { CrossedLabel evtSrc = (CrossedLabel) mvt.getSource(); for (int i = 0; i < WEEKS_TO_SHOW * 7; i++) { if (evtSrc.equals(daysInMonth[i / 7][i % 7])) { selectedDate = datesInMonth[i / 7][i % 7]; break; }//from w w w . java2 s. co m } buildCalendar(); }
From source file:io.github.jeremgamer.editor.panels.Actions.java
public Actions(final JFrame frame, final ActionPanel ap) { this.frame = frame; this.setBorder(BorderFactory.createTitledBorder("")); JButton add = null;/*from w w w . j a va 2s .c om*/ 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 l'action :", "Crer une action", 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 ActionSave(name); OtherPanel.updateLists(); ButtonPanel.updateLists(); ActionPanel.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 (actionList.getSelectedValue() != null) { File file = new File("projects/" + Editor.getProjectName() + "/actions/" + actionList.getSelectedValue() + ".rbd"); JOptionPane jop = new JOptionPane(); @SuppressWarnings("static-access") int option = jop.showConfirmDialog(null, "tes-vous sr de vouloir supprimer cette action?", "Avertissement", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (option == JOptionPane.OK_OPTION) { if (actionList.getSelectedValue().equals(ap.getFileName())) { ap.setFileName(""); } ap.hide(); file.delete(); data.remove(actionList.getSelectedIndex()); OtherPanel.updateLists(); ButtonPanel.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(); actionList.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) { ap.show(); ap.load(new File("projects/" + Editor.getProjectName() + "/actions/" + list.getModel().getElementAt(index) + ".rbd")); previousSelection = list.getSelectedValue(); isOpen = true; } else { try { if (previousSelection.equals(list.getModel().getElementAt(index))) { ap.hide(); previousSelection = list.getSelectedValue(); list.clearSelection(); isOpen = false; } else { ap.hideThenShow(); previousSelection = list.getSelectedValue(); ap.load(new File("projects/" + Editor.getProjectName() + "/actions/" + list.getModel().getElementAt(index) + ".rbd")); } } catch (NullPointerException npe) { ap.hide(); list.clearSelection(); } } } else if (evt.getClickCount() == 3) { int index = list.locationToIndex(evt.getPoint()); if (isOpen == false) { ap.show(); ap.load(new File("projects/" + Editor.getProjectName() + "/actions/" + list.getModel().getElementAt(index) + ".rbd")); previousSelection = list.getSelectedValue(); isOpen = true; } else { try { if (previousSelection.equals(list.getModel().getElementAt(index))) { ap.hide(); previousSelection = list.getSelectedValue(); list.clearSelection(); isOpen = false; } else { ap.hideThenShow(); previousSelection = list.getSelectedValue(); ap.load(new File("projects/" + Editor.getProjectName() + "/actions/" + list.getModel().getElementAt(index) + ".rbd")); } } catch (NullPointerException npe) { ap.hide(); list.clearSelection(); } } } } }); JScrollPane listPane = new JScrollPane(actionList); listPane.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED); this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); this.add(buttons); this.add(listPane); OtherPanel.updateLists(); }
From source file:fitmon.WorkoutLog.java
private void removeItem(java.awt.event.MouseEvent evt) { 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 ww w. ja va2 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: }