Java Code Examples for java.awt.event.ComponentListener

The following are top voted examples for showing how to use java.awt.event.ComponentListener. 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: iSeleda   File: WindowUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Installs/resets a ComponentListener to resize the
 * given window to minWidth/Height if needed.
 *
 * @param window
 * @param minWidth
 * @param minHeight
 */
public static void setMinimumSizeManager(Window window, int minWidth,
                                         int minHeight) {
    ComponentListener[] listeners = window.getComponentListeners();
    ComponentListener listener = null;
    for (ComponentListener l : listeners) {
        if (l instanceof MinSizeComponentListener) {
            listener = l;
            break;
        }
    }
    if (listener == null) {
        window.addComponentListener(new MinSizeComponentListener(
                window, minWidth, minHeight));
    } else {
        ((MinSizeComponentListener) listener).resetSizes(minWidth,
                minHeight);
    }
}
 
Example 3
Project: sc2gears   File: GuiUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Creates and returns a scroll panel which wraps the specified view component.<br>
 * The returned scroll panel disables vertical scroll bar, and only displays the horizontal scroll bar when the view does not fit
 * into the size of the view port. When the view fits into the view port, the scroll pane will not claim the space of the scroll bar.
 * 
 * @param view               view to wrap in the scroll pane
 * @param parentToRevalidate parent to revalidate when the scroll pane decides to change its size
 * 
 * @return the created self managed scroll pane
 */
public static JScrollPane createSelfManagedScrollPane( final Component view, final JComponent parentToRevalidate ) {
	final JScrollPane scrollPane = new JScrollPane( view );
	
	scrollPane.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_NEVER );
	scrollPane.getHorizontalScrollBar().setPreferredSize( new Dimension( 0, 12 ) ); // Only want to restrict the height, width doesn't matter (it takes up whole width)
	scrollPane.getHorizontalScrollBar().setUnitIncrement( 10 );
	
	final ComponentListener scrollPaneComponentListener = new ComponentAdapter() {
		@Override
		public void componentResized( final ComponentEvent event ) {
			scrollPane.setHorizontalScrollBarPolicy( view.getWidth() < scrollPane.getWidth() ? JScrollPane.HORIZONTAL_SCROLLBAR_NEVER : JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS );
			scrollPane.setPreferredSize( null );
			scrollPane.setPreferredSize( new Dimension( 10, scrollPane.getPreferredSize().height ) );
			parentToRevalidate.revalidate();
		}
	};
	scrollPane.addComponentListener( scrollPaneComponentListener );
	
	return scrollPane;
}
 
Example 4
Project: power-matchmaker   File: MungePen.java   Source Code and License 6 votes vote down vote up
/**
 * Removes all listeners associated with the given Component. This is useful when removing to to make sure
 * it does not stick around.
 */
public static void removeAllListeners(Component com) {
	for (FocusListener fl : com.getFocusListeners()) {
		com.removeFocusListener(fl);
	}
	
	for (MouseListener ml : com.getMouseListeners()) {
		com.removeMouseListener(ml);
	}
	
	for (MouseMotionListener mml : com.getMouseMotionListeners()) {
		com.removeMouseMotionListener(mml);
	}
	
	for (KeyListener kl : com.getKeyListeners()) {
		com.removeKeyListener(kl);
	}
	
	for (ComponentListener cl : com.getComponentListeners()) {
		com.removeComponentListener(cl);
	}
}
 
Example 5
Project: aibench-project   File: WindowUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Installs/resets a ComponentListener to resize the
 * given window to minWidth/Height if needed.
 *
 * @param window
 * @param minWidth
 * @param minHeight
 */
public static void setMinimumSizeManager(Window window, int minWidth,
                                         int minHeight) {
    ComponentListener[] listeners = window.getComponentListeners();
    ComponentListener listener = null;
    for (ComponentListener l : listeners) {
        if (l instanceof MinSizeComponentListener) {
            listener = l;
            break;
        }
    }
    if (listener == null) {
        window.addComponentListener(new MinSizeComponentListener(
                window, minWidth, minHeight));
    } else {
        ((MinSizeComponentListener) listener).resetSizes(minWidth,
                                                         minHeight);
    }
}
 
Example 6
Project: S3F   File: MainUI.java   Source Code and License 6 votes vote down vote up
public DockingWindow addView(int order, Configurable obj) {
    Component component = (Component) obj.getData().getProperty(TabProperty.COMPONENT);
    View view = new View(
            (String) obj.getData().getProperty(TabProperty.TITLE),
            (Icon) obj.getData().getProperty(TabProperty.ICON),
            component
    );

    if (component instanceof ComponentListener) {
        view.addComponentListener((ComponentListener) component);
    }

    if (order == 1 && obj instanceof DockingWindowListener) {
        DockingWindowListener dockingWindowListener = (DockingWindowListener) obj;
        view.addListener(dockingWindowListener);
        if (firstTabWindow.getChildWindowCount() == 0) {
            dockingWindowListener.windowShown(view);
        }
    }

    return addView(order, view);
}
 
Example 7
Project: passage   File: Layer.java   Source Code and License 6 votes vote down vote up
/**
 * Fire a component event to the Layer component listeners, with the palette
 * as the component, letting them know if it's visible or not.
 */
public void firePaletteEvent(ComponentEvent event) {
    if (localHackList == null) {
        return;
    }

    palette = (Container) event.getSource();
    int eventType = event.getID();
    for (ComponentListener listener : localHackList) {
        if (eventType == ComponentEvent.COMPONENT_HIDDEN) {
            listener.componentHidden(event);
        } else if (eventType == ComponentEvent.COMPONENT_SHOWN) {
            listener.componentShown(event);
        }
    }

    if (eventType == ComponentEvent.COMPONENT_HIDDEN) {
        palette = null;
    }
}
 
Example 8
Project: passage   File: PaletteHelper.java   Source Code and License 6 votes vote down vote up
/**
 * Get a layer's associated palette as a top-level window
 * 
 * @param gui the Component to place in the window
 * @param cl the listener to associate with the palette
 * @return the frame that the palette is in
 */
public static JFrame getPaletteWindow(Component gui, String windowName,
                                      ComponentListener cl) {

    JScrollPane scrollPane = new JScrollPane(gui, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scrollPane.setAlignmentX(Component.LEFT_ALIGNMENT);
    scrollPane.setAlignmentY(Component.TOP_ALIGNMENT);

    // create the palette internal window
    JFrame paletteWindow = new JFrame(windowName);

    paletteWindow.addComponentListener(cl);
    paletteWindow.getContentPane().add(scrollPane);
    //layout all the components
    paletteWindow.pack();
    return paletteWindow;
}
 
Example 9
Project: passage   File: PaletteHelper.java   Source Code and License 6 votes vote down vote up
/**
 * Get a layer's associated palette as a top-level window
 * 
 * @param gui the Component to place in the window
 * @param cl the listener to associate with the palette
 * @return the frame that the palette is in
 */
public static JFrame getNoScrollPaletteWindow(Component gui,
                                              String windowName,
                                              ComponentListener cl) {

    JPanel pane = new JPanel();
    pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
    pane.setAlignmentX(Component.CENTER_ALIGNMENT);
    pane.setAlignmentY(Component.BOTTOM_ALIGNMENT);
    pane.add(gui);
    JFrame paletteWindow = new JFrame(windowName);
    paletteWindow.addComponentListener(cl);
    paletteWindow.getContentPane().add(pane);
    paletteWindow.pack();

    return paletteWindow;
}
 
Example 10
Project: passage   File: WindowSupport.java   Source Code and License 6 votes vote down vote up
/**
 * Sets the content in the JInternalFrame/JDialog.
 */
public void setContent(Component comp) {

    if (content instanceof ComponentListener) {
        removeComponentListener((ComponentListener) content);
    }

    content = comp;
    if (display != null) {
        display.setContent(comp);
    }

    if (content instanceof ComponentListener) {
        addComponentListener((ComponentListener) content);
    }
}
 
Example 11
Project: cn1   File: Component.java   Source Code and License 6 votes vote down vote up
private void processComponentEventImpl(ComponentEvent e, Collection<ComponentListener> c) {
    for (ComponentListener listener : c) {
        switch (e.getID()) {
            case ComponentEvent.COMPONENT_HIDDEN:
                listener.componentHidden(e);
                break;
            case ComponentEvent.COMPONENT_MOVED:
                listener.componentMoved(e);
                break;
            case ComponentEvent.COMPONENT_RESIZED:
                listener.componentResized(e);
                break;
            case ComponentEvent.COMPONENT_SHOWN:
                listener.componentShown(e);
                break;
        }
    }
}
 
Example 12
Project: freemind_1.0.0_20140624_214725   File: EditNodeTextField.java   Source Code and License 6 votes vote down vote up
private void hideMe() {
	final JComponent parent = (JComponent) textfield.getParent();
	final Rectangle bounds = textfield.getBounds();
	textfield.removeFocusListener(textFieldListener);
	textfield.removeKeyListener((KeyListener) textFieldListener);
	textfield.removeMouseListener((MouseListener) textFieldListener);
	mFocusListener
			.removeComponentListener((ComponentListener) textFieldListener);
	// workaround for java bug
	// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7075600, see
	// FreeMindStarter
	parent.remove(textfield);
	parent.revalidate();
	parent.repaint(bounds);
	textFieldListener = null;
}
 
Example 13
Project: desktopclient-java   File: ComponentUtils.java   Source Code and License 6 votes vote down vote up
private void showPopupPanel() {
    if (mPopup == null)
        mPopup = new ComponentUtils.ModalPopup(this);

    PopupPanel panel = this.getPanel().orElse(null);
    if (panel == null)
        return;

    mPopup.removeAll();
    panel.onShow();

    for (ComponentListener cl : panel.getComponentListeners())
        panel.removeComponentListener(cl);

    panel.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentHidden(ComponentEvent e) {
            mPopup.close();
        }
    });
    mPopup.add(panel);
    mPopup.showPopup();
}
 
Example 14
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 15
Project: freeVM   File: Component.java   Source Code and License 6 votes vote down vote up
private void processComponentEventImpl(ComponentEvent e, Collection<ComponentListener> c) {
    for (ComponentListener listener : c) {
        switch (e.getID()) {
            case ComponentEvent.COMPONENT_HIDDEN:
                listener.componentHidden(e);
                break;
            case ComponentEvent.COMPONENT_MOVED:
                listener.componentMoved(e);
                break;
            case ComponentEvent.COMPONENT_RESIZED:
                listener.componentResized(e);
                break;
            case ComponentEvent.COMPONENT_SHOWN:
                listener.componentShown(e);
                break;
        }
    }
}
 
Example 16
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 17
Project: freeVM   File: Component.java   Source Code and License 6 votes vote down vote up
private void processComponentEventImpl(ComponentEvent e, Collection<ComponentListener> c) {
    for (ComponentListener listener : c) {
        switch (e.getID()) {
            case ComponentEvent.COMPONENT_HIDDEN:
                listener.componentHidden(e);
                break;
            case ComponentEvent.COMPONENT_MOVED:
                listener.componentMoved(e);
                break;
            case ComponentEvent.COMPONENT_RESIZED:
                listener.componentResized(e);
                break;
            case ComponentEvent.COMPONENT_SHOWN:
                listener.componentShown(e);
                break;
        }
    }
}
 
Example 18
Project: freemind   File: EditNodeTextField.java   Source Code and License 6 votes vote down vote up
private void hideMe() {
	final JComponent parent = (JComponent) textfield.getParent();
	final Rectangle bounds = textfield.getBounds();
	textfield.removeFocusListener(textFieldListener);
	textfield.removeKeyListener((KeyListener) textFieldListener);
	textfield.removeMouseListener((MouseListener) textFieldListener);
	mFocusListener
			.removeComponentListener((ComponentListener) textFieldListener);
	// workaround for java bug
	// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7075600, see
	// FreeMindStarter
	parent.remove(textfield);
	parent.revalidate();
	parent.repaint(bounds);
	textFieldListener = null;
}
 
Example 19
Project: incubator-netbeans   File: Outline.java   Source Code and License 5 votes vote down vote up
/** Create a component listener to handle size changes if the table model
 * is large-model */
private ComponentListener getComponentListener() {
    if (componentListener == null) {
        componentListener = new SizeManager();
    }
    return componentListener;
}
 
Example 20
Project: incubator-netbeans   File: FontAndColorsPanel.java   Source Code and License 5 votes vote down vote up
@Override
public void removeNotify() {
    super.removeNotify();
    for (ComponentListener l : getComponentListeners()) {
        super.removeComponentListener(l);
    }
}
 
Example 21
Project: etomica   File: DisplayCanvas.java   Source Code and License 5 votes vote down vote up
public void dispose() {
    ComponentListener[] listeners = getComponentListeners();
    for (int i=0; i<listeners.length; i++) {
        removeComponentListener(listeners[i]);
    }
    MouseListener[] mlisteners = getMouseListeners();
    for (int i=0; i<mlisteners.length; i++) {
        removeMouseListener(mlisteners[i]);
    }
    KeyListener[] klisteners = getKeyListeners();
    for (int i=0; i<klisteners.length; i++) {
        removeKeyListener(klisteners[i]);
    }
}
 
Example 22
Project: openjdk-jdk10   File: ComponentOperator.java   Source Code and License 5 votes vote down vote up
/**
 * Maps {@code Component.addComponentListener(ComponentListener)}
 * through queue
 */
public void addComponentListener(final ComponentListener componentListener) {
    runMapping(new MapVoidAction("addComponentListener") {
        @Override
        public void map() {
            getSource().addComponentListener(componentListener);
        }
    });
}
 
Example 23
Project: openjdk-jdk10   File: ComponentOperator.java   Source Code and License 5 votes vote down vote up
/**
 * Maps {@code Component.removeComponentListener(ComponentListener)}
 * through queue
 */
public void removeComponentListener(final ComponentListener componentListener) {
    runMapping(new MapVoidAction("removeComponentListener") {
        @Override
        public void map() {
            getSource().removeComponentListener(componentListener);
        }
    });
}
 
Example 24
Project: openjdk9   File: ComponentOperator.java   Source Code and License 5 votes vote down vote up
/**
 * Maps {@code Component.addComponentListener(ComponentListener)}
 * through queue
 */
public void addComponentListener(final ComponentListener componentListener) {
    runMapping(new MapVoidAction("addComponentListener") {
        @Override
        public void map() {
            getSource().addComponentListener(componentListener);
        }
    });
}
 
Example 25
Project: openjdk9   File: ComponentOperator.java   Source Code and License 5 votes vote down vote up
/**
 * Maps {@code Component.removeComponentListener(ComponentListener)}
 * through queue
 */
public void removeComponentListener(final ComponentListener componentListener) {
    runMapping(new MapVoidAction("removeComponentListener") {
        @Override
        public void map() {
            getSource().removeComponentListener(componentListener);
        }
    });
}
 
Example 26
Project: j2se_for_android   File: Component.java   Source Code and License 5 votes vote down vote up
public void fireComponentResizedAdAPI(){
	final ComponentEvent event = new ComponentEvent(this, ComponentEvent.COMPONENT_RESIZED);
	
	final ComponentListener[] listeners = getComponentListeners();
	for (int i = 0; i < listeners.length; i++) {
		listeners[i].componentResized(event);
	}
}
 
Example 27
Project: j2se_for_android   File: Component.java   Source Code and License 5 votes vote down vote up
public void fireComponentMovedAdAPI(){
	final ComponentEvent event = new ComponentEvent(this, ComponentEvent.COMPONENT_MOVED);
	
	final ComponentListener[] listeners = getComponentListeners();
	for (int i = 0; i < listeners.length; i++) {
		listeners[i].componentMoved(event);
	}
}
 
Example 28
Project: j2se_for_android   File: Component.java   Source Code and License 5 votes vote down vote up
public void fireComponentShowAdAPI(){
	final ComponentEvent event = new ComponentEvent(this, ComponentEvent.COMPONENT_SHOWN);
	
	final ComponentListener[] listeners = getComponentListeners();
	for (int i = 0; i < listeners.length; i++) {
		listeners[i].componentShown(event);
	}
}
 
Example 29
Project: j2se_for_android   File: Component.java   Source Code and License 5 votes vote down vote up
public void fireComponentHiddenAdAPI(){
	final ComponentEvent event = new ComponentEvent(this, ComponentEvent.COMPONENT_HIDDEN);
	
	final ComponentListener[] listeners = getComponentListeners();
	for (int i = 0; i < listeners.length; i++) {
		listeners[i].componentHidden(event);
	}
}
 
Example 30
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 31
Project: javify   File: StandaloneAppletWindow.java   Source Code and License 5 votes vote down vote up
/**
 * This method is called when the component is resized.
 *
 * @param event the <code>ComponentEvent</code> indicating the resize
 */
public void componentResized(ComponentEvent event)
{
  if (applet != null)
    {
      ComponentListener[] l = applet.getComponentListeners();
      for (int i = 0; i < l.length; i++)
        l[i].componentResized(event);
    }
}
 
Example 32
Project: javify   File: StandaloneAppletWindow.java   Source Code and License 5 votes vote down vote up
/**
 * This method is called when the component is moved.
 *
 * @param event the <code>ComponentEvent</code> indicating the move
 */
public void componentMoved(ComponentEvent event)
{
  if (applet != null)
    {
      ComponentListener[] l = applet.getComponentListeners();
      for (int i = 0; i < l.length; i++)
        l[i].componentMoved(event);
    }
}
 
Example 33
Project: javify   File: StandaloneAppletWindow.java   Source Code and License 5 votes vote down vote up
/**
 * This method is called when the component is made visible.
 *
 * @param event the <code>ComponentEvent</code> indicating the visibility
 */
public void componentShown(ComponentEvent event)
{
  if (applet != null)
    {
      ComponentListener[] l = applet.getComponentListeners();
      for (int i = 0; i < l.length; i++)
        l[i].componentShown(event);
    }
}
 
Example 34
Project: javify   File: StandaloneAppletWindow.java   Source Code and License 5 votes vote down vote up
/**
 * This method is called when the component is hidden.
 *
 * @param event the <code>ComponentEvent</code> indicating the visibility
 */
public void componentHidden(ComponentEvent event)
{
  if (applet != null)
    {
      ComponentListener[] l = applet.getComponentListeners();
      for (int i = 0; i < l.length; i++)
        l[i].componentHidden(event);
    }
}
 
Example 35
Project: javify   File: PluginAppletWindow.java   Source Code and License 5 votes vote down vote up
/**
 * This method is called when the component is resized.
 *
 * @param event the <code>ComponentEvent</code> indicating the resize
 */
public void componentResized(ComponentEvent event)
{
  if (applet != null)
    {
      ComponentListener[] l = applet.getComponentListeners();
      for (int i = 0; i < l.length; i++)
        l[i].componentResized(event);
    }
}
 
Example 36
Project: javify   File: PluginAppletWindow.java   Source Code and License 5 votes vote down vote up
/**
 * This method is called when the component is moved.
 *
 * @param event the <code>ComponentEvent</code> indicating the move
 */
public void componentMoved(ComponentEvent event)
{
  if (applet != null)
    {
      ComponentListener[] l = applet.getComponentListeners();
      for (int i = 0; i < l.length; i++)
        l[i].componentMoved(event);
    }
}
 
Example 37
Project: javify   File: PluginAppletWindow.java   Source Code and License 5 votes vote down vote up
/**
 * This method is called when the component is made visible.
 *
 * @param event the <code>ComponentEvent</code> indicating the visibility
 */
public void componentShown(ComponentEvent event)
{
  if (applet != null)
    {
      ComponentListener[] l = applet.getComponentListeners();
      for (int i = 0; i < l.length; i++)
        l[i].componentShown(event);
    }
}
 
Example 38
Project: javify   File: PluginAppletWindow.java   Source Code and License 5 votes vote down vote up
/**
 * This method is called when the component is hidden.
 *
 * @param event the <code>ComponentEvent</code> indicating the visibility
 */
public void componentHidden(ComponentEvent event)
{
  if (applet != null)
    {
      ComponentListener[] l = applet.getComponentListeners();
      for (int i = 0; i < l.length; i++)
        l[i].componentHidden(event);
    }
}
 
Example 39
Project: intellij-ce-playground   File: FrameState.java   Source Code and License 5 votes vote down vote up
private static FrameState findFrameState(@NotNull Component component) {
  for (ComponentListener listener : component.getComponentListeners()) {
    if (listener instanceof FrameState) {
      return (FrameState)listener;
    }
  }
  return null;
}
 
Example 40
Project: sqlpower-library   File: PopupListenerHandler.java   Source Code and License 5 votes vote down vote up
/**
* Returns true if the {@link Popup} this class handles is visible. Since
* there is no available method in the {@link Popup} class to check whether
* it is visible, it checks if listeners are attached to the owning frame or
* glass pane instead.
*/
  public boolean isPopupVisible() {
  	ComponentListener[] componentListeners = owningFrame.getComponentListeners();
  	if (Arrays.asList(componentListeners).contains(resizeListener)) {
  		return true;
  	}
  	
  	MouseListener[] mouseListeners = glassPane.getMouseListeners();
  	if (Arrays.asList(mouseListeners).contains(clickListener)) {
  		return true;
  	}
  	
  	return false;
  	
  }
 
Example 41
Project: jvm-stm   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 42
Project: jvm-stm   File: StandaloneAppletWindow.java   Source Code and License 5 votes vote down vote up
/**
 * This method is called when the component is resized.
 *
 * @param event the <code>ComponentEvent</code> indicating the resize
 */
public void componentResized(ComponentEvent event)
{
  if (applet != null)
    {
      ComponentListener[] l = applet.getComponentListeners();
      for (int i = 0; i < l.length; i++)
        l[i].componentResized(event);
    }
}
 
Example 43
Project: jvm-stm   File: StandaloneAppletWindow.java   Source Code and License 5 votes vote down vote up
/**
 * This method is called when the component is moved.
 *
 * @param event the <code>ComponentEvent</code> indicating the move
 */
public void componentMoved(ComponentEvent event)
{
  if (applet != null)
    {
      ComponentListener[] l = applet.getComponentListeners();
      for (int i = 0; i < l.length; i++)
        l[i].componentMoved(event);
    }
}
 
Example 44
Project: jvm-stm   File: StandaloneAppletWindow.java   Source Code and License 5 votes vote down vote up
/**
 * This method is called when the component is made visible.
 *
 * @param event the <code>ComponentEvent</code> indicating the visibility
 */
public void componentShown(ComponentEvent event)
{
  if (applet != null)
    {
      ComponentListener[] l = applet.getComponentListeners();
      for (int i = 0; i < l.length; i++)
        l[i].componentShown(event);
    }
}
 
Example 45
Project: jvm-stm   File: StandaloneAppletWindow.java   Source Code and License 5 votes vote down vote up
/**
 * This method is called when the component is hidden.
 *
 * @param event the <code>ComponentEvent</code> indicating the visibility
 */
public void componentHidden(ComponentEvent event)
{
  if (applet != null)
    {
      ComponentListener[] l = applet.getComponentListeners();
      for (int i = 0; i < l.length; i++)
        l[i].componentHidden(event);
    }
}
 
Example 46
Project: jvm-stm   File: PluginAppletWindow.java   Source Code and License 5 votes vote down vote up
/**
 * This method is called when the component is resized.
 *
 * @param event the <code>ComponentEvent</code> indicating the resize
 */
public void componentResized(ComponentEvent event)
{
  if (applet != null)
    {
      ComponentListener[] l = applet.getComponentListeners();
      for (int i = 0; i < l.length; i++)
        l[i].componentResized(event);
    }
}
 
Example 47
Project: jvm-stm   File: PluginAppletWindow.java   Source Code and License 5 votes vote down vote up
/**
 * This method is called when the component is moved.
 *
 * @param event the <code>ComponentEvent</code> indicating the move
 */
public void componentMoved(ComponentEvent event)
{
  if (applet != null)
    {
      ComponentListener[] l = applet.getComponentListeners();
      for (int i = 0; i < l.length; i++)
        l[i].componentMoved(event);
    }
}
 
Example 48
Project: jvm-stm   File: PluginAppletWindow.java   Source Code and License 5 votes vote down vote up
/**
 * This method is called when the component is made visible.
 *
 * @param event the <code>ComponentEvent</code> indicating the visibility
 */
public void componentShown(ComponentEvent event)
{
  if (applet != null)
    {
      ComponentListener[] l = applet.getComponentListeners();
      for (int i = 0; i < l.length; i++)
        l[i].componentShown(event);
    }
}
 
Example 49
Project: jvm-stm   File: PluginAppletWindow.java   Source Code and License 5 votes vote down vote up
/**
 * This method is called when the component is hidden.
 *
 * @param event the <code>ComponentEvent</code> indicating the visibility
 */
public void componentHidden(ComponentEvent event)
{
  if (applet != null)
    {
      ComponentListener[] l = applet.getComponentListeners();
      for (int i = 0; i < l.length; i++)
        l[i].componentHidden(event);
    }
}
 
Example 50
Project: swingx   File: RendererVisualCheck.java   Source Code and License 5 votes vote down vote up
/**
     * List needs special handling, see
     * http://stackoverflow.com/questions/7306295/swing-jlist-with-multiline-text-and-dynamic-height
     * 
     */
    public void interactiveTextAreaRendererList() {
        final DefaultListModel model = new DefaultListModel();
        model.addElement("Start: This is a short text");
        model.addElement("Start: This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. ");
        model.addElement("Start: This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. ");

        final JXList list = new JXList(model) {

            /** 
             * @inherited <p>
             */
            @Override
            public boolean getScrollableTracksViewportWidth() {
                return true;
            }

            
        };
        list.setCellRenderer(new DefaultListRenderer(new TextAreaProvider()));
        
        ComponentListener l = new java.awt.event.ComponentAdapter() {

            @Override
            public void componentResized(ComponentEvent e) {
                list.invalidateCellSizeCache();
                // for core: force cache invalidation by temporarily setting fixed height
//                list.setFixedCellHeight(10);
//                list.setFixedCellHeight(-1);
            }
            
        };

        list.addComponentListener(l);
        showWithScrollingInFrame(list, "TextAreaPovider in JXList");
        
    }
 
Example 51
Project: stendhal   File: ScrolledViewport.java   Source Code and License 5 votes vote down vote up
/**
 * Create a new ScrolledViewport.
 * 
 * @param view child component. The border that view has at the moment when
 * 	the ScrolledViewport is created is used when ant least one of the scroll
 * 	bars is visible.
 */
public ScrolledViewport(JComponent view) {
	this.view = view;
	originalBorder = view.getBorder();
	scrollPane = new JScrollPane(view);
	ComponentListener listener = new ScrollBarVisibilityChangeListener();
	scrollPane.getHorizontalScrollBar().addComponentListener(listener);
	scrollPane.getVerticalScrollBar().addComponentListener(listener);
}
 
Example 52
Project: WorldGrower   File: AskQuestionDialog.java   Source Code and License 5 votes vote down vote up
private void pressAskQuestionButtonOnVisible() {
	ComponentListener listener = new ComponentAdapter() {
		
		// this method is called after componentShown and performs the click
		// otherwise the component may get moved/resized after clicking
		@Override
		public void componentResized(ComponentEvent e) {
			askQuestion.doClick();
		}
	};
	this.addComponentListener(listener);
}
 
Example 53
Project: aTunes   File: VisualHandler.java   Source Code and License 5 votes vote down vote up
public ComponentListener getStandardWindowListener() {
	final int minHeight = 410;
	return new ComponentAdapter() {
		public void componentResized(ComponentEvent e) {
			JFrame f = frame.getFrame();
			
			if (frame.getPlayListPanel().getSize().width < StandardFrame.playListPanelWidth) // Avoid resize
				f.setSize(f.getWidth() + (StandardFrame.playListPanelWidth - frame.getPlayListPanel().getSize().width + 10), f.getHeight());
			
			if (f.getHeight() < minHeight)
				f.setSize(f.getWidth(), minHeight);
		}
	};
}
 
Example 54
Project: SmartTokens   File: TrackingSpacer.java   Source Code and License 5 votes vote down vote up
private ComponentListener createComponentListner() {
    return new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent e) {
            doTrackedComponentResized();
        }
    };
}
 
Example 55
Project: jexer   File: SwingComponent.java   Source Code and License 5 votes vote down vote up
/**
 * Adds the specified component listener to receive component events from
 * this component. If listener l is null, no exception is thrown and no
 * action is performed.
 *
 * @param l the component listener
 */
public void addComponentListener(ComponentListener l) {
    if (frame != null) {
        frame.addComponentListener(l);
    } else {
        component.addComponentListener(l);
    }
}
 
Example 56
Project: seaglass   File: SeaGlassInternalFrameUI.java   Source Code and License 5 votes vote down vote up
protected ComponentListener createComponentListener() {
    if (UIManager.getBoolean("InternalFrame.useTaskBar")) {
        return new ComponentHandler() {
            public void componentResized(ComponentEvent e) {
                if (frame != null && frame.isMaximum()) {
                    JDesktopPane desktop = (JDesktopPane) e.getSource();
                    for (Component comp : desktop.getComponents()) {
                        if (comp instanceof SeaGlassDesktopPaneUI.TaskBar) {
                            frame.setBounds(0, 0, desktop.getWidth(), desktop.getHeight() - comp.getHeight());
                            frame.revalidate();
                            break;
                        }
                    }
                }

                // Update the new parent bounds for next resize, but don't
                // let the super method touch this frame
                JInternalFrame f = frame;
                frame = null;
                super.componentResized(e);
                frame = f;
            }
        };
    } else {
        return super.createComponentListener();
    }
}
 
Example 57
Project: platypus-js   File: JCalendarPanel.java   Source Code and License 5 votes vote down vote up
protected void fireHiddenEvent() {
    ComponentListener[] listeners = getComponentListeners();
    if (listeners != null) {
        ComponentEvent e = new ComponentEvent(this, ComponentEvent.COMPONENT_HIDDEN);
        for (ComponentListener l : listeners) {
            if (l != null) {
                l.componentHidden(e);
            }
        }
    }
}
 
Example 58
Project: DataCleaner   File: HdfsUrlChooser.java   Source Code and License 5 votes vote down vote up
protected void createDialog(final Component chooser, final Component parent, final ComponentListener listener) {
    _dialog = WidgetFactory.createModalDialog(chooser, parent, _openType.getTitle(), true);

    if (listener != null) {
        _dialog.addComponentListener(listener);
    }
    _dialog.setVisible(true);
    _dialog.dispose();
    _dialog = null;
}
 
Example 59
Project: kkMulticopterFlashTool   File: ViewEditor.java   Source Code and License 5 votes vote down vote up
public void addComponentListener(ComponentListener listener)
{
	if (getParent() instanceof ViewEditor)
	{
		super.addComponentListener(listener);
	}
	else
	{
		for (int i = 0; i < viewList.size(); i++)
		{
			ViewEditor editor = (ViewEditor) viewList.elementAt(i);
			editor.addComponentListener(listener);
		}
	}
}
 
Example 60
Project: kkMulticopterFlashTool   File: ViewEditor.java   Source Code and License 5 votes vote down vote up
public void removeComponentListener(ComponentListener listener)
{
	if (getParent() instanceof ViewEditor)
	{
		super.removeComponentListener(listener);
	}
	else
	{
		for (int i = 0; i < viewList.size(); i++)
		{
			ViewEditor editor = (ViewEditor) viewList.elementAt(i);
			editor.removeComponentListener(listener);
		}
	}
}