Java Code Examples for java.awt.event.HierarchyListener

The following are top voted examples for showing how to use java.awt.event.HierarchyListener. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: cn1   File: Component.java   Source Code and License 7 votes vote down vote up
@SuppressWarnings("unchecked")
public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
    if (ComponentListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getComponentListeners();
    } else if (FocusListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getFocusListeners();
    } else if (HierarchyBoundsListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getHierarchyBoundsListeners();
    } else if (HierarchyListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getHierarchyListeners();
    } else if (InputMethodListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getInputMethodListeners();
    } else if (KeyListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getKeyListeners();
    } else if (MouseWheelListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getMouseWheelListeners();
    } else if (MouseMotionListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getMouseMotionListeners();
    } else if (MouseListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getMouseListeners();
    } else if (PropertyChangeListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getPropertyChangeListeners();
    }
    return (T[]) Array.newInstance(listenerType, 0);
}
 
Example 2
Project: incubator-netbeans   File: OQLControllerUI.java   Source Code and License 6 votes vote down vote up
public QueryUI(OQLController.QueryController queryController, OQLEngine engine) {
    super(Bundle.OQLControllerUI_QueryEditorCaption(), ICON, true);

    this.queryController = queryController;

    initComponents(engine);
    
    addHierarchyListener(new HierarchyListener() {
        public void hierarchyChanged(HierarchyEvent e) {
            if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
                if (isShowing()) {
                    updateUIState();
                    QueryUI.this.removeHierarchyListener(this);
                }
            }
        }
    });
}
 
Example 3
Project: incubator-netbeans   File: InstancesListControllerUI.java   Source Code and License 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 4
Project: incubator-netbeans   File: JTreeTablePanel.java   Source Code and License 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 5
Project: VASSAL-src   File: SpecialDiceButton.java   Source Code and License 6 votes vote down vote up
/**
 * Expects to be added to a SymbolDice. Adds the button to the control window's toolbar and registers itself as a
 * {@link KeyStrokeListener}
 */
public void addTo(Buildable parent) {
  resultsIcon.setResults(new int[dice.size()]);
  launch.addHierarchyListener(new HierarchyListener() {
    public void hierarchyChanged(HierarchyEvent e) {
      if (launch.isShowing()) {
        dialog.setLocationRelativeTo(launch);
        launch.removeHierarchyListener(this);
      }
    }
  });
  final GameModule mod = GameModule.getGameModule();
  ran = mod.getRNG();
  mod.getToolBar().add(launch);
  idMgr.add(this);
  mod.addCommandEncoder(this);
  property.addTo((MutablePropertiesContainer)parent);
}
 
Example 6
Project: JavaGraph   File: GraphPreviewDialog.java   Source Code and License 6 votes vote down vote up
/** Returns the main panel shown on this dialog. */
public GraphPreviewPanel getContent() {
    if (this.contentPanel == null) {
        this.contentPanel = new GraphPreviewPanel(getJGraph());
        this.contentPanel.initialise();
        this.contentPanel.setEnabled(true);
        // make any dialog in which this panel is embedded resizable
        // taken from https://blogs.oracle.com/scblog/entry/tip_making_joptionpane_dialog_resizable
        this.contentPanel.addHierarchyListener(new HierarchyListener() {
            @Override
            public void hierarchyChanged(HierarchyEvent e) {
                Window window =
                    SwingUtilities.getWindowAncestor(GraphPreviewDialog.this.contentPanel);
                if (window instanceof Dialog) {
                    Dialog dialog = (Dialog) window;
                    if (!dialog.isResizable()) {
                        dialog.setResizable(true);
                    }
                }
            }
        });
    }
    return this.contentPanel;
}
 
Example 7
Project: OpenJSharp   File: WindowsMenuBarUI.java   Source Code and 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 8
Project: jdk8u-jdk   File: WindowsMenuBarUI.java   Source Code and 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 9
Project: openjdk-jdk10   File: WindowsMenuBarUI.java   Source Code and 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 10
Project: openjdk9   File: WindowsMenuBarUI.java   Source Code and 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 11
Project: PhET   File: PCanvas.java   Source Code and License 6 votes vote down vote up
/**
 * Construct a canvas with the basic scene graph consisting of a root,
 * camera, and layer. Zooming and panning are automatically installed.
 */
public PCanvas() {
    CURRENT_ZCANVAS = this;
    cursorStack = new PStack();
    setCamera(createDefaultCamera());
    setDefaultRenderQuality(PPaintContext.HIGH_QUALITY_RENDERING);
    setAnimatingRenderQuality(PPaintContext.LOW_QUALITY_RENDERING);
    setInteractingRenderQuality(PPaintContext.LOW_QUALITY_RENDERING);
    setPanEventHandler(new PPanEventHandler());
    setZoomEventHandler(new PZoomEventHandler());
    setBackground(Color.WHITE);
    setOpaque(true);

    addHierarchyListener(new HierarchyListener() {
        public void hierarchyChanged(final HierarchyEvent e) {
            if (e.getComponent() == PCanvas.this) {
                if (getParent() == null) {
                    removeInputSources();
                }
                else if (isEnabled()) {
                    installInputSources();
                }
            }
        }
    });
}
 
Example 12
Project: jdk8u_jdk   File: WindowsMenuBarUI.java   Source Code and 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 13
Project: littleluck   File: BezierAnimationPanel.java   Source Code and License 6 votes vote down vote up
/**
 * BezierAnimationPanel Constructor
 */
public BezierAnimationPanel() {
    setOpaque(true);

    colors.put(BACKGROUND, new Color(0, 0, 153));
    colors.put(OUTER, new Color(255, 255, 255));
    colors.put(GRADIENT_A, new Color(255, 0, 101));
    colors.put(GRADIENT_B, new Color(255, 255, 0));

    addHierarchyListener(new HierarchyListener() {
        public void hierarchyChanged(HierarchyEvent e) {
            if (isShowing()) {
                start();
            } else {
                stop();
            }
        }
    }
    );
}
 
Example 14
Project: lookaside_java-1.8.0-openjdk   File: WindowsMenuBarUI.java   Source Code and 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 15
Project: cuba   File: DetachedFrame.java   Source Code and License 6 votes vote down vote up
private void initUI() {
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    glassPane = new DisabledGlassPane();
    JRootPane rootPane = SwingUtilities.getRootPane(this);
    rootPane.setGlassPane(glassPane);

    final java.awt.Component topLevelGlassPane = DesktopComponentsHelper.getTopLevelFrame(parentContainer).getGlassPane();
    topLevelGlassPane.addHierarchyListener(new HierarchyListener() {
        @Override
        public void hierarchyChanged(HierarchyEvent e) {
            if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) == HierarchyEvent.SHOWING_CHANGED) {
                if (topLevelGlassPane.isVisible()) {
                    glassPane.activate(null);
                } else {
                    glassPane.deactivate();
                }
            }
        }
    });
}
 
Example 16
Project: javify   File: Component.java   Source Code and License 6 votes vote down vote up
/**
 * Adds the specified listener to this component. This is harmless if the
 * listener is null, but if the listener has already been registered, it
 * will now be registered twice.
 *
 * @param listener the new listener to add
 * @see HierarchyEvent
 * @see #removeHierarchyListener(HierarchyListener)
 * @see #getHierarchyListeners()
 * @since 1.3
 */
public synchronized void addHierarchyListener(HierarchyListener listener)
{
  if (listener != null)
    {
      hierarchyListener = AWTEventMulticaster.add(hierarchyListener,
                                                  listener);
      newEventsOnly = true;
      // Need to lock the tree, otherwise we might end up inconsistent.
      synchronized (getTreeLock())
      {
        numHierarchyListeners++;
        if (parent != null)
          parent.updateHierarchyListenerCount(AWTEvent.HIERARCHY_EVENT_MASK,
                                              1);
      }
    }
}
 
Example 17
Project: triplea   File: PbemSetupPanel.java   Source Code and License 6 votes vote down vote up
private void createComponents() {
  final JScrollPane scrollPane = new JScrollPane(localPlayerPanel);
  localPlayerPanel.addHierarchyListener(new HierarchyListener() {
    @Override
    public void hierarchyChanged(final HierarchyEvent e) {
      final Window window = SwingUtilities.getWindowAncestor(localPlayerPanel);
      if (window instanceof Dialog) {
        final Dialog dialog = (Dialog) window;
        if (!dialog.isResizable()) {
          dialog.setResizable(true);
          dialog.setMinimumSize(new Dimension(700, 700));
        }
      }
    }
  });
  localPlayerSelection.addActionListener(
      e -> JOptionPane.showMessageDialog(PbemSetupPanel.this, scrollPane, "Select Local Players and AI's",
          JOptionPane.PLAIN_MESSAGE));
}
 
Example 18
Project: beautyeye   File: BezierAnimationPanel.java   Source Code and License 6 votes vote down vote up
/**
 * BezierAnimationPanel Constructor
 */
public BezierAnimationPanel() {
    setOpaque(true);

    colors.put(BACKGROUND, new Color(0, 0, 153));
    colors.put(OUTER, new Color(255, 255, 255));
    colors.put(GRADIENT_A, new Color(255, 0, 101));
    colors.put(GRADIENT_B, new Color(255, 255, 0));

    addHierarchyListener(new HierarchyListener() {
        public void hierarchyChanged(HierarchyEvent e) {
            if (isShowing()) {
                start();
            } else {
                stop();
            }
        }
    }
    );
}
 
Example 19
Project: jvm-stm   File: Component.java   Source Code and License 6 votes vote down vote up
/**
 * Adds the specified listener to this component. This is harmless if the
 * listener is null, but if the listener has already been registered, it
 * will now be registered twice.
 *
 * @param listener the new listener to add
 * @see HierarchyEvent
 * @see #removeHierarchyListener(HierarchyListener)
 * @see #getHierarchyListeners()
 * @since 1.3
 */
public synchronized void addHierarchyListener(HierarchyListener listener)
{
  if (listener != null)
    {
      hierarchyListener = AWTEventMulticaster.add(hierarchyListener,
                                                  listener);
      newEventsOnly = true;
      // Need to lock the tree, otherwise we might end up inconsistent.
      synchronized (getTreeLock())
      {
        numHierarchyListeners++;
        if (parent != null)
          parent.updateHierarchyListenerCount(AWTEvent.HIERARCHY_EVENT_MASK,
                                              1);
      }
    }
}
 
Example 20
Project: netbeans-mmd-plugin   File: UiUtils.java   Source Code and License 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 21
Project: metasfresh   File: CTable.java   Source Code and License 6 votes vote down vote up
private final HierarchyListener createHierarchyListener()
{
	return new HierarchyListener()
	{

		@Override
		public void hierarchyChanged(HierarchyEvent e)
		{
			if (e.getChangeFlags() == HierarchyEvent.PARENT_CHANGED)
			{
				configureColumnControl();
			}
		}

	};
}
 
Example 22
Project: CommandGenerator   File: Tag.java   Source Code and License 6 votes vote down vote up
/** Displays the Tag panel. Returns true if the user canceled. */
protected boolean showPanel()
{
	isEmpty = true;

	panel.addHierarchyListener(new HierarchyListener() {
		@Override
		public void hierarchyChanged(HierarchyEvent e)
		{
			Window window = SwingUtilities.getWindowAncestor(panel);
			if (window instanceof Dialog)
			{
				Dialog dialog = (Dialog) window;
				if (!dialog.isResizable())
				{
					dialog.setResizable(true);
				}
			}
		}
	});
	boolean cancel = JOptionPane.showConfirmDialog(null, panel, Generator.translate("GUI:tag.add") + " : " + getName(), JOptionPane.OK_CANCEL_OPTION) != JOptionPane.OK_OPTION;
	if (!cancel) isEmpty = false;
	return cancel;
}
 
Example 23
Project: piccolo2d.java   File: PCanvas.java   Source Code and License 6 votes vote down vote up
/**
 * Construct a canvas with the basic scene graph consisting of a root,
 * camera, and layer. Zooming and panning are automatically installed.
 */
public PCanvas() {
    cursorStack = new PStack();
    setCamera(createDefaultCamera());
    setDefaultRenderQuality(PPaintContext.HIGH_QUALITY_RENDERING);
    setAnimatingRenderQuality(PPaintContext.LOW_QUALITY_RENDERING);
    setInteractingRenderQuality(PPaintContext.LOW_QUALITY_RENDERING);
    setPanEventHandler(new PPanEventHandler());
    setZoomEventHandler(new PZoomEventHandler());
    setBackground(Color.WHITE);
    setOpaque(true);

    addHierarchyListener(new HierarchyListener() {
        public void hierarchyChanged(final HierarchyEvent e) {
            if (e.getComponent() == PCanvas.this) {
                if (getParent() == null) {
                    removeInputSources();
                }
                else if (isEnabled()) {
                    installInputSources();
                }
            }
        }
    });
}
 
Example 24
Project: infobip-open-jdk-8   File: WindowsMenuBarUI.java   Source Code and 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 25
Project: jdk8u-dev-jdk   File: WindowsMenuBarUI.java   Source Code and 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 26
Project: vassal   File: SpecialDiceButton.java   Source Code and License 6 votes vote down vote up
/**
 * Expects to be added to a SymbolDice. Adds the button to the control window's toolbar and registers itself as a
 * {@link KeyStrokeListener}
 */
public void addTo(Buildable parent) {
  resultsIcon.setResults(new int[dice.size()]);
  launch.addHierarchyListener(new HierarchyListener() {
    public void hierarchyChanged(HierarchyEvent e) {
      if (launch.isShowing()) {
        dialog.setLocationRelativeTo(launch);
        launch.removeHierarchyListener(this);
      }
    }
  });
  final GameModule mod = GameModule.getGameModule();
  ran = mod.getRNG();
  mod.getToolBar().add(launch);
  idMgr.add(this);
  mod.addCommandEncoder(this);
  property.addTo((MutablePropertiesContainer)parent);
}
 
Example 27
Project: jo-widgets   File: SwingDisposeObservable.java   Source Code and License 6 votes vote down vote up
public SwingDisposeObservable(final Component component) {
    Assert.paramNotNull(component, "component");

    this.wasDisplayable = component.isDisplayable();
    component.addHierarchyListener(new HierarchyListener() {
        @Override
        public void hierarchyChanged(final HierarchyEvent e) {
            if ((e.getChangeFlags() & HierarchyEvent.DISPLAYABILITY_CHANGED) != 0) {
                if (wasDisplayable && !component.isDisplayable()) {
                    fireAfterDispose();
                }
                else if (!wasDisplayable && component.isDisplayable()) {
                    wasDisplayable = true;
                }
            }
        }
    });
}
 
Example 28
Project: jdk7-jdk   File: WindowsMenuBarUI.java   Source Code and 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 29
Project: openjdk-source-code-learn   File: WindowsMenuBarUI.java   Source Code and 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 30
Project: OLD-OpenJDK8   File: WindowsMenuBarUI.java   Source Code and 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 31
Project: cn1   File: BasicInternalFrameTitlePane.java   Source Code and License 6 votes vote down vote up
protected void installListeners() {
    if (propertyChangeListener == null) {
        propertyChangeListener = createPropertyChangeListener();
    }
    frame.addPropertyChangeListener(propertyChangeListener);

    // propertyChangeListener will be uninstalled
    // when title pane is removed from internal frame
    addHierarchyListener(new HierarchyListener() {
        public void hierarchyChanged(final HierarchyEvent e) {
            if (e.getChanged() == BasicInternalFrameTitlePane.this
                    && (e.getChangeFlags() & HierarchyEvent.PARENT_CHANGED) != 0
                    && !frame.isAncestorOf(BasicInternalFrameTitlePane.this)) {
                uninstallListeners();
            }
        }
    });
}
 
Example 32
Project: JamVM-PH   File: Component.java   Source Code and License 6 votes vote down vote up
/**
 * Adds the specified listener to this component. This is harmless if the
 * listener is null, but if the listener has already been registered, it
 * will now be registered twice.
 *
 * @param listener the new listener to add
 * @see HierarchyEvent
 * @see #removeHierarchyListener(HierarchyListener)
 * @see #getHierarchyListeners()
 * @since 1.3
 */
public synchronized void addHierarchyListener(HierarchyListener listener)
{
  if (listener != null)
    {
      hierarchyListener = AWTEventMulticaster.add(hierarchyListener,
                                                  listener);
      newEventsOnly = true;
      // Need to lock the tree, otherwise we might end up inconsistent.
      synchronized (getTreeLock())
      {
        numHierarchyListeners++;
        if (parent != null)
          parent.updateHierarchyListenerCount(AWTEvent.HIERARCHY_EVENT_MASK,
                                              1);
      }
    }
}
 
Example 33
Project: UiL-OTS-Video-Coding-System   File: VLCMediaPlayer.java   Source Code and License 6 votes vote down vote up
private void internalCreateNewVisualComponent(String [] prepareOptions) {
       playerComponent = new EmbeddedMediaPlayerComponent();
       player = playerComponent.getMediaPlayer();
       player.addMediaPlayerEventListener(infoListener);
       
       playerComponent.addHierarchyListener(new HierarchyListener() {
		// This makes sure that when the player window becomes displayable
		// (which is a subset of visible) the player shows some frame in it. 
		// This can't be done before that time.
           public void hierarchyChanged(HierarchyEvent e) {
           	long flags = e.getChangeFlags() & (HierarchyEvent.PARENT_CHANGED);
               if ((flags != 0) &&	e.getComponent().isDisplayable()) {
                   player.start();
                  	player.pause();
           	}
           }
       });
       
       // configure the player with the given media file
       player.prepareMedia(mediaURL, prepareOptions);
       player.parseMedia();
       
       player.setEnableMouseInputHandling(false);
       player.setEnableKeyInputHandling(false);
}
 
Example 34
Project: openjdk-jdk7u-jdk   File: WindowsMenuBarUI.java   Source Code and 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 35
Project: wandora   File: ProcessingTopicPanel.java   Source Code and License 6 votes vote down vote up
private void showRichErrorDialog(String msg) {
final JTextArea area = new JTextArea();
area.setFont(errorMessageFont);
//area.setPreferredSize(new Dimension(520, 180));
area.setEditable(false);
area.setText(msg);

// Make the JOptionPane resizable using the HierarchyListener
       area.addHierarchyListener(new HierarchyListener() {
           public void hierarchyChanged(HierarchyEvent e) {
               Window window = SwingUtilities.getWindowAncestor(area);
               if (window instanceof Dialog) {
                   Dialog dialog = (Dialog)window;
                   if (!dialog.isResizable()) {
                       dialog.setResizable(true);
                   }
               }
           }
       });

JScrollPane scroller = new JScrollPane(area);
scroller.setPreferredSize(new Dimension(520, 180));
JOptionPane.showMessageDialog(Wandora.getWandora(), scroller, "Errors", JOptionPane.PLAIN_MESSAGE);
   }
 
Example 36
Project: classpath   File: Component.java   Source Code and License 6 votes vote down vote up
/**
 * Adds the specified listener to this component. This is harmless if the
 * listener is null, but if the listener has already been registered, it
 * will now be registered twice.
 *
 * @param listener the new listener to add
 * @see HierarchyEvent
 * @see #removeHierarchyListener(HierarchyListener)
 * @see #getHierarchyListeners()
 * @since 1.3
 */
public synchronized void addHierarchyListener(HierarchyListener listener)
{
  if (listener != null)
    {
      hierarchyListener = AWTEventMulticaster.add(hierarchyListener,
                                                  listener);
      newEventsOnly = true;
      // Need to lock the tree, otherwise we might end up inconsistent.
      synchronized (getTreeLock())
      {
        numHierarchyListeners++;
        if (parent != null)
          parent.updateHierarchyListenerCount(AWTEvent.HIERARCHY_EVENT_MASK,
                                              1);
      }
    }
}
 
Example 37
Project: freeVM   File: Component.java   Source Code and License 6 votes vote down vote up
@SuppressWarnings("unchecked")
public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
    if (ComponentListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getComponentListeners();
    } else if (FocusListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getFocusListeners();
    } else if (HierarchyBoundsListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getHierarchyBoundsListeners();
    } else if (HierarchyListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getHierarchyListeners();
    } else if (InputMethodListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getInputMethodListeners();
    } else if (KeyListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getKeyListeners();
    } else if (MouseWheelListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getMouseWheelListeners();
    } else if (MouseMotionListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getMouseMotionListeners();
    } else if (MouseListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getMouseListeners();
    } else if (PropertyChangeListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getPropertyChangeListeners();
    }
    return (T[]) Array.newInstance(listenerType, 0);
}
 
Example 38
Project: freeVM   File: BasicInternalFrameTitlePane.java   Source Code and License 6 votes vote down vote up
protected void installListeners() {
    if (propertyChangeListener == null) {
        propertyChangeListener = createPropertyChangeListener();
    }
    frame.addPropertyChangeListener(propertyChangeListener);

    // propertyChangeListener will be uninstalled
    // when title pane is removed from internal frame
    addHierarchyListener(new HierarchyListener() {
        public void hierarchyChanged(final HierarchyEvent e) {
            if (e.getChanged() == BasicInternalFrameTitlePane.this
                    && (e.getChangeFlags() & HierarchyEvent.PARENT_CHANGED) != 0
                    && !frame.isAncestorOf(BasicInternalFrameTitlePane.this)) {
                uninstallListeners();
            }
        }
    });
}
 
Example 39
Project: freeVM   File: Component.java   Source Code and License 6 votes vote down vote up
@SuppressWarnings("unchecked")
public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
    if (ComponentListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getComponentListeners();
    } else if (FocusListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getFocusListeners();
    } else if (HierarchyBoundsListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getHierarchyBoundsListeners();
    } else if (HierarchyListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getHierarchyListeners();
    } else if (InputMethodListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getInputMethodListeners();
    } else if (KeyListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getKeyListeners();
    } else if (MouseWheelListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getMouseWheelListeners();
    } else if (MouseMotionListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getMouseMotionListeners();
    } else if (MouseListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getMouseListeners();
    } else if (PropertyChangeListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getPropertyChangeListeners();
    }
    return (T[]) Array.newInstance(listenerType, 0);
}
 
Example 40
Project: freeVM   File: BasicInternalFrameTitlePane.java   Source Code and License 6 votes vote down vote up
protected void installListeners() {
    if (propertyChangeListener == null) {
        propertyChangeListener = createPropertyChangeListener();
    }
    frame.addPropertyChangeListener(propertyChangeListener);

    // propertyChangeListener will be uninstalled
    // when title pane is removed from internal frame
    addHierarchyListener(new HierarchyListener() {
        public void hierarchyChanged(final HierarchyEvent e) {
            if (e.getChanged() == BasicInternalFrameTitlePane.this
                    && (e.getChangeFlags() & HierarchyEvent.PARENT_CHANGED) != 0
                    && !frame.isAncestorOf(BasicInternalFrameTitlePane.this)) {
                uninstallListeners();
            }
        }
    });
}
 
Example 41
Project: Darcula   File: BezierAnimationPanel.java   Source Code and License 6 votes vote down vote up
/**
 * BezierAnimationPanel Constructor
 */
public BezierAnimationPanel() {
    setOpaque(true);

    colors.put(BACKGROUND, new Color(0, 0, 153));
    colors.put(OUTER, new Color(255, 255, 255));
    colors.put(GRADIENT_A, new Color(255, 0, 101));
    colors.put(GRADIENT_B, new Color(255, 255, 0));

    addHierarchyListener(new HierarchyListener() {
        public void hierarchyChanged(HierarchyEvent e) {
            if (isShowing()) {
                start();
            } else {
                stop();
            }
        }
    }
    );
}
 
Example 42
Project: openjdk-icedtea7   File: WindowsMenuBarUI.java   Source Code and 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 43
Project: Reer   File: SinglePaneUIInstance.java   Source Code and License 5 votes vote down vote up
private Component createCenterPanel() {
    splitter = new JSplitPane(JSplitPane.VERTICAL_SPLIT);

    splitter.setTopComponent(createMainGradlePanel());
    splitter.setBottomComponent(outputPanelLord.getMainPanel());

    splitter.setContinuousLayout(true);

    //This little bit of tedium is so we can set our size based on window's size. This listens
    //for when the window is actually shown. It then adds a listen to store the location.
    splitter.addHierarchyListener(new HierarchyListener() {
        public void hierarchyChanged(HierarchyEvent e) {
            if (HierarchyEvent.SHOWING_CHANGED == (e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED)) {
                splitter.removeHierarchyListener(this); //we only want the first one of these, so remove ourselves as a listener.
                Window window = SwingUtilities.getWindowAncestor(splitter);
                if (window != null) {
                    Dimension dimension = window.getSize();
                    int halfHeight = dimension.height / 2; //we'll just make ourselves half the height of the window
                    splitter.setDividerLocation(halfHeight);
                }
                PreferencesAssistant.restoreSettings(settings, splitter, SPLITTER_PREFERENCES_ID, SinglePaneUIInstance.class);

                //Now that we're visible, this is so we save the location when the splitter is moved.
                splitter.addPropertyChangeListener(new PropertyChangeListener() {
                    public void propertyChange(PropertyChangeEvent evt) {
                        if (JSplitPane.DIVIDER_LOCATION_PROPERTY.equals(evt.getPropertyName())) {
                            PreferencesAssistant.saveSettings(settings, splitter, SPLITTER_PREFERENCES_ID, SinglePaneUIInstance.class);
                        }
                    }
                });
            }
        }
    });

    splitter.setResizeWeight(1);   //this keeps the bottom the same size when resizing the window. Extra space is added/removed from the top.

    return splitter;
}
 
Example 44
Project: incubator-netbeans   File: ResultsOutlineSupport.java   Source Code and License 5 votes vote down vote up
private void createOutlineView() {
    outlineView = new OutlineView(UiUtils.getText(
            "BasicSearchResultsPanel.outline.nodes"));              //NOI18N
    outlineView.getOutline().setDefaultRenderer(Node.Property.class,
            new ResultsOutlineCellRenderer());
    setOutlineColumns();
    outlineView.getOutline().setAutoCreateColumnsFromModel(false);
    outlineView.addTreeExpansionListener(
            new ExpandingTreeExpansionListener());
    outlineView.getOutline().setRootVisible(false);
    outlineView.addHierarchyListener(new HierarchyListener() {
        @Override
        public void hierarchyChanged(HierarchyEvent e) {
            if ((e.getChangeFlags() & HierarchyEvent.DISPLAYABILITY_CHANGED)
                    != 0) {
                if (outlineView.isDisplayable()) {
                    outlineView.expandNode(resultsNode);
                }
            }
        }
    });
    outlineView.getOutline().getColumnModel().addColumnModelListener(
            new ColumnsListener());
    outlineView.getOutline().getInputMap().remove(
            KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0)); //#209949
    outlineView.getOutline().getInputMap().put(KeyStroke.getKeyStroke(
            KeyEvent.VK_DELETE,
            0), "hide"); //NOI18N
    outlineView.getOutline().getActionMap().put("hide", SystemAction.get( //NOI18N
            HideResultAction.class));
    outlineView.getOutline().setShowGrid(false);
    Font font = outlineView.getOutline().getFont();
    FontMetrics fm = outlineView.getOutline().getFontMetrics(font);
    outlineView.getOutline().setRowHeight(
            Math.max(16, fm.getHeight()) + VERTICAL_ROW_SPACE);
    outlineView.setTreeHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_POLICY);
    setTooltipHidingBehavior();
}
 
Example 45
Project: incubator-netbeans   File: VisibilityHandler.java   Source Code and License 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 46
Project: incubator-netbeans   File: TransparentToolBar.java   Source Code and License 5 votes vote down vote up
public TransparentToolBar() {
    toolbar = needsPanel() ? null : new JToolBar();
    setOpaque(false);
    if (toolbar == null) {
        // Toolbar is a JPanel (GTK)
        setLayout(new HorizontalLayout(false));
    } else {
        // Toolbar is a JToolBar (default)
        toolbar.setBorderPainted(false);
        toolbar.setFloatable(false);
        toolbar.setRollover(true);
        toolbar.setOpaque(false);
        toolbar.setBorder(BorderFactory.createEmptyBorder());
        setLayout(new BorderLayout());
        add(toolbar, BorderLayout.CENTER);
    }
    addHierarchyListener(new HierarchyListener() {
        public void hierarchyChanged(HierarchyEvent e) {
            if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
                if (isShowing()) {
                    removeHierarchyListener(this);
                    for (Component c : getComponents()) {
                        if (c instanceof AbstractButton) {
                            listener.refresh((AbstractButton)c);
                        }
                    }
                }
            }
        }
    });
}
 
Example 47
Project: incubator-netbeans   File: ClassesControllerUI.java   Source Code and License 5 votes vote down vote up
private void initComponents() {
    setLayout(new BorderLayout());

    final JPanel staticFieldsBrowserPanel = classesController.getStaticFieldsBrowserController().getPanel();
    staticFieldsBrowserPanel.setPreferredSize(new Dimension(250, 500));
    staticFieldsBrowserPanel.setVisible(false);

    contentsSplit = new JExtendedSplitPane(JSplitPane.HORIZONTAL_SPLIT,
                                           classesController.getClassesListController().getPanel(), staticFieldsBrowserPanel);
    contentsSplit.setResizeWeight(1d);

    final JPanel legendPanel = new LegendPanel(false);
    legendPanel.setVisible(false);

    tweakSplitPaneUI(contentsSplit);

    add(contentsSplit, BorderLayout.CENTER);
    add(legendPanel, BorderLayout.SOUTH);

    staticFieldsBrowserPanel.addHierarchyListener(new HierarchyListener() {
            public void hierarchyChanged(HierarchyEvent e) {
                if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
                    legendPanel.setVisible(staticFieldsBrowserPanel.isShowing());
                }
            }
        });
}
 
Example 48
Project: incubator-netbeans   File: GraphPanel.java   Source Code and License 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();
            }
        }
    });
}
 
Example 49
Project: finances   File: CommitActionTest.java   Source Code and License 5 votes vote down vote up
@Test
public void savesNewTransaction() throws Exception {
    final Transaction transaction = new TransactionBuilder().detailAmounts(BigDecimal.ONE).get();
    final int rowIndex = random.nextInt();
    final int viewIndex = random.nextInt();
    final int beanCount = random.nextInt();
    when(transactionTable.getSelectedTransaction()).thenReturn(transaction);
    when(transactionTable.convertRowIndexToView(rowIndex)).thenReturn(viewIndex);
    when(tableModel.rowIndexOf(transaction)).thenReturn(rowIndex);
    when(tableModel.isChanged(transaction)).thenReturn(true);
    when(tableModel.getBeanCount()).thenReturn(beanCount);
    when(tableModel.getBean(beanCount-1)).thenReturn(new Transaction(-1L));

    commitAction.actionPerformed(null);
    waitForUI();

    verify(transactionTable, atLeastOnce()).isShowing();
    verify(transactionTable).getSelectedTransaction();
    verify(transactionTable, atLeastOnce()).getModel();
    verify(transactionTable).convertRowIndexToView(rowIndex);
    verify(transactionTable).getParent();
    verify(transactionTable).addHierarchyListener(any(HierarchyListener.class));
    verify(transactionTable, timeout(1000)).selectLastTransaction();
    verify(transactionTable, atLeastOnce()).getModel();
    verify(tableModel).addEmptyTransaction();
    verifyNoMoreInteractions(transactionTable);
    verify(transactionService).saveTransaction(any(TransactionUpdate.class));
    domainEvents.forEach(event -> verify(domainEventPublisher).publishEvent(event));
}
 
Example 50
Project: finances   File: CommitActionTest.java   Source Code and License 5 votes vote down vote up
@Test
public void updatesExistingTransaction() throws Exception {
    final Transaction transaction = new TransactionBuilder().nextId().detailAmounts(BigDecimal.ONE).get();
    final int rowIndex = random.nextInt();
    final int viewIndex = random.nextInt();
    final int beanCount = random.nextInt();
    when(transactionTable.getSelectedTransaction()).thenReturn(transaction);
    when(transactionTable.convertRowIndexToView(rowIndex)).thenReturn(viewIndex);
    when(tableModel.rowIndexOf(transaction)).thenReturn(rowIndex);
    when(tableModel.isChanged(transaction)).thenReturn(true);
    when(tableModel.getBeanCount()).thenReturn(beanCount);
    when(tableModel.getBean(beanCount-1)).thenReturn(new Transaction());
    when(transactionTable.getSelectedRowCount()).thenReturn(1);

    commitAction.actionPerformed(null);
    waitForUI();

    verify(transactionTable, atLeastOnce()).isShowing();
    verify(transactionTable).getSelectedTransaction();
    verify(transactionTable, atLeastOnce()).getModel();
    verify(transactionTable).convertRowIndexToView(rowIndex);
    verify(transactionTable).getParent();
    verify(transactionTable).addHierarchyListener(any(HierarchyListener.class));
    verify(transactionTable, timeout(1000)).getSelectedRowCount();
    verify(transactionTable, timeout(1000)).nextTransaction(viewIndex);
    verify(transactionTable, atLeastOnce()).getModel();
    verify(tableModel, times(0)).addEmptyTransaction();
    verifyNoMoreInteractions(transactionTable);
    verify(transactionService).saveTransaction(any(TransactionUpdate.class));
}
 
Example 51
Project: finances   File: CommitActionTest.java   Source Code and License 5 votes vote down vote up
@Test
public void deletesEmptyTransactionAndSelectsNextTransaction() throws Exception {
    final Transaction transaction = new TransactionBuilder().nextId().detailAmounts(BigDecimal.ONE).get();
    final int rowIndex = random.nextInt();
    final int viewIndex = random.nextInt();
    final int beanCount = random.nextInt();
    when(transactionTable.getSelectedTransaction()).thenReturn(transaction);
    when(transactionTable.convertRowIndexToView(rowIndex)).thenReturn(viewIndex);
    when(transactionTable.getSelectedRowCount()).thenReturn(0);
    when(tableModel.rowIndexOf(transaction)).thenReturn(rowIndex);
    when(tableModel.isChanged(transaction)).thenReturn(true);
    when(tableModel.getDetailDeletes(transaction)).thenReturn(transaction.getDetails());
    when(transactionService.deleteTransaction(transaction)).thenReturn(new ArrayList<>());
    when(tableModel.getBeanCount()).thenReturn(beanCount);
    when(tableModel.getBean(beanCount-1)).thenReturn(new Transaction());

    commitAction.actionPerformed(null);
    waitForUI();

    verify(transactionTable, atLeastOnce()).isShowing();
    verify(transactionTable).getSelectedTransaction();
    verify(transactionTable, atLeastOnce()).getModel();
    verify(transactionTable).convertRowIndexToView(rowIndex);
    verify(transactionTable).getParent();
    verify(transactionTable).addHierarchyListener(any(HierarchyListener.class));
    verify(transactionTable, timeout(1000)).getSelectedRowCount();
    verify(transactionTable, timeout(1000)).selectRowAt(viewIndex);
    verify(transactionTable, atLeastOnce()).getModel();
    verifyNoMoreInteractions(transactionTable);
    verify(transactionService).deleteTransaction(transaction);
}
 
Example 52
Project: finances   File: CommitActionTest.java   Source Code and License 5 votes vote down vote up
@Test
public void deletesTransactionAndSelectsNextTransaction() throws Exception {
    final Transaction transaction = new TransactionBuilder().nextId().detailAmounts(BigDecimal.ONE).get();
    final int rowIndex = random.nextInt();
    final int viewIndex = random.nextInt();
    final int beanCount = random.nextInt();
    when(transactionTable.getSelectedTransaction()).thenReturn(transaction);
    when(transactionTable.convertRowIndexToView(rowIndex)).thenReturn(viewIndex);
    when(transactionTable.getSelectedRowCount()).thenReturn(0);
    when(tableModel.rowIndexOf(transaction)).thenReturn(rowIndex);
    when(tableModel.isChanged(transaction)).thenReturn(true);
    when(tableModel.isPendingDelete(transaction)).thenReturn(true);
    when(transactionService.deleteTransaction(transaction)).thenReturn(new ArrayList<>());
    when(tableModel.getBeanCount()).thenReturn(beanCount);
    when(tableModel.getBean(beanCount-1)).thenReturn(new Transaction());

    commitAction.actionPerformed(null);
    waitForUI();

    verify(transactionTable, atLeastOnce()).isShowing();
    verify(transactionTable).getSelectedTransaction();
    verify(transactionTable, atLeastOnce()).getModel();
    verify(transactionTable).convertRowIndexToView(rowIndex);
    verify(transactionTable).getParent();
    verify(transactionTable).addHierarchyListener(any(HierarchyListener.class));
    verify(transactionTable, timeout(1000)).getSelectedRowCount();
    verify(transactionTable, timeout(1000)).selectRowAt(viewIndex);
    verify(transactionTable, atLeastOnce()).getModel();
    verifyNoMoreInteractions(transactionTable);
    verify(transactionService).deleteTransaction(transaction);
}
 
Example 53
Project: File-Copy-Manager   File: FileDrop.java   Source Code and License 5 votes vote down vote up
private void makeDropTarget( final PrintStream out, final Component c, boolean recursive )
{
    // Make drop target
    final DropTarget dt = new DropTarget();
    try
    {   dt.addDropTargetListener( dropListener );
    }   // end try
    catch(TooManyListenersException e )
    {   e.printStackTrace();
        log(out, "FileDrop: Drop will not work due to previous error. Do you have another listener attached?" );
    }   // end catch
    // Listen for hierarchy changes and remove the drop target when the parent gets cleared out.
    c.addHierarchyListener( new HierarchyListener()
    {   public void hierarchyChanged( HierarchyEvent evt )
        {   log( out, "FileDrop: Hierarchy changed." );
            Component parent = c.getParent();
            if( parent == null )
            {   c.setDropTarget( null );
                log( out, "FileDrop: Drop target cleared from component." );
            }   // end if: null parent
            else
            {   
                new DropTarget(c, dropListener);
                log( out, "FileDrop: Drop target added to component." );
            }   // end else: parent not null
        }   // end hierarchyChanged
    }); // end hierarchy listener
    if( c.getParent() != null )
        new DropTarget(c, dropListener);
    if( recursive && (c instanceof Container ) )
    {   
        // Get the container
        Container cont = (Container) c;
        // Get it's components
        Component[] comps = cont.getComponents();
        // Set it's components as listeners also
        for( int i = 0; i < comps.length; i++ )
            makeDropTarget( out, comps[i], recursive );
    }   // end if: recursively set components as listener
}
 
Example 54
Project: pumpernickel   File: GraphicsWriterDemo.java   Source Code and License 5 votes vote down vote up
public GraphicsWriterDemo() {
	JTextArea textArea = new JTextArea("Press the F5 key to launch the GraphicsWriterDebugger. (You can do this no matter what panel is showing in this demo.)\n\nThis is one application of the GraphicsWriter architecture. In this case it helps you identify the exact stacktraces used to render certain components. So if you've ever had trouble understanding what entity was rendering a line, shadow or image: this debugging tool can give you a starting point.");
	textArea.setLineWrap(true);
	textArea.setWrapStyleWord(true);
	textArea.setEditable(false);
	textArea.setOpaque(false);
	
	setLayout(new GridBagLayout());
	GridBagConstraints c = new GridBagConstraints();
	c.insets = new Insets(10,10,10,10);
	c.gridx = 0; c.gridy = 0; c.weighty = 1; c.weightx = 1; c.fill = GridBagConstraints.BOTH;
	add(textArea, c);
	
	addHierarchyListener(new HierarchyListener() {

		@Override
		public void hierarchyChanged(HierarchyEvent e) {
			Window w = SwingUtilities.getWindowAncestor(GraphicsWriterDemo.this);

			if(w!=null) 
			{
				GraphicsWriterDebugger.installDebugHotkey(w, KeyEvent.VK_F5);
				removeHierarchyListener(this);
			}
		}
		
	});
}
 
Example 55
Project: javify   File: Component.java   Source Code and License 5 votes vote down vote up
/**
 * Removes the specified listener from the component. This is harmless if
 * the listener was not previously registered.
 *
 * @param listener the listener to remove
 * @see HierarchyEvent
 * @see #addHierarchyListener(HierarchyListener)
 * @see #getHierarchyListeners()
 * @since 1.3
 */
public synchronized void removeHierarchyListener(HierarchyListener listener)
{
  hierarchyListener = AWTEventMulticaster.remove(hierarchyListener, listener);

  // Need to lock the tree, otherwise we might end up inconsistent.
  synchronized (getTreeLock())
    {
      numHierarchyListeners--;
      if (parent != null)
        parent.updateHierarchyListenerCount(AWTEvent.HIERARCHY_EVENT_MASK,
                                            -1);
    }
}
 
Example 56
Project: javify   File: Component.java   Source Code and License 5 votes vote down vote up
/**
 * Deserializes this component. This regenerates all serializable listeners
 * which were registered originally.
 *
 * @param s the stream to read from
 * @throws ClassNotFoundException if deserialization fails
 * @throws IOException if the stream fails
 */
private void readObject(ObjectInputStream s)
  throws ClassNotFoundException, IOException
{
  s.defaultReadObject();
  String key = (String) s.readObject();
  while (key != null)
    {
      Object listener = s.readObject();
      if ("componentL".equals(key))
        addComponentListener((ComponentListener) listener);
      else if ("focusL".equals(key))
        addFocusListener((FocusListener) listener);
      else if ("keyL".equals(key))
        addKeyListener((KeyListener) listener);
      else if ("mouseL".equals(key))
        addMouseListener((MouseListener) listener);
      else if ("mouseMotionL".equals(key))
        addMouseMotionListener((MouseMotionListener) listener);
      else if ("inputMethodL".equals(key))
        addInputMethodListener((InputMethodListener) listener);
      else if ("hierarchyL".equals(key))
        addHierarchyListener((HierarchyListener) listener);
      else if ("hierarchyBoundsL".equals(key))
        addHierarchyBoundsListener((HierarchyBoundsListener) listener);
      else if ("mouseWheelL".equals(key))
        addMouseWheelListener((MouseWheelListener) listener);
      key = (String) s.readObject();
    }
}
 
Example 57
Project: javify   File: StandaloneAppletWindow.java   Source Code and License 5 votes vote down vote up
/**
 * Called when the hierarchy of this component changes. Use
 * <code>getChangeFlags()</code> on the event to see what exactly changed.
 *
 * @param event the event describing the change
 */
public void hierarchyChanged(HierarchyEvent event)
{
  if (applet != null)
    {
      HierarchyListener[] l = applet.getHierarchyListeners();
      for (int i = 0; i < l.length; i++)
        l[i].hierarchyChanged(event);
    }
}
 
Example 58
Project: javify   File: PluginAppletWindow.java   Source Code and License 5 votes vote down vote up
/**
 * Called when the hierarchy of this component changes. Use
 * <code>getChangeFlags()</code> on the event to see what exactly changed.
 *
 * @param event the event describing the change
 */
public void hierarchyChanged(HierarchyEvent event)
{
  if (applet != null)
    {
      HierarchyListener[] l = applet.getHierarchyListeners();
      for (int i = 0; i < l.length; i++)
        l[i].hierarchyChanged(event);
    }
}
 
Example 59
Project: beautyeye   File: BezierAnimationPanel.java   Source Code and License 5 votes vote down vote up
/**
    * BezierAnimationPanel Constructor.
    */
   public BezierAnimationPanel() {
       addHierarchyListener(
    new HierarchyListener() {
       public void hierarchyChanged(HierarchyEvent e) {
	   if(isShowing()) {
	       start();
	   } else {
	       stop();
	   }
       }
   }
);
setBackground(getBackgroundColor());
   }
 
Example 60
Project: jvm-stm   File: Component.java   Source Code and License 5 votes vote down vote up
/**
 * Removes the specified listener from the component. This is harmless if
 * the listener was not previously registered.
 *
 * @param listener the listener to remove
 * @see HierarchyEvent
 * @see #addHierarchyListener(HierarchyListener)
 * @see #getHierarchyListeners()
 * @since 1.3
 */
public synchronized void removeHierarchyListener(HierarchyListener listener)
{
  hierarchyListener = AWTEventMulticaster.remove(hierarchyListener, listener);

  // Need to lock the tree, otherwise we might end up inconsistent.
  synchronized (getTreeLock())
    {
      numHierarchyListeners--;
      if (parent != null)
        parent.updateHierarchyListenerCount(AWTEvent.HIERARCHY_EVENT_MASK,
                                            -1);
    }
}