本文整理汇总了Java中java.awt.event.MouseEvent.BUTTON1_MASK属性的典型用法代码示例。如果您正苦于以下问题:Java MouseEvent.BUTTON1_MASK属性的具体用法?Java MouseEvent.BUTTON1_MASK怎么用?Java MouseEvent.BUTTON1_MASK使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.awt.event.MouseEvent
的用法示例。
在下文中一共展示了MouseEvent.BUTTON1_MASK属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mouseDragged
@Override
public void mouseDragged(MouseEvent e) {
// WORKAROUND: Since JTextComponent only updates the caret
// location on mouse clicked and released, we'll do it on dragged
// events when the left mouse button is clicked.
if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) {
Caret caret = getCaret();
dot = caret.getDot();
mark = caret.getMark();
fireCaretUpdate(this);
}
}
示例2: mousePressed
@Override
public void mousePressed(MouseEvent e) {
if (e.isPopupTrigger()) { // OS X popup triggers are on pressed
showPopup(e);
}
else if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) {
Caret caret = getCaret();
dot = caret.getDot();
mark = caret.getMark();
fireCaretUpdate(this);
}
}
示例3: mouseDragged
/**
* {@inheritDoc}
*/
@Override
public void mouseDragged(MouseEvent e) {
if ((e.getModifiers() & MouseEvent.BUTTON1_MASK)
!= MouseEvent.BUTTON1_MASK) return; // Do not use getButton!
performDragScrollIfActive(e);
if (canvas.isGotoStarted()) {
getGUI().updateGotoPath(canvas.convertToMapTile(e.getX(), e.getY()));
} else if (canvas.isDrag(e.getX(), e.getY())) {
canvas.startGoto();
}
}
示例4: mouseDragged
/**
* Invoked when the mouse has been dragged.
*
* @param e The MouseEvent that holds all the information.
*/
@Override
public void mouseDragged(MouseEvent e) {
performDragScrollIfActive(e);
Tile tile = canvas.convertToMapTile(e.getX(), e.getY());
if (tile != null
&& ((e.getModifiers() & MouseEvent.BUTTON1_MASK)
== MouseEvent.BUTTON1_MASK)) {
// only perform the goto for the left mouse button
if (canvas.isGotoStarted()) {
Unit active = canvas.getActiveUnit();
if (active == null) {
canvas.stopGoto();
} else if (lastTile != tile) {
lastTile = tile;
PathNode dragPath = active.findPath(tile);
canvas.setGotoPath(dragPath);
}
} else {
// Only start a goto if the drag is 16 pixels or more
Point dragPoint = canvas.getDragPoint();
int deltaX = Math.abs(e.getX() - dragPoint.x);
int deltaY = Math.abs(e.getY() - dragPoint.y);
if (deltaX >= DRAG_THRESHOLD || deltaY >= DRAG_THRESHOLD) {
canvas.startGoto();
}
}
}
}
示例5: testClickInvokesCustomEditor
public void testClickInvokesCustomEditor() throws Exception {
if( !ExtTestCase.canSafelyRunFocusTests() )
return;
Node n = new ANode();
setCurrentNode (n, sheet);
sleep();
requestFocus (sheet.table);
sleep();
Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();
if (owner == sheet.table) { //sanity check to avoid random failures on some window managers
System.out.println ("About to click cell");
Rectangle r = sheet.table.getCellRect(1, 1, false);
final MouseEvent me = new MouseEvent (sheet.table, MouseEvent.MOUSE_PRESSED,
System.currentTimeMillis(), MouseEvent.BUTTON1_MASK, r.x + 3,
r.y + 3, 2, false);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
sheet.table.dispatchEvent(me);
}
});
sleep();
sleep();
System.out.println ("Now checking focus");
owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
assertTrue ("Focus owner should be custom editor, not " + owner, owner instanceof JTextArea);
JComponent jc = (JComponent) owner;
assertTrue ("Custom editor should have been invoked, but focus owner's top level ancestor is not a dialog", jc.getTopLevelAncestor() instanceof Dialog);
Dialog d = (Dialog) jc.getTopLevelAncestor();
d.setVisible(false);
}
requestFocus (sheet.table);
sleep();
owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();
if (owner == sheet.table) { //sanity check to avoid random failures on some window managers
pressKey(sheet.table, KeyEvent.VK_SPACE);
sleep();
owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();
assertTrue ("After pressing a key, focus owner should still be the table, not " + owner, sheet.table == owner);
}
}
示例6: mouseClicked
public void mouseClicked(MouseEvent e) {
//System.out.println("PlotCanvas.mouseClicked");
/*
* System.out.println("PlotCanvas.mouseClicked"); System.out.println("
* mouseClick = [" + mouseClick[0] + " " + mouseClick[1] + "]");
* System.out.println(" mouseCurent = [" + mouseCurent[0] + " " +
* mouseCurent[1] + "]");
*/
mouseCurent[0] = e.getX();
mouseCurent[1] = e.getY();
e.consume();
mouseClick[0] = mouseCurent[0];
mouseClick[1] = mouseCurent[1];
if (allowEdit) {
if (e.getModifiers() == MouseEvent.BUTTON1_MASK && e.getClickCount() > 1) {
for (int i = 0; i < grid.getAxis().length; i++) {
if (grid.getAxis(i).isSelected(mouseClick, draw) != null) {
grid.getAxis(i).edit(this);
return;
}
}
for (int i = 0; i < plots.size(); i++) {
if (getPlot(i).isSelected(mouseClick, draw) != null) {
getPlot(i).edit(this);
return;
}
}
}
}
if (!dragging && allowNote) {
for (int i = 0; i < plots.size(); i++) {
double[] _coordNoted = getPlot(i).isSelected(mouseClick, draw);
if (e.getModifiers() == MouseEvent.BUTTON1_MASK) {
if (_coordNoted != null) {
getPlot(i).noted = !getPlot(i).noted;
} else {
getPlot(i).noted = false;
}
} else if (e.getModifiers() == MouseEvent.BUTTON3_MASK) {
if (_coordNoted != null) {
if (getPlot(i).coordNoted != null) {
boolean alreadyNoted = true;
for (int j = 0; j < _coordNoted.length; j++) {
alreadyNoted = alreadyNoted && _coordNoted[j] == getPlot(i).coordNoted[j];
}
if (alreadyNoted) {
getPlot(i).coordNoted = null;
} else {
getPlot(i).coordNoted = _coordNoted;
}
} else {
getPlot(i).coordNoted = _coordNoted;
}
}
}
}
repaint();
} else {
dragging = false;
}
}
示例7: processMouseEvents
/**
* Processes all caught <code>MouseEvent</code>s.
*
* @param e the <code>MouseEvent</code>
*/
private void processMouseEvents(MouseEvent e) {
int tabNumber = getUI().tabForCoordinate(this, e.getX(), e.getY());
if (tabNumber < 0)
return;
CloseTabIcon icon = (CloseTabIcon) getIconAt(tabNumber);
if (icon != null) {
Rectangle rect = icon.getBounds();
Point pos = headerViewport == null ? new Point() : headerViewport
.getViewPosition();
Rectangle drawRect = new Rectangle(rect.x - pos.x, rect.y - pos.y,
rect.width, rect.height);
if (e.getID() == MouseEvent.MOUSE_PRESSED) {
icon.mousepressed = e.getModifiers() == MouseEvent.BUTTON1_MASK;
repaint(drawRect);
} else if (e.getID() == MouseEvent.MOUSE_MOVED
|| e.getID() == MouseEvent.MOUSE_DRAGGED
|| e.getID() == MouseEvent.MOUSE_CLICKED) {
pos.x += e.getX();
pos.y += e.getY();
if (rect.contains(pos)) {
if (e.getID() == MouseEvent.MOUSE_CLICKED) {
int selIndex = getSelectedIndex();
if (fireCloseTab(selIndex)) {
if (selIndex > 0) {
// to prevent uncatchable null-pointers
Rectangle rec = getUI().getTabBounds(this,
selIndex - 1);
MouseEvent event = new MouseEvent((Component) e
.getSource(), e.getID() + 1, System
.currentTimeMillis(), e.getModifiers(),
rec.x, rec.y, e.getClickCount(), e
.isPopupTrigger(), e
.getButton());
dispatchEvent(event);
}
// the tab is being closed
// removeTabAt(tabNumber);
remove(selIndex);
} else {
icon.mouseover = false;
icon.mousepressed = false;
repaint(drawRect);
}
} else {
icon.mouseover = true;
icon.mousepressed = e.getModifiers() == MouseEvent.BUTTON1_MASK;
}
} else {
icon.mouseover = false;
}
repaint(drawRect);
}
}
}
示例8: processMouseEvents
/**
* Processes all caught <code>MouseEvent</code>s.
*
* @param e the <code>MouseEvent</code>
*/
private void processMouseEvents(MouseEvent e) {
int tabNumber = getUI().tabForCoordinate(this, e.getX(), e.getY());
if (tabNumber < 0) {
return;
}
CloseTabIcon icon = (CloseTabIcon) getIconAt(tabNumber);
if (icon != null) {
// TODO: draw states of button '+'
if (icon instanceof AddTabIcon && (e.getID() == MouseEvent.MOUSE_CLICKED)) {
tabButtonPressed();
return;
}
/* allow all tabs closing feature */
if (getTabCount() <= (allowAllTabsClosing ? (addTabLabel != null ? 1 : 0)
: addTabLabel != null ? 2 : 1)) {
return;
}
Rectangle rect = icon.getBounds();
Point pos = headerViewport == null ? new Point() : headerViewport
.getViewPosition();
Rectangle drawRect = new Rectangle(rect.x - pos.x, rect.y - pos.y,
rect.width, rect.height);
if (e.getID() == MouseEvent.MOUSE_PRESSED) {
icon.mousepressed = e.getModifiers() == MouseEvent.BUTTON1_MASK;
repaint(drawRect);
} else if (e.getID() == MouseEvent.MOUSE_MOVED
|| e.getID() == MouseEvent.MOUSE_DRAGGED
|| e.getID() == MouseEvent.MOUSE_CLICKED) {
pos.x += e.getX();
pos.y += e.getY();
if (rect.contains(pos)) {
if (e.getID() == MouseEvent.MOUSE_CLICKED) {
int selIndex = getSelectedIndex();
if (fireCloseTab(selIndex)) {
if (selIndex > 0) {
// to prevent uncatchable null-pointers
Rectangle rec = getUI().getTabBounds(this,
selIndex - 1);
MouseEvent event = new MouseEvent((Component) e
.getSource(), e.getID() + 1, System
.currentTimeMillis(), e.getModifiers(),
rec.x, rec.y, e.getClickCount(), e
.isPopupTrigger(), e
.getButton());
dispatchEvent(event);
}
// the tab is being closed
// removeTabAt(tabNumber);
//remove(selIndex);
removeTabAt(selIndex);
} else {
icon.mouseover = false;
icon.mousepressed = false;
repaint(drawRect);
}
} else {
icon.mouseover = true;
icon.mousepressed = e.getModifiers() == MouseEvent.BUTTON1_MASK;
}
} else {
icon.mouseover = false;
}
repaint(drawRect);
}
}
}