List of usage examples for java.awt.event MouseEvent getX
public int getX()
From source file:ucar.unidata.idv.control.chart.TimeSeriesChartWrapper.java
/** * Is mouse on top axis//from w ww . j av a 2s .c o m * * @param mouseEvent the event * * @return On top axis */ private boolean isOnTopDomainAxis(MouseEvent mouseEvent) { Rectangle2D dataArea = chartPanel.getScreenDataArea(); if (mouseEvent.getX() < dataArea.getX()) { return false; } if (mouseEvent.getX() > dataArea.getX() + dataArea.getWidth()) { return false; } double top = dataArea.getY(); return mouseEvent.getY() <= top + 20; }
From source file:ucar.unidata.idv.control.chart.TimeSeriesChartWrapper.java
/** * Is mouse on bottom axis//from ww w . j a v a2 s . co m * * @param mouseEvent the event * * @return on bottom axis */ private boolean isOnBottomDomainAxis(MouseEvent mouseEvent) { Rectangle2D dataArea = chartPanel.getScreenDataArea(); if (mouseEvent.getX() < dataArea.getX()) { return false; } if (mouseEvent.getX() > dataArea.getX() + dataArea.getWidth()) { return false; } double bottom = dataArea.getY() + dataArea.getHeight(); return mouseEvent.getY() >= bottom - 20; }
From source file:dbseer.gui.panel.DBSeerSelectableChartPanel.java
@Override public void mousePressed(MouseEvent e) { super.mousePressed(e); Rectangle2D origArea = this.getScreenDataArea(); Plot plot = chart.getPlot();/* ww w. j a va2 s .c o m*/ if (!(plot instanceof XYPlot)) { return; } XYPlot xyPlot = chart.getXYPlot(); String origDomainAxisLabel = xyPlot.getDomainAxis().getLabel(); if (SwingUtilities.isRightMouseButton(e)) { return; } for (DBSeerSelectableChartPanel panel : DBSeerPlotPresetFrame.chartPanels) { if (panel != this) { Plot otherPlot = panel.getChart().getPlot(); if (!(otherPlot instanceof XYPlot)) { continue; } Rectangle2D otherArea = panel.getScreenDataArea(); XYPlot otherXYPlot = panel.getChart().getXYPlot(); String otherDomainAxisLabel = otherXYPlot.getDomainAxis().getLabel(); if (origDomainAxisLabel.equalsIgnoreCase(otherDomainAxisLabel)) { double origRangeX = origArea.getMaxX() - origArea.getMinX(); double origRangeY = origArea.getMaxY() - origArea.getMinY(); double otherRangeX = otherArea.getMaxX() - otherArea.getMinX(); double otherRangeY = otherArea.getMaxY() - otherArea.getMinY(); double syncX = otherArea.getMinX() + (e.getX() - origArea.getMinX()) / origRangeX * otherRangeX; double syncY = otherArea.getMinY() + (e.getY() - origArea.getMinY()) / origRangeY * otherRangeY; MouseEvent syncEvent = new MouseEvent(this, 0, 0, 0, (int) syncX, (int) syncY, 1, false); panel.syncMousePressed(syncEvent); } } } }
From source file:dbseer.gui.panel.DBSeerSelectableChartPanel.java
@Override public void mouseDragged(MouseEvent e) { super.mouseDragged(e); Rectangle2D origArea = this.getScreenDataArea(); Plot plot = chart.getPlot();/*from w ww .ja v a 2 s. c om*/ if (!(plot instanceof XYPlot)) { return; } XYPlot xyPlot = chart.getXYPlot(); String origDomainAxisLabel = xyPlot.getDomainAxis().getLabel(); if (SwingUtilities.isRightMouseButton(e)) { return; } for (DBSeerSelectableChartPanel panel : DBSeerPlotPresetFrame.chartPanels) { if (panel != this) { Plot otherPlot = panel.getChart().getPlot(); if (!(otherPlot instanceof XYPlot)) { continue; } Rectangle2D otherArea = panel.getScreenDataArea(); XYPlot otherXYPlot = panel.getChart().getXYPlot(); String otherDomainAxisLabel = otherXYPlot.getDomainAxis().getLabel(); if (origDomainAxisLabel.equalsIgnoreCase(otherDomainAxisLabel)) { double origRangeX = origArea.getMaxX() - origArea.getMinX(); double origRangeY = origArea.getMaxY() - origArea.getMinY(); double otherRangeX = otherArea.getMaxX() - otherArea.getMinX(); double otherRangeY = otherArea.getMaxY() - otherArea.getMinY(); double syncX = otherArea.getMinX() + (e.getX() - origArea.getMinX()) / origRangeX * otherRangeX; double syncY = otherArea.getMinY() + (e.getY() - origArea.getMinY()) / origRangeY * otherRangeY; MouseEvent syncEvent = new MouseEvent(this, 0, 0, 0, (int) syncX, (int) syncY, 1, false); panel.syncMouseDragged(syncEvent); } } } }
From source file:game.Clue.ClueGameUI.java
public void mouseReleased(MouseEvent e) { System.out.println("Mouse clicked/released on chosen room" + e.getSource().toString()); if (player == null) { return;/*w ww .j av a2s. com*/ } //validate move by sending move request to Server before allowing move int valid = 1; player.setVisible(false); Component c = jPanel5.findComponentAt(e.getX(), e.getY()); if (c instanceof JLabel) { Container parent = c.getParent(); if (parent.getComponentCount() == 0) { System.out.println("------"); //parent.remove(0); parent.add(player); } else { System.out.println("%%%%%"); parent.add(player); parent.validate(); //return; } } else { Container parent = (Container) c; if (parent.getComponentCount() == 1) { System.out.println("*****"); return; } else { System.out.println("&&&&&"); parent.add(player); } } if (valid != 0) { System.out.println("Player move allowed" + " x:" + e.getX() + "y: " + e.getY()); System.out.println("Previous x:" + previous_room_x + " Y:" + previous_room_y); player.setLocation(previous_room_x, previous_room_y); // player.setLocation(e.getX(),e.getY()); } else { } player.setHorizontalAlignment(SwingConstants.CENTER); player.setVisible(true); }
From source file:dbseer.gui.panel.DBSeerSelectableChartPanel.java
@Override public void mouseReleased(MouseEvent e) { super.mouseReleased(e); Rectangle2D origArea = this.getScreenDataArea(); Plot plot = chart.getPlot();/*from w w w. j a v a 2s .c om*/ if (!(plot instanceof XYPlot)) { return; } XYPlot xyPlot = chart.getXYPlot(); String origDomainAxisLabel = xyPlot.getDomainAxis().getLabel(); if (SwingUtilities.isRightMouseButton(e)) { return; } for (DBSeerSelectableChartPanel panel : DBSeerPlotPresetFrame.chartPanels) { if (panel != this) { Plot otherPlot = panel.getChart().getPlot(); if (!(otherPlot instanceof XYPlot)) { continue; } Rectangle2D otherArea = panel.getScreenDataArea(); XYPlot otherXYPlot = panel.getChart().getXYPlot(); String otherDomainAxisLabel = otherXYPlot.getDomainAxis().getLabel(); if (origDomainAxisLabel.equalsIgnoreCase(otherDomainAxisLabel)) { double origRangeX = origArea.getMaxX() - origArea.getMinX(); double origRangeY = origArea.getMaxY() - origArea.getMinY(); double otherRangeX = otherArea.getMaxX() - otherArea.getMinX(); double otherRangeY = otherArea.getMaxY() - otherArea.getMinY(); double syncX = otherArea.getMinX() + (e.getX() - origArea.getMinX()) / origRangeX * otherRangeX; double syncY = otherArea.getMinY() + (e.getY() - origArea.getMinY()) / origRangeY * otherRangeY; MouseEvent syncEvent = new MouseEvent(this, 0, 0, 0, (int) syncX, (int) syncY, 1, false); panel.syncMouseReleased(syncEvent); } } } }
From source file:gdt.jgui.entity.webset.JWeblinkEditor.java
private void showLoginMenu(MouseEvent e) { try {/*from w w w . jav a 2 s . c o m*/ JPopupMenu logonMenu = new JPopupMenu(); JMenuItem copyItem = new JMenuItem("Copy"); logonMenu.add(copyItem); copyItem.setHorizontalTextPosition(JMenuItem.RIGHT); copyItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { StringSelection stringSelection = new StringSelection(loginField.getText()); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(stringSelection, JWeblinkEditor.this); } catch (Exception ee) { Logger.getLogger(getClass().getName()).info(ee.toString()); } } }); logonMenu.show(e.getComponent(), e.getX(), e.getY()); } catch (Exception ee) { Logger.getLogger(getClass().getName()).severe(ee.toString()); } }
From source file:MouseNavigateTest.java
/** * Dispatches mouse events as appropriate. Should not need to overide this * method./* ww w . j a va2 s . c o m*/ */ //***************************************************************************** protected void processMouseEvent(java.awt.event.MouseEvent evt) { if (m_Object != null) { if (isStartBehaviorEvent(evt) != false) adjustTransform(evt.getX(), evt.getY()); else if (isStopBehaviorEvent(evt) != false) onEndDrag(); } }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.SpectraPanel.java
public void mouseReleased(MouseEvent e) { if (MouseUtils.isPopupTrigger(e)) { // clear all if (zoom_rectangle != null) { Graphics2D g2 = (Graphics2D) getGraphics(); g2.setXORMode(java.awt.Color.gray); g2.draw(zoom_rectangle);//w w w . j a va2 s . c o m g2.dispose(); } mouse_start_point = null; zoom_rectangle = null; // open popup current_peak = findPeakAt(e.getPoint()); enforceSelection(current_peak); createPopupMenu(current_peak != null).show(theChartPanel, e.getX(), e.getY()); } else { if (zoom_rectangle != null && mouse_start_point != null) { if (Math.abs(e.getX() - mouse_start_point.getX()) > 10) { //if( e.getX() < mouse_start_point.getX() ) { // unzoom all // onZoomNone(); //} //else { // zoom area double start_x = Math.min(e.getX(), mouse_start_point.getX()); double end_x = Math.max(e.getX(), mouse_start_point.getX()); Rectangle2D data_area = theChartPanel.getScreenDataArea((int) start_x, (int) mouse_start_point.getY()); double new_lower_bound = screenToDataCoordX(start_x); double new_upper_bound = screenToDataCoordX(Math.min(end_x, data_area.getMaxX())); thePlot.getDomainAxis().setRange(new Range(new_lower_bound, new_upper_bound)); } else { // clear rectangle Graphics2D g2 = (Graphics2D) getGraphics(); g2.setXORMode(java.awt.Color.gray); g2.draw(zoom_rectangle); g2.dispose(); } } // restore zooming if (!was_moving && is_moving) onActivateZooming(); zoom_rectangle = null; mouse_start_point = null; } }
From source file:edu.ku.brc.specify.tasks.subpane.ESResultsTablePanel.java
/** * //w w w . ja va 2s . c o m */ protected void addContextMenu() { MouseAdapter mouseAdapter = new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { super.mousePressed(e); if (e.isPopupTrigger()) { if (table.getSelectedColumnCount() > 0) { if (popupMenu != null && popupMenu.isVisible()) { popupMenu.setVisible(false); } if (popupMenu == null) { popupMenu = new JPopupMenu(); JMenuItem mi = popupMenu.add(new JMenuItem(UIRegistry.getResourceString("Remove"))); mi.addActionListener(createRemoveItemAL()); } Point p = table.getLocationOnScreen(); popupMenu.setLocation(p.x + e.getX() + 1, p.y + e.getY() + 1); popupMenu.setVisible(true); } } } }; table.addMouseListener(mouseAdapter); }