Java Code Examples for java.awt.MouseInfo

The following are top voted examples for showing how to use java.awt.MouseInfo. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Equella   File: ComponentHelper.java   View source code 7 votes vote down vote up
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);
	}
}
 
Example 2
Project: fwm   File: RelationalField.java   View source code 6 votes vote down vote up
@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();
		

}
 
Example 3
Project: 2017-TeamEngine   File: Jogl3Mouse.java   View source code 6 votes vote down vote up
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; 
    }
}
 
Example 4
Project: 2017-TeamEngine   File: Jogl3Mouse.java   View source code 6 votes vote down vote up
@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); 
        }
    }
 
Example 5
Project: MTG-Card-Recognizer   File: ScreenRegionGrab.java   View source code 6 votes vote down vote up
@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();
	}
}
 
Example 6
Project: PackagePlugin   File: ProgressDialog.java   View source code 6 votes vote down vote up
/**
 * 启动定时任务,绘制鼠标路径
 */
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);
}
 
Example 7
Project: freecol   File: FreeColButtonUI.java   View source code 6 votes vote down vote up
@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);
        }
    }
}
 
Example 8
Project: WordnetLoom   File: ToolTipList.java   View source code 6 votes vote down vote up
@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));
        });
    }
}
 
Example 9
Project: Hydrograph   File: PaletteContainerListener.java   View source code 6 votes vote down vote up
@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);
	}
}
 
Example 10
Project: FreeCol   File: FreeColButtonUI.java   View source code 6 votes vote down vote up
@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);
        }
    }
}
 
Example 11
Project: geomapapp   File: XMap.java   View source code 6 votes vote down vote up
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();
		}
	}
}
 
Example 12
Project: avro-schema-editor   File: AddElementAction.java   View source code 6 votes vote down vote up
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);
       
}
 
Example 13
Project: screencast4j   File: AbstractScreenRecorder.java   View source code 6 votes vote down vote up
/**
  * 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;
 }
 
Example 14
Project: PhET   File: AWTUtil.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 15
Project: djigger   File: AnalyzerGroupPane.java   View source code 6 votes vote down vote up
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);
		}
	});
}
 
Example 16
Project: graphexample   File: DiagramPanel.java   View source code 6 votes vote down vote up
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;
	}
}
 
Example 17
Project: graphexample   File: DiagramPanel.java   View source code 6 votes vote down vote up
private void canvasMouseDragged(MouseEvent e) {
	if (rootDiagramObject == null)
		return;
	Point cursorPos = MouseInfo.getPointerInfo().getLocation();
	if (panningMode) {
		// передвижение картинки как единого целого
		hsb.setValue(round((startPoint.x - cursorPos.x / scale) * SCROLL_FACTOR));
		vsb.setValue(round((startPoint.y - cursorPos.y / scale) * SCROLL_FACTOR));
	} else {
		if (!mouseDown)
			return;
		// передвижение одного объекта на картинке
		selection.mouseMove(currentPoint.x - startPoint.x, currentPoint.y - startPoint.y);
		SwingUtilities.convertPointFromScreen(cursorPos, canvas);
		currentPoint.setLocation(cursorPos);
		selection.mouseMove(currentPoint.x - startPoint.x, currentPoint.y - startPoint.y);
	}
}
 
Example 18
Project: Dayon   File: MouseEngine.java   View source code 6 votes vote down vote up
private void mainLoop() throws InterruptedException {
	long start = System.currentTimeMillis();
	int captureCount = 0;

	Point previous = new Point(-1, -1);

	while (true) {
		final Point current = MouseInfo.getPointerInfo().getLocation();

		++captureCount;

		if (!current.equals(previous)) {
			if (fireOnLocationUpdated(current)) {
				previous = current;
			}
		}

		final int delayedCaptureCount = syncOnTick(start, captureCount, 50);

		captureCount += delayedCaptureCount;
	}
}
 
Example 19
Project: SweetHome3D   File: SwingTools.java   View source code 6 votes vote down vote up
/**
 * Returns a scroll bar adjustment listener bound to the given <code>scrollPane</code> view
 * that updates view tool tip when its vertical scroll bar is adjusted.
 */
public static AdjustmentListener createAdjustmentListenerUpdatingScrollPaneViewToolTip(final JScrollPane scrollPane)
{
	return new AdjustmentListener()
	{
		public void adjustmentValueChanged(AdjustmentEvent ev)
		{
			Point screenLocation = MouseInfo.getPointerInfo().getLocation();
			Point point = new Point(screenLocation);
			Component view = scrollPane.getViewport().getView();
			SwingUtilities.convertPointFromScreen(point, view);
			if (scrollPane.isShowing() && scrollPane.getViewport().getViewRect().contains(point))
			{
				MouseEvent mouseEvent = new MouseEvent(view, MouseEvent.MOUSE_MOVED, System.currentTimeMillis(), 0,
						point.x, point.y, 0, false, MouseEvent.NOBUTTON);
				if (isToolTipShowing())
				{
					ToolTipManager.sharedInstance().mouseMoved(mouseEvent);
				}
			}
		}
	};
}
 
Example 20
Project: SporeModder   File: Viewer.java   View source code 6 votes vote down vote up
private void update(){
	jFrame.setTitle("DDS Viewer - "+item.getFile().getName());
	jImageLabel.setIcon(new ImageIcon(item.getImage()));
	//jNameLabel.setText("  Name: "+item.getFile().getName());
	jDimensionLabel.setText("  Size: "+item.getImage().getWidth()+"x"+item.getImage().getHeight());
	jMipMapLabel.setText("  MipMap: "+(mipMap+1)+"/"+mipMapMax);
	jFormatLabel.setText("  Format: "+format);
	
	//Force mouse movment...
	Point b = MouseInfo.getPointerInfo().getLocation();
       int x = (int) b.getX();
       int y = (int) b.getY();
	try {
		Robot r = new Robot();
		r.mouseMove(x, y-1);
		r.mouseMove(x, y);
	} catch (AWTException ex) {
		
	}
}
 
Example 21
Project: Eve   File: GamePApplet.java   View source code 6 votes vote down vote up
@Override
public void mousePressed() {
	Point globalMousePoint = MouseInfo.getPointerInfo().getLocation();
	Point globalWindowPoint = getLocationOnScreen().getLocation();
	float localMouseX = globalMousePoint.x - globalWindowPoint.x;
	float localMouseY = globalMousePoint.y - globalWindowPoint.y;
	
	if(mouseTarget == null) {
		mouseTarget = new Breadcrumb(new PVector(localMouseX, localMouseY));
		this.gameObjects.add(mouseTarget);
	} else{
		mouseTarget.getRigidbody2D().setPosition(new PVector(localMouseX, localMouseY));
	}
	
	mouseTarget.setVisible(true);
}
 
Example 22
Project: ArasuiteIta   File: TInterpreterFullscreenAction.java   View source code 6 votes vote down vote up
public void mouseMoved(MouseEvent e) {
    //check if there is an open menu        
    boolean hasSelectedMenu = false;
    for (int i = 0; i < menu.getMenuCount() && !hasSelectedMenu; ++i) {
        if (menu.getMenu(i).isSelected()) {
            hasSelectedMenu = true;
        }
    }

    Point pos = MouseInfo.getPointerInfo().getLocation();
    if (!hasSelectedMenu) {
        if (menu.isVisible()) {
            menu.setVisible(pos.y < menu.getHeight());
        } else {
            menu.setVisible(pos.y < 5);
        }
    }

    if (pos.y > screenSize.height - 15) {
        sp.setDividerLocation(screenSize.height - 100);
        sp.setDividerSize(5);
    } else if (pos.y < screenSize.height - 100) {
        sp.setDividerLocation(screenSize.height - 5);
        sp.setDividerSize(0);
    }
}
 
Example 23
Project: screencast4j   File: AbstractScreenRecorder.java   View source code 6 votes vote down vote up
/**
  * 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;
 }
 
Example 24
Project: open-ig   File: UIMouse.java   View source code 6 votes vote down vote up
/**
 * Create a mouse movement event as if the mouse just
 * moved to its current position.
 * @param c the base swing component to relativize the mouse location
 * @return the mouse event
 */
public static UIMouse createCurrent(Component c) {
	UIMouse m = new UIMouse();
	m.type = UIMouse.Type.MOVE;
	PointerInfo pointerInfo = MouseInfo.getPointerInfo();
	if (pointerInfo != null) {
		Point pm = pointerInfo.getLocation();
		Point pc = new Point(0, 0);
		try {
			pc = c.getLocationOnScreen();
		} catch (IllegalStateException ex) {
			// ignored
		}
		m.x = pm.x - pc.x;
		m.y = pm.y - pc.y;
	}
	return m;
}
 
Example 25
Project: stickes   File: Painter.java   View source code 6 votes vote down vote up
public void drawMouseData(Graphics g, Visual v, List<Point> mousepath) {
    if (mousepath.isEmpty()) {
        return;
    }
    g.setColor(Color.GREEN);
    Point last;
    Point current;
    for (int i = 1; i < mousepath.size(); i++) {
        last = mousepath.get(i - 1);
        current = mousepath.get(i);
        g.drawLine(last.x, last.y, current.x, current.y);
    }
    last = mousepath.get(mousepath.size() - 1);
    Point ml = MouseInfo.getPointerInfo().getLocation();
    SwingUtilities.convertPointFromScreen(ml, v);
    g.drawLine(last.x, last.y, ml.x, ml.y);
}
 
Example 26
Project: chatty   File: ActivityTracker.java   View source code 6 votes vote down vote up
/**
 * Check if mouse location has changed from previous check.
 */
private static void checkMouseLocation() {
    PointerInfo info = MouseInfo.getPointerInfo();
    // This can sometimes be null, so check for it (e.g. when Windows' UAC
    // screen is active)
    if (info == null) {
        return;
    }
    Point currentLocation = info.getLocation();
    
    if (lastLocation != null && !lastLocation.equals(currentLocation)) {
        lastMoved = System.currentTimeMillis();
        triggerActivity();
    }
    lastLocation = currentLocation;
}
 
Example 27
Project: stendhal   File: UpdateProgressBar.java   View source code 6 votes vote down vote up
/**
 * Creates update progress bar.
 * 
 * @param max max file size
 * @param urlBase base url for the browser
 * @param fromVersion the version the update is based on, may be <code>null</code>
 * @param toVersion the version the download leads to
 */
UpdateProgressBar(final int max, final String urlBase, final String fromVersion, final String toVersion) {
	super("Downloading...", MouseInfo.getPointerInfo().getDevice().getDefaultConfiguration());
	setLocationByPlatform(true);
	setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
	addWindowListener(new UpdateProgressBarWindowListener());

	this.max = max;
	this.urlBase = urlBase;
	this.fromVersion = fromVersion;
	this.toVersion = toVersion;

	try {
		final URL url = this.getClass().getClassLoader().getResource(
				ClientGameConfiguration.get("GAME_ICON"));
		setIconImage(new ImageIcon(url).getImage());
	} catch (final RuntimeException e) {
		// in case that resource is not available
	}

	initializeComponents();

	this.pack();
}
 
Example 28
Project: stendhal   File: MainFrame.java   View source code 6 votes vote down vote up
/**
 * Prepare a frame for use as the main window, or create a new one if
 * needed.
 * 
 * @param frame frame to be used as the main game window. If
 * 	<code>null</code>, then a new frame will be created
 * @return frame suitable for use as the main game window
 */
static JFrame prepare(JFrame frame) {
	if (frame == null) {
		// Open on the screen where the mouse cursor is
		GraphicsConfiguration gc = MouseInfo.getPointerInfo().getDevice().getDefaultConfiguration();
		frame =  new JFrame(gc);
		frame.setLocationByPlatform(true);
	}
	setTitle(frame);
	setIcon(frame);
	// Splash screen uses the same identifier on purpose. It is the same 
	// window.
	WindowUtils.trackLocation(frame, "main", true);
	/*
	 * When the user tries to close the window, don't close immediately,
	 * but let it show a confirmation dialog.
	 */
	frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
	WindowUtils.closeOnEscape(frame);

	return frame;
}
 
Example 29
Project: AppWoksUtils   File: ToolTipController.java   View source code 6 votes vote down vote up
/**
 * 
 */
protected void showTooltip() {
    ToolTipController.this.hideTooltip();
    final JComponent aC = ToolTipController.this.activeComponent;
    if (aC != null && (!aC.isFocusable() || aC.hasFocus() || ((ToolTipHandler) aC).isTooltipWithoutFocusEnabled()) && !ToolTipController.this.isTooltipVisible() && ToolTipController.this.mouseOverComponent(MouseInfo.getPointerInfo().getLocation())) {
        if (aC instanceof JTable && ((JTable) aC).getDropLocation() != null) {
            System.out.println("drop is going on");
            return;
        }
        final Window ownerWindow = SwingUtilities.getWindowAncestor(aC);
        // if the components window is not the active any more, for exmaple
        // because we opened a dialog, don't show tooltip

        if (ownerWindow.isActive()) {
            final Point p = new Point(ToolTipController.this.mousePosition);
            SwingUtilities.convertPointFromScreen(p, aC);
            this.show(((ToolTipHandler) aC).createExtTooltip(p));
        }

    }

}
 
Example 30
Project: openmeetings   File: Core.java   View source code 6 votes vote down vote up
public void sendCursorStatus() {
	try {
		Point mouseP = MouseInfo.getPointerInfo().getLocation();

		float scaleFactor = (1.0f * dim.getResizeX()) / dim.getSpinnerWidth();

		// Real size: Real mouse position = Resize : X
		int x = (int)((mouseP.getX() - dim.getSpinnerX()) * scaleFactor);
		int y = (int)((mouseP.getY() - dim.getSpinnerY()) * scaleFactor);

		if (instance.getConnection() != null) {
			if (Red5.getConnectionLocal() == null) {
				Red5.setConnectionLocal(instance.getConnection());
			}
			instance.invoke("setNewCursorPosition", new Object[] { x, y }, this);
		}
	} catch (NullPointerException npe) {
		//noop
	} catch (Exception err) {
		frame.setStatus("Exception: " + err);
		log.error("[sendCursorStatus]", err);
	}
}
 
Example 31
Project: nanobot   File: BlueStacksMacPlatform.java   View source code 6 votes vote down vote up
@Override
protected void doLeftClick(final Point point) throws InterruptedException {
    // TODO non funziona
    final PointerInfo a = MouseInfo.getPointerInfo();
    final java.awt.Point b = a.getLocation();
    final int xOrig = (int) b.getX();
    final int yOrig = (int) b.getY();
    try {
        final Point p = clientToScreen(point);
        robot.mouseMove(p.x(), p.y());
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
    } finally {
        robot.mouseMove(xOrig, yOrig);
    }
}
 
Example 32
Project: power-matchmaker   File: MungePen.java   View source code 6 votes vote down vote up
private JPopupMenu buildPopup(Map<Class, StepDescription> stepMap) {
	JPopupMenu pop = new JPopupMenu();
	
	JMenu add = new JMenu("Add Transformer");
	JMenuItem labelMenuItem = new JMenuItem("Add Label");
	//figure out where the user clicked
	
	PointerInfo pi = MouseInfo.getPointerInfo();
       Point startLocation = pi.getLocation();
       SwingUtilities.convertPointFromScreen(startLocation,this);
       labelMenuItem.addActionListener(new AddLabelAction(this, startLocation));
	pop.add(add);
	pop.add(labelMenuItem);
	
	StepDescription[] sds = stepMap.values().toArray(new StepDescription[0]);
	Arrays.sort(sds);
	for (StepDescription sd : sds) {
		JMenuItem item = new JMenuItem(sd.getName(), sd.getIcon());
		item.addActionListener(new AddStepActon(sd.getLogicClass()));
		add.add(item);
	}
	
	return pop;
}
 
Example 33
Project: org.csstudio.display.builder   File: AutoScrollHandler.java   View source code 6 votes vote down vote up
/**
 * Scrolls the {@link ScrollPane} along the given {@code edge}.
 *
 * @param edge The scrolling side.
 */
private void scroll ( Edge edge ) {

    if ( edge == null ) {
        return;
    }

    Point screenLocation = MouseInfo.getPointerInfo().getLocation();
    Point2D localLocation = scrollPane.screenToLocal(screenLocation.getX(), screenLocation.getY());

    switch ( edge ) {
        case LEFT:
            scrollPane.setHvalue(scrollPane.getHvalue() + Math.min(1.0, localLocation.getX() / 2.0) / scrollPane.getWidth());
            break;
        case RIGHT:
            scrollPane.setHvalue(scrollPane.getHvalue() + Math.max(1.0, ( localLocation.getX() - scrollPane.getWidth() ) / 2.0) / scrollPane.getWidth());
            break;
        case TOP:
            scrollPane.setVvalue(scrollPane.getVvalue() + Math.min(1.0, localLocation.getY() / 2.0) / scrollPane.getHeight());
            break;
        case BOTTOM:
            scrollPane.setVvalue(scrollPane.getVvalue() + Math.max(1.0, ( localLocation.getY() - scrollPane.getHeight() ) / 2.0) / scrollPane.getHeight());
            break;
    }

}
 
Example 34
Project: Chatty-Twitch-Client   File: ActivityTracker.java   View source code 6 votes vote down vote up
/**
 * Check if mouse location has changed from previous check.
 */
private static void checkMouseLocation() {
    PointerInfo info = MouseInfo.getPointerInfo();
    // This can sometimes be null, so check for it (e.g. when Windows' UAC
    // screen is active)
    if (info == null) {
        return;
    }
    Point currentLocation = info.getLocation();
    
    if (lastLocation != null && !lastLocation.equals(currentLocation)) {
        lastMoved = System.currentTimeMillis();
        triggerActivity();
    }
    lastLocation = currentLocation;
}
 
Example 35
Project: Creatures   File: WorldInputListener.java   View source code 6 votes vote down vote up
public void handlePressedMouseButtons(WorldView view) {
	double deltaX = MouseInfo.getPointerInfo().getLocation().x - lastPosition.x;
	double deltaY = MouseInfo.getPointerInfo().getLocation().y - lastPosition.y;

	if (rightButtonPressed || leftButtonPressed) {
		if (Math.abs(deltaX) > 0) {
			controller.changeOffsetX(((int) deltaX) * view.getZoomFactor());
		}

		if (Math.abs(deltaY) > 0) {
			controller.changeOffsetY(((int) deltaY) * view.getZoomFactor());
		}
	}

	lastPosition = MouseInfo.getPointerInfo().getLocation();
}
 
Example 36
Project: nabs   File: ClickManager.java   View source code 6 votes vote down vote up
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
    Point panelPoint = panel.getLocationOnScreen();
    Point mousePoint = MouseInfo.getPointerInfo().getLocation();
    
    int x = (int)(mousePoint.getX() - panelPoint.getX());
    int y = (int)(mousePoint.getY() - panelPoint.getY());
    
    Role role = panel.getRoleAt(x, y);
    popupMenu.removeAll();

    if (role == null) {
        makeUnhideMenu();
    } else {
        Host host = role.getHostAt(x, y);
        if (host == null) {
            makeHideMenu(role.getRoleName());
        } else {
            curHost = host;
            makeHostMenu(host.toString());
        }
    }
}
 
Example 37
Project: nabs   File: ClickManager.java   View source code 6 votes vote down vote up
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
    Point panelPoint = panel.getLocationOnScreen();
    Point mousePoint = MouseInfo.getPointerInfo().getLocation();
    
    int x = (int)(mousePoint.getX() - panelPoint.getX());
    int y = (int)(mousePoint.getY() - panelPoint.getY());
    
    Role role = panel.getRoleAt(x, y);
    popupMenu.removeAll();

    if (role == null) {
        makeUnhideMenu();
    } else {
        Host host = role.getHostAt(x, y);
        if (host == null) {
            makeHideMenu(role.getRoleName());
        } else {
            curHost = host;
            makeHostMenu(host.toString());
        }
    }
}
 
Example 38
Project: MathEOS   File: EspaceDessin.java   View source code 6 votes vote down vote up
@Override
public void setEnabled(boolean b) {//On gèle la détection de la souris en cas de désactivation
    super.setEnabled(b);
    
    //On envoie un event pour simuler l'entrée ou la sortie de la souris lors de la réactivation ou la désactivation de l'espace dessin
    java.awt.Point P = MouseInfo.getPointerInfo().getLocation();
    SwingUtilities.convertPointFromScreen(P, this);
    MouseEvent e = new MouseEvent(this, 0, System.currentTimeMillis(), 0, P.x, P.y, 0, false);
    if(b) {
        addMouseEventListener();
        mouseListener.mouseEntered(e);
    } else {
        mouseListener.mouseExited(e);
        removeMouseEventListener();
    }
    for(Component c : getComponents()) {c.setEnabled(b);}
}
 
Example 39
Project: Visual-Servo-Controller   File: visual_servo_controller.java   View source code 6 votes vote down vote up
public void mouseDragged () {
	Point mouse, winloc;
	mouse = MouseInfo.getPointerInfo ().getLocation ();
	winloc =frame.getLocation ();

	if (!frame.isUndecorated()) {
		winloc.x += 3;
		winloc.y += 29;
	}
	mouseX = mouse.x-winloc.x;
	mouseY = mouse.y-winloc.y;

	if (isMoveWindow) {
		frame.setLocation(
				frame.getLocationOnScreen().x+mouseX-cx, 
				frame.getLocationOnScreen().y+mouseY-cy);
		oldx = mouseX;
		oldy = mouseY;
	}
}
 
Example 40
Project: Wolf_game   File: AWTUtil.java   View source code 6 votes vote down vote up
/**
 * 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;
}