Java Code Examples for javax.swing.SwingUtilities#convertPointFromScreen()

The following examples show how to use javax.swing.SwingUtilities#convertPointFromScreen() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public void moveIt(Point location) {
    Point oldLocation = this.location;
    SwingUtilities.convertPointFromScreen(location, this);
    this.location = location;
    
    Rectangle newClip = new Rectangle(location.x - image.getWidth() / 2, location.y - image.getHeight() / 2,
            image.getWidth(), image.getHeight());
    newClip.add(new Rectangle(oldLocation.x - image.getWidth() / 2, oldLocation.y - image.getHeight() / 2,
            image.getWidth(), image.getHeight()));
    newClip.add(new Rectangle(oldLocation.x - image.getWidth() / 2, oldLocation.y - image.getHeight() / 2,
            shadow.getWidth(), shadow.getHeight()));
    newClip.add(new Rectangle(location.x - image.getWidth() / 2, location.y - image.getHeight() / 2,
            shadow.getWidth(), shadow.getHeight()));

    repaint(newClip);
}
 
Example 2
Source Project: pumpernickel   File: CustomizedToolbar.java    License: MIT License 6 votes vote down vote up
protected void endDrag(DragSourceDropEvent e) {
	if (draggingComponent != null) {
		Point p = e.getLocation();
		SwingUtilities.convertPointFromScreen(p, this);
		if (contains(p) == false) {
			// adding this extra ability to commit changes
			// makes sure if you simply drag an element
			// off the toolbar: it gets recorded.
			setContents(getContents(new Point(-1000, -1000)));
		}
	}
	draggingComponent = null;
	/**
	 * TODO: is there some way when a drop ends if it IS accepted to NOT
	 * show the image slide back to its original location? For example: 1.
	 * Open this demo app 2. Click "Customize" 3. Drag a component off the
	 * toolbar in the window into nothingness. Note the *image* slides back
	 * to where it came from, because this is how the OS shows the drag was
	 * not accepted. But even though it was not accepted by any other
	 * entity: the drag was successful, and showing that sliding image is
	 * incorrect.
	 */
}
 
Example 3
Source Project: netbeans   File: AnnotationBar.java    License: Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param event
 */
private void showTooltipWindow (MouseEvent event) {
    Point p = new Point(event.getPoint());
    SwingUtilities.convertPointToScreen(p, this);
    Point p2 = new Point(p);
    SwingUtilities.convertPointFromScreen(p2, textComponent);
    
    // annotation for target line
    AnnotateLine al = null;
    if (!elementAnnotations.isEmpty()) {
        al = getAnnotateLine(getLineFromMouseEvent(event));
    }

    /**
     * al.getCommitMessage() != null - since commit messages are initialized separately from the AL constructor
     */
    if (al != null && al.getCommitMessage() != null) {
        TooltipWindow ttw = new TooltipWindow(this, al);
        ttw.show(new Point(p.x - p2.x, p.y));
    }
}
 
Example 4
/**
 * Get the corresponding local point wrt a containing component
 *
 * @param component the provided component
 * @return the local point, wrt component top left corner
 */
public Point getLocalPoint (Component component)
{
    Point localPoint = new Point(x, y);
    SwingUtilities.convertPointFromScreen(localPoint, component);

    return localPoint;
}
 
Example 5
private void updateClientCursor() {
    Point p = MouseInfo.getPointerInfo().getLocation();
    SwingUtilities.convertPointFromScreen(p, this);
    Component target = SwingUtilities.getDeepestComponentAt(this, p.x, p.y);
    if (target != null) {
        content.setCursor(target.getCursor());
    }
}
 
Example 6
public void showIt(BufferedImage image, Point location) {
    this.image = image;
    this.shadow = new ShadowRenderer(5, 0.3f, Color.BLACK).createShadow(image);

    SwingUtilities.convertPointFromScreen(location, this);
    this.location = location;
    
    setVisible(true);
}
 
Example 7
private void updateClientCursor() {
    Point p = MouseInfo.getPointerInfo().getLocation();
    SwingUtilities.convertPointFromScreen(p, this);
    Component target = SwingUtilities.getDeepestComponentAt(this, p.x, p.y);
    if (target != null) {
        content.setCursor(target.getCursor());
    }
}
 
Example 8
Source Project: nanoleaf-desktop   File: EffectOptionsMenu.java    License: MIT License 5 votes vote down vote up
private Point getMenuLocation()
{
	Point menuPoint = MouseInfo.getPointerInfo().getLocation();
	JScrollPane scrollPane = (JScrollPane)effectsPanel.getList().getParent().getParent();
	SwingUtilities.convertPointFromScreen(menuPoint, scrollPane);
	int listLocation = effectsPanel.getY();
	return new Point(menuPoint.x, menuPoint.y + listLocation);
}
 
Example 9
private void updateClientCursor() {
    Point p = MouseInfo.getPointerInfo().getLocation();
    SwingUtilities.convertPointFromScreen(p, this);
    Component target = SwingUtilities.getDeepestComponentAt(this, p.x, p.y);
    if (target != null) {
        content.setCursor(target.getCursor());
    }
}
 
Example 10
Source Project: netbeans   File: SplitLayerUI.java    License: Apache License 2.0 5 votes vote down vote up
private void update( Point locationOnScreen ) {
    if( null != locationOnScreen ) {
        SwingUtilities.convertPointFromScreen( locationOnScreen, content );
        lastLocation = locationOnScreen;
        horizontalSplit = calculateOrientation();
        lastLocation.x = Math.max( 0, lastLocation.x );
        lastLocation.y = Math.max( 0, lastLocation.y );
        lastLocation.x = Math.min( content.getWidth()-splitterWidth, lastLocation.x );
        lastLocation.y = Math.min( content.getHeight()-splitterWidth, lastLocation.y );
        content.repaint();
    } else {
        lastLocation = null;
    }
}
 
Example 11
private void repaintBadge(JComponent field) {
    Point p = field.getLocationOnScreen();
    SwingUtilities.convertPointFromScreen(p, this);
    
    int x = p.x - warningIcon.getWidth() / 2;
    int y = (int) (p.y + field.getHeight() - warningIcon.getHeight() / 1.5);
    
    repaint(x, y, warningIcon.getWidth(), warningIcon.getHeight());
}
 
Example 12
Source Project: netbeans   File: MergeDialogComponent.java    License: Apache License 2.0 5 votes vote down vote up
/** Shows given popup on given coordinations and takes care about the
 *  situation when menu can exceed screen limits.
 *  Copied from org.netbeans.core.windows.frames.DefaultContainerImpl
 */
private static void showPopupMenu(JPopupMenu popup, Point p, Component comp) {
    SwingUtilities.convertPointToScreen(p, comp);
    Dimension popupSize = popup.getPreferredSize();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    
    if (p.x + popupSize.width > screenSize.width) {
        p.x = screenSize.width - popupSize.width;
    }
    if (p.y + popupSize.height > screenSize.height) {
        p.y = screenSize.height - popupSize.height;
    }
    SwingUtilities.convertPointFromScreen(p, comp);
    popup.show(comp, p.x, p.y);
}
 
Example 13
Source Project: binnavi   File: GuiHelper.java    License: Apache License 2.0 5 votes vote down vote up
public static Component findComponentAt(final Container c, final Point sp) {
  final Point cp = new Point(sp.x, sp.y);
  SwingUtilities.convertPointFromScreen(cp, c);

  if (!c.contains(cp.x, cp.y)) {
    return c;
  }

  final int ncomponents = c.getComponentCount();
  final Component component[] = c.getComponents();
  for (int i = 0; i < ncomponents; i++) {
    final Component comp = component[i];
    final Point loc = comp.getLocation();
    if ((comp.contains(cp.x - loc.x, cp.y - loc.y)) && (comp.isVisible() == true)) {
      // found a component that intersects the point, see if there
      // is a deeper possibility.
      if (comp instanceof Container) {
        final Container child = (Container) comp;
        final Component deeper = findComponentAt(child, sp);
        if (deeper != null) {
          return deeper;
        }
      } else {
        return comp;
      }
    }
  }

  return c;
}
 
Example 14
Source Project: pumpernickel   File: MagnificationPanel.java    License: MIT License 5 votes vote down vote up
protected Point getMouseLoc() {
	// I observed a null PointerInfo after unplugging a second monitor
	PointerInfo pointerInfo = MouseInfo.getPointerInfo();
	if (pointerInfo == null)
		return null;
	Point p = pointerInfo.getLocation();
	SwingUtilities.convertPointFromScreen(p, zoomedComponent);
	return p;
}
 
Example 15
@Override
public void actionPerformed(ActionEvent actionEvent) {
	Point location = MouseInfo.getPointerInfo().getLocation();
	SwingUtilities.convertPointFromScreen(location, container);
	showBuildingsAction(location.x, location.y);
}
 
Example 16
Source Project: netbeans   File: ListView.java    License: Apache License 2.0 4 votes vote down vote up
void createPopup(int xpos, int ypos, boolean contextMenu) {
    if (manager == null) {
        return;
    }

    if (!popupAllowed) {
        return;
    }
    
    if (!isShowing()) {
        return;
    }

    JPopupMenu popup;

    if (contextMenu) {
        popup = Utilities.actionsToPopup(manager.getExploredContext().getActions(true), this);
    } else {
        Action[] actions = NodeOp.findActions(manager.getSelectedNodes());
        popup = Utilities.actionsToPopup(actions, this);
    }

    if ((popup != null) && (popup.getSubElements().length > 0)) {
        Point p = getViewport().getViewPosition();
        p.x = xpos - p.x;
        p.y = ypos - p.y;

        SwingUtilities.convertPointToScreen(p, ListView.this);

        Dimension popupSize = popup.getPreferredSize();
        Rectangle screenBounds = Utilities.getUsableScreenBounds(getGraphicsConfiguration());

        if ((p.x + popupSize.width) > (screenBounds.x + screenBounds.width)) {
            p.x = (screenBounds.x + screenBounds.width) - popupSize.width;
        }

        if ((p.y + popupSize.height) > (screenBounds.y + screenBounds.height)) {
            p.y = (screenBounds.y + screenBounds.height) - popupSize.height;
        }

        SwingUtilities.convertPointFromScreen(p, ListView.this);
        popup.show(this, p.x, p.y);
    }
}
 
Example 17
@Override
public void actionPerformed(ActionEvent actionEvent) {
	Point location = MouseInfo.getPointerInfo().getLocation();
	SwingUtilities.convertPointFromScreen(location, container);
	showProductionBuildingsAction(location.x, location.y);
}
 
Example 18
private boolean isPointWithinParentBounds(final Point pointInScreenCoordinates) {
  final Point pointInParentCoordinates = new Point(pointInScreenCoordinates);
  SwingUtilities.convertPointFromScreen(pointInParentCoordinates, parent);
  return parent.getBounds().contains(pointInParentCoordinates);
}
 
Example 19
@Override
public void actionPerformed(ActionEvent actionEvent) {
	Point location = MouseInfo.getPointerInfo().getLocation();
	SwingUtilities.convertPointFromScreen(location, container);
	showPlayerCharacterMenu(location.x, location.y);
}
 
Example 20
@Override
public void actionPerformed(ActionEvent actionEvent) {
	Point location = MouseInfo.getPointerInfo().getLocation();
	SwingUtilities.convertPointFromScreen(location, container);
	showPlantAction(location.x, location.y);
}