Example usage for java.awt Window addComponentListener

List of usage examples for java.awt Window addComponentListener

Introduction

In this page you can find the example usage for java.awt Window addComponentListener.

Prototype

public synchronized void addComponentListener(ComponentListener l) 

Source Link

Document

Adds the specified component listener to receive component events from this component.

Usage

From source file:Utils.java

/**
 * Installs/resets a ComponentListener to resize the
 * given window to minWidth/Height if needed.
 *
 * @param window/*  ww w. jav a2 s .  c  o m*/
 * @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);
    }
}

From source file:net.schweerelos.parrot.CombinedParrotApp.java

@SuppressWarnings("serial")
private JToggleButton setupNavigatorButton(final String name, final String accelerator,
        final NavigatorComponent navigator) {
    final Component component = navigator.asJComponent();
    AbstractAction showNavigatorAction = new AbstractAction(name) {
        @Override//from  www.j ava  2  s.  c  o m
        public void actionPerformed(ActionEvent e) {
            if (!(e.getSource() instanceof JToggleButton)) {
                return;
            }
            final Window window;
            if (component instanceof Window) {
                window = (Window) component;
            } else {
                window = SwingUtilities.getWindowAncestor(component);
            }
            JToggleButton button = (JToggleButton) e.getSource();
            boolean show = button.isSelected();
            if (show) {
                if (window != CombinedParrotApp.this && preferredFrameLocations.containsKey(window)) {
                    window.setLocation(preferredFrameLocations.get(window));
                }
            }
            if (navigator.tellSelectionWhenShown()) {
                Collection<NodeWrapper> selectedNodes = activeMainView.getSelectedNodes();
                navigator.setSelectedNodes(selectedNodes);
            }
            component.setVisible(show);
            if (show) {
                window.setVisible(true);
            } else if (window != CombinedParrotApp.this) {
                window.setVisible(false);
            }
        }
    };
    showNavigatorAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control " + accelerator));
    final JToggleButton button = new JToggleButton(showNavigatorAction);
    button.setToolTipText("Show " + name.toLowerCase());
    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            button.setToolTipText((button.isSelected() ? "Hide " : "Show ") + name.toLowerCase());
        }
    });
    final Window window;
    if (component instanceof Window) {
        window = (Window) component;
    } else {
        window = SwingUtilities.getWindowAncestor(component);
    }
    if (window != null) {
        window.addComponentListener(new ComponentAdapter() {
            @Override
            public void componentHidden(ComponentEvent e) {
                button.setSelected(false);
                if (window != CombinedParrotApp.this) {
                    preferredFrameLocations.put(window, window.getLocation());
                }
            }

            @Override
            public void componentShown(ComponentEvent e) {
                button.setSelected(true);
            }
        });
    }
    return button;
}

From source file:net.pms.newgui.components.WindowProperties.java

/**
 * Creates a new instance using the specified parameters.
 *
 * @param window the {@link Window} whose properties to keep track of.
 * @param standardSize the standard size of {@code window}.
 * @param mimimumSize the minimum size of {@code window}.
 * @param windowConfiguration the {@link WindowPropertiesConfiguration}
 *            instance for reading and writing the window properties.
 *///from  w  w w .j a v a  2s  . c o m
public WindowProperties(@Nonnull Window window, @Nullable Dimension standardSize,
        @Nullable Dimension mimimumSize, @Nullable WindowPropertiesConfiguration windowConfiguration) {
    if (window == null) {
        throw new IllegalArgumentException("window cannot be null");
    }
    this.window = window;
    this.minimumSize = mimimumSize;
    if (mimimumSize != null) {
        window.setMinimumSize(mimimumSize);
    }
    this.windowConfiguration = windowConfiguration;
    if (windowConfiguration != null) {
        getConfiguration();
        GraphicsConfiguration windowGraphicsConfiguration = window.getGraphicsConfiguration();
        if (windowBounds != null && effectiveScreenBounds != null && graphicsDevice != null
                && graphicsDevice.equals(windowGraphicsConfiguration.getDevice().getIDstring())
                && screenBounds != null && screenBounds.equals(windowGraphicsConfiguration.getBounds())) {
            setWindowBounds();
        } else {
            Rectangle screen = effectiveScreenBounds != null ? effectiveScreenBounds
                    : windowGraphicsConfiguration.getBounds();
            if (standardSize != null && screen.width >= standardSize.width
                    && screen.height >= standardSize.height) {
                window.setSize(standardSize);
            } else if (mimimumSize != null && (window.getWidth() < mimimumSize.width
                    || window.getHeight() < mimimumSize.getHeight())) {
                window.setSize(mimimumSize);
            }
            window.setLocationByPlatform(true);
        }
        if (window instanceof Frame) {
            // Set maximized state
            int maximizedState = windowState & Frame.MAXIMIZED_BOTH;
            if (maximizedState != 0) {
                ((Frame) window).setExtendedState(((Frame) window).getExtendedState() | maximizedState);
            }
        }
    }
    window.addWindowListener(this);
    window.addComponentListener(this);
}