Java Code Examples for java.awt.event.HierarchyEvent#PARENT_CHANGED

The following examples show how to use java.awt.event.HierarchyEvent#PARENT_CHANGED . 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 File: DarkRootPaneUI.java    From darklaf with MIT License 6 votes vote down vote up
@Override
public void hierarchyChanged(final HierarchyEvent e) {
    if (rootPane == null) return;
    Component parent = rootPane.getParent();
    if (parent == null) {
        return;
    }
    if (parent.getClass().getName().startsWith("org.jdesktop.jdic.tray")
        || (parent.getClass().getName().equals("javax.swing.Popup$HeavyWeightWindow"))) {
        SwingUtilities.invokeLater(() -> {
            if (rootPane != null) {
                rootPane.removeHierarchyListener(this);
            }
        });
    }
    if (e.getChangeFlags() == HierarchyEvent.PARENT_CHANGED) {
        if (DarkUIUtil.getWindow(rootPane) != window) {
            updateClientDecoration();
        }
    }
}
 
Example 2
Source File: RemoteAWTHierarchyListener.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void eventDispatched(AWTEvent event) {
    HierarchyEvent e = (HierarchyEvent) event;
    if ((e.getChangeFlags() & HierarchyEvent.PARENT_CHANGED) != 0) {
        Component c = e.getChanged();
        Container p = c.getParent();
        if (p == null) {
            // Component was removed from the hierarchy
            components.remove(c);
        } else {
            Throwable t = new RuntimeException();
            StringWriter sw = new StringWriter();
            t.printStackTrace(new PrintWriter(sw));
            String stackTrace = sw.toString();
            String stackLine = getComponentAddStackLine(stackTrace);
            components.put(c, stackLine);
        }
    }
}
 
Example 3
Source File: JBRCustomDecorations.java    From FlatLaf with Apache License 2.0 5 votes vote down vote up
static void install( JRootPane rootPane ) {
	if( !isSupported() )
		return;

	// check whether root pane already has a parent, which is the case when switching LaF
	if( rootPane.getParent() != null )
		return;

	// Use hierarchy listener to wait until the root pane is added to a window.
	// Enabling JBR decorations must be done very early, probably before
	// window becomes displayable (window.isDisplayable()). Tried also using
	// "ancestor" property change event on root pane, but this is invoked too late.
	HierarchyListener addListener = new HierarchyListener() {
		@Override
		public void hierarchyChanged( HierarchyEvent e ) {
			if( e.getChanged() != rootPane || (e.getChangeFlags() & HierarchyEvent.PARENT_CHANGED) == 0 )
				return;

			Container parent = e.getChangedParent();
			if( parent instanceof Window )
				install( (Window) parent );

			// use invokeLater to remove listener to avoid that listener
			// is removed while listener queue is processed
			EventQueue.invokeLater( () -> {
				rootPane.removeHierarchyListener( this );
			} );
		}
	};
	rootPane.addHierarchyListener( addListener );
}
 
Example 4
Source File: BufferedCanvasComponent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void hierarchyChanged(HierarchyEvent e) {
    if ((e.getChangeFlags() & HierarchyEvent.PARENT_CHANGED) != 0) {
        Window parentWindow = SwingUtilities.getWindowAncestor(BufferedCanvasComponent.this);
        if (lastParentWindow != parentWindow) {
            if (lastParentWindow != null) lastParentWindow.removeWindowListener(VisibilityHandler.this);
            if (parentWindow != null) parentWindow.addWindowListener(VisibilityHandler.this);
            lastParentWindow = parentWindow;
        }
    }
    
    if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
        if (isShowing()) BufferedCanvasComponent.this.shown();
        else BufferedCanvasComponent.this.hidden();
    }
}
 
Example 5
Source File: FoldHierarchyExecution.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void hierarchyChanged(HierarchyEvent e) {
    if ((e.getChangeFlags() & HierarchyEvent.PARENT_CHANGED) == 0) {
        return;
    }
    // the component may be reparented, usually in the same execution sequence
    // within an event. Let's update (suspend or resume) the changes depending on
    // the stabilized state in a next AWT event:
    if (updating) {
        return;
    }
    updating = true;
    SwingUtilities.invokeLater(this);
}
 
Example 6
Source File: BufferedCanvasComponent.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public void hierarchyChanged(HierarchyEvent e) {
    if ((e.getChangeFlags() & HierarchyEvent.PARENT_CHANGED) != 0) {
        Window parentWindow = SwingUtilities.getWindowAncestor(BufferedCanvasComponent.this);
        if (lastParentWindow != parentWindow) {
            if (lastParentWindow != null) lastParentWindow.removeWindowListener(VisibilityHandler.this);
            if (parentWindow != null) parentWindow.addWindowListener(VisibilityHandler.this);
            lastParentWindow = parentWindow;
        }
    }
    
    if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
        if (isShowing()) BufferedCanvasComponent.this.shown();
        else BufferedCanvasComponent.this.hidden();
    }
}
 
Example 7
Source File: AbstractDecorationPainter.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Informs about hierarchy changes.
 * Note that this method will only be fired when component {@link #usesHierarchyBasedView()}.
 *
 * @param event {@link HierarchyEvent}
 */
protected void hierarchyChanged ( @NotNull final HierarchyEvent event )
{
    // Ensure component is still available
    // This might happen if painter is replaced from another HierarchyListener
    if ( AbstractDecorationPainter.this.component != null )
    {
        // Listening only for parent change event
        // It will inform us when parent container for this component changes
        // Ancestor listener is not really reliable because it might inform about consequent parent changes
        if ( ( event.getChangeFlags () & HierarchyEvent.PARENT_CHANGED ) == HierarchyEvent.PARENT_CHANGED )
        {
            // If there was a previous container...
            if ( ancestor != null )
            {
                // Stop tracking neighbours
                ancestor.removeContainerListener ( neighboursTracker );
            }

            // Updating ancestor
            ancestor = AbstractDecorationPainter.this.component.getParent ();

            // If there is a new container...
            if ( ancestor != null )
            {
                // Start tracking neighbours
                ancestor.addContainerListener ( neighboursTracker );

                // Updating border
                updateBorder ();
            }
        }
    }
}