java.awt.event.HierarchyEvent Java Examples

The following examples show how to use java.awt.event.HierarchyEvent. 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: 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 #2
Source File: AboutDialogPanel.java    From visualvm with 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 #3
Source File: ShowFilterAction.java    From consulo with 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 #4
Source File: WindowsMenuBarUI.java    From jdk8u60 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 #5
Source File: AnimationAutoCompletion.java    From 3Dscript with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * 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 #6
Source File: WindowsMenuBarUI.java    From TencentKona-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 #7
Source File: MainPanel.java    From java-swing-tips with 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 #8
Source File: UiUtils.java    From netbeans-mmd-plugin with 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 #9
Source File: AbstractSelectionNavigationAction.java    From ghidra with 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 #10
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 #11
Source File: InstancesListControllerUI.java    From visualvm with GNU General Public License v2.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 File: WindowsMenuBarUI.java    From jdk1.8-source-analysis with 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 #13
Source File: TruffleObjectPreviewPlugin.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
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 #14
Source File: FileNameController.java    From netbeans with 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 #15
Source File: PumpernickelShowcaseApp.java    From pumpernickel with 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 #16
Source File: SwingSet3.java    From beautyeye with 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 #17
Source File: MainPanel.java    From java-swing-tips with 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 #18
Source File: CPUView.java    From visualvm with 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 #19
Source File: WindowsMenuBarUI.java    From hottub 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 #20
Source File: JTreeTablePanel.java    From visualvm with 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 #21
Source File: JXLabel.java    From pgptool with 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 #22
Source File: WindowsMenuBarUI.java    From jdk8u-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 #23
Source File: MemoryView.java    From visualvm with 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 #24
Source File: InstancesListControllerUI.java    From netbeans with 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 #25
Source File: SwingSet3.java    From Darcula with 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 #26
Source File: WindowsMenuBarUI.java    From openjdk-jdk8u-backup 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 #27
Source File: CPUView.java    From visualvm with 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 #28
Source File: RecordingViewSupport.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
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 #29
Source File: SearchReplaceAttackParameterGui.java    From OpenID-Attacker with GNU General Public License v2.0 5 votes vote down vote up
private void formAncestorResized(HierarchyEvent evt) {//GEN-FIRST:event_formAncestorResized
    Component parent = evt.getChangedParent();
    
    // TODO: small hack that prevent the application from throwing exceptions
    if (parent == null) {
        return;
    }
    
    int newHeight = getSize().height;
    int newWidth = parent.getSize().width - 40;
    setSize(newWidth, newHeight);
    setPreferredSize(getSize());
    revalidate();
}
 
Example #30
Source File: GraphPanel.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public SmallTooltip(ProfilerXYChart chart) {
    super();
    setComponent(chart);

    addHierarchyListener(new HierarchyListener() {
        public void hierarchyChanged(HierarchyEvent e) {
            if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
                if (isShowing()) smallTooltipManager.enableSelection();
                else smallTooltipManager.disableSelection();
            }
        }
    });
}