List of usage examples for java.awt.event MouseEvent getID
public int getID()
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./* w w w. j av a2s. co 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:it.unibas.spicygui.vista.listener.MyMouseEventListener.java
private void dispacciaEventoDrag(Component com, MouseEvent e, Point point, boolean draggedEvent) { Point componentPoint = SwingUtilities.convertPoint(component, e.getPoint(), com); if (com != null) { if (com instanceof JTree) { TreePath treePath = ((JTree) com).getPathForLocation(componentPoint.x, componentPoint.y); if (treePath == null || draggedEvent) { component.updateUI();// w w w .j ava 2s. c o m return; } } if ((!(com instanceof JScrollBar) && (tmp12 instanceof JScrollBar))) { jLayeredPane.moveToFront(component); component.updateUI(); return; } com.dispatchEvent(new MouseEvent(component, e.getID(), e.getWhen(), e.getModifiers(), componentPoint.x, componentPoint.y, e.getClickCount(), e.isPopupTrigger())); jLayeredPane.moveToFront(component); component.updateUI(); } jLayeredPane.moveToFront(component); component.updateUI(); }
From source file:org.yccheok.jstock.gui.charting.ChartLayerUI.java
private void processEvent(MouseEvent e, JXLayer layer) { if (MouseEvent.MOUSE_DRAGGED == e.getID()) { return;//from www . j a v a 2s.c o m } final Point mousePoint = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), layer); if (this.updateMainTraceInfo(mousePoint)) { this.updateIndicatorTraceInfos(this.mainTraceInfo.getDataIndex()); this.setDirty(true); } }
From source file:it.unibas.spicygui.vista.listener.MyMouseEventListener.java
private void dispacciaEvento(Component com, MouseEvent e, Point point, boolean draggedEvent) { if (com == null) { com = SwingUtilities.getDeepestComponentAt(pannelloPrincipale, point.x, point.y); }/* ww w . j a v a 2 s.co m*/ Point componentPoint = SwingUtilities.convertPoint(component, e.getPoint(), com); if (com != null) { if (com instanceof JTree) { TreePath treePath = ((JTree) com).getPathForLocation(componentPoint.x, componentPoint.y); if (treePath == null || draggedEvent) { jLayeredPane.moveToFront(component); component.updateUI(); if (e.getButton() == MouseEvent.BUTTON3) { return; } } } com.dispatchEvent(new MouseEvent(com, e.getID(), e.getWhen(), e.getModifiers(), componentPoint.x, componentPoint.y, e.getClickCount(), e.isPopupTrigger())); jLayeredPane.moveToFront(component); component.updateUI(); } jLayeredPane.moveToFront(component); component.updateUI(); }
From source file:org.yccheok.jstock.gui.charting.InvestmentFlowLayerUI.java
private void processEvent(MouseEvent e, JXLayer layer) { if (MouseEvent.MOUSE_DRAGGED == e.getID()) { return;/*from ww w .j a va 2 s.c o m*/ } if (MouseEvent.MOUSE_CLICKED == e.getID()) { // Transfer focus to chart if user clicks on the chart. this.investmentFlowChartJDialog.getChartPanel().requestFocus(); } final Point mousePoint = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), layer); final boolean status0 = this.updateInvestPoint(mousePoint); final boolean status1 = this.updateROIPoint(mousePoint); if (status0 || status1) { this.setDirty(true); } }
From source file:com.limegroup.gnutella.gui.tables.ActionIconAndNameEditor.java
public Component getTableCellEditorComponent(final JTable table, Object value, boolean isSelected, int row, int column) { ActionIconAndNameHolder in = (ActionIconAndNameHolder) value; action = in.getAction();/*from ww w. j av a2 s. c o m*/ final Component component = new ActionIconAndNameRenderer().getTableCellRendererComponent(table, value, isSelected, true, row, column); component.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { if (actionRegion == null) { component_mousePressed(e); } else { if (actionRegion.contains(e.getPoint())) { component_mousePressed(e); } else { if (e.getClickCount() >= 2) { Toolkit.getDefaultToolkit().getSystemEventQueue() .postEvent(new MouseEvent(table, MouseEvent.MOUSE_CLICKED, e.getWhen(), e.getModifiers(), component.getX() + e.getX(), component.getY() + e.getY(), e.getClickCount(), false)); } } } } else if (e.getButton() == MouseEvent.BUTTON3) { Toolkit.getDefaultToolkit().getSystemEventQueue() .postEvent(new MouseEvent(table, e.getID(), e.getWhen(), e.getModifiers(), component.getX() + e.getX(), component.getY() + e.getY(), e.getClickCount(), true)); } } }); return component; }
From source file:components.GlassPaneDemo.java
private void redispatchMouseEvent(MouseEvent e, boolean repaint) { Point glassPanePoint = e.getPoint(); Container container = contentPane; Point containerPoint = SwingUtilities.convertPoint(glassPane, glassPanePoint, contentPane); if (containerPoint.y < 0) { //we're not in the content pane if (containerPoint.y + menuBar.getHeight() >= 0) { //The mouse event is over the menu bar. //Could handle specially. } else {// w w w .j a v a 2 s.c om //The mouse event is over non-system window //decorations, such as the ones provided by //the Java look and feel. //Could handle specially. } } else { //The mouse event is probably over the content pane. //Find out exactly which component it's over. Component component = SwingUtilities.getDeepestComponentAt(container, containerPoint.x, containerPoint.y); if ((component != null) && (component.equals(liveButton))) { //Forward events over the check box. Point componentPoint = SwingUtilities.convertPoint(glassPane, glassPanePoint, component); component.dispatchEvent(new MouseEvent(component, e.getID(), e.getWhen(), e.getModifiers(), componentPoint.x, componentPoint.y, e.getClickCount(), e.isPopupTrigger())); } } //Update the glass pane if requested. if (repaint) { glassPane.setPoint(glassPanePoint); glassPane.repaint(); } }
From source file:GlassPaneDemo.java
private void redispatchMouseEvent(MouseEvent e, boolean repaint) { Point glassPanePoint = e.getPoint(); Container container = contentPane; Point containerPoint = SwingUtilities.convertPoint(glassPane, glassPanePoint, contentPane); if (containerPoint.y < 0) { // we're not in the content pane if (containerPoint.y + menuBar.getHeight() >= 0) { // The mouse event is over the menu bar. // Could handle specially. } else {/*from w ww.j a v a2 s. c o m*/ // The mouse event is over non-system window // decorations, such as the ones provided by // the Java look and feel. // Could handle specially. } } else { // The mouse event is probably over the content pane. // Find out exactly which component it's over. Component component = SwingUtilities.getDeepestComponentAt(container, containerPoint.x, containerPoint.y); if ((component != null) && (component.equals(liveButton))) { // Forward events over the check box. Point componentPoint = SwingUtilities.convertPoint(glassPane, glassPanePoint, component); component.dispatchEvent(new MouseEvent(component, e.getID(), e.getWhen(), e.getModifiers(), componentPoint.x, componentPoint.y, e.getClickCount(), e.isPopupTrigger())); } } // Update the glass pane if requested. if (repaint) { glassPane.setPoint(glassPanePoint); glassPane.repaint(); } }
From source file:edu.ku.brc.ui.tmanfe.SpreadSheet.java
@Override public void processMouseEvent(MouseEvent ev) { int type = ev.getID(); //int modifiers = ev.getModifiers(); mouseDown = type == MouseEvent.MOUSE_PRESSED; // XXX For Java 5 Bug // I am not sure if we still need this if (mouseDown && UIHelper.getOSType() == UIHelper.OSTYPE.MacOSX) { int rowIndexStart = rowAtPoint(ev.getPoint()); int colIndexStart = columnAtPoint(ev.getPoint()); //System.out.println(isEditing()+" "+rowIndexStart+" "+colIndexStart+" "+prevRowSelInx+" "+prevColSelInx+" "); if (isEditing() && (prevRowSelInx != rowIndexStart || prevColSelInx != colIndexStart)) { getCellEditor().stopCellEditing(); }// ww w. j av a 2 s .co m } // Done - For Java 5 Bug if (ev.isPopupTrigger()) { // No matter what, stop editing if we are editing if (isEditing()) { getCellEditor().stopCellEditing(); } // Now check to see if we right clicked on a different rowor column boolean isOnSelectedCell = false; int rowIndexStart = rowAtPoint(ev.getPoint()); int colIndexStart = columnAtPoint(ev.getPoint()); // Check to see if we are in the selection of mulitple rows and cols if (getSelectedRowCount() > 0) { int[] cols = getSelectedColumns(); for (int r : getSelectedRows()) { if (r == rowIndexStart) { for (int c : cols) { if (c == colIndexStart) { isOnSelectedCell = true; break; } } } } } if (!isOnSelectedCell) { setRowSelectionInterval(rowIndexStart, rowIndexStart); setColumnSelectionInterval(colIndexStart, colIndexStart); } if (popupMenu != null) { popupMenu.setVisible(false); } popupMenu = createMenuForSelection(ev.getPoint()); if (popupMenu.isVisible()) { popupMenu.setVisible(false); } else { //popupMenu.setTargetCells(_selection); Point p = getLocationOnScreen(); popupMenu.setLocation(p.x + ev.getX() + 1, p.y + ev.getY() + 1); popupMenu.setVisible(true); } } super.processMouseEvent(ev); }
From source file:MouseNavigateTest.java
protected boolean isStartBehaviorEvent(java.awt.event.MouseEvent evt) { int nId = evt.getID(); return ((nId == MouseEvent.MOUSE_DRAGGED) && (evt.isAltDown() == false) && (evt.isMetaDown() == false)); }