@Override protected void draw(final Graphics g, final int x, final int y) { g.enterViewport(getX(), getY(), getWidth(), getHeight()); for (final Component c : components) { if (viewerBounds.intersects(c.getX(), c.getY(), c.getWidth(), c.getHeight())) { // draw component g.enterViewport(c.getX(), c.getY(), c.getWidth(), c.getHeight()); c.draw(g, x + getX() - viewerBounds.getX(), y + getY() - viewerBounds.getY()); g.exitViewport(); } } g.exitViewport(); }
@Override public void setBounds(int x, int y, int width, int height, int op) { super.setBounds(x, y, width, height, op); if (xtext != null) { /* * Fixed 6277332, 6198290: * the coordinates is coming (to peer): relatively to closest HW parent * the coordinates is setting (to textField): relatively to closest ANY parent * the parent of peer is target.getParent() * the parent of textField is the same * see 6277332, 6198290 for more information */ int childX = x; int childY = y; Component parent = target.getParent(); // we up to heavyweight parent in order to be sure // that the coordinates of the text pane is relatively to closest parent while (parent.isLightweight()) { childX -= parent.getX(); childY -= parent.getY(); parent = parent.getParent(); } xtext.setBounds(childX, childY, width, height); xtext.validate(); } }
public SynchronizeMessage createSynchronizationMessage(Object obj) { Component component = (Component) obj; Synchronize2DMessage message = new Synchronize2DMessage(); message.setPositionX(component.getX()); message.setPositionY(component.getY()); return message; }
public static final Component getChildAtLine( Container container, Point point, boolean horizontal) { if (horizontal) { for (int i = 0; i < container.getComponentCount(); i++) { Component component = container.getComponent(i); if (point.x >= component.getX() && point.x < component.getX() + component.getWidth()) return component; } } else { for (int i = 0; i < container.getComponentCount(); i++) { Component component = container.getComponent(i); if (point.y >= component.getY() && point.y < component.getY() + component.getHeight()) return component; } } return null; }
public static final Component getVisibleChildAt(Container container, Point point) { for (int i = 0; i < container.getComponentCount(); i++) { Component component = container.getComponent(i); if (component.isVisible() && component.contains(point.x - component.getX(), point.y - component.getY())) return component; } return null; }
static Point getLocationInQueryTextArea(Component childComp) { Point ret = new Point(0, 0); Component comp = childComp; while (false == comp instanceof QueryTextArea) { ret.translate(comp.getX(), comp.getY()); comp = comp.getParent(); } return ret; }
/** * Centers the given component in relation to its owner. * * @param component the component to center * @param owner the parent frame */ public static void centerComponent(Component component, Component owner) { // find the difference in width to see the offsets int widthDifference = owner.getWidth() - component.getWidth(); int heightDifference = owner.getHeight() - component.getHeight(); // we can divide the differences by 2 and add that to the owner's top left // and then make that the top left of the component // to center the frame int leftOffset = widthDifference / 2; int topOffset = heightDifference / 2; // these are the new locations int left = owner.getX() + leftOffset; int top = owner.getY() + topOffset; Utils.changeFrameLocation(component, left, top); }
private void paintOnComponentUnderViewport(Component component, Graphics g) { JBViewport viewport = ObjectUtils.tryCast(myOwner, JBViewport.class); if (viewport == null || viewport.getView() != component || viewport.isPaintingNow()) return; // We're painting a component which has a viewport as it's ancestor. // As the viewport paints status text, we'll erase it, so we need to schedule a repaint for the // viewport with status text's bounds. // But it causes flicker, so we paint status text over the component first and then schedule the // viewport repaint. Rectangle textBoundsInViewport = getTextComponentBound(); int xInOwner = textBoundsInViewport.x - component.getX(); int yInOwner = textBoundsInViewport.y - component.getY(); Rectangle textBoundsInOwner = new Rectangle(xInOwner, yInOwner, textBoundsInViewport.width, textBoundsInViewport.height); doPaintStatusText(g, textBoundsInOwner); viewport.repaint(textBoundsInViewport); }
@Override public void mouseMovedOrUp(int x, int y, int button) { if (Minecraft.getMinecraft().currentScreen == null) return; super.mouseMovedOrUp(x, y, button); for (Frame frame : guiManager.getFrames()) { if (!frame.isVisible()) continue; if (!frame.isMinimized() && !frame.getArea().contains(x, y)) { for (Component component : frame.getChildren()) { for (Rectangle area : component.getTheme().getUIForComponent(component).getInteractableRegions(component)) { if (area.contains( x - frame.getX() - component.getX(), y - frame.getY() - component.getY())) { frame.onMouseRelease(x - frame.getX(), y - frame.getY(), button); guiManager.bringForward(frame); return; } } } } } for (Frame frame : guiManager.getFrames()) { if (!frame.isVisible()) continue; if (!frame.isMinimized() && frame.getArea().contains(x, y)) { frame.onMouseRelease(x - frame.getX(), y - frame.getY(), button); guiManager.bringForward(frame); break; } else if (frame.isMinimized()) { for (Rectangle area : frame.getTheme().getUIForComponent(frame).getInteractableRegions(frame)) { if (area.contains(x - frame.getX(), y - frame.getY())) { frame.onMouseRelease(x - frame.getX(), y - frame.getY(), button); guiManager.bringForward(frame); return; } } } } }