List of usage examples for java.awt.event MouseEvent getX
public int getX()
From source file:Main.java
/** * Display mouse events that don't involve mouse motion. The mousemods() * method prints modifiers, and is defined below. The other methods return * additional information about the mouse event. showLine() displays a line * of text in the window. It is defined at the end of this class, along with * the paintComponent() method.//from ww w. jav a2 s. com */ public void processMouseEvent(MouseEvent e) { String type = null; switch (e.getID()) { case MouseEvent.MOUSE_DRAGGED: type = "MOUSE_DRAGGED"; break; case MouseEvent.MOUSE_RELEASED: type = "MOUSE_RELEASED"; break; case MouseEvent.MOUSE_CLICKED: type = "MOUSE_CLICKED"; break; case MouseEvent.MOUSE_ENTERED: type = "MOUSE_ENTERED"; break; case MouseEvent.MOUSE_EXITED: type = "MOUSE_EXITED"; break; } showLine(mousemods(e) + type + ": [" + e.getX() + "," + e.getY() + "] " + "num clicks = " + e.getClickCount() + (e.isPopupTrigger() ? "; is popup trigger" : "")); // When the mouse enters the component, request keyboard focus so // we can receive and respond to keyboard events if (e.getID() == MouseEvent.MOUSE_ENTERED) requestFocus(); }
From source file:TransferableScribblePane.java
/** * This method is called for mouse motion events. We don't have to detect * gestures that initiate a drag in this method. That is the job of the * DragGestureRecognizer we created in the constructor: it will notify the * DragGestureListener defined below./* w w w . j a va 2 s . c om*/ */ public void processMouseMotionEvent(MouseEvent e) { if (e.getID() == MouseEvent.MOUSE_DRAGGED && // If we're dragging currentLine != null) { // and a line exists currentLine.addSegment(e.getX(), e.getY()); // Add a line segment e.consume(); // Eat the event repaint(); // Redisplay all lines } super.processMouseMotionEvent(e); // Invoke any listeners }
From source file:gda.gui.dv.panels.vispanels.ColourSelector.java
/** * The function that performs the histogram Drawing * //from ww w. j a v a2 s. co m * @param raw * the raw data * @return the new data in the appropriate form */ @Override public ImageData cast(DoubleDataset raw) { dataLink = raw; if (max == null) { max = raw.max().doubleValue(); } if (min == null) { min = raw.min().doubleValue(); } ImageData result = colourCast(raw, max, min); // if old stuff exists then remove it. if (chart != null) { chart.removeAll(); } // now plot the histogram HistogramDataset histData = new HistogramDataset(); histData.addSeries("h1", raw.getData(), 100, min, max); histogram = ChartFactory.createHistogram("Histogram", "Value", "Counts", histData, PlotOrientation.VERTICAL, false, false, false); if (unconfigured == false) { this.remove(chart); } unconfigured = false; chart = new DrawChart(histogram); chart.setMouseZoomable(false); chart.setPreferredSize(new Dimension(300, 300)); chart.setMinimumSize(new Dimension(200, 200)); c.gridx = 0; c.gridy = 4; c.gridwidth = 2; this.add(chart, c); chart.addMouseListener(new MouseListener() { Double tmin = min; Double tmax = max; @Override public void mouseClicked(MouseEvent e) { } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { SimpleDataCoordinate coordinates = convertMouseEvent(e); if (chart.getScreenDataArea().contains(e.getX(), e.getY())) { tmin = coordinates.getX(); } else { if (chart.getScreenDataArea().outcode(e.getX(), e.getY()) != Rectangle2D.OUT_RIGHT) { // System.out.println("out of bounds"); // System.out.printf("Mouse: %d\n", e.getX()); } else { tmin = max; } } } @Override public void mouseReleased(MouseEvent e) { boolean update = false; SimpleDataCoordinate coordinates = convertMouseEvent(e); if (chart.getScreenDataArea().contains(e.getX(), e.getY())) { tmax = coordinates.getX(); update = true; } else { if (chart.getScreenDataArea().outcode(e.getX(), e.getY()) != Rectangle2D.OUT_LEFT) { // System.out.println("out of bounds"); // System.out.printf("Mouse: %d\n", e.getX()); } else { tmax = min; update = true; } } if (update && tmin != tmax) { if (tmin > tmax) { // check and correct limits Double t = tmin; tmin = tmax; tmax = t; } min = tmin; max = tmax; owner.getDataSetImage().applyColorCast(); owner.getDataSetPlot3D().applyColorCast(); owner.getDataSetImage().repaint(); } } public SimpleDataCoordinate convertMouseEvent(MouseEvent me) { return new SimpleDataCoordinate( histogram.getXYPlot().getDomainAxis().java2DToValue(me.getX(), chart.getScreenDataArea(), histogram.getXYPlot().getDomainAxisEdge()), histogram.getXYPlot().getRangeAxis().java2DToValue(me.getY(), chart.getScreenDataArea(), histogram.getXYPlot().getRangeAxisEdge())); } }); lblchart.invalidate(); lblchart.validate(); this.invalidate(); this.validate(); return result; }
From source file:net.sf.jabref.gui.plaintextimport.TextInputDialog.java
private void maybeShowPopup(MouseEvent e) { if (e.isPopupTrigger()) { popMenu.show(e.getComponent(), e.getX(), e.getY()); } }
From source file:org.fhcrc.cpl.viewer.mrm.utilities.MRMerMouseListener.java
public void mouseReleased(MouseEvent e) { try {//from w w w. j av a 2 s .co m if ((e.isShiftDown() || e.getButton() == MouseEvent.BUTTON3) || shifted) { // Rectangle2D scaledDataArea = _chartPanel.getScreenDataArea( // (int) this.coElutionStart.getX(), (int) this.coElutionStart.getY()); JFreeChart jfc = _cp.getChart(); XYPlot p = jfc.getXYPlot(); CenterZoomNumberAxis czna = (CenterZoomNumberAxis) p.getDomainAxis(); Rectangle2D screenDataArea = _cp.getScreenDataArea(e.getX(), e.getY()); Rectangle2D plotboundaries = _cp.getChartRenderingInfo().getPlotInfo().getPlotArea(); double leftmostOnAxis = czna.getLowerBound(); double rightmostOnAxis = czna.getUpperBound(); double leftmostOnRange = this.coElutionRegion.getX(); double rightmostOnRange = this.coElutionRegion.getX() + this.coElutionRegion.getWidth(); double leftmostonscreen = screenDataArea.getX(); double rightmostonscreen = leftmostonscreen + screenDataArea.getWidth(); double slope = (rightmostOnAxis - leftmostOnAxis) / (rightmostonscreen - leftmostonscreen); double transformedLeftRange = (slope * (leftmostOnRange - leftmostonscreen)) + leftmostOnAxis; double transformedRightRange = (slope * (rightmostOnRange - leftmostonscreen)) + leftmostOnAxis; shifted = false; MRMDialog ultimateParent = (MRMDialog) MRMAncestor(); if (ultimateParent != null) { MRMTransition transition = ultimateParent.transitionOnPlot; MRMTransition mrmt = transition; if (mrmt != null) { int row = mrmt.getTableRow(); _ptm.data[row][MRMDialog.peaksData.CoStart.colno] = new Float(0f); _ptm.data[row][MRMDialog.peaksData.CoEnd.colno] = new Float(10000000f); _ptm.setValueAt(new Float(transformedRightRange), row, MRMDialog.peaksData.CoEnd.colno); _ptm.setValueAt(new Float(transformedLeftRange), row, MRMDialog.peaksData.CoStart.colno); } } Graphics2D g2 = (Graphics2D) _cp.getGraphics(); if (this.coElutionRegion != null) drawCoElutionRegion(g2); this.coElutionRegion = null; this.coElutionStart = null; } else { _cp.mouseReleased(e); } } catch (Exception ee) { } }
From source file:JavaXWin.java
public void mouseDragged(MouseEvent e) { int h = m_resizeComponent.getHeight(); int w = m_resizeComponent.getWidth(); int x = m_resizeComponent.getX(); int y = m_resizeComponent.getY(); int ex = e.getX(); int ey = e.getY(); switch (m_mode) { case SOUTH:/*from w ww .jav a 2s.c om*/ if (h + (ey - m_dragY) >= MIN_HEIGHT) m_resizeComponent.setBounds(x, y, w, h + (ey - m_dragY)); else m_resizeComponent.setBounds(x, y, w, MIN_HEIGHT); break; case SOUTHEAST: if (h + (ey - m_dragY) >= MIN_HEIGHT && w + (ex - (getWidth() - CORNER)) >= MIN_WIDTH) m_resizeComponent.setBounds(x, y, w + (ex - (getWidth() - CORNER)), h + (ey - m_dragY)); else if (h + (ey - m_dragY) >= MIN_HEIGHT && !(w + (ex - (getWidth() - CORNER)) >= MIN_WIDTH)) m_resizeComponent.setBounds(x, y, MIN_WIDTH, h + (ey - m_dragY)); else if (!(h + (ey - m_dragY) >= MIN_HEIGHT) && w + (ex - (getWidth() - CORNER)) >= MIN_WIDTH) m_resizeComponent.setBounds(x, y, w + (ex - (getWidth() - CORNER)), MIN_HEIGHT); else m_resizeComponent.setBounds(x, y, MIN_WIDTH, MIN_HEIGHT); break; case SOUTHWEST: if (h + (ey - m_dragY) >= MIN_HEIGHT && w - (ex - m_dragX) >= MIN_WIDTH) m_resizeComponent.setBounds(x + (ex - m_dragX), y, w - (ex - m_dragX), h + (ey - m_dragY)); else if (h + (ey - m_dragY) >= MIN_HEIGHT && !(w - (ex - m_dragX) >= MIN_WIDTH)) { if (x + MIN_WIDTH < m_rightX) m_resizeComponent.setBounds(m_rightX - MIN_WIDTH, y, MIN_WIDTH, h + (ey - m_dragY)); else m_resizeComponent.setBounds(x, y, w, h + (ey - m_dragY)); } else if (!(h + (ey - m_dragY) >= MIN_HEIGHT) && w - (ex - m_dragX) >= MIN_WIDTH) m_resizeComponent.setBounds(x + (ex - m_dragX), y, w - (ex - m_dragX), MIN_HEIGHT); else m_resizeComponent.setBounds(m_rightX - MIN_WIDTH, y, MIN_WIDTH, MIN_HEIGHT); break; } m_rightX = x + w; m_resizeComponent.validate(); }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakAnnotationCalibrationPanel.java
public void onMouseClicked(MouseEvent e) { // find peak under mouse if (e.getButton() == MouseEvent.BUTTON3 && e.getClickCount() == 1 && (e.getModifiers() & MOD_MASK) == e.BUTTON3_MASK) { // open popup createPopupMenu().show(theChartPanel, e.getX(), e.getY()); }// w w w. j a va2 s.c o m }
From source file:JavaXWin.java
public void mouseDragged(MouseEvent e) { int h = m_resizeComponent.getHeight(); int w = m_resizeComponent.getWidth(); int x = m_resizeComponent.getX(); int y = m_resizeComponent.getY(); int ex = e.getX(); int ey = e.getY(); switch (m_mode) { case NORTH:/*w w w .j a v a 2s .c o m*/ if (h - (ey - m_dragY) >= MIN_HEIGHT) m_resizeComponent.setBounds(x, y + (ey - m_dragY), w, h - (ey - m_dragY)); else m_resizeComponent.setBounds(x, m_lowerY - MIN_HEIGHT, w, MIN_HEIGHT); break; case NORTHEAST: if (h - (ey - m_dragY) >= MIN_HEIGHT && w + (ex - (getWidth() - CORNER)) >= MIN_WIDTH) m_resizeComponent.setBounds(x, y + (ey - m_dragY), w + (ex - (getWidth() - CORNER)), h - (ey - m_dragY)); else if (h - (ey - m_dragY) >= MIN_HEIGHT && !(w + (ex - (getWidth() - CORNER)) >= MIN_WIDTH)) m_resizeComponent.setBounds(x, y + (ey - m_dragY), MIN_WIDTH, h - (ey - m_dragY)); else if (!(h - (ey - m_dragY) >= MIN_HEIGHT) && w + (ex - (getWidth() - CORNER)) >= MIN_WIDTH) m_resizeComponent.setBounds(x, m_lowerY - MIN_HEIGHT, w + (ex - (getWidth() - CORNER)), MIN_HEIGHT); else m_resizeComponent.setBounds(x, m_lowerY - MIN_HEIGHT, MIN_WIDTH, MIN_HEIGHT); break; case NORTHWEST: if (h - (ey - m_dragY) >= MIN_HEIGHT && w - (ex - m_dragX) >= MIN_WIDTH) m_resizeComponent.setBounds(x + (ex - m_dragX), y + (ey - m_dragY), w - (ex - m_dragX), h - (ey - m_dragY)); else if (h - (ey - m_dragY) >= MIN_HEIGHT && !(w - (ex - m_dragX) >= MIN_WIDTH)) { if (x + MIN_WIDTH < m_rightX) m_resizeComponent.setBounds(m_rightX - MIN_WIDTH, y + (ey - m_dragY), MIN_WIDTH, h - (ey - m_dragY)); else m_resizeComponent.setBounds(x, y + (ey - m_dragY), w, h - (ey - m_dragY)); } else if (!(h - (ey - m_dragY) >= MIN_HEIGHT) && w - (ex - m_dragX) >= MIN_WIDTH) m_resizeComponent.setBounds(x + (ex - m_dragX), m_lowerY - MIN_HEIGHT, w - (ex - m_dragX), MIN_HEIGHT); else m_resizeComponent.setBounds(m_rightX - MIN_WIDTH, m_lowerY - MIN_HEIGHT, MIN_WIDTH, MIN_HEIGHT); break; } m_rightX = x + w; m_resizeComponent.validate(); }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopTree.java
@Override public void setLookupSelectHandler(Runnable selectHandler) { impl.addMouseListener(new MouseAdapter() { @Override//from w w w. j a va 2s. co m public void mousePressed(MouseEvent e) { if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) { int rowForLocation = impl.getRowForLocation(e.getX(), e.getY()); TreePath pathForLocation = impl.getPathForRow(rowForLocation); if (pathForLocation != null) { CollectionDatasource treeCds = getDatasource(); if (treeCds != null) { TreeModelAdapter.Node treeItem = (TreeModelAdapter.Node) pathForLocation .getLastPathComponent(); if (treeItem != null) { treeCds.setItem(treeItem.getEntity()); selectHandler.run(); } } } } } }); }
From source file:ja.lingo.application.gui.main.describer.DescriberGui.java
public void mouseClickedOnEditorPane(MouseEvent e) { if (!articlePanel.hasArticle()) { return;/*from www . ja v a2s . c o m*/ } if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() > 1) { if (getSelectedTextTrimmed().length() > 0) { Rectangle rectangle; try { rectangle = articlePanel.getEditorPane() .modelToView(articlePanel.getEditorPane().getSelectionStart()); } catch (BadLocationException e1) { throw new RuntimeException(e1); } showMenuOnSelect(e.getX(), (int) (rectangle.getY() + rectangle.getHeight())); } return; } if (SwingUtilities.isRightMouseButton(e)) { if (getSelectedTextTrimmed().length() > 0) { showMenuOnSelect(e.getX(), e.getY()); } else { menu.show(articlePanel, e.getX(), e.getY()); } } }