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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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: scanning   File: ViewUtil.java   Source Code and License 6 votes vote down vote up
/**
    * Show the top where the mouse is.
    * @param tip
    * @param message
    */
public static void showTip(ToolTip tip, String message) {

	if (tip==null) return;
tip.setMessage(message);
	PointerInfo a = MouseInfo.getPointerInfo();
	java.awt.Point loc = a.getLocation();

	tip.setLocation(loc.x, loc.y+20);
       tip.setVisible(true);
}
 
Example 6
Project: MTG-Card-Recognizer   File: ScreenRegionGrab.java   Source Code and License 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 7
Project: PackagePlugin   File: ProgressDialog.java   Source Code and License 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 8
Project: freecol   File: FreeColButtonUI.java   Source Code and License 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 9
Project: WordnetLoom   File: ToolTipList.java   Source Code and License 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 10
Project: Hydrograph   File: PaletteContainerListener.java   Source Code and License 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 11
Project: FreeCol   File: FreeColButtonUI.java   Source Code and License 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 12
Project: geomapapp   File: XMap.java   Source Code and License 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 13
Project: avro-schema-editor   File: AddElementAction.java   Source Code and License 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 14
Project: screencast4j   File: AbstractScreenRecorder.java   Source Code and License 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 15
Project: PhET   File: AWTUtil.java   Source Code and License 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 16
Project: djigger   File: AnalyzerGroupPane.java   Source Code and License 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 17
Project: graphexample   File: DiagramPanel.java   Source Code and License 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 18
Project: graphexample   File: DiagramPanel.java   Source Code and License 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 19
Project: Dayon   File: MouseEngine.java   Source Code and License 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 20
Project: SweetHome3D   File: SwingTools.java   Source Code and License 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 21
Project: SporeModder   File: Viewer.java   Source Code and License 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 22
Project: Eve   File: GamePApplet.java   Source Code and License 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 23
Project: ArasuiteIta   File: TInterpreterFullscreenAction.java   Source Code and License 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 24
Project: screencast4j   File: AbstractScreenRecorder.java   Source Code and License 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 25
Project: open-ig   File: UIMouse.java   Source Code and License 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 26
Project: stickes   File: Painter.java   Source Code and License 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 27
Project: chatty   File: ActivityTracker.java   Source Code and License 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 28
Project: stendhal   File: UpdateProgressBar.java   Source Code and License 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 29
Project: stendhal   File: MainFrame.java   Source Code and License 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 30
Project: AppWoksUtils   File: ToolTipController.java   Source Code and License 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 31
Project: openmeetings   File: Core.java   Source Code and License 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 32
Project: nanobot   File: BlueStacksMacPlatform.java   Source Code and License 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 33
Project: power-matchmaker   File: MungePen.java   Source Code and License 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 34
Project: org.csstudio.display.builder   File: AutoScrollHandler.java   Source Code and License 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 35
Project: Chatty-Twitch-Client   File: ActivityTracker.java   Source Code and License 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 36
Project: Creatures   File: WorldInputListener.java   Source Code and License 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 37
Project: nabs   File: ClickManager.java   Source Code and License 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: nabs   File: ClickManager.java   Source Code and License 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 39
Project: MathEOS   File: EspaceDessin.java   Source Code and License 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 40
Project: Visual-Servo-Controller   File: visual_servo_controller.java   Source Code and License 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 41
Project: Wolf_game   File: AWTUtil.java   Source Code and License 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 42
Project: hyperbolic-space   File: InputHandler.java   Source Code and License 6 votes vote down vote up
/**
 * Determines how far the mouse moved from the center and resets the mouse to the center.
 * The information can be retrieved with {@code getMouseX()} and {@code getMouseY()}.
 * @see #getMouseX
 * @see #getMouseY
 */
public void readMouse() {
	GLWindow win = c.getWindow();
	
	if (win.hasFocus() && focused) {
		Point mousePos = MouseInfo.getPointerInfo().getLocation();
		int centerX = win.getX() + win.getWidth()/2;
		int centerY = win.getY() + win.getHeight()/2;
		
		mouseX = (mousePos.getX()-centerX)*mouseSensitivity;
		mouseY = (mousePos.getY()-centerY)*mouseSensitivity;
		
		robot.mouseMove(centerX, centerY);
	} else {
		setFocused(false);
		mouseX = 0;
		mouseY = 0;
	}
}
 
Example 43
Project: jace   File: Joystick.java   Source Code and License 6 votes vote down vote up
public Joystick(int port, Computer computer) {
    super(computer);
    centerPoint = new Point(screenSize.width / 2, screenSize.height / 2);
    this.port = port;
    if (port == 0) {
        xSwitch = (MemorySoftSwitch) SoftSwitches.PDL0.getSwitch();
        ySwitch = (MemorySoftSwitch) SoftSwitches.PDL1.getSwitch();
    } else {
        xSwitch = (MemorySoftSwitch) SoftSwitches.PDL2.getSwitch();
        ySwitch = (MemorySoftSwitch) SoftSwitches.PDL3.getSwitch();
    }
    lastMouseLocation = MouseInfo.getPointerInfo().getLocation();
    try {
        robot = new Robot();
    } catch (AWTException ex) {
        Logger.getLogger(Joystick.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
Example 44
Project: cn1   File: ToolTipManager.java   Source Code and License 6 votes vote down vote up
private void showPopup() {
    if (!isEnabled()) {
        return;
    }

    if (Utilities.isEmptyString(tipText) || !component.isShowing()) {
        hidePopup();
        return;
    }
    JToolTip t = component.createToolTip();
    t.setTipText(tipText);

    if (popup != null) {
        popup.hide();
    }
    PopupFactory factory = PopupFactory.getSharedInstance();
    Point toolTipPoint = MouseInfo.getPointerInfo().getLocation();
    factory.setLWPopupsEnabled(isLightWeightPopupEnabled());
    popup = factory.getPopup(component, t, toolTipPoint.x, toolTipPoint.y + MOUSE_CURSOR_HEIGHT);
    factory.setLWPopupsEnabled(false);
    popup.show();
    stillInsideTimer.restart();
}
 
Example 45
Project: rdpro   File: ReproMainForm.java   Source Code and License 6 votes vote down vote up
public void init() {
	frame = new JFrame("Recursive Directory Removal Pro "+RdProUI.version);
	frame.setContentPane(layoutPanel1);
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

	frame.pack();

	/*position it*/
	//frame.setLocationRelativeTo(null);  // *** this will center your app ***
	PointerInfo a = MouseInfo.getPointerInfo();
	Point b = a.getLocation();
	int x = (int) b.getX();
	int y = (int) b.getY();
	frame.setLocation(x + 100, y);

	btnEditRootDir.setBorder(null);
	btnCancel.setText("Close");
	//resize();

	frame.setVisible(true);

}
 
Example 46
Project: magarena   File: DeckCellRenderer.java   Source Code and License 6 votes vote down vote up
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {

    String deckName = (String) value;
    JLabel lbl = new JLabel(deckName);
    lbl.setOpaque(true);

    if (isSelected) {
        lbl.setForeground(table.getSelectionForeground());
        lbl.setBackground(table.getSelectionBackground());
    } else {
        lbl.setForeground(table.getForeground());
        lbl.setBackground(table.getBackground());
    }

    Point mp = MouseInfo.getPointerInfo().getLocation();
    SwingUtilities.convertPointFromScreen(mp, table);
    int mRow = table.rowAtPoint(mp);
    int mCol = table.columnAtPoint(mp);
    if (row == mRow && column == mCol) {
        lbl.setForeground(Color.blue);
        lbl.setFont(withUnderline);
    }

    return lbl;
}
 
Example 47
Project: KJController   File: Main.java   Source Code and License 6 votes vote down vote up
/**
 * 处理鼠标移动
 */
public void mouseMove(String info) {
    String args[] = info.split(",");
    String x = args[0];
    String y = args[1];
    float px = Float.valueOf(x);
    float py = Float.valueOf(y);

    PointerInfo pinfo = MouseInfo.getPointerInfo(); // 得到鼠标的坐标
    java.awt.Point p = pinfo.getLocation();
    double mx = p.getX(); // 得到当前电脑鼠标的坐标
    double my = p.getY();
    try {
        java.awt.Robot robot = new Robot();
        robot.mouseMove((int) (mx + px), (int) (my + py));
    } catch (AWTException e) {
    }
}
 
Example 48
Project: TwitchChatClient   File: ActivityTracker.java   Source Code and License 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 49
Project: GPVM   File: AWTUtil.java   Source Code and License 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 50
Project: GPVM   File: AWTUtil.java   Source Code and License 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 51
Project: JLS   File: TruthTable.java   Source Code and License 6 votes vote down vote up
/**
 * Display dialog to get characteristics.
 * 
 * @param g The Graphics object to use to initialize sizes
 * @param editWindow The editor window this constant will be displayed in.
 * @param x The x-coordinate of the last known mouse position.
 * @param y The y-coordinate of the last known mouse position.
 * 
 * @return false if cancelled, true otherwise.
 */
public boolean setup(Graphics g, JPanel editWindow, int x, int y) {

	// show creation dialog
	edit = new TTEditor(this);

	// don't do anything if user cancelled gate
	if (cancelled)
		return false;

	// complete initialization
	init(g);

	// save position
	Point p = MouseInfo.getPointerInfo().getLocation();
	Point win = editWindow.getLocationOnScreen();
	p.x -= win.x;
	p.y -= win.y;
	if (p != null) {
		super.setXY(p.x-width/2,p.y-height/2);
	}

	return true;
}
 
Example 52
Project: JLS   File: StateMachine.java   Source Code and License 6 votes vote down vote up
/**
 * Display dialog to get characteristics.
 * 
 * @param g The Graphics object to use to initialize sizes
 * @param editWindow The editor window this constant will be displayed in.
 * @param x The x-coordinate of the last known mouse position.
 * @param y The y-coordinate of the last known mouse position.
 * 
 * @return false if canceled, true otherwise.
 */
public boolean setup(Graphics g, JPanel editWindow, int x, int y) {
	
	// show creation dialog
	new StateEditor(this,true);
	
	// don't do anything if user canceled
	if (canceled)
		return false;
	
	// complete initialization
	init(g);
	
	// save position
	Point p = MouseInfo.getPointerInfo().getLocation();
	Point win = editWindow.getLocationOnScreen();
	p.x -= win.x;
	p.y -= win.y;
	if (p != null) {
		super.setXY(p.x-width/2,p.y-height/2);
	}
	
	return true;
}
 
Example 53
Project: SpaceStationAlpha   File: AWTUtil.java   Source Code and License 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 54
Project: TeacherSmash   File: AWTUtil.java   Source Code and License 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 55
Project: mouseless-server   File: MouseControll.java   Source Code and License 6 votes vote down vote up
/**
 * @param coords
 */
public void move(Integer[] coords) {
    Point mouseLocation = MouseInfo.getPointerInfo().getLocation();
    Integer x = (int) mouseLocation.getX();
    Integer y = (int) mouseLocation.getY();

    Integer aX = coords[0];
    Integer aY = coords[1];

    System.out.println("X: " + aX + ", Y: " + aY);

    x = x - aX;
    y = y + aY;

    robot.mouseMove(x, y);
}
 
Example 56
Project: freeVM   File: ToolTipManager.java   Source Code and License 6 votes vote down vote up
private void showPopup() {
    if (!isEnabled()) {
        return;
    }

    if (Utilities.isEmptyString(tipText) || !component.isShowing()) {
        hidePopup();
        return;
    }
    JToolTip t = component.createToolTip();
    t.setTipText(tipText);

    if (popup != null) {
        popup.hide();
    }
    PopupFactory factory = PopupFactory.getSharedInstance();
    Point toolTipPoint = MouseInfo.getPointerInfo().getLocation();
    factory.setLWPopupsEnabled(isLightWeightPopupEnabled());
    popup = factory.getPopup(component, t, toolTipPoint.x, toolTipPoint.y + MOUSE_CURSOR_HEIGHT);
    factory.setLWPopupsEnabled(false);
    popup.show();
    stillInsideTimer.restart();
}
 
Example 57
Project: freeVM   File: ToolTipManager.java   Source Code and License 6 votes vote down vote up
private void showPopup() {
    if (!isEnabled()) {
        return;
    }

    if (Utilities.isEmptyString(tipText) || !component.isShowing()) {
        hidePopup();
        return;
    }
    JToolTip t = component.createToolTip();
    t.setTipText(tipText);

    if (popup != null) {
        popup.hide();
    }
    PopupFactory factory = PopupFactory.getSharedInstance();
    Point toolTipPoint = MouseInfo.getPointerInfo().getLocation();
    factory.setLWPopupsEnabled(isLightWeightPopupEnabled());
    popup = factory.getPopup(component, t, toolTipPoint.x, toolTipPoint.y + MOUSE_CURSOR_HEIGHT);
    factory.setLWPopupsEnabled(false);
    popup.show();
    stillInsideTimer.restart();
}
 
Example 58
Project: metro-swt   File: MetroShell.java   Source Code and License 6 votes vote down vote up
protected void cmpTitleBar_mouseMove(MouseEvent arg0) {
	if (isWindowMoving) {
		UpdateShadowsPositon(MouseInfo.getPointerInfo().getLocation().x
				- oldPos.x, MouseInfo.getPointerInfo().getLocation().y
				- oldPos.y);
		this.setLocation(MouseInfo.getPointerInfo().getLocation().x
				- oldPos.x, MouseInfo.getPointerInfo().getLocation().y
				- oldPos.y);
	}

	if (isMaximized && ((arg0.stateMask & SWT.BUTTON1) != 0)
			&& MouseInfo.getPointerInfo().getLocation().y > 10) {
		oldPos.x = (int) (((float) arg0.x / getSize().x) * prevSize.x);
		oldPos.y = (int) (((float) arg0.y / getSize().y) * prevSize.y);
		setMaximized(false, MouseInfo.getPointerInfo().getLocation().x
				- oldPos.x, MouseInfo.getPointerInfo().getLocation().y
				- oldPos.y);
		isWindowMoving = true;
		SetShadowsAlpha(3);
		cmpTitleBar.setCursor(new Cursor(getDisplay(), SWT.CURSOR_SIZEALL));
	}
}
 
Example 59
Project: metro-swt   File: MetroShell.java   Source Code and License 6 votes vote down vote up
protected void cmpTitleBar_mouseUp(MouseEvent arg0) {
	isWindowMoving = false;
	SetShadowsAlpha(30);
	UpdateShadowsPositon(getLocation().x, getLocation().y);
	cmpTitleBar.setCursor(new Cursor(getDisplay(), SWT.CURSOR_ARROW));
	if (MouseInfo.getPointerInfo().getLocation().y < 10) {
		setMaximized(true);
	} else if (MouseInfo.getPointerInfo().getLocation().x < 10) {
		setLocation(getMonitor().getClientArea().x, getMonitor()
				.getClientArea().y);
		setSize(getMonitor().getClientArea().width / 2, getMonitor()
				.getClientArea().height);
		UpdateShadowsPositon(getLocation().x, getLocation().y);
		UpdateShadowsSize();
	} else if (MouseInfo.getPointerInfo().getLocation().x > getDisplay()
			.getPrimaryMonitor().getClientArea().width - 10) {
		setLocation(getMonitor().getClientArea().x
				+ getCurrentMonitor().getClientArea().width / 2,
				getCurrentMonitor().getClientArea().y);
		setSize(getMonitor().getClientArea().width / 2, getMonitor()
				.getClientArea().height);
		UpdateShadowsPositon(getLocation().x, getLocation().y);
		UpdateShadowsSize();
	}
}
 
Example 60
Project: jclic   File: FressaFunctions.java   Source Code and License 6 votes vote down vote up
/*******************************************************************************************************/
public void startSwayingTimer() {
    if (swayingTimer == null) {
        swayingTimer = new Timer(SWAYING_SPAN, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                changeSwayingPos();
            }
        });
        swayingCounter = 0;
        Point p = MouseInfo.getPointerInfo().getLocation();
        swayingCursorX = p.x;
        swayingCursorY = p.y;
        swayingTimer.start();
    }

    if (!swayingTimer.isRunning()) {
        swayingTimer.start();
    }
}