Example usage for java.awt Window addWindowListener

List of usage examples for java.awt Window addWindowListener

Introduction

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

Prototype

public synchronized void addWindowListener(WindowListener l) 

Source Link

Document

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

Usage

From source file:Main.java

public static void setInitialFocus(Window w, Component c) {
    w.addWindowListener(new FocusSetter(c));
}

From source file:Main.java

/**
 * Attaches a {@link WindowListener} to the given Window so it is disposed
 * when the close button is hit. Some windows do not respond to the
 * DISPOSE_ON_CLOSE operation, so this is better than using that.
 *///from  w  w  w .  j a v a 2 s. co  m
public static void attachDisposeOnClose(final Window w) {
    w.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            w.setVisible(false);
            w.dispose();
        }
    });
}

From source file:Main.java

public static void packLater(final Window win, final Component parent) {
    win.pack();/*from   ww  w. j a v a2  s. co  m*/
    win.setLocationRelativeTo(parent);
    win.addWindowListener(new WindowAdapter() {
        @Override
        public void windowOpened(WindowEvent e) {
            win.pack();
            win.setLocationRelativeTo(parent);
        }
    });
}

From source file:com.all.app.ApplicationUtils.java

public static void showFrameAndWaitForClose(Window window) {
    try {/*from w ww  . j  a  va 2  s.co m*/
        final Semaphore lock = new Semaphore(0);
        window.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                lock.release();
            }
        });
        window.setVisible(true);
        lock.acquire();
    } catch (Exception e) {
        LOG.error(e, e);
    }
}

From source file:components.SliderDemo.java

/** Add a listener for window events. */
void addWindowListener(Window w) {
    w.addWindowListener(this);
}

From source file:com.diversityarrays.kdxplore.vistool.VisToolbarFactory.java

static public VisToolToolBar create(final String title, final JComponent comp, final Closure<File> snapshotter,
        final VisToolDataProvider visToolDataProvider, boolean floatable, final String[] imageSuffixes) {
    Window window = GuiUtil.getOwnerWindow(comp);

    boolean anyButtons = false;

    final JCheckBox keepOnTop;

    if (window == null) {
        keepOnTop = null;//  w  w  w. j  a  va2s  . c  o  m
    } else {
        anyButtons = true;
        keepOnTop = new JCheckBox(Msg.OPTION_KEEP_ON_TOP(), true);

        keepOnTop.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                window.setAlwaysOnTop(keepOnTop.isSelected());
            }
        });
        window.setAlwaysOnTop(keepOnTop.isSelected());

        //         buttons.add(keepOnTop);

        final PropertyChangeListener alwaysOnTopListener = new PropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                keepOnTop.setSelected(window.isAlwaysOnTop());
            }
        };
        window.addPropertyChangeListener(PROPERTY_ALWAYS_ON_TOP, alwaysOnTopListener);

        window.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosed(WindowEvent e) {
                window.removeWindowListener(this);
                window.removePropertyChangeListener(PROPERTY_ALWAYS_ON_TOP, alwaysOnTopListener);
            }
        });
    }

    final JButton cameraButton;
    if (snapshotter == null) {
        cameraButton = null;
    } else {
        Action cameraAction = new AbstractAction(Msg.ACTION_SNAPSHOT()) {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (chooser == null) {
                    chooser = new JFileChooser();
                    chooser.setFileFilter(new FileFilter() {
                        @Override
                        public boolean accept(File f) {
                            if (!f.isFile()) {
                                return true;
                            }
                            String loname = f.getName().toLowerCase();
                            for (String sfx : imageSuffixes) {
                                if (loname.endsWith(sfx)) {
                                    return true;
                                }
                            }
                            return false;
                        }

                        @Override
                        public String getDescription() {
                            return Msg.DESC_IMAGE_FILE();
                        }
                    });
                    chooser.setMultiSelectionEnabled(false);
                    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
                }

                if (JFileChooser.APPROVE_OPTION == chooser.showSaveDialog(comp)) {
                    File file = chooser.getSelectedFile();
                    snapshotter.execute(file);
                }
            }
        };

        ImageIcon icon = loadIcon("camera-24.png"); //$NON-NLS-1$
        if (icon != null) {
            cameraAction.putValue(Action.SMALL_ICON, icon);
            cameraAction.putValue(Action.NAME, null);
        }

        anyButtons = true;
        cameraButton = new JButton(cameraAction);
    }

    final JButton refreshButton;
    if (visToolDataProvider == null) {
        refreshButton = null;
    } else {
        anyButtons = true;

        refreshButton = new JButton(Msg.ACTION_REFRESH());

        ImageIcon icon = loadIcon("refresh-24.png"); //$NON-NLS-1$
        if (icon != null) {
            refreshButton.setIcon(icon);
            // don't remove the name
        }

        refreshButton.setForeground(Color.RED);
        refreshButton.setEnabled(false);

        refreshButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (visToolDataProvider.refreshData()) {
                    refreshButton.setEnabled(false);
                }
            }
        });

        visToolDataProvider.addVisToolDataChangedListener(new VisToolDataChangedListener() {
            @Override
            public void visToolDataChanged(Object source) {
                refreshButton.setEnabled(true);
            }
        });
    }

    VisToolToolBar toolBar = null;

    if (anyButtons) {
        toolBar = new VisToolToolBar(keepOnTop, cameraButton, refreshButton);
        toolBar.setFloatable(floatable);
    }
    return toolBar;

}

From source file:org.keyboardplaying.xtt.ui.UIController.java

/** Builds and shows the main window. */
public void showMainWindow() {
    /* Create UI. */
    JPanel pane = new JPanel(new GridBagLayout());

    /* Arrange the components */
    GridBagConstraints c;// w w w  .j  a  v a2 s  .c o m

    c = new GridBagConstraints();
    c.gridx = 0;
    c.gridy = 0;
    c.gridwidth = 2;
    c.fill = GridBagConstraints.BOTH;
    pane.add(makeProjectActionButton("action.construct", "action-construct", ImageSize.W_16, constructAction),
            c);

    c = new GridBagConstraints();
    c.gridx = 0;
    c.gridy = 1;
    c.gridwidth = 2;
    c.fill = GridBagConstraints.BOTH;
    pane.add(makeProjectActionButton("action.deconstruct", "action-deconstruct", ImageSize.W_16,
            deconstructAction), c);

    c = new GridBagConstraints();
    c.gridx = 2;
    c.gridy = 0;
    c.gridheight = 2;
    c.fill = GridBagConstraints.BOTH;
    pane.add(makeActionButton(null, "icon-settings", ImageSize.W_32, settingsAction), c);

    Window window = makeWindow("app.name", "icon-timetracker", pane);
    window.addWindowListener(new WindowAdapter() {

        /*
         * (non-Javadoc)
         *
         * @see java.awt.event.WindowAdapter#windowClosing(java.awt.event. WindowEvent)
         */
        @Override
        public void windowClosing(WindowEvent e) {
            super.windowClosing(e);
            Frame[] windows = JFrame.getFrames();
            for (Frame w : windows) {
                w.dispose();
            }
        }
    });
    window.setVisible(true);
}

From source file:de.codesourcery.eve.skills.ui.frames.WindowManager.java

/**
 * Registers an new window./*from w w  w .  j av a 2  s .c o  m*/
 * 
 * @param key
 * @param frame
 */
public void registerWindow(final String key, final Window frame) {

    if (frame == null) {
        throw new IllegalArgumentException("frame cannot be NULL");
    }

    if (StringUtils.isBlank(key)) {
        throw new IllegalArgumentException("key cannot be blank / NULL");
    }

    synchronized (windows) {

        final Window oldFrame = windows.get(key);
        if (oldFrame != null) {
            log.warn("registerWindow(): REPLACING existing window with key '" + key + "'");
            unregisterWindow(key, oldFrame);
        }

        log.debug("registerWindow(): Registering window with key = " + key);

        windows.put(key, frame);

        frame.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent e) {
                unregisterWindow(key, frame);
            }
        });

        if (frame instanceof IWindowManagerAware) {
            ((IWindowManagerAware) frame).windowManaged();
        }
    }
}

From source file:org.jdal.swing.PageableTable.java

/**
 * @param toEdit model to edit/*from w w w.j  a v  a  2s . c om*/
 * @return model editor.
 */
public Window getEditor(Object toEdit) {
    Window dlg = openDialogs.get(toEdit);
    if (dlg == null) {
        dlg = getEditor();

        if (dlg == null)
            return null;

        openDialogs.put(toEdit, dlg);
        ((View<Object>) dlg).setModel(toEdit);
        ((View<Object>) dlg).refresh();
        dlg.addWindowListener(new DialogWindowListener());
        if (dlg instanceof Editor) {
            Editor<T> editor = (Editor<T>) dlg;
            editor.addEditorListener(new EditorListener() {

                public void modelChanged(EditorEvent e) {
                    refresh();
                }
            });
        }
    }
    ((View<T>) dlg).refresh();

    return dlg;
}

From source file:corelyzer.ui.CorelyzerApp.java

public void installPaletteVisibilityManager() {
    for (Window canvasWindow : windowVec) {
        canvasWindow.addWindowListener(pvm);
    }//  w w w  .ja  v  a2  s .  com

    toolFrame.addWindowListener(pvm);
    getMainFrame().addWindowListener(pvm);
}