/** Creates a new instance of AsyncInitComponent * @param comp4Init Component to be initialized. Mustn't be showing at this * time. IllegalStateException is thrown if component is already showing. * @param initJob Instance of initialization job. */ public AsyncInitSupport(Component comp4Init, AsyncGUIJob initJob) { this.comp4Init = comp4Init; this.initJob = initJob; if (comp4Init.isShowing()) { throw new IllegalStateException("Component already shown, can't be inited: " + comp4Init); } comp4Init.addHierarchyListener(this); LOG.log(Level.FINE, "addHierarchyListener for {0}", comp4Init); }
/** Impl of HierarchyListener, starts init job with delay when component shown, * stops listening to asociated component it isn't showing anymore, * calls cancel if desirable. * @param evt hierarchy event */ @Override public void hierarchyChanged(HierarchyEvent evt) { final boolean hierachyChanged = (evt.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0; LOG.log(Level.FINE, "Hierarchy Changed {0}", hierachyChanged); if (hierachyChanged) { boolean isShowing = comp4Init.isShowing(); if (timer == null && isShowing) { timer = new Timer(20, this); timer.setRepeats(false); timer.start(); LOG.log(Level.FINE, "Timer started for {0}", comp4Init); } else if (!isShowing) { comp4Init.removeHierarchyListener(this); LOG.log(Level.FINE, "Not showing, cancling for {0}", comp4Init); cancel(); } } }
/** * Centers the window over a component (usually another window). * The window must already have been sized. */ public static void centerWindowOnComponent(Window window, Component over) { if ((over == null) || !over.isShowing()) { centerWindowOnScreen(window); return; } Point parentLocation = over.getLocationOnScreen(); Dimension parentSize = over.getSize(); Dimension size = window.getSize(); // Center it. int x = parentLocation.x + (parentSize.width - size.width) / 2; int y = parentLocation.y + (parentSize.height - size.height) / 2; // Now, make sure it's onscreen Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); // This doesn't actually work on the Mac, where the screen // doesn't necessarily start at 0,0 if (x + size.width > screenSize.width) x = screenSize.width - size.width; if (x < 0) x = 0; if (y + size.height > screenSize.height) y = screenSize.height - size.height; if (y < 0) y = 0; window.setLocation(x, y); }
public static Component findComponentUnderGlassPaneAt(Point p, Component top) { Component c = null; if (top.isShowing()) { if (top instanceof RootPaneContainer) c = ((RootPaneContainer) top).getLayeredPane().findComponentAt( SwingUtilities.convertPoint(top, p, ((RootPaneContainer) top).getLayeredPane())); else c = ((Container) top).findComponentAt(p); } return c; }
/** Creates a new instance of AsyncInitComponent * @param comp4Init Component to be initialized. Mustn't be showing at this * time. IllegalStateException is thrown if component is already showing. * @param initJob Instance of initialization job. */ public AsyncInitSupport(Component comp4Init, AsyncGUIJob initJob) { this.comp4Init = comp4Init; this.initJob = initJob; if (comp4Init.isShowing()) { throw new IllegalStateException("Component already shown, can't be inited: " + comp4Init); } comp4Init.addHierarchyListener(this); LOG.log(Level.FINE, "addHierarchyListener for {0}", comp4Init); }
/** Impl of HierarchyListener, starts init job with delay when component shown, * stops listening to asociated component it isn't showing anymore, * calls cancel if desirable. * @param evt hierarchy event */ @Override public void hierarchyChanged(HierarchyEvent evt) { final boolean hierachyChanged = (evt.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0; LOG.log(Level.FINE, "Hierarchy Changed {0}", hierachyChanged); if (hierachyChanged) { boolean isShowing = comp4Init.isShowing(); if (timer == null && isShowing) { timer = new Timer(20, this); timer.setRepeats(false); timer.start(); LOG.log(Level.FINE, "Timer started for {0}", comp4Init); } else if (!isShowing) { comp4Init.removeHierarchyListener(this); LOG.log(Level.FINE, "Not showing, cancling for {0}", comp4Init); cancel(); } } }
public boolean matches(Component c) { return cls.isAssignableFrom(c.getClass()) && (!mustBeShowing || c.isShowing()); } public String toString() {
/** * */ public void run() { if ((editorComp != null) && editorComp.isShowing()) { editorComp.requestFocus(); } }
@Override public Component getDefaultComponent(Container focusCycleRoot) { if (inRemoveRequest && isEditing() && editorComp.isShowing()) { return editorComp; } else { return TreeTable.this; } }
private JAWTComponentListener() { isShowing = component.isShowing(); AWTEDTExecutor.singleton.invoke(false, new Runnable() { // Bug 952: Avoid deadlock via AWTTreeLock acquisition .. @Override public void run() { if(DEBUG) { System.err.println(jawtStr()+".attach @ Thread "+getThreadName()+": "+JAWTComponentListener.this.toString()); } component.addComponentListener(JAWTComponentListener.this); component.addHierarchyListener(JAWTComponentListener.this); } } ); }
@Override public void drawWatermarkImage(Graphics graphics, Component c, int x, int y, int width, int height) { if (!c.isShowing()) return; int dx = c.getLocationOnScreen().x; int dy = c.getLocationOnScreen().y; graphics.drawImage(SubstanceCrosshatchWatermark.watermarkImage, x, y, x + width, y + height, x + dx, y + dy, x + dx + width, y + dy + height, null); }
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) {
public static void setDialogLocationRelativeTo(final JDialog dialog, final Component c) { if (c == null || ! c.isShowing()) { return; } final Point location = findBestLocation(dialog, c); dialog.setLocation(location); }
@Override public Component getDefaultComponent(Container focusCycleRoot) { if (!inEditorRemoveRequest() && isEditing() && editorComp.isShowing()) { return editorComp; } else { return SheetTable.this; } }
private void tryRestoringFocusOwner() { if (focusOwner != null) { if (focusOwner.isDisplayable() && focusOwner.isShowing()) { focusOwner.requestFocus(); } } }
@Override public void hierarchyChanged(HierarchyEvent e) { if( 0 != (e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED)) presentationState.setHighlightsNodes(e.getComponent().isShowing()); } });
public static boolean isEditingText() { final Component focusOwner = FocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); final boolean isTextComponentFocused = focusOwner instanceof JEditorPane; return isTextComponentFocused && focusOwner.isShowing() && ((JTextComponent)focusOwner).isEditable(); }
@Override protected boolean accept(Component aComponent) { //Do not allow focus to go to a child of the editor we're using if //we are in the process of removing the editor if (isEditing() && inEditRequest) { return isKnownComponent(aComponent); } return super.accept(aComponent) && aComponent.isShowing(); } }
@Override public void hierarchyChanged(HierarchyEvent e) { final Component component = e.getComponent(); if(component.isShowing()){ attributeNames.requestFocus(); component.removeHierarchyListener(this); } } });
public void hierarchyChanged(HierarchyEvent e) { if(e.getID() != HierarchyEvent.ANCESTOR_MOVED && e.getID() != HierarchyEvent.ANCESTOR_RESIZED) Controller.getCurrentModeController().setBlocked(e.getComponent().isShowing()); } }