List of usage examples for java.awt.event MouseEvent getX
public int getX()
From source file:ucar.unidata.idv.control.chart.ChartHolder.java
/** * show popup/*from w ww . ja v a 2 s. c o m*/ * * @param event event */ private void showPopupMenu(MouseEvent event) { List items = new ArrayList(); getMenuItems(items); JPopupMenu popupMenu = GuiUtils.makePopupMenu(items); popupMenu.show(chartPanel, event.getX(), event.getY()); }
From source file:pipeline.parameter_cell_views.FloatRangeSlider.java
/** * Translates MouseEvent screen coordinates to coordinates in chart units * /*from www.j av a 2s. c o m*/ * @param e * MouseEvent containing coordinates of interest * @return Chart coordinates (evaluated as double) */ private @Nullable Point2D getChartCoordinates(MouseEvent e) { if (chartPanel.getChartRenderingInfo().getChartArea().getHeight() == 0) { Utils.log("Cannot translate to chart coordinates", LogLevel.DEBUG); return null; } int mouseX = e.getX(); int mouseY = e.getY(); Utils.log("x = " + mouseX + ", y = " + mouseY, LogLevel.DEBUG); Point2D p = chartPanel.translateScreenToJava2D(new Point(mouseX, mouseY)); XYPlot plot = (XYPlot) chart.getPlot(); Rectangle2D plotArea = this.chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea(); ValueAxis domainAxis = plot.getDomainAxis(); RectangleEdge domainAxisEdge = plot.getDomainAxisEdge(); ValueAxis rangeAxis = plot.getRangeAxis(); RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge(); double chartX = domainAxis.java2DToValue(p.getX(), plotArea, domainAxisEdge); double chartY = rangeAxis.java2DToValue(p.getY(), plotArea, rangeAxisEdge); return new Point2D.Double(chartX, chartY); }
From source file:canreg.client.gui.analysis.FrequenciesByYearInternalFrame.java
/** * * @param offset/* ww w . ja va2 s . c om*/ * @param evt */ public void showPopUpMenu(int offset, java.awt.event.MouseEvent evt) { JTable target = (JTable) evt.getSource(); int rowNumber = target.rowAtPoint(new Point(evt.getX(), evt.getY())); rowNumber = target.convertRowIndexToModel(rowNumber); JPopupMenu jpm = new JPopupMenu(); jpm.add(java.util.ResourceBundle .getBundle("canreg/client/gui/analysis/resources/FrequenciesByYearInternalFrame") .getString("SHOW_IN_BROWSER")); TableModel tableModel = target.getModel(); // resultTable.get // jpm.add("Column " + rowNumber +" " + tableColumnModel.getColumn(tableColumnModel.getColumnIndexAtX(evt.getX())).getHeaderValue()); int year = Integer.parseInt((String) tableModel.getValueAt(rowNumber, 0)); String filterString = "INCID >= '" + year * 10000 + "' AND INCID <'" + (year + 1) * 10000 + "'"; for (DatabaseVariablesListElement dvle : chosenVariables) { int columnNumber = tableColumnModel .getColumnIndex(canreg.common.Tools.toUpperCaseStandardized(dvle.getDatabaseVariableName())); String value = tableModel.getValueAt(rowNumber, columnNumber).toString(); filterString += " AND " + canreg.common.Tools.toUpperCaseStandardized(dvle.getDatabaseVariableName()) + " = " + dvle.getSQLqueryFormat(value); } DatabaseFilter filter = new DatabaseFilter(); filter.setFilterString(filterString); Logger.getLogger(FrequenciesByYearInternalFrame.class.getName()).log(Level.INFO, "FilterString: {0}", filterString); try { tableDatadescriptionPopUp = canreg.client.CanRegClientApp.getApplication() .getDistributedTableDescription(filter, rangeFilterPanel.getSelectedTable()); Object[][] rows = canreg.client.CanRegClientApp.getApplication().retrieveRows( tableDatadescriptionPopUp.getResultSetID(), 0, MAX_ENTRIES_DISPLAYED_ON_RIGHT_CLICK); String[] variableNames = tableDatadescriptionPopUp.getColumnNames(); for (Object[] row : rows) { String line = ""; int i = 0; for (Object obj : row) { if (obj != null) { line += variableNames[i] + ": " + obj.toString() + ", "; } i++; } jpm.add(line); } } catch (SQLException ex) { Logger.getLogger(FrequenciesByYearInternalFrame.class.getName()).log(Level.SEVERE, null, ex); } catch (RemoteException ex) { Logger.getLogger(FrequenciesByYearInternalFrame.class.getName()).log(Level.SEVERE, null, ex); } catch (SecurityException ex) { Logger.getLogger(FrequenciesByYearInternalFrame.class.getName()).log(Level.SEVERE, null, ex); } catch (DistributedTableDescriptionException ex) { Logger.getLogger(FrequenciesByYearInternalFrame.class.getName()).log(Level.SEVERE, null, ex); } catch (UnknownTableException ex) { Logger.getLogger(FrequenciesByYearInternalFrame.class.getName()).log(Level.SEVERE, null, ex); } int cases = (Integer) tableModel.getValueAt(rowNumber, tableColumnModel.getColumnIndex("CASES")); if (MAX_ENTRIES_DISPLAYED_ON_RIGHT_CLICK < cases) { jpm.add("..."); } MenuItem menuItem = new MenuItem(); jpm.show(target, evt.getX(), evt.getY()); }
From source file:DragPictureDemo2.java
public void mouseDragged(MouseEvent e) { //Don't bother to drag if the component displays no image. if (image == null) return;/*w w w . jav a2 s.c o m*/ if (firstMouseEvent != null) { e.consume(); //If they are holding down the control key, COPY rather than MOVE int ctrlMask = InputEvent.CTRL_DOWN_MASK; int action = ((e.getModifiersEx() & ctrlMask) == ctrlMask) ? TransferHandler.COPY : TransferHandler.MOVE; int dx = Math.abs(e.getX() - firstMouseEvent.getX()); int dy = Math.abs(e.getY() - firstMouseEvent.getY()); //Arbitrarily define a 5-pixel shift as the //official beginning of a drag. if (dx > 5 || dy > 5) { //This is a drag, not a click. JComponent c = (JComponent) e.getSource(); TransferHandler handler = c.getTransferHandler(); //Tell the transfer handler to initiate the drag. handler.exportAsDrag(c, firstMouseEvent, action); firstMouseEvent = null; } } }
From source file:net.bioclipse.model.ScatterPlotMouseHandler.java
@Override public void mouseDragged(MouseEvent e) { super.mouseDragged(e); ChartPanel chartPanel = getChartPanel(e); JFreeChart selectedChart = chartPanel.getChart(); ChartDescriptor cd = ChartUtils.getChartDescriptor(selectedChart); int[] indices = cd.getSourceIndices(); XYPlot plot = (XYPlot) chartPanel.getChart().getPlot(); //Create double buffer Image buffer = chartPanel.createImage(chartPanel.getWidth(), chartPanel.getHeight()); Graphics bufferGraphics = buffer.getGraphics(); chartPanel.paint(bufferGraphics);//from ww w.ja v a 2 s. c o m if (lastX == 0 && lastY == 0) { lastX = e.getX(); lastY = e.getY(); } drawRect = new Rectangle(); int x1 = Math.min(Math.min(e.getX(), lastX), startX); int y1 = Math.min(Math.min(e.getY(), lastY), startY); int x2 = Math.max(Math.max(e.getX(), lastX), startX); int y2 = Math.max(Math.max(e.getY(), lastY), startY); drawRect.x = x1; drawRect.y = y1; drawRect.width = x2 - drawRect.x; drawRect.height = y2 - drawRect.y; //Create a clipping rectangle Rectangle clipRect = new Rectangle(drawRect.x - 100, drawRect.y - 100, drawRect.width + 200, drawRect.height + 200); //Check for selected points for (int j = 0; j < plot.getDataset().getItemCount(plot.getDataset().getSeriesCount() - 1); j++) { for (int i = 0; i < plot.getDataset().getSeriesCount(); i++) { Number xK = plot.getDataset().getX(i, j); Number yK = plot.getDataset().getY(i, j); Point2D datasetPoint2D = new Point2D.Double(domainValueTo2D(chartPanel, plot, xK.doubleValue()), rangeValueTo2D(chartPanel, plot, yK.doubleValue())); if (drawRect.contains(datasetPoint2D)) { PlotPointData cp = new PlotPointData(indices[j], cd.getXLabel(), cd.getYLabel()); boolean pointAdded = mouseDragSelection.addPoint(cp); if (pointAdded) { ((ScatterPlotRenderer) plot.getRenderer()).addMarkedPoint(j, i); selectedChart.plotChanged(new PlotChangeEvent(plot)); } } else if (!mouseDragSelection.isEmpty()) { PlotPointData cp = new PlotPointData(indices[j], cd.getXLabel(), cd.getYLabel()); boolean pointRemoved = mouseDragSelection.removePoint(cp); if (pointRemoved) { ((ScatterPlotRenderer) plot.getRenderer()).removeMarkedPoint(new Point(j, i)); selectedChart.plotChanged(new PlotChangeEvent(plot)); } } } } Iterator<PlotPointData> iterator = currentSelection.iterator(); while (iterator.hasNext()) { PlotPointData next = iterator.next(); Point dataPoint = next.getDataPoint(); ((ScatterPlotRenderer) plot.getRenderer()).addMarkedPoint(dataPoint); } lastX = e.getX(); lastY = e.getY(); Graphics graphics = chartPanel.getGraphics(); graphics.setClip(clipRect); //Draw selection rectangle bufferGraphics.drawRect(drawRect.x, drawRect.y, drawRect.width, drawRect.height); graphics.drawImage(buffer, 0, 0, chartPanel.getWidth(), chartPanel.getHeight(), null); }
From source file:burlov.ultracipher.swing.MainPanel.java
public MainPanel(Translator translator) { editDataPanel = new EditDataPanel(translator); translator.addToComponent(searchField); listPopup.add(getNewEntryAction());/* w ww. j a v a2s. c o m*/ listPopup.add(getDeleteEntryAction()); setLayout(new BorderLayout()); add(splitPane); /* * Suchpanel initialisieren */ JPanel panel = new JPanel(new BorderLayout()); JPanel searchPanel = new JPanel(new BorderLayout()); searchPanel.add(new JLabel(new ImageIcon(getClass().getResource("find.png"))), BorderLayout.WEST); searchPanel.add(searchField, BorderLayout.CENTER); searchField.setToolTipText("Search"); panel.add(searchPanel, BorderLayout.NORTH); panel.add(new JScrollPane(searchResults), BorderLayout.CENTER); splitPane.setLeftComponent(panel); /* * Anzeigepanel initialisieren */ panel = new JPanel(new BorderLayout()); panel.add(editDataPanel, BorderLayout.CENTER); panel.add(new PassGeneratorPanel(), BorderLayout.SOUTH); splitPane.setRightComponent(panel); searchResults.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { showDeletePopup(e); } @Override public void mouseReleased(MouseEvent e) { showDeletePopup(e); } private void showDeletePopup(MouseEvent e) { if (!e.isPopupTrigger()) { return; } int index = searchResults.locationToIndex(e.getPoint()); if (index > -1) { searchResults.setSelectedIndex(index); } listPopup.show(e.getComponent(), e.getX(), e.getY()); } }); searchResults.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { editDataPanel.editData((DataEntry) searchResults.getSelectedValue(), false); } }); searchField.getDocument().addDocumentListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { initResultList(); } @Override public void insertUpdate(DocumentEvent e) { initResultList(); } @Override public void changedUpdate(DocumentEvent e) { initResultList(); } }); editDataPanel.addNameChangeListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { int index = searchResultModel.indexOf(editDataPanel.getData()); if (index >= 0) { searchResultModel.set(index, editDataPanel.getData()); } } @Override public void insertUpdate(DocumentEvent e) { int index = searchResultModel.indexOf(editDataPanel.getData()); if (index >= 0) { searchResultModel.set(index, editDataPanel.getData()); } } @Override public void changedUpdate(DocumentEvent e) { int index = searchResultModel.indexOf(editDataPanel.getData()); if (index >= 0) { searchResultModel.set(index, editDataPanel.getData()); } } }); searchField.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { showTextPopup(e); } else { // searchField.selectAll(); } } @Override public void mouseReleased(MouseEvent e) { showTextPopup(e); } }); // searchField.addFocusListener(new FocusListener() { // @Override // public void focusLost(FocusEvent e) { // System.out.println("MainPanel.MainPanel().new FocusListener() {...}.focusLost()"); // } // // @Override // public void focusGained(FocusEvent e) { // System.out.println("MainPanel.MainPanel().new FocusListener() {...}.focusGained()"); // //searchField.selectAll(); // } // }); }
From source file:TransferableScribblePane.java
/** * This method is called on mouse button events. It begins a new line or tries * to select an existing line./*from w ww .j av a2 s.c o m*/ */ public void processMouseEvent(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { // Left mouse button if (e.getID() == MouseEvent.MOUSE_PRESSED) { // Pressed down if (e.isShiftDown()) { // with Shift key // If the shift key is down, try to select a line int x = e.getX(); int y = e.getY(); // Loop through the lines checking to see if we hit one PolyLine selection = null; int numlines = lines.size(); for (int i = 0; i < numlines; i++) { PolyLine line = (PolyLine) lines.get(i); if (line.intersects(x - 2, y - 2, 4, 4)) { selection = line; e.consume(); break; } } // If we found an intersecting line, save it and repaint if (selection != selectedLine) { // If selection changed selectedLine = selection; // remember which is selected repaint(); // will make selection dashed } } else if (!e.isControlDown()) { // no shift key or ctrl key // Start a new line on mouse down without shift or ctrl currentLine = new PolyLine(e.getX(), e.getY()); lines.add(currentLine); e.consume(); } } else if (e.getID() == MouseEvent.MOUSE_RELEASED) {// Left Button Up // End the line on mouse up if (currentLine != null) { currentLine = null; e.consume(); } } } // The superclass method dispatches to registered event listeners super.processMouseEvent(e); }
From source file:net.fenyo.gnetwatch.GUI.BasicComponent.java
public void mousePressed(MouseEvent e) { if (!manual_mode) { manual_now = System.currentTimeMillis(); manual_delay_per_interval = getDelayPerInterval(); manual_mode = true;//w ww . j a v a2 s . c om } drag_x_start = e.getX(); drag_now_start = manual_now; }
From source file:de.tntinteractive.portalsammler.gui.DocumentTable.java
private void showPopup(final MouseEvent ev) { final JMenuItem open = new JMenuItem("Anzeigen"); open.addActionListener(new ActionListener() { @Override/*from w w w .j a v a2 s . c o m*/ public void actionPerformed(final ActionEvent e) { DocumentTable.this.openSelectedRows(); } }); final JMenuItem export = new JMenuItem("Exportieren"); export.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { DocumentTable.this.exportSelectedRows(); } }); final JPopupMenu menu = new JPopupMenu(); menu.add(open); menu.add(export); menu.show(ev.getComponent(), ev.getX(), ev.getY()); }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopTree.java
@Override public void setItemClickAction(Action action) { if (this.doubleClickAction != action) { if (action != null) { if (itemClickListener == null) { itemClickListener = new MouseAdapter() { @Override//from w w w .j av a2 s. c o m public void mouseClicked(MouseEvent e) { if (isEditable()) { if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2 && doubleClickAction != null) { int rowForLocation = impl.getRowForLocation(e.getX(), e.getY()); TreePath pathForLocation = impl.getPathForRow(rowForLocation); if (pathForLocation != null) { impl.setSelectionPath(pathForLocation); doubleClickAction.actionPerform(DesktopTree.this); } } } } }; impl.addMouseListener(itemClickListener); impl.setToggleClickCount(0); } } else { impl.removeMouseListener(itemClickListener); impl.setToggleClickCount(2); itemClickListener = null; } this.doubleClickAction = action; } }