本文整理汇总了Java中java.awt.MouseInfo类的典型用法代码示例。如果您正苦于以下问题:Java MouseInfo类的具体用法?Java MouseInfo怎么用?Java MouseInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MouseInfo类属于java.awt包,在下文中一共展示了MouseInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: centreOnScreen
import java.awt.MouseInfo; //导入依赖的package包/类
public static void centreOnScreen(Window window)
{
Window owner = window.getOwner();
// If the window has an owner, use the same graphics configuration so it
// will
// open on the same screen. Otherwise, grab the mouse pointer and work
// from there.
GraphicsConfiguration gc = owner != null ? owner.getGraphicsConfiguration() : MouseInfo.getPointerInfo()
.getDevice().getDefaultConfiguration();
if( gc != null )
{
window.setBounds(centre(getUsableScreenBounds(gc), window.getBounds()));
}
else
{
// Fall-back to letting Java do the work
window.setLocationRelativeTo(null);
}
}
示例2: handleAddButton
import java.awt.MouseInfo; //导入依赖的package包/类
@FXML
private void handleAddButton() {
popup.setAutoHide( true );
popup.setHideOnEscape( true );
popup.setAutoFix( true );
try {
sl = SearchList.createSearchList(relationType, this);
} catch (IOException e1) {
e1.printStackTrace();
}
popup.getContent().addAll(sl.getOurRoot());
Point p = MouseInfo.getPointerInfo().getLocation();
popup.show( getOurRoot(), p.getX(), p.getY());
sl.setMaxImageSize(16);
sl.getSearchField().requestFocus();
}
示例3: update
import java.awt.MouseInfo; //导入依赖的package包/类
public void update() {
synchronized (lock) {
for (int i = 0; i < MAX_BUTTONS; i++) {
if (down[i]) {
buttons[i]++;
}
else {
buttons[i] = 0;
}
}
Point p = MouseInfo.getPointerInfo().getLocation();
int curX = p.x - display.getX();
int curY = p.y - display.getY();
dx = curX - x;
dy = curY - y;
x = curX;
y = curY;
dir = curDir;
curDir = ScrollDirection.NONE;
}
}
示例4: setPosition
import java.awt.MouseInfo; //导入依赖的package包/类
@Override
public void setPosition(float newX, float newY) {
synchronized (lock) {
Point p = MouseInfo.getPointerInfo().getLocation();
int curX = p.x - display.getX();
int curY = p.y - display.getY();
int oldX = x;
int oldY = x;
this.x = (int)newX;
this.y = (int)(display.getHeight() - (int)newY - 1);
if (display.getCanvas().hasFocus()) robot.mouseMove(display.getX() + this.x, display.getY() + this.y);
// resetPosition();
this.dx = curX - oldX;
this.dy = curY - oldY;
// lastX += -(curX - oldX);
// lastY += -(curY - oldY);
}
}
示例5: mouseClicked
import java.awt.MouseInfo; //导入依赖的package包/类
@Override
public void mouseClicked(MouseEvent arg0) {
Point p = MouseInfo.getPointerInfo().getLocation();
if(num==1)
{
pt1 = p;
win2 = new ScreenRegionGrab(2);
}
else
{
pt2 = p;
int x = Math.min(pt1.x,pt2.x);
int y = Math.min(pt1.y, pt2.y);
int w = Math.max(pt1.x,pt2.x)-x;
int h = Math.max(pt1.y,pt2.y)-y;
BufferedImage a = rob.createScreenCapture(new Rectangle(x,y,w,h));
RecogApp.doRecog(a);
win1.dispose();
win1=win2=null;
pt1=pt2=null;
dispose();
}
}
示例6: initTimer
import java.awt.MouseInfo; //导入依赖的package包/类
/**
* 启动定时任务,绘制鼠标路径
*/
public void initTimer() {
timer = new Timer();
timer.schedule(new TimerTask() {
int x, y;
int flag = random.nextInt(5);
@Override
public void run() {
Graphics g = getGraphics();
if (g != null) {
if (count == 0) {//遮罩背景只绘制一次
paintMask(g);
count++;
}
Point p = MouseInfo.getPointerInfo().getLocation();
g.setColor(Color.red);
if (x != 0 && y != 0) {
switch (flag) {
case 0:
g.drawLine(x - 123, y - 10, p.x - 123, p.y - 10);
case 1:
g.drawLine(x - 123, y - 5, p.x - 123, p.y - 5);
case 2:
g.drawLine(x - 123, y, p.x - 123, p.y);
case 3:
g.drawLine(x - 123, y + 5, p.x - 123, p.y + 5);
case 4:
g.drawLine(x - 123, y + 10, p.x - 123, p.y + 10);
}
}
x = p.x;
y = p.y;
}
}
}, 0, 50);
}
示例7: paint
import java.awt.MouseInfo; //导入依赖的package包/类
@Override
public void paint(Graphics g, JComponent c) {
LAFUtilities.setProperties(g, c);
if (c.isOpaque()) {
ImageLibrary.drawTiledImage("image.background.FreeColButton", g, c, null);
}
super.paint(g, c);
AbstractButton a = (AbstractButton) c;
if (a.isRolloverEnabled()) {
Point p = MouseInfo.getPointerInfo().getLocation();
SwingUtilities.convertPointFromScreen(p, c);
boolean rollover = c.contains(p);
if (rollover) {
paintButtonPressed(g, (AbstractButton) c);
}
}
}
示例8: onSuccess
import java.awt.MouseInfo; //导入依赖的package包/类
@Override
public void onSuccess(final Object o) {
/**
* naprawione odświeżanie się tooltipów po załadowaniu
*/
final Point locationOnScreen = MouseInfo.getPointerInfo().getLocation();
final Point locationOnComponent = new Point(locationOnScreen);
SwingUtilities.convertPointFromScreen(locationOnComponent, component);
if (component.contains(locationOnComponent)) {
SwingUtilities.invokeLater(() -> {
ToolTipManager.sharedInstance().mouseMoved(
new MouseEvent(component, -1, System.currentTimeMillis(),
0, locationOnComponent.x, locationOnComponent.y,
locationOnScreen.x, locationOnScreen.y, 0, false, 0));
});
}
}
示例9: mouseHover
import java.awt.MouseInfo; //导入依赖的package包/类
@Override
public void mouseHover(MouseEvent e) {
final java.awt.Point mouseLocation1 = MouseInfo.getPointerInfo().getLocation();
EditPart paletteInternalController = viewer.findObjectAt(new Point(
e.x, e.y));
if(paletteInternalController.getModel() instanceof CombinedTemplateCreationEntry){
setGenericComponent(paletteInternalController);
// Hide tooltip if already showing
hidePaletteToolTip();
showToolTipWithDelay(mouseLocation1);
}
}
示例10: keyPressed
import java.awt.MouseInfo; //导入依赖的package包/类
public void keyPressed(KeyEvent e) {
if ( e.getKeyCode() == KeyEvent.VK_SPACE) {
setSpaceBarPress(true);
}
if(getSpaceBarPress()) {
// Set locations
screenPressedX = MouseInfo.getPointerInfo().getLocation().x;
screenPressedY = MouseInfo.getPointerInfo().getLocation().y;
pressedX = scrollPane.getHorizontalScrollBar().getValue();
pressedY = scrollPane.getVerticalScrollBar().getValue();
// Set cursor to closed hand
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();
}
}
}
示例11: openPopupMenu
import java.awt.MouseInfo; //导入依赖的package包/类
protected void openPopupMenu(NodeType[] availableTypes, final AvroNode targetNode, final AvroContext context) {
Shell shell = Display.getCurrent().getActiveShell();
final Menu menu = new Menu(shell, SWT.POP_UP);
for (NodeType availableType : availableTypes) {
final NodeType type = availableType;
MenuItem item = new MenuItem(menu, SWT.PUSH);
item.setText(type.getDisplayLabel());
item.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
menu.dispose();
IEditCommand cmd = context.getService(IEditCommandFactory.class)
.createAddElementCommand(targetNode, type, getNotifications());
context.getService(ICommandExecutor.class).execute(cmd);
}
});
}
Point location = MouseInfo.getPointerInfo().getLocation();
int x = location.x;
int y = location.y;
menu.setLocation(x, y);
menu.setVisible(true);
}
示例12: drawCursor
import java.awt.MouseInfo; //导入依赖的package包/类
/**
* Draws the cursor on the frame, if required.
*
* @param frame the frame to update
* @return the (potentially) updated frame
*/
protected BufferedImage drawCursor(BufferedImage frame) {
PointerInfo pointer;
if (m_CaptureMouse && (m_Cursor != null)) {
pointer = MouseInfo.getPointerInfo();
frame.getGraphics().drawImage(
m_Cursor,
(int) pointer.getLocation().getX() - m_X,
(int) pointer.getLocation().getY() - m_Y,
m_Cursor.getWidth(null),
m_Cursor.getHeight(null),
m_BackgroundColor,
null);
}
return frame;
}
示例13: getPointerLocation
import java.awt.MouseInfo; //导入依赖的package包/类
/**
* Use reflection to access the JDK 1.5 pointer location, if possible and
* only if the given component is on the same screen as the cursor. Return
* null otherwise.
*/
private static Point getPointerLocation(final Component component) {
try {
final GraphicsConfiguration config = component.getGraphicsConfiguration();
if (config != null) {
PointerInfo pointer_info = AccessController.doPrivileged(new PrivilegedExceptionAction<PointerInfo>() {
public PointerInfo run() throws Exception {
return MouseInfo.getPointerInfo();
}
});
GraphicsDevice device = pointer_info.getDevice();
if (device == config.getDevice()) {
return pointer_info.getLocation();
}
return null;
}
} catch (Exception e) {
LWJGLUtil.log("Failed to query pointer location: " + e.getCause());
}
return null;
}
示例14: AnalyzerGroupPane
import java.awt.MouseInfo; //导入依赖的package包/类
public AnalyzerGroupPane(final Session parent, final NodePresentationHelper presentationHelper) {
super(false);
this.parent = parent;
listeners = new ArrayList<AnalyzerPaneListener>();
addChangeListener(this);
analyzerService = new AnalyzerService();
this.presentationHelper = presentationHelper;
final AnalyzerGroupPane me = this;
setAddTabAction(new Runnable() {
@Override
public void run() {
Point p1 = MouseInfo.getPointerInfo().getLocation();
SwingUtilities.convertPointFromScreen(p1, me);
AddTabPopUp popup = new AddTabPopUp(me);
popup.show(me, p1.x, p1.y);
}
});
}
示例15: canvasMouseDown
import java.awt.MouseInfo; //导入依赖的package包/类
private void canvasMouseDown(MouseEvent e) {
if (rootDiagramObject == null)
return;
// SetFocus; // don't remember for what purpose??
Point cursorPos = MouseInfo.getPointerInfo().getLocation();
if (panningMode) {
// set mouse cursor to 'closed hand'
// Screen.Cursor = crClHand;
startPoint.x = round(hsb.getValue() / SCROLL_FACTOR + cursorPos.x / scale);
startPoint.y = round(vsb.getValue() / SCROLL_FACTOR + cursorPos.y / scale);
} else {
SwingUtilities.convertPointFromScreen(cursorPos, canvas);
startPoint.setLocation(cursorPos);
currentPoint.setLocation(startPoint);
selection.mouseDown(rootDiagramObject.testHit(currentPoint.x, currentPoint.y),
(e.getModifiersEx() & (InputEvent.SHIFT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK)) > 0);
mouseDown = true;
}
}