List of usage examples for java.awt PointerInfo getLocation
public Point getLocation()
From source file:com.haulmont.cuba.desktop.sys.DesktopToolTipManager.java
protected Point getToolTipLocation(PointerInfo pointerInfo, String text) { Point mouseLocation = pointerInfo.getLocation(); Rectangle bounds = getDeviceBounds(pointerInfo.getDevice()); // Location on the current screen (suitable if there is more than one screen) Point currentScreenMouseLocation = getCurrentScreenMouseLocation(mouseLocation, bounds); // Location to display tooltip Point location = new Point(mouseLocation); Dimension dimension = DesktopComponentsHelper.measureHtmlText(text); location.x += getIndentation(bounds.width, dimension.width, currentScreenMouseLocation.x, DEFAULT_HORIZONTAL_INDENTATION); location.y += getIndentation(bounds.height, dimension.height, currentScreenMouseLocation.y, DEFAULT_VERTICAL_INDENTATION); return location; }
From source file:com.haulmont.cuba.desktop.sys.DesktopWindowManager.java
protected void showNotificationPopup(String popupText, NotificationType type) { JPanel panel = new JPanel(new MigLayout("flowy")); panel.setBorder(BorderFactory.createLineBorder(Color.gray)); switch (type) { case WARNING: case WARNING_HTML: panel.setBackground(Color.yellow); break;//w ww . j a va2 s.com case ERROR: case ERROR_HTML: panel.setBackground(Color.orange); break; default: panel.setBackground(Color.cyan); } JLabel label = new JLabel(popupText); panel.add(label); Dimension labelSize = DesktopComponentsHelper.measureHtmlText(popupText); int x = frame.getX() + frame.getWidth() - (50 + labelSize.getSize().width); int y = frame.getY() + frame.getHeight() - (50 + labelSize.getSize().height); PopupFactory factory = PopupFactory.getSharedInstance(); final Popup popup = factory.getPopup(frame, panel, x, y); popup.show(); panel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { popup.hide(); } }); PointerInfo pointerInfo = MouseInfo.getPointerInfo(); if (pointerInfo != null) { final Point location = pointerInfo.getLocation(); final Timer timer = new Timer(3000, null); timer.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { PointerInfo currentPointer = MouseInfo.getPointerInfo(); if (currentPointer == null) { timer.stop(); } else if (!currentPointer.getLocation().equals(location)) { popup.hide(); timer.stop(); } } }); timer.start(); } }
From source file:openqcm.mainGUI.java
private void chartDataMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_chartDataMouseMoved // TODO add your handling code here: //this will be some mouse-moved stuff PointerInfo a = MouseInfo.getPointerInfo(); Point b = a.getLocation(); int x = (int) b.getX(); int y = (int) b.getY(); String xycoords = "x: " + Integer.toString(x) + " y:" + Integer.toString(y); System.out.println(xycoords); jTextField2.setText(xycoords);//from ww w .j av a2s. co m }