Java Code Examples for java.awt.Component#getY()

The following examples show how to use java.awt.Component#getY() . 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
Source Project: binnavi   File: GuiHelper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Centers the child component relative to it's parent component
 * 
 * @param parent
 * @param child
 * @param bStayOnScreen
 */
public static final void centerChildToParent(final Component parent, final Component child,
    final boolean bStayOnScreen) {
  int x = (parent.getX() + (parent.getWidth() / 2)) - (child.getWidth() / 2);
  int y = (parent.getY() + (parent.getHeight() / 2)) - (child.getHeight() / 2);
  if (bStayOnScreen) {
    final Toolkit tk = Toolkit.getDefaultToolkit();
    final Dimension ss = new Dimension(tk.getScreenSize());
    if ((x + child.getWidth()) > ss.getWidth()) {
      x = (int) (ss.getWidth() - child.getWidth());
    }
    if ((y + child.getHeight()) > ss.getHeight()) {
      y = (int) (ss.getHeight() - child.getHeight());
    }
    if (x < 0) {
      x = 0;
    }
    if (y < 0) {
      y = 0;
    }
  }
  child.setLocation(x, y);
}
 
Example 2
Source Project: binnavi   File: GuiHelper.java    License: Apache License 2.0 6 votes vote down vote up
/** Centers the child component relative to its parent component. */
public static final void centerChildToParent(
    final Component parent, final Component child, final boolean bStayOnScreen) {
  int x = (parent.getX() + (parent.getWidth() / 2)) - (child.getWidth() / 2);
  int y = (parent.getY() + (parent.getHeight() / 2)) - (child.getHeight() / 2);
  if (bStayOnScreen) {
    final Toolkit tk = Toolkit.getDefaultToolkit();
    final Dimension ss = new Dimension(tk.getScreenSize());
    if ((x + child.getWidth()) > ss.getWidth()) {
      x = (int) (ss.getWidth() - child.getWidth());
    }
    if ((y + child.getHeight()) > ss.getHeight()) {
      y = (int) (ss.getHeight() - child.getHeight());
    }
    if (x < 0) {
      x = 0;
    }
    if (y < 0) {
      y = 0;
    }
  }
  child.setLocation(x, y);
}
 
Example 3
Source Project: pdfxtk   File: GraphPanel.java    License: Apache License 2.0 6 votes vote down vote up
public GraphPort findPortAt(GraphNode node, int mx, int my) {
   GraphPort[] ports = node.getPorts();

   Component cmp = (Component)node.get(COMPONENT);
   
   int    mind = Integer.MAX_VALUE;
   int    min  = 0;
   int    cw   = cmp.getWidth();
   int    ch   = cmp.getHeight();
   int    cx   = cmp.getX();
   int    cy   = cmp.getY();
   for(int i = 0; i < ports.length; i++) {
     GraphNodePort port = (GraphNodePort)ports[i].get(GRAPH_NODE_PORT);
     if(port == null) return null;
     int x = mx - (int)(port.x * cw + cx);
     int y = my - (int)(port.y * ch + cy);
     int d = x * x + y * y;
     if(d < mind) {
min  = i;
mind = d;
     }
   }
   
   return ports[min];
 }
 
Example 4
Source Project: FlatLaf   File: FlatInspector.java    License: Apache License 2.0 5 votes vote down vote up
private Component getDeepestComponentAt( Component parent, int x, int y ) {
	if( !parent.contains( x, y ) )
		return null;

	if( parent instanceof Container ) {
		for( Component child : ((Container)parent).getComponents() ) {
			if( child == null || !child.isVisible() )
				continue;

			int cx = x - child.getX();
			int cy = y - child.getY();
			Component c = (child instanceof Container)
				? getDeepestComponentAt( child, cx, cy )
				: child.getComponentAt( cx, cy );
			if( c == null || !c.isVisible() )
				continue;

			// ignore highlight figure and tooltip
			if( c == highlightFigure || c == tip )
				continue;

			// ignore glass pane
			if( c.getParent() instanceof JRootPane && c == ((JRootPane)c.getParent()).getGlassPane() )
				continue;

			if( "com.formdev.flatlaf.ui.FlatWindowResizer".equals( c.getClass().getName() ) )
				continue;

			return c;
		}
	}

	return parent;
}
 
Example 5
Source Project: marathonv5   File: ContextMenuHandler.java    License: Apache License 2.0 5 votes vote down vote up
public void showPopup(KeyEvent keyEvent) {
    if (isContextMenuOn()) {
        return;
    }
    Component component = keyEvent.getComponent();
    if (component instanceof JMenuItem && (!(component instanceof JMenu) || ((JMenu) component).isSelected())) {
        return;
    }
    Point point = new Point(component.getX() + component.getWidth() / 2, component.getY() + component.getHeight() / 2);
    showPopup(component, point);
}
 
Example 6
Source Project: gcs   File: UIUtilities.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Converts a {@link Point} from on the screen to a position within the component.
 *
 * @param pt        The point to convert.
 * @param component The component the point should be translated to.
 */
public static void convertPointFromScreen(Point pt, Component component) {
    while (component != null) {
        pt.x -= component.getX();
        pt.y -= component.getY();
        if (component instanceof Window) {
            break;
        }
        component = component.getParent();
    }
}
 
Example 7
Source Project: gcs   File: UIUtilities.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Converts a {@link Point} in a component to its position on the screen.
 *
 * @param pt        The point to convert.
 * @param component The component the point originated in.
 */
public static void convertPointToScreen(Point pt, Component component) {
    while (component != null) {
        pt.x += component.getX();
        pt.y += component.getY();
        if (component instanceof Window) {
            break;
        }
        component = component.getParent();
    }
}
 
Example 8
Source Project: gcs   File: UIUtilities.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Converts a {@link Rectangle} from on the screen to a position within the component.
 *
 * @param bounds    The rectangle to convert.
 * @param component The component the rectangle should be translated to.
 */
public static void convertRectangleFromScreen(Rectangle bounds, Component component) {
    while (component != null) {
        bounds.x -= component.getX();
        bounds.y -= component.getY();
        if (component instanceof Window) {
            break;
        }
        component = component.getParent();
    }
}
 
Example 9
Source Project: gcs   File: UIUtilities.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Converts a {@link Rectangle} in a component to its position on the screen.
 *
 * @param bounds    The rectangle to convert.
 * @param component The component the rectangle originated in.
 */
public static void convertRectangleToScreen(Rectangle bounds, Component component) {
    while (component != null) {
        bounds.x += component.getX();
        bounds.y += component.getY();
        if (component instanceof Window) {
            break;
        }
        component = component.getParent();
    }
}
 
Example 10
Source Project: RipplePower   File: UIRes.java    License: Apache License 2.0 5 votes vote down vote up
public static Point getPointToCenter(Component component, Dimension dimension) {

		Dimension screenSize = getDefaultDeviceScreenSize();

		if (component == null) {

			if (dimension.height > screenSize.height) {
				dimension.height = screenSize.height;
			}

			if (dimension.width > screenSize.width) {
				dimension.width = screenSize.width;
			}

			return new Point((screenSize.width - dimension.width) / 2, (screenSize.height - dimension.height) / 2);
		}

		Dimension frameDim = component.getSize();
		Rectangle dRec = new Rectangle(component.getX(), component.getY(), (int) frameDim.getWidth(),
				(int) frameDim.getHeight());

		int dialogX = dRec.x + ((dRec.width - dimension.width) / 2);
		int dialogY = dRec.y + ((dRec.height - dimension.height) / 2);

		if (dialogX <= 0 || dialogY <= 0) {

			if (dimension.height > screenSize.height) {
				dimension.height = screenSize.height;
			}

			if (dimension.width > screenSize.width) {
				dimension.width = screenSize.width;
			}

			dialogX = (screenSize.width - dimension.width) / 2;
			dialogY = (screenSize.height - dimension.height) / 2;
		}

		return new Point(dialogX, dialogY);
	}
 
Example 11
Source Project: wandora   File: AWTWrapper.java    License: GNU General Public License v3.0 5 votes vote down vote up
private Point getTopDistance() throws Exception {
    Component c = this;
    Point ret = new Point();
    while(!AbstractTraditionalTopicPanel.class.isInstance(c)) {
        ret.x += c.getX();
        ret.y += c.getY();
        c = c.getParent();
        if(c == null)
            throw new Exception("Couldn't find a topic panel in the parent chain!");
    }
    return ret;
}
 
Example 12
Source Project: Luyten   File: WindowPosition.java    License: Apache License 2.0 5 votes vote down vote up
private void readPositionFromComponent(Component component) {
	isFullScreen = false;
	windowWidth = component.getWidth();
	windowHeight = component.getHeight();
	windowX = component.getX();
	windowY = component.getY();
}
 
Example 13
Source Project: FlatLaf   File: FlatInspector.java    License: Apache License 2.0 4 votes vote down vote up
private String buildToolTipText( Component c ) {
	String name = c.getClass().getName();
	name = name.substring( name.lastIndexOf( '.' ) + 1 );

	String text =
		"Class: " + name + " (" + c.getClass().getPackage().getName() + ")\n" +
		"Size: " + c.getWidth() + ',' + c.getHeight() + "  @ " + c.getX() + ',' + c.getY() + '\n';

	if( c instanceof Container )
		text += "Insets: " + toString( ((Container)c).getInsets() ) + '\n';

	Insets margin = null;
	if( c instanceof AbstractButton )
		margin = ((AbstractButton) c).getMargin();
	else if( c instanceof JTextComponent )
		margin = ((JTextComponent) c).getMargin();
	else if( c instanceof JMenuBar )
		margin = ((JMenuBar) c).getMargin();
	else if( c instanceof JToolBar )
		margin = ((JToolBar) c).getMargin();

	if( margin != null )
		text += "Margin: " + toString( margin ) + '\n';

	Dimension prefSize = c.getPreferredSize();
	Dimension minSize = c.getMinimumSize();
	Dimension maxSize = c.getMaximumSize();
	text += "Pref size: " + prefSize.width + ',' + prefSize.height + '\n' +
		"Min size: " + minSize.width + ',' + minSize.height + '\n' +
		"Max size: " + maxSize.width + ',' + maxSize.height + '\n';

	if( c instanceof JComponent )
		text += "Border: " + toString( ((JComponent)c).getBorder() ) + '\n';

	text += "Background: " + toString( c.getBackground() ) + '\n' +
		"Foreground: " + toString( c.getForeground() ) + '\n' +
		"Font: " + toString( c.getFont() ) + '\n';

	if( c instanceof JComponent ) {
		try {
			Field f = JComponent.class.getDeclaredField( "ui" );
			f.setAccessible( true );
			Object ui = f.get( c );
			text += "UI: " + (ui != null ? ui.getClass().getName() : "null") + '\n';
		} catch( NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex ) {
			// ignore
		}
	}

	if( c instanceof Container ) {
		LayoutManager layout = ((Container)c).getLayout();
		if( layout != null )
			text += "Layout: " + layout.getClass().getName() + '\n';
	}

	text += "Enabled: " + c.isEnabled() + '\n';
	text += "Opaque: " + c.isOpaque() + (c instanceof JComponent &&
		FlatUIUtils.hasOpaqueBeenExplicitlySet( (JComponent) c ) ? " EXPLICIT" : "") + '\n';
	if( c instanceof AbstractButton )
		text += "ContentAreaFilled: " + ((AbstractButton)c).isContentAreaFilled() + '\n';
	text += "Focusable: " + c.isFocusable() + '\n';
	text += "Left-to-right: " + c.getComponentOrientation().isLeftToRight() + '\n';
	text += "Parent: " + (c.getParent() != null ? c.getParent().getClass().getName() : "null");

	if( inspectParentLevel > 0 )
		text += "\n\nParent level: " + inspectParentLevel;

	if( inspectParentLevel > 0 )
		text += "\n(press Ctrl/Shift to increase/decrease level)";
	else
		text += "\n\n(press Ctrl key to inspect parent)";

	return text;
}
 
Example 14
Source Project: pdfxtk   File: GraphNodePort.java    License: Apache License 2.0 4 votes vote down vote up
public Point getLocation(Component c) {
  return new Point((int)(x * c.getWidth())  + c.getX(), (int)(y * c.getHeight()) + c.getY());
}
 
Example 15
Source Project: pdfxtk   File: GraphNodePort.java    License: Apache License 2.0 4 votes vote down vote up
public void paint(Component c, Graphics g, boolean selected) {
  int ix = (int)(x * c.getWidth())  + c.getX();
  int iy = (int)(y * c.getHeight()) + c.getY();
  (selected ? SELECTED : DESELECTED).paintIcon(c, g, ix - 2, iy - 2);
}
 
Example 16
/**
 * Get the vertical center point of a component.
 *
 * @param component component to be checked
 * @return the Y coordinate of the component center point
 */
private int componentYCenter(Component component) {
	return component.getY() + component.getHeight() / 2;
}
 
Example 17
Source Project: pdfxtk   File: GraphPanelEditor.java    License: Apache License 2.0 votes vote down vote up
int card(Component c) {return c.getY();} 
Example 18
Source Project: pdfxtk   File: GraphPanelEditor.java    License: Apache License 2.0 votes vote down vote up
int card(Component c) {return c.getY() + c.getHeight() / 2;} 
Example 19
Source Project: pdfxtk   File: GraphPanelEditor.java    License: Apache License 2.0 votes vote down vote up
int card(Component c) {return c.getY() + c.getHeight();}