private void readPositionFromComponent(Component component) { isFullScreen = false; windowWidth = component.getWidth(); windowHeight = component.getHeight(); windowX = component.getX(); windowY = component.getY(); }
@Override public void mousePressed(MouseEvent e) { popup.applyComponentOrientation(ComponentOrientation.getOrientation(I18n.getLocaleDefault())); if (ComponentOrientation.getOrientation(I18n.getLocaleDefault()) == ComponentOrientation.RIGHT_TO_LEFT) { radioCustomMethod.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 6)); } else { radioCustomMethod.setBorder(BorderFactory.createEmptyBorder(0, 6, 0, 0)); } popup.show( e.getComponent(), ComponentOrientation.getOrientation(I18n.getLocaleDefault()) == ComponentOrientation.RIGHT_TO_LEFT ? e.getComponent().getX() - e.getComponent().getWidth() - popup.getWidth() : e.getComponent().getX(), e.getComponent().getY() + e.getComponent().getWidth() ); popup.setLocation( ComponentOrientation.getOrientation(I18n.getLocaleDefault()) == ComponentOrientation.RIGHT_TO_LEFT ? e.getComponent().getLocationOnScreen().x + e.getComponent().getWidth() - popup.getWidth() : e.getComponent().getLocationOnScreen().x, e.getComponent().getLocationOnScreen().y + e.getComponent().getWidth() ); } });
public static void keepComponentInsideFrame(int centerX, int centerY, Component component) { Rectangle frameRec = MageFrame.getInstance().getBounds(); boolean setLocation = false; if (component.getX() > (frameRec.width - OVERLAP_LIMIT)) { setLocation = true; } if (component.getY() > (frameRec.height - OVERLAP_LIMIT)) { setLocation = true; } if (setLocation) { component.setLocation(centerX, centerY); } }
@Override public final int getY() { return c.getY(); }
private int getSize(Component c) { if (c==null) return 0; return c.getY()+c.getHeight(); }
public static void convertPointFromAncestor(final Component ancestor, final Point p, Component c) { int x, y; while (c != ancestor && c != null) { x = c.getX(); y = c.getY(); p.x -= x; p.y -= y; c = c.getParent(); }; }
public static void convertPointToAncestor(final Component from, final Point p, final Component destination) { int x, y; for (Component c = from; c != destination && c != null; c = c.getParent()) { x = c.getX(); y = c.getY(); p.x += x; p.y += y; }; }
/** Returns true if the specified component's top edge touches * the top edge of the parent component. */ protected boolean isTouchingTopEdge(Component c) { if(!isHidingEdges) return false; Component parent=getParent(c); if(parent==null) return false; return c.getY()==c.getParent().getInsets().top; }
/** * Centers the first component on the second */ public static void center(Component componentToMove, Component componentToCenterOn) { Dimension componentToCenterOnSize = componentToCenterOn.getSize(); componentToMove.setLocation( componentToCenterOn.getX() + ((componentToCenterOnSize.width - componentToMove.getWidth()) / 2), componentToCenterOn.getY() + ((componentToCenterOnSize.height - componentToMove.getHeight()) / 2)); }
@Override public void actionPerformed(ActionEvent e) { JPopupMenu popup = getChooseClassPopupMenu(); // show the popup where the source component is if (e.getSource() instanceof Component) { Component comp = (Component) e.getSource(); popup.show(comp, comp.getX(), comp.getY()); } } });
public void paintIcon(Component c, Graphics g, int x, int y) { super.setColor(new Color(10, 10, 10, 0)); super.paintIcon(c, g, x, y); g2d.setFont(new Font("SansSerif", Font.BOLD, 14)); g2d.setColor(Color.DARK_GRAY); final Font font = (Font) value; g2d.setFont(new Font(font.getFontName(), font.getStyle(), 40)); g2d.setColor(new Color(10, 10, 10, 40)); g2d.drawString("Font", c.getX() + 15, c.getY() - 10); g2d.setFont(new Font("SansSerif", Font.BOLD, 14)); } };
private static Point getFeedbackComponentOrigin(JComponent feedbackComponent, Component contentComponent) { boolean isLTR = contentComponent.getComponentOrientation().isLeftToRight(); int x = contentComponent.getX() + (isLTR ? 0 : contentComponent.getWidth() - 1) - feedbackComponent.getWidth() / 2; int y = contentComponent.getY() + contentComponent.getHeight() - feedbackComponent.getHeight() + 2; return new Point(x, y); }
private String str(final Object obj) { if( null == obj ) { return "0xnil: null"; } else if( obj instanceof Component ) { final Component c = (Component)obj; return id(obj)+": "+c.getClass().getSimpleName()+"[visible "+c.isVisible()+", showing "+c.isShowing()+", valid "+c.isValid()+ ", displayable "+c.isDisplayable()+", "+c.getX()+"/"+c.getY()+" "+c.getWidth()+"x"+c.getHeight()+"]"; } else { return id(obj)+": "+obj.getClass().getSimpleName()+"[..]"; } } private String s(final ComponentEvent e) {
protected void refresh() { if ( getComponent().getParent() != null ) { Component papi = getComponent(); papi.getParent().repaint( papi.getX()-5, papi.getY()-5, papi.getWidth()+10, papi.getHeight()+10); } }
protected void refreshBorder() { if ( getComponent().getParent() != null ) { Component papi = getComponent(); papi.getParent().repaint( papi.getX()-5, papi.getY()-5, papi.getWidth()+10, papi.getHeight()+10); } }
public class Basic { public static void moveLeft(Component component, int offset) { component.setLocation(component.getX() - offset, component.getY()); } }
@Override public boolean contains(final int x, final int y) { if (super.contains(x, y)) return true; for(int i = 0; i < getComponentCount(); i++){ final Component comp = getComponent(i); if(comp.isVisible() && comp.contains(x-comp.getX(), y-comp.getY())) return true; } return false; }
/** * Packs this dialog, makes it non-resizable and visible. */ public void showDialog() { pack(); if(locationRelativeComp==null) DialogToolkit.centerOnScreen(this); else setLocation(locationRelativeComp.getX()+(locationRelativeComp.getWidth()-getWidth())/2, locationRelativeComp.getY()+(locationRelativeComp.getHeight()-getHeight())/2); setVisible(true); }
private void formComponentMoved(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentMoved if (isShowing() && !isMaximum() && isRecording()) { final Component c = evt.getComponent(); prefs.putInt(getKey("x"), c.getX()); prefs.putInt(getKey("y"), c.getY()); } }//GEN-LAST:event_formComponentMoved