javax.swing.SwingUtilities#isDescendingFrom ( )源码实例Demo

下面列出了javax.swing.SwingUtilities#isDescendingFrom ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: wpcleaner   文件: ProgressPanel.java
@Override
public void setVisible(boolean visible) {
  boolean oldVisible = isVisible();
  super.setVisible(visible);
  JRootPane rootPane = SwingUtilities.getRootPane(this);
  if ((rootPane != null) && (isVisible() != oldVisible)) {
    if (isVisible()) {
      Component focusOwner = KeyboardFocusManager.
          getCurrentKeyboardFocusManager().getPermanentFocusOwner();
      if ((focusOwner != null) &&
          SwingUtilities.isDescendingFrom(focusOwner, rootPane)) {
        recentFocusOwner = focusOwner;
      }
      rootPane.getLayeredPane().setVisible(false);
      requestFocusInWindow();
    } else {
      rootPane.getLayeredPane().setVisible(true);
      if (recentFocusOwner != null) {
        recentFocusOwner.requestFocusInWindow();
      }
      recentFocusOwner = null;
    }
  }
}
 
源代码2 项目: ghidra   文件: WindowUtilities.java
private static Dialog findYoungestChildDialogOfParentDialog(Dialog parentDialog,
		List<Dialog> openModalDialogs) {

	if (parentDialog == null) {
		return null;
	}

	for (Dialog potentialChildDialog : openModalDialogs) {
		if (parentDialog == potentialChildDialog) {
			continue;
		}
		if (SwingUtilities.isDescendingFrom(potentialChildDialog, parentDialog)) {
			return findYoungestChildDialogOfParentDialog(potentialChildDialog,
				openModalDialogs);
		}
	}
	return parentDialog;
}
 
源代码3 项目: netbeans   文件: CloneableEditor.java
/** Transfer the focus to the editor pane.
 */
@Deprecated
@Override
public boolean requestFocusInWindow() {
    super.requestFocusInWindow();

    if (pane != null) {
        if ((customComponent != null) && !SwingUtilities.isDescendingFrom(pane, customComponent)) {
            return customComponent.requestFocusInWindow();
        } else {
            return pane.requestFocusInWindow();
        }
    }

    return false;
}
 
源代码4 项目: rapidminer-studio   文件: PanningManager.java
@Override
public void eventDispatched(AWTEvent e) {
	if (e instanceof MouseEvent) {
		MouseEvent me = (MouseEvent) e;
		if (!SwingUtilities.isDescendingFrom(me.getComponent(), target)) {
			return;
		}
		if (me.getID() == MouseEvent.MOUSE_RELEASED) {
			// stop when mouse released
			mouseOnScreenPoint = null;
			if (timer.isRunning()) {
				timer.stop();
			}
		} else if (me.getID() == MouseEvent.MOUSE_DRAGGED && me.getComponent() == target) {
			mouseOnScreenPoint = me.getLocationOnScreen();
		} else if (me.getID() == MouseEvent.MOUSE_PRESSED && me.getComponent() == target) {
			mouseOnScreenPoint = me.getLocationOnScreen();
			timer.start();
		}
	}
}
 
源代码5 项目: rapidminer-studio   文件: PopupPanel.java
/**
 * Checks if the focus is still on this component or its child components.
 */
private boolean isFocusInside(Object newFocusedComp) {
	if (newFocusedComp instanceof Popup) {
		return true;
	}
	if (newFocusedComp instanceof Component && !SwingUtilities.isDescendingFrom((Component) newFocusedComp, this)) {
		// Check if focus is on other window
		if (containingWindow == null) {
			return false;
		}

		Window focusedWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();

		// if focus is on other window in owner chain, return false
		Window parent = containingWindow;
		do {
			if (parent == focusedWindow) {
				return false;
			} else {
				parent = parent.getOwner();
			}
		} while (parent != null);
	}
	return true;
}
 
源代码6 项目: FlatLaf   文件: FlatBorder.java
protected boolean isFocused( Component c ) {
	if( c instanceof JScrollPane ) {
		JViewport viewport = ((JScrollPane)c).getViewport();
		Component view = (viewport != null) ? viewport.getView() : null;
		if( view != null ) {
			if( FlatUIUtils.isPermanentFocusOwner( view ) )
				return true;

			if( (view instanceof JTable && ((JTable)view).isEditing()) ||
				(view instanceof JTree && ((JTree)view).isEditing()) )
			{
				Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
				if( focusOwner != null )
					return SwingUtilities.isDescendingFrom( focusOwner, view );
			}
		}
		return false;
	} else if( c instanceof JComboBox && ((JComboBox<?>)c).isEditable() ) {
		Component editorComponent = ((JComboBox<?>)c).getEditor().getEditorComponent();
		return (editorComponent != null) ? FlatUIUtils.isPermanentFocusOwner( editorComponent ) : false;
	} else if( c instanceof JSpinner ) {
		if( FlatUIUtils.isPermanentFocusOwner( c ) )
			return true;

		JComponent editor = ((JSpinner)c).getEditor();
		if( editor instanceof JSpinner.DefaultEditor ) {
			JTextField textField = ((JSpinner.DefaultEditor)editor).getTextField();
			if( textField != null )
				return FlatUIUtils.isPermanentFocusOwner( textField );
		}
		return false;
	} else
		return FlatUIUtils.isPermanentFocusOwner( c );
}
 
源代码7 项目: wandora   文件: WandoraBackgroundPaint.java
public void paint( BackgroundComponent background, PaintableComponent paintable, Graphics g ){
    if( SwingUtilities.isDescendingFrom( background.getComponent(), content )){
        /* If we are painting an non-transparent component we paint our custom background image, otherwise
         * we just let it shine through */
        if( paintable.getTransparency() == Transparency.SOLID ){
            Point point = new Point( 0, 0 );
            point = SwingUtilities.convertPoint( paintable.getComponent(), point, content );
            BufferedImage image = getImage();
            if( image != null ){
                int w = paintable.getComponent().getWidth();
                int h = paintable.getComponent().getHeight();
                g.drawImage( image, 0, 0, w, h, point.x, point.y, point.x + w, point.y + h, null );
            }
        }

        /* and now we paint the original content of the component */
        Graphics2D g2 = (Graphics2D)g.create();

        //g2.setComposite( alpha );

        paintable.paintBackground( g2 );
        paintable.paintForeground( g );
        paintable.paintBorder( g2 );

        g2.dispose();

        paintable.paintChildren( g );

    }
}
 
源代码8 项目: netbeans   文件: I18nPanel.java
/** Overrides superclass method to set default button. */
@Override
public void addNotify() {
    super.addNotify();
    
    if (withButtons) {
        if (SwingUtilities.isDescendingFrom(replaceButton, this)) {
            getRootPane().setDefaultButton(replaceButton);
        }
    }
}
 
源代码9 项目: netbeans   文件: ResultView.java
public boolean isFocused() {
    ResultViewPanel rvp = getCurrentResultViewPanel();
    if (rvp != null) {
        Component owner = FocusManager.getCurrentManager().getFocusOwner();
        return owner != null && SwingUtilities.isDescendingFrom(owner, rvp);
    } else {
        return false;
    }
}
 
源代码10 项目: netbeans   文件: CloneableEditor.java
/** Transfer the focus to the editor pane.
 */
@Deprecated
@Override
public void requestFocus() {
    super.requestFocus();

    if (pane != null) {
        if ((customComponent != null) && !SwingUtilities.isDescendingFrom(pane, customComponent)) {
            customComponent.requestFocus();
        } else {
            pane.requestFocus();
        }
    }
}
 
源代码11 项目: nmonvisualizer   文件: IntervalManagerDialog.java
@Override
public void propertyChange(PropertyChangeEvent evt) {
    if (evt.getNewValue() != null) {
        // absolute parent => tabs
        // if any of the data entry forms are selected, unselect the interval table
        if (SwingUtilities.isDescendingFrom((java.awt.Component) evt.getNewValue(), absolute.getParent())) {
            intervals.getTable().clearSelection();
            systemTimes.getTable().clearSelection();
        }
        else if (intervals.getTable() == evt.getNewValue()) {
            systemTimes.getTable().clearSelection();
        }
    }
}
 
源代码12 项目: netbeans   文件: EditorOnlyDisplayer.java
private boolean switchCurrentEditor() {
    final TopComponent tc = TopComponent.getRegistry().getActivated();
    if( null == tc || !TopComponentTracker.getDefault().isEditorTopComponent( tc ) )
        return false;

    final WindowManagerImpl wmi = WindowManagerImpl.getInstance();
    final JFrame mainWnd = ( JFrame ) wmi.getMainWindow();
    if( SwingUtilities.isDescendingFrom( tc, mainWnd.getContentPane() ) )
        return true;
    JPanel panel = new JPanel( new BorderLayout() );
    panel.add( tc, BorderLayout.CENTER  );
    try {
        mainWnd.setContentPane( panel );
    } catch( IndexOutOfBoundsException e ) {
        Logger.getLogger(EditorOnlyDisplayer.class.getName()).log(Level.INFO, "Error while switching current editor.", e);
        //#245541 - something is broken in the component hierarchy, let's try restoring to the default mode
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                cancel(false);
            }
        });
    }
    mainWnd.invalidate();
    mainWnd.revalidate();
    mainWnd.repaint();
    SwingUtilities.invokeLater( new Runnable() {
        @Override
        public void run() {
            tc.requestFocusInWindow();
        }
    });
    return true;
}
 
源代码13 项目: netbeans   文件: DebugRepaintManager.java
@Override
public void addDirtyRegion(JComponent c, int x, int y, int w, int h) {
    for (JComponent dc : logComponents) {
        if (SwingUtilities.isDescendingFrom(dc, c)) {
            String boundsMsg = ViewUtils.toString(new Rectangle(x, y, w, h));
            ViewHierarchyImpl.REPAINT_LOG.log(Level.FINER,
                    "Component-REPAINT: " + boundsMsg + // NOI18N
                    " c:" + ViewUtils.toString(c), // NOI18N
                    new Exception("Component-Repaint of " + boundsMsg + " cause:")); // NOI18N
            break;
        }
    }

    super.addDirtyRegion(c, x, y, w, h);
}
 
源代码14 项目: netbeans   文件: EditorRegistryWatcher.java
public void notifyActiveTopComponentChanged(Component activeTopComponent) {
    if (activeTopComponent != null) {
        JTextComponent activeTextComponent = activeTextComponentRef.get();
        if (activeTextComponent != null) {
            if (!SwingUtilities.isDescendingFrom(activeTextComponent, activeTopComponent)) {
                // A top component was focused that does not contain focused text component
                // so notify that there's in fact no active text component
                if (LOG.isLoggable(Level.FINE)) {
                    LOG.fine("EditorRegistryWatcher: TopComponent without active JTextComponent\n");
                }
                updateActiveActionInPresenters(null);
            }
        }
    }
}
 
源代码15 项目: netbeans   文件: NavigatorController.java
public void actionPerformed (ActionEvent evt) {
    Component focusOwner = FocusManager.getCurrentManager().getFocusOwner();
    // move focus away only from navigator AWT children,
    // but not combo box to preserve its ESC functionality
    if (lastActivatedRef == null ||
        focusOwner == null ||
        !SwingUtilities.isDescendingFrom(focusOwner, navigatorTC.getTopComponent()) ||
        focusOwner instanceof JComboBox) {
        return;
    }
    TopComponent prevFocusedTc = lastActivatedRef.get();
    if (prevFocusedTc != null) {
        prevFocusedTc.requestActive();
    }
}
 
源代码16 项目: netbeans   文件: StatusLineFactories.java
static void refreshStatusLine() {
    LOG.fine("StatusLineFactories.refreshStatusLine()\n");
    List<? extends JTextComponent> componentList = EditorRegistry.componentList();
    for (JTextComponent component : componentList) {
        boolean underMainWindow = (SwingUtilities.isDescendingFrom(component,
                WindowManager.getDefault().getMainWindow()));
        EditorUI editorUI = Utilities.getEditorUI(component);
        if (LOG.isLoggable(Level.FINE)) {
            String componentDesc = component.toString();
            Document doc = component.getDocument();
            Object streamDesc;
            if (doc != null && ((streamDesc = doc.getProperty(Document.StreamDescriptionProperty)) != null)) {
                componentDesc = streamDesc.toString();
            }
            LOG.fine("  underMainWindow=" + underMainWindow + // NOI18N
                    ", text-component: " + componentDesc + "\n");
        }
        if (editorUI != null) {
            StatusBar statusBar = editorUI.getStatusBar();
            statusBar.setVisible(!underMainWindow);
            boolean shouldUpdateGlobal = underMainWindow && component.isShowing();
            if (shouldUpdateGlobal) {
                statusBar.updateGlobal();
                LOG.fine("  end of refreshStatusLine() - found main window component\n\n"); // NOI18N
                return; // First non-docked one found and updated -> quit
            }
        }
    }
    clearStatusLine();
    LOG.fine("  end of refreshStatusLine() - no components - status line cleared\n\n"); // NOI18N
}
 
源代码17 项目: microba   文件: BasicCalendarPaneUI.java
public void focusLost(FocusEvent e) {
	boolean isFocusableComponent = focusableComponents.contains(e
			.getSource());
	boolean isNonEmptyOpposite = e.getOppositeComponent() != null;
	if (isFocusableComponent
			&& isNonEmptyOpposite
			&& !SwingUtilities.isDescendingFrom(e
					.getOppositeComponent(), peer)) {
		peer.commitOrRevert();
	}
}
 
源代码18 项目: pumpernickel   文件: AbstractComponentVisibility.java
public static boolean isInsideActiveWindow(Component comp) {
	Window activeWindow = KeyboardFocusManager
			.getCurrentKeyboardFocusManager().getActiveWindow();
	if (activeWindow == null)
		return false;
	return activeWindow == comp
			|| SwingUtilities.isDescendingFrom(comp, activeWindow);
}
 
源代码19 项目: netbeans   文件: Central.java
/** */
public void activateModeTopComponent(ModeImpl mode, TopComponent tc) {
    if(!getModeOpenedTopComponents(mode).contains(tc)) {
        return;
    }
    
    ModeImpl oldActiveMode = getActiveMode();
    //#45650 -some API users call the activation all over again all the time on one item.
    // improve performance for such cases.
    if (oldActiveMode != null && oldActiveMode.equals(mode)) {
        if (tc != null && tc.equals(model.getModeSelectedTopComponent(mode))) {
            // #82385, #139319 do repeat activation if focus is not
            // owned by tc to be activated
            Component fOwn = KeyboardFocusManager.getCurrentKeyboardFocusManager().
                    getFocusOwner();
            if (fOwn != null && SwingUtilities.isDescendingFrom(fOwn, tc)) {
                //#70173 - activation request came probably from a sliding
                //window in 'hover' mode, so let's hide it
                slideOutSlidingWindows( mode );
                return;
            }
        }
    }
    model.setActiveMode(mode);
    model.setModeSelectedTopComponent(mode, tc);
    
    if(isVisible()) {
        viewRequestor.scheduleRequest(new ViewRequest(mode, 
            View.CHANGE_TOPCOMPONENT_ACTIVATED, null, tc));

        //restore floating windows if iconified
        if( mode.getState() == Constants.MODE_STATE_SEPARATED ) {
            Frame frame = (Frame) SwingUtilities.getAncestorOfClass(Frame.class, tc);
            if( null != frame && frame != WindowManagerImpl.getInstance().getMainWindow()
                    && (frame.getExtendedState() & Frame.ICONIFIED) > 0 ) {
                frame.setExtendedState(frame.getExtendedState() - Frame.ICONIFIED );
            }
        }
    }
    
    // Notify registry.
    WindowManagerImpl.notifyRegistryTopComponentActivated(tc);
    
    if(oldActiveMode != mode) {
        WindowManagerImpl.getInstance().doFirePropertyChange(
            WindowManagerImpl.PROP_ACTIVE_MODE, oldActiveMode, mode);
    }
}
 
源代码20 项目: CodenameOne   文件: BasicOutlookBarUI.java
public void layoutContainer(Container parent) {
  int selectedIndex = tabPane.getSelectedIndex();
  Component visibleComponent = getVisibleComponent();
  
  if (selectedIndex < 0) {
    if (visibleComponent != null) {
      // The last tab was removed, so remove the component
      setVisibleComponent(null);
    }
  } else {
    Component selectedComponent = tabPane.getComponentAt(selectedIndex);
    boolean shouldChangeFocus = false;

    // In order to allow programs to use a single component
    // as the display for multiple tabs, we will not change
    // the visible compnent if the currently selected tab
    // has a null component. This is a bit dicey, as we don't
    // explicitly state we support this in the spec, but since
    // programs are now depending on this, we're making it work.
    //
    if (selectedComponent != null) {
      if (selectedComponent != visibleComponent && visibleComponent != null) {
        // get the current focus owner
        Component currentFocusOwner = KeyboardFocusManager
          .getCurrentKeyboardFocusManager().getFocusOwner();
        // check if currentFocusOwner is a descendant of visibleComponent
        if (currentFocusOwner != null
          && SwingUtilities.isDescendingFrom(currentFocusOwner,
            visibleComponent)) {
          shouldChangeFocus = true;
        }
      }
      setVisibleComponent(selectedComponent);

      // make sure only the selected component is visible
      Component[] components = parent.getComponents();
      for (int i = 0; i < components.length; i++) {
        if (!(components[i] instanceof UIResource)
          && components[i].isVisible()
          && components[i] != selectedComponent) {
          components[i].setVisible(false);
          setConstraint(components[i], "*");
        }
      }
      
      if (BasicOutlookBarUI.this.nextVisibleComponent != null) {
        BasicOutlookBarUI.this.nextVisibleComponent.setVisible(true);
      }
    }

    super.layoutContainer(parent);

    if (shouldChangeFocus) {
      if (!requestFocusForVisibleComponent0()) {
        tabPane.requestFocus();
      }
    }
  }
}