Java Code Examples for java.awt.event.HierarchyEvent#getChangeFlags()

The following examples show how to use java.awt.event.HierarchyEvent#getChangeFlags() . 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: WindowsMenuBarUI.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void installListeners() {
    if (WindowsLookAndFeel.isOnVista()) {
        installWindowListener();
        hierarchyListener =
            new HierarchyListener() {
                public void hierarchyChanged(HierarchyEvent e) {
                    if ((e.getChangeFlags()
                            & HierarchyEvent.DISPLAYABILITY_CHANGED) != 0) {
                        if (menuBar.isDisplayable()) {
                            installWindowListener();
                        } else {
                            uninstallWindowListener();
                        }
                    }
                }
        };
        menuBar.addHierarchyListener(hierarchyListener);
    }
    super.installListeners();
}
 
Example 2
Source File: WindowsMenuBarUI.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void installListeners() {
    if (WindowsLookAndFeel.isOnVista()) {
        installWindowListener();
        hierarchyListener =
            new HierarchyListener() {
                public void hierarchyChanged(HierarchyEvent e) {
                    if ((e.getChangeFlags()
                            & HierarchyEvent.DISPLAYABILITY_CHANGED) != 0) {
                        if (menuBar.isDisplayable()) {
                            installWindowListener();
                        } else {
                            uninstallWindowListener();
                        }
                    }
                }
        };
        menuBar.addHierarchyListener(hierarchyListener);
    }
    super.installListeners();
}
 
Example 3
Source File: UiNotifyConnector.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void hierarchyChanged(@Nonnull HierarchyEvent e) {
  if (isDisposed()) return;

  if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) > 0) {
    final Runnable runnable = () -> {
      final Component c = myComponent.get();
      if (isDisposed() || c == null) return;

      if (c.isShowing()) {
        showNotify();
      }
      else {
        hideNotify();
      }
    };
    final Application app = ApplicationManager.getApplication();
    if (app != null && app.isDispatchThread()) {
      app.invokeLater(runnable, ModalityState.current());
    }
    else {
      //noinspection SSBasedInspection
      SwingUtilities.invokeLater(runnable);
    }
  }
}
 
Example 4
Source File: WindowsMenuBarUI.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
@Override
protected void installListeners() {
    if (WindowsLookAndFeel.isOnVista()) {
        installWindowListener();
        hierarchyListener =
            new HierarchyListener() {
                public void hierarchyChanged(HierarchyEvent e) {
                    if ((e.getChangeFlags()
                            & HierarchyEvent.DISPLAYABILITY_CHANGED) != 0) {
                        if (menuBar.isDisplayable()) {
                            installWindowListener();
                        } else {
                            uninstallWindowListener();
                        }
                    }
                }
        };
        menuBar.addHierarchyListener(hierarchyListener);
    }
    super.installListeners();
}
 
Example 5
Source File: SamplerImpl.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
DataViewComponent.MasterView getMasterView() {
    initComponents();
    setState(State.INACTIVE);

    final HierarchyListener hl = new HierarchyListener() {
        public void hierarchyChanged(HierarchyEvent e) {
            if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
                if (view.isShowing()) {
                    initializeCpuSampling();
                    initializeMemorySampling();
                    view.removeHierarchyListener(this);
                }
            }
        }
    };
    view.addHierarchyListener(hl);

    return new DataViewComponent.MasterView(NbBundle.getMessage(
               SamplerImpl.class, "LBL_Sampler"), null, view); // NOI18N
}
 
Example 6
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 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 ();
            }
        }
    }
}
 
Example 8
Source File: JExtendedSplitPane.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.SHOWING_CHANGED) != 0) {
        boolean visible = c.isVisible();
        if (wasVisible == visible) return;

        wasVisible = visible;

        if (visible) componentShown();
        else componentHidden(c);
    }
}
 
Example 9
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 10
Source File: Splitter.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.SHOWING_CHANGED) != 0 ||
        (e.getChangeFlags() & HierarchyEvent.DISPLAYABILITY_CHANGED) != 0) {
        
        boolean visible = c.isVisible();
        if (wasVisible == visible) return;

        wasVisible = visible;

        if (visible) componentShown();
        else componentHidden(c);
    }
}
 
Example 11
Source File: VisibilityHandler.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private HierarchyListener createListener() {
    return new HierarchyListener() {
        public void hierarchyChanged(HierarchyEvent e) {
            if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
                boolean visible = component.isShowing();
                if (wasVisible == visible) return;

                wasVisible = visible;

                if (visible) shown();
                else hidden();
            }
        }
    };
}
 
Example 12
Source File: TailLogActionListener.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
@Override
public void hierarchyChanged(HierarchyEvent e) {
  if (e.getChangeFlags() == 1 && e.getChanged().getParent() == null) {
    // if (e.getChangeFlags() == 6) {
    for (SoftReference<Stoppable> ref : referencesList) {
      Stoppable stoppable = ref.get();
      LOGGER.debug("Tab removed, stopping thread if reference is != null (actual: " + stoppable + ")");
      if (stoppable != null) {
        stoppable.stop();
      }
    }
  }

}
 
Example 13
Source File: VisibilityHandler.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private HierarchyListener createListener() {
    return new HierarchyListener() {
        public void hierarchyChanged(HierarchyEvent e) {
            if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
                boolean visible = component.isShowing();
                if (wasVisible == visible) return;

                wasVisible = visible;

                if (visible) shown();
                else hidden();
            }
        }
    };
}
 
Example 14
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
@Override public void hierarchyChanged(HierarchyEvent e) {
  if ((e.getChangeFlags() & HierarchyEvent.DISPLAYABILITY_CHANGED) != 0) {
    if (e.getComponent().isDisplayable()) {
      timer.start();
    } else {
      timer.stop();
    }
  }
}
 
Example 15
Source File: IOObjectCacheViewer.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void hierarchyChanged(HierarchyEvent e) {
	// update whenever the component visibility changes, the view is dirty (prior updates
	// have been ignored), and not more than one update is scheduled
	synchronized (updateLock) {
		if ((HierarchyEvent.SHOWING_CHANGED & e.getChangeFlags()) != 0 && isDirty && scheduledUpdates <= 1) {
			scheduledUpdates++;
			SwingUtilities.invokeLater(updateEntries);
		}
	}
}
 
Example 16
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 17
Source File: Splitter.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.SHOWING_CHANGED) != 0 ||
        (e.getChangeFlags() & HierarchyEvent.DISPLAYABILITY_CHANGED) != 0) {
        
        boolean visible = c.isVisible();
        if (wasVisible == visible) return;

        wasVisible = visible;

        if (visible) componentShown();
        else componentHidden(c);
    }
}
 
Example 18
Source File: MainPanel.java    From java-swing-tips with MIT License 4 votes vote down vote up
@Override public void hierarchyChanged(HierarchyEvent e) {
  if ((e.getChangeFlags() & HierarchyEvent.DISPLAYABILITY_CHANGED) != 0 && !e.getComponent().isDisplayable()) {
    inside.stop();
    outside.stop();
  }
}
 
Example 19
Source File: MainPanel.java    From java-swing-tips with MIT License 4 votes vote down vote up
@Override public void hierarchyChanged(HierarchyEvent e) {
  if ((e.getChangeFlags() & HierarchyEvent.DISPLAYABILITY_CHANGED) != 0 && !e.getComponent().isDisplayable()) {
    animator.stop();
  }
}
 
Example 20
Source File: MainPanel.java    From java-swing-tips with MIT License 4 votes vote down vote up
@Override public void hierarchyChanged(HierarchyEvent e) {
  if ((e.getChangeFlags() & HierarchyEvent.DISPLAYABILITY_CHANGED) != 0 && !e.getComponent().isDisplayable()) {
    scroller.stop();
    scroller.removeActionListener(listener);
  }
}