@Override public void ancestorWindowShown(final PanelEvent evt) { ((KeyPanel) evt.getSource()).runFeedback(); }
/** * Returns an array of all the panel listeners * registered on this component. * * @return All of this panel's {@code PanelListener}s or an empty * array if no panel listeners are currently registered. * * @see #addPanelListener * @see #removePanelListener */ public PanelListener[] getPanelListeners() { return getListeners(PanelListener.class); }
/** * Calls {@link #fireAncestorWindowShown} or * {@link #fireAncestorWindowHidden}, depending on the ID of the given * {@code event}. */ protected void processPanelEvent(final PanelEvent event) { switch (event.getID()) { case PanelEvent.ANCESTOR_WINDOW_SHOWN: fireAncestorWindowShown(event); break; case PanelEvent.ANCESTOR_WINDOW_HIDDEN: fireAncestorWindowHidden(event); break; default: throw new AssertionError(); } }
@Override public void hierarchyChanged(final HierarchyEvent e) { if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != HierarchyEvent.SHOWING_CHANGED) return; final Window window = getAncestorWindow(); assert null != window : "A showing panel must have a containing window!"; final boolean windowShown = window.isShowing(); if (windowShown != isShowing()) return; processPanelEvent(new PanelEvent(EnhancedPanel.this, windowShown ? PanelEvent.ANCESTOR_WINDOW_SHOWN : PanelEvent.ANCESTOR_WINDOW_HIDDEN)); } } // class EnhancedPanelHierarchyListener
@Test public void testFireAncestorWindowShown() { final CountingPanelListener l = new CountingPanelListener(); instance.addPanelListener(l); instance.addPanelListener(l); // add again to receive same event twice! assertEquals(0, l.shown); PanelEvent event = null; instance.fireAncestorWindowShown(event); assertEquals(2, l.shown); }
@Test public void testFireAncestorWindowHidden() { final CountingPanelListener l = new CountingPanelListener(); instance.addPanelListener(l); instance.addPanelListener(l); // add again to receive same event twice! assertEquals(0, l.hidden); PanelEvent event = null; instance.fireAncestorWindowHidden(event); assertEquals(2, l.hidden); }
@Before public void setUp() { instance = new EnhancedPanel(); instance.add(new JLabel("Hello world!")); }
@Test public void testGetAncestorWindow() throws InterruptedException { assertNull(instance.getAncestorWindow()); JFrameOperator frame = showFrameWith(instance); Window window1 = instance.getAncestorWindow(); assertSame(frame.getSource(), window1); frame.dispose(); frame = showFrameWith(instance); // change enclosing frame Window window2 = instance.getAncestorWindow(); assertSame(frame.getSource(), window2); frame.dispose(); assertNotSame(window1, window2); }
/** * Returns the ancestor {@link Window} of this {@code Panel} or * {@code null} if the component is not (yet) placed in a * {@code Window}. */ public @Nullable Window getAncestorWindow() { return getAncestorWindow(this); }
private void changeComboBox( final @CheckForNull JComboBox<E> oldCB, final @CheckForNull JComboBox<E> newCB, final boolean update) { if (newCB == oldCB) return; ComboBoxEditor oldCBE = null; if (null != oldCB) { oldCB.removePropertyChangeListener("editor", listener); oldCBE = oldCB.getEditor(); oldCB.setEditor(((AbstractComboBoxBrowser<?>.DecoratingComboBoxEditor) oldCBE).getEditor()); } this.comboBox = newCB; ComboBoxEditor newCBE = null; if (null != newCB) { newCB.updateUI(); // ensure comboBoxEditor is initialized newCBE = new DecoratingComboBoxEditor(newCB.getEditor()); newCB.setEditor(newCBE); newCB.addPropertyChangeListener("editor", listener); } changeEditor(oldCBE, newCBE, update); }
/** * Sets the combo box which this object is auto completing and updates the * drop down list with the auto completion for the currently selected item. * * @param comboBox The combo box to enable browsing for auto completions. * May be {@code null}. */ public void setComboBox(final @CheckForNull JComboBox<E> comboBox) { changeComboBox(getComboBox(), comboBox, true); }
/** * Create a new buffered {@code EnhancedPanel} with the specified * layout manager. * * @param layout The {@link LayoutManager} to use. */ public EnhancedPanel(LayoutManager layout) { super(layout); super.addHierarchyListener(new EnhancedPanelHierarchyListener()); }
/** * Creates a new combo box auto completion browser. Note that this * constructor does <em>not</em> call {@link #update} and hence the drop * down list of the combo box is left unchanged. * * @param comboBox The combo box to enable browsing for auto completions. * May be {@code null}. */ protected AbstractComboBoxBrowser(final @CheckForNull JComboBox<E> comboBox) { changeComboBox(null, comboBox, false); }
/** * Notifies all registered listeners about the event. * This is a synchronous operation. * * @param event The event to be fired. */ void fireAncestorWindowShown(final PanelEvent event) { final Object[] listeners = listenerList.getListenerList(); for (int i = listeners.length - 2; i >= 0; i -= 2) if (listeners[i] == PanelListener.class) ((PanelListener) listeners[i+1]).ancestorWindowShown(event); }
/** * Notifies all registered listeners about the event. * This is a synchronous operation. * * @param event The event to be fired. */ void fireAncestorWindowHidden(final PanelEvent event) { final Object[] listeners = listenerList.getListenerList(); for (int i = listeners.length - 2; i >= 0; i -= 2) if (listeners[i] == PanelListener.class) ((PanelListener) listeners[i+1]).ancestorWindowHidden(event); }
/** * Overridden in order to process {@link PanelEvent}s. * * @deprecated See {@link PanelEvent}. */ @Override @Deprecated protected void processEvent(final AWTEvent event) { if (event instanceof PanelEvent) { //assert false : "This is dead code since the refactoring for TrueZIP 6.4!"; processPanelEvent((PanelEvent) event); } else { super.processEvent(event); } }
@Override public void run() { JemmyProperties.push(); setUpJemmyProperties(); } });
/** * Creates a new {@code EnhancedPanel} with a double buffer * and a flow layout. */ public EnhancedPanel() { super.addHierarchyListener(new EnhancedPanelHierarchyListener()); }
/** * Creates a new {@code EnhancedPanel} with the specified layout * manager and buffering strategy. * * @param layout The {@link LayoutManager} to use. * @param isDoubleBuffered A boolean, true for double-buffering, which * uses additional memory space to achieve fast, flicker-free * updates. */ public EnhancedPanel(LayoutManager layout, boolean isDoubleBuffered) { super(layout, isDoubleBuffered); super.addHierarchyListener(new EnhancedPanelHierarchyListener()); }
/** * Creates a new {@code EnhancedPanel} with {@code FlowLayout} * and the specified buffering strategy. * If {@code isDoubleBuffered} is true, the {@code EnhancedPanel} * will use a double buffer. * * @param isDoubleBuffered A boolean, true for double-buffering, which * uses additional memory space to achieve fast, flicker-free * updates. */ public EnhancedPanel(boolean isDoubleBuffered) { super(isDoubleBuffered); super.addHierarchyListener(new EnhancedPanelHierarchyListener()); }