Java Code Examples for java.awt.event.MouseEvent.getModifiers()

The following are Jave code examples for showing how to use getModifiers() of the java.awt.event.MouseEvent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: geomapapp   File: UnknownDataSet.java   View Source Code Vote up 6 votes
public void mouseDragged(MouseEvent e) {
	
	if (station){
		//if a datapoint is selected, move it to a new location and update the lat/lon values.
		//only works for editable datasets (ie imported datasets)
		if (tm.editable && selectedRow >= 0) {
			Point2D latlon = getMouseLatLon(e);
			tm.setValueAt(String.valueOf(latlon.getX()), selectedRow, lonIndex);
			tm.setValueAt(String.valueOf(latlon.getY()), selectedRow, latIndex);
		}
	}
	
	if (db.panTB.isSelected() || e.getModifiers()==4 || !db.lassoTB.isSelected()) return;

	if (poly!=null){
		if (Math.abs(poly.xpoints[poly.npoints-1]-e.getX())<=1
				&&Math.abs(poly.ypoints[poly.npoints-1]-e.getY())<=1)  return;
		poly.addPoint(e.getX(), e.getY());
		drawLasso();
	} else if (p1!=null) {
		drawSelectionBox();
		p2=e.getPoint();
		drawSelectionBox();
	}
}
 
Example 2
Project: powertext   File: ConfigurableCaret.java   View Source Code Vote up 5 votes
/**
 * Adjusts the caret location based on the MouseEvent.
 */
private void adjustCaret(MouseEvent e) {
	if ((e.getModifiers()&ActionEvent.SHIFT_MASK)!=0 && getDot()!=-1) {
		moveCaret(e);
	}
	else {
		positionCaret(e);
	}
}
 
Example 3
Project: incubator-netbeans   File: FileCompletionPopup.java   View Source Code Vote up 5 votes
private MouseEvent convertMouseEvent( MouseEvent e ) {
    Point convertedPoint = SwingUtilities.convertPoint( (Component)e.getSource(),
            e.getPoint(), list );
    MouseEvent newEvent = new MouseEvent( (Component)e.getSource(),
            e.getID(),
            e.getWhen(),
            e.getModifiers(),
            convertedPoint.x,
            convertedPoint.y,
            e.getClickCount(),
            e.isPopupTrigger() );
    return newEvent;
}
 
Example 4
Project: openjdk-jdk10   File: bug7170657.java   View Source Code Vote up 5 votes
private static void test(final Frame frame, final MouseEvent me) {
    MouseEvent newme = SwingUtilities.convertMouseEvent(frame, me, frame);
    if (me.getModifiersEx() != newme.getModifiersEx()
            || me.getModifiers() != newme.getModifiers()) {
        fail(me, newme);
    }
}
 
Example 5
Project: jmt   File: SelectState.java   View Source Code Vote up 5 votes
@Override
public void handleRelease(MouseEvent e) {
	mediator.setIsReleased(true);
	try {
		if (e != null && !e.isConsumed()) {
			if (ml.getHandler() == ml.getMarquee() && ml.getMarquee() != null) {
				ml.getMarquee().mouseReleased(e);
			} else if (ml.getHandler() == ml.getHandle() && ml.getHandle() != null) {
				ml.getHandle().mouseReleased(e);
			}
			if (ml.isDescendant(ml.getCell(), ml.getFocus()) && e.getModifiers() != 0) {
				// Do not switch to parent if Special Selection
				ml.setCell(ml.getFocus());
			}

			// Puts selected cells in good place to avoid overlapping
			if (moved && Xmin.length > 0 && Ymin.length > 0) {
				mediator.putSelectedCellsInGoodPlace(cells, Xmin, Ymin);
				mediator.avoidOverlappingCell(cells);
				moved = false;
			}

			if (!e.isConsumed() && ml.getCell() != null) {
				Object tmp = ml.getCell().getCell();
				boolean wasSelected = mediator.isCellSelected(tmp);
				mediator.selectCellForEvent(tmp, e);
				ml.setFocus(ml.getCell());
				ml.postProcessSelection(e, tmp, wasSelected);
			}
			// Notify mediator that object can have been placed inside or
			// outside a blocking region
			mediator.handlesBlockingRegionDrag();
		}
	} finally {
		ml.setHandler(null);
		ml.setCell(null);
	}

}
 
Example 6
Project: geomapapp   File: XMap.java   View Source Code Vote up 5 votes
public void mouseClicked(MouseEvent e) {
	// GMA 1.6.4: Center on spot where user double-clicks (but not if Digitizer is open)
	if ( e.getClickCount() >= 2 && e.getModifiers()==16 && !((MapApp)app).digitizer.isEnabled()) {
		Point p = e.getPoint();
		doZoom( p, 1 );
	}
}
 
Example 7
Project: incubator-netbeans   File: JTitledPanel.java   View Source Code Vote up 5 votes
public void mouseClicked(MouseEvent e) {
    if ((e.getModifiers() == InputEvent.BUTTON1_MASK) && (e.getClickCount() == 2)) {
        if (isMaximized()) {
            restore();
        } else {
            maximize();
        }
    }

    ;
}
 
Example 8
Project: openjdk-jdk10   File: MouseButtonsAndKeyMasksTest.java   View Source Code Vote up 5 votes
@Override
public void mousePressed(MouseEvent e) {

    modMouse = e.getModifiers();
    modMouseEx = e.getModifiersEx();
    mousePressFired = true;
    synchronized (lock) { lock.notifyAll(); }
}
 
Example 9
Project: jdk8u-jdk   File: bug7170657.java   View Source Code Vote up 5 votes
private static void test(final Frame frame, final MouseEvent me) {
    MouseEvent newme = SwingUtilities.convertMouseEvent(frame, me, frame);
    if (me.getModifiersEx() != newme.getModifiersEx()
            || me.getModifiers() != newme.getModifiers()) {
        fail(me, newme);
    }
}
 
Example 10
Project: litiengine   File: Mouse.java   View Source Code Vote up 4 votes
private MouseEvent createEvent(final MouseEvent original) {
  return new MouseEvent(original.getComponent(), original.getID(), original.getWhen(), original.getModifiers(), (int) this.getLocation().getX(), (int) this.getLocation().getY(), original.getXOnScreen(), original.getYOnScreen(), original.getClickCount(), original.isPopupTrigger(),
      original.getButton());
}
 
Example 11
Project: openjdk-jdk10   File: bug7146377.java   View Source Code Vote up 4 votes
private static boolean oldIsRightMouseButton(MouseEvent e) {
    return ((e.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK);
}
 
Example 12
Project: incubator-netbeans   File: FindTypesSupport.java   View Source Code Vote up 4 votes
@Override
    public void mouseMoved(MouseEvent e) {
        JTextPane pane = (JTextPane)e.getSource();
        StyledDocument doc = pane.getStyledDocument();

        int offset = pane.viewToModel(e.getPoint());
        Element elem = doc.getCharacterElement(offset);

        Highlight h = getHighlight(pane, offset);
        Highlight prevHighlight = (Highlight) pane.getClientProperty(PREV_HIGHLIGHT_PROPERTY);
        AttributeSet prevAs = (AttributeSet) pane.getClientProperty(PREV_HIGHLIGHT_ATTRIBUTES);
//        if(h != null && h.equals(prevHighlight)) {
//            return; // nothing to do
//        } else 
        if(prevHighlight != null && prevAs != null) {
            doc.setCharacterAttributes(prevHighlight.startOffset, prevHighlight.endOffset - prevHighlight.startOffset, prevAs, true);
            pane.putClientProperty(PREV_HIGHLIGHT_PROPERTY, null);
            pane.putClientProperty(PREV_HIGHLIGHT_ATTRIBUTES, null);
        }

        int modifiers = e.getModifiers() | e.getModifiersEx();
        if ( (modifiers & InputEvent.CTRL_DOWN_MASK) == InputEvent.CTRL_DOWN_MASK ||
             (modifiers & InputEvent.META_DOWN_MASK) == InputEvent.META_DOWN_MASK) 
        {            
            AttributeSet as = elem.getAttributes();
            if (StyleConstants.isUnderline(as)) {
                // do not underline whats already underlined
                return;
            }

            Font font = doc.getFont(as);
            FontMetrics fontMetrics = pane.getFontMetrics(font);
            try {
                Rectangle rectangle = new Rectangle(
                        pane.modelToView(elem.getStartOffset()).x,
                        pane.modelToView(elem.getStartOffset()).y,
                        fontMetrics.stringWidth(doc.getText(elem.getStartOffset(), elem.getEndOffset() - elem.getStartOffset())),
                        fontMetrics.getHeight());

                if (h != null && offset < elem.getEndOffset() - 1 && rectangle.contains(e.getPoint())) {
                    Style hlStyle = doc.getStyle("regularBlue-findtype");               // NOI18N

                    pane.putClientProperty(PREV_HIGHLIGHT_ATTRIBUTES, as.copyAttributes());
                    doc.setCharacterAttributes(h.startOffset, h.endOffset - h.startOffset, hlStyle, true);
    //                doc.setCharacterAttributes(h.startOffset, h.endOffset - h.startOffset, as.copyAttributes(), true);
                    pane.putClientProperty(PREV_HIGHLIGHT_PROPERTY, h);
                } 
            } catch (BadLocationException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
    }
 
Example 13
Project: SER316-Aachen   File: JTreeTable.java   View Source Code Vote up 4 votes
/**
 * Overridden to return false, and if the event is a mouse event it is
 * forwarded to the tree.
 * <p>
 * The behavior for this is debatable, and should really be offered as a
 * property. By returning false, all keyboard actions are implemented in
 * terms of the table. By returning true, the tree would get a chance to
 * do something with the keyboard events. For the most part this is ok.
 * But for certain keys, such as left/right, the tree will
 * expand/collapse where as the table focus should really move to a
 * different column. Page up/down should also be implemented in terms of
 * the table. By returning false this also has the added benefit that
 * clicking outside of the bounds of the tree node, but still in the
 * tree column will select the row, whereas if this returned true that
 * wouldn't be the case.
 * <p>
 * By returning false we are also enforcing the policy that the tree
 * will never be editable (at least by a key sequence).
 */
public boolean isCellEditable(EventObject e) {
	if (e instanceof MouseEvent) {
		for (int counter = getColumnCount() - 1; counter >= 0; counter--) {
			if (getColumnClass(counter) == TreeTableModel.class) {
				MouseEvent me = (MouseEvent) e;
				MouseEvent newME = new MouseEvent(tree, me.getID(), me
						.getWhen(), me.getModifiers(), me.getX()
						- getCellRect(0, counter, true).x, me.getY(),
						me.getClickCount(), me.isPopupTrigger());
				tree.dispatchEvent(newME);
				break;
			}
		}
	}
	return false;
}
 
Example 14
Project: SER316-Dresden   File: TaskTable.java   View Source Code Vote up 4 votes
/**
 * Overridden to return false, and if the event is a mouse event it is
 * forwarded to the tree.
 * <p>
 * The behavior for this is debatable, and should really be offered as a
 * property. By returning false, all keyboard actions are implemented in
 * terms of the table. By returning true, the tree would get a chance to
 * do something with the keyboard events. For the most part this is ok.
 * But for certain keys, such as left/right, the tree will
 * expand/collapse where as the table focus should really move to a
 * different column. Page up/down should also be implemented in terms of
 * the table. By returning false this also has the added benefit that
 * clicking outside of the bounds of the tree node, but still in the
 * tree column will select the row, whereas if this returned true that
 * wouldn't be the case.
 * <p>
 * By returning false we are also enforcing the policy that the tree
 * will never be editable (at least by a key sequence).
 */
public boolean isCellEditable(EventObject e) {
    if (e instanceof MouseEvent) {
        for (int counter = getColumnCount() - 1; counter >= 0; counter--) {
            if (getColumnClass(counter) == TreeTableModel.class) {
                MouseEvent me = (MouseEvent) e;
                MouseEvent newME = new MouseEvent(tree, me.getID(), me
                        .getWhen(), me.getModifiers(), me.getX()
                        - getCellRect(0, counter, true).x, me.getY(),
                        me.getClickCount(), me.isPopupTrigger());
                tree.dispatchEvent(newME);
                break;
            }
        }
    }
    return false;
}
 
Example 15
Project: openjdk-jdk10   File: bug7146377.java   View Source Code Vote up 4 votes
private static boolean oldIsMiddleMouseButton(MouseEvent e) {
    return ((e.getModifiers() & InputEvent.BUTTON2_MASK) == InputEvent.BUTTON2_MASK);
}
 
Example 16
Project: jdk8u-jdk   File: bug7146377.java   View Source Code Vote up 4 votes
private static boolean oldIsMiddleMouseButton(MouseEvent e) {
    return ((e.getModifiers() & InputEvent.BUTTON2_MASK) == InputEvent.BUTTON2_MASK);
}
 
Example 17
Project: openjdk-jdk10   File: XButtonPeer.java   View Source Code Vote up 4 votes
void handleJavaMouseEvent(MouseEvent e) {
    super.handleJavaMouseEvent(e);
    int id = e.getID();
    switch (id) {
      case MouseEvent.MOUSE_PRESSED:
          if (XToolkit.isLeftMouseButton(e) ) {
              Button b = (Button) e.getSource();

              if(b.contains(e.getX(), e.getY())) {
                  if (!isEnabled()) {
                      // Disabled buttons ignore all input...
                      return;
                  }
                  pressed = true;
                  armed = true;
                  repaint();
              }
          }

          break;

      case MouseEvent.MOUSE_RELEASED:
          if (XToolkit.isLeftMouseButton(e)) {
              if (armed)
              {
                  @SuppressWarnings("deprecation")
                  final int modifiers = e.getModifiers();
                  action(e.getWhen(), modifiers);
              }
              pressed = false;
              armed = false;
              repaint();
          }

          break;

      case  MouseEvent.MOUSE_ENTERED:
          if (pressed)
              armed = true;
          break;
      case MouseEvent.MOUSE_EXITED:
          armed = false;
          break;
    }
}
 
Example 18
Project: OpenDA   File: EditablePlot.java   View Source Code Vote up 4 votes
public void mouseReleased(MouseEvent event) {
    if ((event.getModifiers() & InputEvent.BUTTON3_MASK)!= 0) {
        EditablePlot.this._edit(event.getX(), event.getY());
    }
}
 
Example 19
Project: SER316-Ingolstadt   File: TaskTable.java   View Source Code Vote up 4 votes
/**
 * Overridden to return false, and if the event is a mouse event it is
 * forwarded to the tree.
 * <p>
 * The behavior for this is debatable, and should really be offered as a
 * property. By returning false, all keyboard actions are implemented in
 * terms of the table. By returning true, the tree would get a chance to
 * do something with the keyboard events. For the most part this is ok.
 * But for certain keys, such as left/right, the tree will
 * expand/collapse where as the table focus should really move to a
 * different column. Page up/down should also be implemented in terms of
 * the table. By returning false this also has the added benefit that
 * clicking outside of the bounds of the tree node, but still in the
 * tree column will select the row, whereas if this returned true that
 * wouldn't be the case.
 * <p>
 * By returning false we are also enforcing the policy that the tree
 * will never be editable (at least by a key sequence).
 */
public boolean isCellEditable(EventObject e) {
    if (e instanceof MouseEvent) {
        for (int counter = getColumnCount() - 1; counter >= 0; counter--) {
            if (getColumnClass(counter) == TreeTableModel.class) {
                MouseEvent me = (MouseEvent) e;
                MouseEvent newME = new MouseEvent(tree, me.getID(), me
                        .getWhen(), me.getModifiers(), me.getX()
                        - getCellRect(0, counter, true).x, me.getY(),
                        me.getClickCount(), me.isPopupTrigger());
                tree.dispatchEvent(newME);
                break;
            }
        }
    }
    return false;
}
 
Example 20
Project: geomapapp   File: XMap.java   View Source Code Vote up 4 votes
public void mouseDragged(MouseEvent e) {

		// GMA 1.6.4: Perform pan while "Pan" button is selected by performing a centering on the point that is dragged to.
		// Pan with right click of mouse equivalent of modifier 4
		if ( (((MapApp)app).tools.panB.isSelected() && e.getModifiers()==16) ||
				((e.getModifiers()==4)) ) {
			// Set cursor to closed hand while drag
			Toolkit toolkit = Toolkit.getDefaultToolkit();
			ClassLoader loader = org.geomapapp.util.Icons.class.getClassLoader();
			String path = "org/geomapapp/resources/icons/close_hand.png";
			java.net.URL url = loader.getResource(path);
			try {
				BufferedImage im = ImageIO.read(url);
				Cursor closeHandCursor = toolkit.createCustomCursor( im, new Point(0,0), "close_hand");
				setCursor(closeHandCursor);
			} catch (IOException e1) {
				e1.printStackTrace();
			}
			int newX = pressedX - ( MouseInfo.getPointerInfo().getLocation().x - screenPressedX );
			if (wrap > 0) {
				double dx = wrap * zoom;
				while (newX < 0) {
					newX += dx;
				}
				int test = getPreferredSize().width - getVisibleRect().width;
				while (newX > test)
					newX -= dx;
			}
			scrollPane.getHorizontalScrollBar().setValue( newX );
			/*if ( screenPressedX < MouseInfo.getPointerInfo().getLocation().x ) {
				scrollPane.getHorizontalScrollBar().setValue( newX );
			}
			else {
				scrollPane.getHorizontalScrollBar().setValue( newX );
			} */
			if ( screenPressedY < MouseInfo.getPointerInfo().getLocation().y ) {
				scrollPane.getVerticalScrollBar().setValue( pressedY - ( MouseInfo.getPointerInfo().getLocation().y - screenPressedY ) );
			}
			else {
				scrollPane.getVerticalScrollBar().setValue( pressedY + ( screenPressedY - MouseInfo.getPointerInfo().getLocation().y ) );
			}
			revalidate();
			repaint();
		} 
		else {
			setSpaceBarPress(false);
		}
		// Request focus on so that KeyEvents work again
		requestFocusInWindow();
	}