Java Code Examples for java.awt.event.HierarchyEvent

The following examples show how to use java.awt.event.HierarchyEvent. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: visualvm   Source File: SamplerImpl.java    License: 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 2
Source Project: jdk1.8-source-analysis   Source File: WindowsMenuBarUI.java    License: Apache License 2.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 Project: ghidra   Source File: AbstractSelectionNavigationAction.java    License: Apache License 2.0 6 votes vote down vote up
private void initialize() {
	// We want to load our state after we have been associated with a DockingWindowManager. 
	// If the table is displayable, then we are are properly setup...
	if (table.isDisplayable()) {
		restoreState();
		return;
	}

	// ...otherwise, we are using this listener to know when the table has been added to 
	// the component hierarchy, as it has been connected to a DockingWindowManager by then.
	table.addHierarchyListener(new HierarchyListener() {
		@Override
		public void hierarchyChanged(HierarchyEvent e) {
			long changeFlags = e.getChangeFlags();
			if (HierarchyEvent.DISPLAYABILITY_CHANGED == (changeFlags &
				HierarchyEvent.DISPLAYABILITY_CHANGED)) {

				// check for the first time we are put together                    
				if (table.isDisplayable()) {
					restoreState();
					table.removeHierarchyListener(this); // cleanup
				}
			}
		}
	});
}
 
Example 4
@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 Project: jdk8u60   Source File: WindowsMenuBarUI.java    License: 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 6
/**
 * Called when the component hierarchy for our text component changes.
 * When the text component is added to a new {@link Window}, this method
 * registers listeners on that <code>Window</code>.
 *
 * @param e The event.
 */
@Override
public void hierarchyChanged(HierarchyEvent e) {

	// NOTE: e many be null as we call this method at other times.
	// System.out.println("Hierarchy changed! " + e);

	Window oldParentWindow = parentWindow;
	parentWindow = SwingUtilities.getWindowAncestor(textComponent);
	if (parentWindow != oldParentWindow) {
		if (oldParentWindow != null) {
			parentWindowListener.removeFrom(oldParentWindow);
		}
		if (parentWindow != null) {
			parentWindowListener.addTo(parentWindow);
		}
	}

}
 
Example 7
Source Project: netbeans   Source File: FileNameController.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void hierarchyChanged(HierarchyEvent e) {
    if ((e.getComponent() != txtComp)
            || ((e.getChangeFlags() & DISPLAYABILITY_CHANGED) == 0)
            || !txtComp.isDisplayable()) {
        return;
    }

    watcherLogger.finer("componentShown()");                    //NOI18N
    if (foregroundColor == null) {
        foregroundColor = txtComp.getForeground();
    }
    if ((doc.getLength() == 0) && !txtComp.isFocusOwner()) {
        displayInfo();
    }
}
 
Example 8
Source Project: java-swing-tips   Source File: MainPanel.java    License: MIT License 6 votes vote down vote up
protected MarqueePanel() {
  super();
  addHierarchyListener(e -> {
    if ((e.getChangeFlags() & HierarchyEvent.DISPLAYABILITY_CHANGED) != 0 && !e.getComponent().isDisplayable()) {
      animator.stop();
    }
  });

  String text = "abcdefghijklmnopqrstuvwxyz";
  Font font = new Font(Font.SERIF, Font.PLAIN, 100);
  FontRenderContext frc = new FontRenderContext(null, true, true);

  gv = font.createGlyphVector(frc, text);
  lm = font.getLineMetrics(text, frc);

  GlyphMetrics xgm = gv.getGlyphMetrics(23);
  corpusSize = (float) xgm.getBounds2D().getHeight();
  animator.start();
}
 
Example 9
Source Project: visualvm   Source File: CPUView.java    License: GNU General Public License v2.0 6 votes vote down vote up
CPUView(AbstractSamplerSupport.Refresher refresher, CPUSamplerSupport.SnapshotDumper
        snapshotDumper, CPUSamplerSupport.ThreadDumper threadDumper, Application application) {
    this.refresher = refresher;
    this.snapshotDumper = snapshotDumper;
    this.threadDumper = threadDumper;
    
    initComponents(application);

    addHierarchyListener(new HierarchyListener() {
        public void hierarchyChanged(HierarchyEvent e) {
            if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
                if (isShowing()) CPUView.this.refresher.refresh();
            }
        }
    });
}
 
Example 10
Source Project: visualvm   Source File: MemoryView.java    License: GNU General Public License v2.0 6 votes vote down vote up
MemoryView(Application application, AbstractSamplerSupport.Refresher refresher, int mode,
           MemoryMXBean memoryBean, MemorySamplerSupport.SnapshotDumper snapshotDumper,
           MemorySamplerSupport.HeapDumper heapDumper) {

    this.refresher = refresher;
    this.mode = mode;

    this.memoryBean = memoryBean;
    this.snapshotDumper = snapshotDumper;
    this.heapDumper = heapDumper;
    
    initComponents(application);

    addHierarchyListener(new HierarchyListener() {
        public void hierarchyChanged(HierarchyEvent e) {
            if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
                if (isShowing()) MemoryView.this.refresher.refresh();
            }
        }
    });
}
 
Example 11
Source Project: netbeans   Source File: InstancesListControllerUI.java    License: Apache License 2.0 6 votes vote down vote up
InstanceScrollPane(Heap heap) {
    this.heap = heap;
    
    setBorder(BorderFactory.createEmptyBorder());
    setViewportBorder(BorderFactory.createLineBorder(
            UIManager.getLookAndFeel().getID().equals("Metal") ? // NOI18N
            UIManager.getColor("Button.darkShadow") : // NOI18N
            UIManager.getColor("Button.shadow"))); // NOI18N
    
    addHierarchyListener(new HierarchyListener() {
        public void hierarchyChanged(HierarchyEvent e) {
            if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
                if (instancePending && isShowing()) showInstanceImpl();
            }
        }
    });
}
 
Example 12
Source Project: visualvm   Source File: CPUView.java    License: GNU General Public License v2.0 6 votes vote down vote up
CPUView(AbstractSamplerSupport.Refresher refresher, CPUSamplerSupport.SnapshotDumper
        snapshotDumper, CPUSamplerSupport.ThreadDumper threadDumper, Application application) {
    this.refresher = refresher;
    this.snapshotDumper = snapshotDumper;
    this.threadDumper = threadDumper;
    
    initComponents(application);

    addHierarchyListener(new HierarchyListener() {
        public void hierarchyChanged(HierarchyEvent e) {
            if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
                if (isShowing()) CPUView.this.refresher.refresh();
            }
        }
    });
}
 
Example 13
@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 14
Source Project: Darcula   Source File: SwingSet3.java    License: Apache License 2.0 6 votes vote down vote up
public void hierarchyChanged(HierarchyEvent event) {
    if ((event.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) > 0) {
        JComponent component = (JComponent)event.getComponent();
        final Demo demo = (Demo)component.getClientProperty("swingset3.demo");
        if (!component.isShowing()) {
            demo.stop();
        } else {
            demoContainer.revalidate();
            EventQueue.invokeLater(new Runnable() {
                public void run() {
                    demo.start();
                }
            });
        }
    }            
}
 
Example 15
Source Project: jdk8u-jdk   Source File: WindowsMenuBarUI.java    License: 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 16
Source Project: pgptool   Source File: JXLabel.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Helper method for initializing multi line support.
 */
private void initLineWrapSupport() {
	addPropertyChangeListener(new MultiLineSupport());
	// FYI: no more listening for componentResized. Those events are delivered out
	// of order and without old values are meaningless and forcing us to react when
	// not necessary. Instead overriding reshape() ensures we have control over old
	// AND new size.
	addHierarchyBoundsListener(new HierarchyBoundsAdapter() {
		@Override
		public void ancestorResized(HierarchyEvent e) {
			// if one of the parents is viewport, resized events will not be propagated down
			// unless viewport is changing visibility of scrollbars.
			// To make sure Label is able to re-wrap text when viewport size changes,
			// initiate re-wrapping here by changing size of view
			if (e.getChanged() instanceof JViewport) {
				Rectangle viewportBounds = e.getChanged().getBounds();
				if (viewportBounds.getWidth() < getWidth()) {
					View view = getWrappingView();
					if (view != null) {
						view.setSize(viewportBounds.width, viewportBounds.height);
					}
				}
			}
		}
	});
}
 
Example 17
Source Project: visualvm   Source File: JTreeTablePanel.java    License: GNU General Public License v2.0 6 votes vote down vote up
/** Creates a new instance of JTreeTablePanel */
public JTreeTablePanel(JTreeTable treeTable) {
    super(new BorderLayout());
    this.treeTable = treeTable;

    initComponents();
    hookHeaderColumnResize();
    hookScrollBarValueChange();
    hookTreeCollapsedExpanded();

    addHierarchyListener(new HierarchyListener() {
        public void hierarchyChanged(HierarchyEvent e) {
            if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
                if (isShowing()) {
                    updateScrollBar(true);
                }
            }
        }
    });
}
 
Example 18
Source Project: hottub   Source File: WindowsMenuBarUI.java    License: 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 19
Source Project: beautyeye   Source File: SwingSet3.java    License: Apache License 2.0 6 votes vote down vote up
public void hierarchyChanged(HierarchyEvent event) {
    if ((event.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) > 0) {
        JComponent component = (JComponent)event.getComponent();
        final Demo demo = (Demo)component.getClientProperty("swingset3.demo");
        if (!component.isShowing()) {
            demo.stop();
        } else {
            demoContainer.revalidate();
            EventQueue.invokeLater(new Runnable() {
                public void run() {
                    demo.start();
                }
            });
        }
    }            
}
 
Example 20
Source Project: pumpernickel   Source File: PumpernickelShowcaseApp.java    License: MIT License 6 votes vote down vote up
public LazyDemoPanel(String demoClassName) {
	super();
	this.demoClassName = "com.pump.showcase." + demoClassName;
	setLayout(cardLayout);
	add(loadingPanel, "loading");
	cardLayout.show(this, "loading");

	// loadingPanel is never really shown to the user,
	// so there's no point in putting a throbber or other content in it
	addHierarchyListener(new HierarchyListener() {

		@Override
		public void hierarchyChanged(HierarchyEvent e) {
			if (loadingPanel.isShowing()) {
				loadPanel();
				removeHierarchyListener(this);
			}
		}

	});
}
 
Example 21
private void initComponents(JFRModel model) {
    setLayout(new BorderLayout());
    setOpaque(false);

    if (model == null) {
        add(MessageComponent.notAvailable(), BorderLayout.CENTER);
    } else {
        area = new HTMLTextArea(createSummary(model));
        area.setBorder(BorderFactory.createEmptyBorder(14, 8, 14, 8));

        add(area, BorderLayout.CENTER);

        addHierarchyListener(new HierarchyListener() {
            public void hierarchyChanged(HierarchyEvent e) {
                if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
                    if (isShowing()) {
                        removeHierarchyListener(this);
                        SwingUtilities.invokeLater(new Runnable() {
                            public void run() { firstShown(); }
                        });
                    }
                }
            }
        });
    }
}
 
Example 22
Source Project: consulo   Source File: ShowFilterAction.java    License: Apache License 2.0 6 votes vote down vote up
private void showPopup(@Nonnull Project project, @Nonnull Component anchor) {
  if (myFilterPopup != null || !anchor.isValid()) {
    return;
  }
  JBPopupListener popupCloseListener = new JBPopupListener() {
    @Override
    public void onClosed(@Nonnull LightweightWindowEvent event) {
      myFilterPopup = null;
    }
  };
  myFilterPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(createFilterPanel(), null).setModalContext(false).setFocusable(false).setResizable(true).setCancelOnClickOutside(false)
          .setMinSize(new Dimension(200, 200)).setDimensionServiceKey(project, getDimensionServiceKey(), false).addListener(popupCloseListener).createPopup();
  anchor.addHierarchyListener(new HierarchyListener() {
    @Override
    public void hierarchyChanged(HierarchyEvent e) {
      if (e.getID() == HierarchyEvent.HIERARCHY_CHANGED && !anchor.isValid()) {
        anchor.removeHierarchyListener(this);
        if (myFilterPopup != null) {
          myFilterPopup.cancel();
        }
      }
    }
  });
  myFilterPopup.showUnderneathOf(anchor);
}
 
Example 23
Source Project: visualvm   Source File: AboutDialogPanel.java    License: GNU General Public License v2.0 6 votes vote down vote up
AboutDialogPanel() {
    initComponents();

    final Runnable repainter = new Runnable() {
        public void run() { AboutDialogPanel.this.repaint(); }
    };
    
    addHierarchyListener(new HierarchyListener() {
        public void hierarchyChanged(HierarchyEvent e) {
            if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0 && isShowing()) {
                SwingUtilities.invokeLater(repainter);
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() { SwingUtilities.invokeLater(repainter); }
                });
            }
        }
    });
}
 
Example 24
InstanceScrollPane() {
            setBorder(BorderFactory.createEmptyBorder());
            setViewportBorder(BorderFactory.createEmptyBorder());
//            setViewportBorder(BorderFactory.createLineBorder(
//                    UIManager.getLookAndFeel().getID().equals("Metal") ? // NOI18N
//                    UIManager.getColor("Button.darkShadow") : // NOI18N
//                    UIManager.getColor("Button.shadow"))); // NOI18N
            
            addHierarchyListener(new HierarchyListener() {
                public void hierarchyChanged(HierarchyEvent e) {
                    if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
                        if (instancePending && isShowing()) showInstanceImpl();
                    }
                }
            });
            
            showInstanceImpl();
        }
 
Example 25
Source Project: java-swing-tips   Source File: MainPanel.java    License: MIT License 6 votes vote down vote up
@Override public void updateUI() {
  removeHierarchyListener(listener);
  super.updateUI();
  listener = e -> {
    Component c = e.getComponent();
    if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0 && c.isShowing()) {
      // Component w = SwingUtilities.getRoot(c);
      // if (w instanceof JWindow) {
      //   System.out.println("Popup$HeavyWeightWindow");
      //   w.setBackground(new Color(0x0, true));
      // }
      Optional.ofNullable(SwingUtilities.getRoot(c))
          .filter(JWindow.class::isInstance).map(JWindow.class::cast)
          .ifPresent(w -> w.setBackground(new Color(0x0, true)));
    }
  };
  addHierarchyListener(listener);
  setOpaque(false);
  setBorder(BorderFactory.createEmptyBorder(8, 5, 0, 5));
}
 
Example 26
Source Project: netbeans-mmd-plugin   Source File: UiUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static void makeOwningDialogResizable(@Nonnull final Component component, @Nonnull @MustNotContainNull final Runnable... extraActions) {
  final HierarchyListener listener = new HierarchyListener() {
    @Override
    public void hierarchyChanged(@Nonnull final HierarchyEvent e) {
      final Window window = SwingUtilities.getWindowAncestor(component);
      if (window instanceof Dialog) {
        final Dialog dialog = (Dialog) window;
        if (!dialog.isResizable()) {
          dialog.setResizable(true);
          component.removeHierarchyListener(this);

          for (final Runnable r : extraActions) {
            r.run();
          }
        }
      }
    }
  };
  component.addHierarchyListener(listener);
}
 
Example 27
Source Project: openjdk-8   Source File: WindowsMenuBarUI.java    License: 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 28
InstanceScrollPane(Heap heap) {
    this.heap = heap;
    
    setBorder(BorderFactory.createEmptyBorder());
    setViewportBorder(BorderFactory.createLineBorder(
            UIManager.getLookAndFeel().getID().equals("Metal") ? // NOI18N
            UIManager.getColor("Button.darkShadow") : // NOI18N
            UIManager.getColor("Button.shadow"))); // NOI18N
    
    addHierarchyListener(new HierarchyListener() {
        public void hierarchyChanged(HierarchyEvent e) {
            if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
                if (instancePending && isShowing()) showInstanceImpl();
            }
        }
    });
}
 
Example 29
Source Project: FlatLaf   Source File: JBRCustomDecorations.java    License: 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 30
@Override
public void hierarchyChanged(HierarchyEvent e) {
	if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
		if (!list.isShowing()) {
			lastLocation = null;
			setHoverIndex(-1);
		}
		// else: nothing to be done as mouse location is not known (only 1.5)
	}
}