Example usage for java.awt.event WindowAdapter WindowAdapter

List of usage examples for java.awt.event WindowAdapter WindowAdapter

Introduction

In this page you can find the example usage for java.awt.event WindowAdapter WindowAdapter.

Prototype

WindowAdapter

Source Link

Usage

From source file:JavaXWin.java

public JavaXWin() {
    setTitle("JavaXWin");
    m_count = m_tencount = 0;/*from  w  ww  .j  a va 2 s .c  o m*/
    m_desktop = new JDesktopPane();

    JScrollPane scroller = new JScrollPane();
    m_wm = new WindowManager(m_desktop);
    m_desktop.setDesktopManager(m_wm);
    m_desktop.add(m_wm.getWindowWatcher(), JLayeredPane.PALETTE_LAYER);
    m_wm.getWindowWatcher().setBounds(555, 5, 200, 150);

    viewport = new JViewport() {
        public void setViewPosition(Point p) {
            super.setViewPosition(p);
            m_wm.getWindowWatcher().setLocation(m_wm.getWindowWatcher().getX() + (getViewPosition().x - m_wmX),
                    m_wm.getWindowWatcher().getY() + (getViewPosition().y - m_wmY));
            m_wmX = getViewPosition().x;
            m_wmY = getViewPosition().y;
        }
    };
    viewport.setView(m_desktop);
    scroller.setViewport(viewport);

    ComponentAdapter ca = new ComponentAdapter() {
        JViewport view = viewport;

        public void componentResized(ComponentEvent e) {
            m_wm.getWindowWatcher().setLocation(
                    view.getViewPosition().x + view.getWidth() - m_wm.getWindowWatcher().getWidth() - 15,
                    view.getViewPosition().y + 5);
        }
    };
    viewport.addComponentListener(ca);

    m_newFrame = new JButton("New Frame");
    m_newFrame.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            newFrame();
        }
    });

    JPanel topPanel = new JPanel(true);
    topPanel.setLayout(new FlowLayout());

    getContentPane().setLayout(new BorderLayout());
    getContentPane().add("North", topPanel);
    getContentPane().add("Center", scroller);

    topPanel.add(m_newFrame);

    Dimension dim = getToolkit().getScreenSize();
    setSize(800, 600);
    setLocation(dim.width / 2 - getWidth() / 2, dim.height / 2 - getHeight() / 2);
    m_desktop.setPreferredSize(new Dimension(1600, 1200));
    setVisible(true);
    WindowListener l = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    addWindowListener(l);
}

From source file:edu.umich.robot.ViewerApplication.java

public ViewerApplication(String[] args) {
    JPopupMenu.setDefaultLightWeightPopupEnabled(false);
    ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);

    Config config = (args.length > 0) ? ConfigUtil.getDefaultConfig(args) : promptForConfig();
    if (config == null)
        System.exit(1);//ww  w .j av a 2s.c o m

    setupViewerConfig(config);
    viewer = new Viewer(config);
    viewer.getVisCanvas().getViewManager().setInterfaceMode(3);

    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosed(WindowEvent e) {
            frame.dispose();

            try {
                Thread.sleep(500);
            } catch (InterruptedException ignored) {
            }
            System.exit(0); // No way to shut down april threads
        }
    });
    frame.setLayout(new BorderLayout());

    viewerView = new ViewerView(viewer.getVisCanvas());

    // TODO SoarApril
    // viewer.getVisCanvas().setDrawGround(true);

    frame.add(viewerView, BorderLayout.CENTER);

    Preferences windowPrefs = getWindowPreferences();
    if (windowPrefs.get("x", null) != null) {
        frame.setBounds(windowPrefs.getInt("x", 0), windowPrefs.getInt("y", 0),
                windowPrefs.getInt("width", 800), windowPrefs.getInt("height", 800));
    } else {
        frame.setBounds(windowPrefs.getInt("x", 0), windowPrefs.getInt("y", 0),
                windowPrefs.getInt("width", 600), windowPrefs.getInt("height", 600));
        frame.setLocationRelativeTo(null); // center
    }

    frame.getRootPane().registerKeyboardAction(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            frame.dispose();
        }
    }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);

    frame.pack();

    frame.setVisible(true);

    String[] splinters = config.getStrings("splinters", new String[0]);
    for (String s : splinters) {
        addViewRobot(s);
        addViewLidars(s);
        addViewWaypoints(s);

        // TODO SoarApril
        addViewTrajectory(s);
    }
}

From source file:ru.codemine.pos.ui.salespanel.QuantitySetupWindow.java

public QuantitySetupWindow() {
    setTitle(" ?");
    setSize(300, 150);//from  w w w. j a v  a  2 s.c  o m
    setLocationRelativeTo(null);

    okButton.setMargin(5);
    cancelButton.setMargin(5);
    okButton.setRound(StyleConstants.largeRound);
    cancelButton.setRound(StyleConstants.largeRound);
    GroupPanel buttonsGroupPanel = new GroupPanel(10, okButton, cancelButton);

    TableLayout layout = new TableLayout(
            new double[][] { { 10, TableLayout.PREFERRED, 10, TableLayout.FILL, 10 },
                    { 10, TableLayout.PREFERRED, // ? -
                            10, TableLayout.PREFERRED, // ? -
                            10, TableLayout.PREFERRED, 10 } // 
            });
    setLayout(layout);

    add(quantityLabel, "1, 1");
    add(spinner, "3, 1");
    add(onStoresLabel, "3, 3");
    add(buttonsGroupPanel, "1, 5, 3, 5, C, T");

    setResizable(false);
    getRootPane().setDefaultButton(okButton);

    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            mainWindow.unblockBarcodeInput();
            setVisible(false);
        }
    });

    actionListenersInit = false;
}

From source file:opendial.gui.stateviewer.DistributionViewer.java

/**
 * Constructs a new viewer for the given distribution, connected to the state viewer component.
 * //from  w  ww.  j  ava  2  s  .  co  m
 * @param currentState the current dialogue state
 * @param queryVar the variable to display
 * @param viewer the state viewer component
 */
public DistributionViewer(final DialogueState currentState, final String queryVar, final StateViewer viewer) {
    super(viewer.tab.getMainFrame().getFrame(), Dialog.ModalityType.MODELESS);
    setTitle("Distribution Viewer");
    this.queryVar = queryVar;
    update(currentState);

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            super.windowClosing(e);
            viewer.shownDistribs.remove(queryVar);
        }

    });
}

From source file:GCWrapper.java

public CapabilitiesTest(GraphicsDevice dev) {
    super(dev.getDefaultConfiguration());
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent ev) {
            System.exit(0);/*from ww w. ja  v  a  2 s .c  om*/
        }
    });
    initComponents(getContentPane());
    GraphicsConfiguration[] gcs = dev.getConfigurations();
    for (int i = 0; i < gcs.length; i++) {
        gcSelection.addItem(new GCWrapper(gcs[i], i));
    }
    gcSelection.addItemListener(this);
    gcChanged();
}

From source file:SimpleHelp.java

public SimpleHelp(String windowName, String helpIndexFileName) {
    super(windowName + " Help Window");
    cp = getContentPane();//from w  w w .  j  av a 2 s . c om
    getAccessibleContext().setAccessibleName(windowName + " Help Window");
    getAccessibleContext().setAccessibleDescription(
            "A window for viewing the help for " + windowName + ", which is somewhat hyperlinked.");

    try {
        URL url = new File(helpIndexFileName).toURL();
        // Only create the window once.
        if (help == null) {
            // System.out.println("Creat-ing help window for " + url);
            help = new JEditorPane(url);
            // System.out.println("Done!");
            help.setEditable(false);
            help.addHyperlinkListener(this);
            JScrollPane scroller = new JScrollPane();
            scroller.setBorder(BorderFactory.createTitledBorder(windowName + " Help"));
            scroller.getViewport().add(help);
            cp.add(BorderLayout.CENTER, scroller);
            addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                    SimpleHelp.this.setVisible(false);
                    SimpleHelp.this.dispose();
                }
            });
            setSize(500, 400);
        } else {
            System.out.println("Re-using help window!");
        }
    } catch (MalformedURLException e) {
        System.out.println("Malformed URL: " + e);
    } catch (IOException e) {
        System.out.println("IOException: " + e);
    }
}

From source file:com.github.benchdoos.weblocopener.weblocOpener.gui.EditDialog.java

private void initGui(String pathToEditingFile) {
    setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/images/icon96.png")));

    this.path = pathToEditingFile;
    setContentPane(contentPane);/*  ww w. ja v a  2 s . c  o m*/

    getRootPane().setDefaultButton(buttonOK);

    buttonOK.addActionListener(e -> onOK());

    buttonCancel.addActionListener(e -> onCancel());

    // call onCancel() when cross is clicked
    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        @Override
        public void windowActivated(WindowEvent e) {
            if (textField.getText().isEmpty()) {
                fillTextFieldWithClipboard();
            }
            super.windowActivated(e);
        }

        @Override
        public void windowClosing(WindowEvent e) {
            onCancel();
        }
    });

    // call onCancel() on ESCAPE
    contentPane.registerKeyboardAction(e -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    createWeblocFileTextPane.setBackground(new Color(232, 232, 232));

    initTextField(pathToEditingFile);

    pack();

    /*setMinimumSize(getSize());
    setPreferredSize(getSize());*/

    setSize(DEFAULT_APPLICATION_WIDTH, 200);
    setResizable(false); //TODO fix setMaximumSize

    setLocation(FrameUtils.getFrameOnCenterLocationPoint(this));
}

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

private void initGUI(Properties properties) {
    try {/*from w  w  w  .  j  av  a2  s.c  o  m*/
        this.setTitle(APP_TITLE);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                for (MainViewComponent mainViewComponent : mainViews) {
                    if (mainViewComponent instanceof ParrotStateListener) {
                        ((ParrotStateListener) mainViewComponent).parrotExiting();
                    }
                }
            }
        });
        setSize(920, 690);

        getContentPane().setLayout(new BorderLayout());

        UserInterfaceManager uiManager = new UserInterfaceManager(properties);
        navigators = new ArrayList<NavigatorComponent>(4);

        // main view
        listView = uiManager.createMainViewComponent(Style.TABLE);
        graphView = uiManager.createMainViewComponent(Style.GRAPH);
        mainViews.add(listView);
        mainViews.add(graphView);

        final JTabbedPane mainPanel = new JTabbedPane();
        mainPanel.add(graphView.getTitle(), graphView.asJComponent());
        mainPanel.add(listView.getTitle(), listView.asJComponent());

        mainPanel.setSelectedIndex(0);
        activeMainView = graphView;
        mainPanel.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                if (e.getSource() != mainPanel) {
                    return;
                }
                int selectedIndex = mainPanel.getSelectedIndex();
                if (selectedIndex == 0) {
                    activeMainView = graphView;
                } else if (selectedIndex == 1) {
                    activeMainView = listView;
                } else {
                    Logger logger = Logger.getLogger(CombinedParrotApp.class);
                    logger.warn("unknown tab index selected: " + selectedIndex);
                }
            }
        });

        add(mainPanel, BorderLayout.CENTER);

        // navigators
        JToolBar navigatorsBar = new JToolBar(JToolBar.HORIZONTAL);
        navigatorsBar.setMargin(new Insets(0, 11, 0, 0));
        navigatorsBar.setFloatable(false);
        getContentPane().add(navigatorsBar, BorderLayout.PAGE_START);

        // timeline
        NavigatorComponent timelineNavigator = uiManager.createTimelineNavigationComponent();
        navigators.add(timelineNavigator);

        JFrame timelineFrame = new JFrame(timelineNavigator.getNavigatorName() + "  " + APP_TITLE);

        timelineFrame.getContentPane().add(timelineNavigator.asJComponent());
        timelineFrame.pack();
        Point preferredLocation = new Point(0, 0);
        preferredFrameLocations.put(timelineFrame, preferredLocation);

        if (timelineNavigator.hasShowHideListener()) {
            timelineFrame.addComponentListener(timelineNavigator.getShowHideListener());
        }
        timelineFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);

        JToggleButton timelineButton = setupNavigatorButton(timelineNavigator.getNavigatorName(),
                timelineNavigator.getAcceleratorKey(), timelineNavigator);
        navigatorsBar.add(timelineButton);

        // map      
        NavigatorComponent mapNavigator = uiManager.createMapNavigationComponent();
        navigators.add(mapNavigator);

        JFrame mapFrame = new JFrame(mapNavigator.getNavigatorName() + "  " + APP_TITLE);

        mapFrame.getContentPane().add(mapNavigator.asJComponent());
        mapFrame.pack();
        preferredLocation = new Point(0,
                Toolkit.getDefaultToolkit().getScreenSize().height - mapFrame.getHeight());
        preferredFrameLocations.put(mapFrame, preferredLocation);

        if (mapNavigator.hasShowHideListener()) {
            mapFrame.addComponentListener(mapNavigator.getShowHideListener());
        }
        mapFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);

        JToggleButton mapButton = setupNavigatorButton(mapNavigator.getNavigatorName(),
                mapNavigator.getAcceleratorKey(), mapNavigator);
        navigatorsBar.add(mapButton);

        // search      
        NavigatorComponent searchNavigator = uiManager.createSearchComponent();
        navigators.add(searchNavigator);

        JFrame searchFrame = new JFrame(searchNavigator.getNavigatorName() + "  " + APP_TITLE);

        searchFrame.getContentPane().add(searchNavigator.asJComponent());
        searchFrame.pack();
        preferredLocation = new Point(
                Toolkit.getDefaultToolkit().getScreenSize().width - searchFrame.getWidth(), 0);
        preferredFrameLocations.put(searchFrame, preferredLocation);

        if (searchNavigator.hasShowHideListener()) {
            searchFrame.addComponentListener(searchNavigator.getShowHideListener());
        }
        searchFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);

        JToggleButton searchButton = setupNavigatorButton(searchNavigator.getNavigatorName(),
                searchNavigator.getAcceleratorKey(), searchNavigator);
        navigatorsBar.add(searchButton);

        // connections
        NavigatorComponent chainNavigator = uiManager.createChainNavigationComponent();
        navigators.add(chainNavigator);

        if (chainNavigator instanceof PickListener) {
            for (MainViewComponent mainViewComponent : mainViews) {
                mainViewComponent.addPickListener((PickListener) chainNavigator);
            }
        }

        if (chainNavigator.hasShowHideListener()) {
            chainNavigator.asJComponent().addComponentListener(chainNavigator.getShowHideListener());
        }

        JToggleButton connectionsButton = setupNavigatorButton(chainNavigator.getNavigatorName(),
                chainNavigator.getAcceleratorKey(), chainNavigator);
        navigatorsBar.add(connectionsButton);

        add(chainNavigator.asJComponent(), BorderLayout.PAGE_END);
        chainNavigator.asJComponent().setVisible(false);
    } catch (RuntimeException e) {
        e.printStackTrace(System.err);
        System.exit(1);
    } catch (UnknownStyleException e) {
        e.printStackTrace(System.err);
        System.exit(1);
    }
}

From source file:de.atomfrede.tools.evalutation.ui.AppWindow.java

/**
 * Initialize the contents of the frame.
 *///from w  w  w.  ja  va  2 s.  c  om
private void initialize() {
    log.info("Plant Evaluator started");
    frame = new JFrame();

    frame.setIconImage(Icons.IC_APPLICATION_X_LARGE.getImage());

    AppWindow._frame = frame;
    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            if (reallyExit() == JOptionPane.YES_OPTION) {
                SingleInstance.release();
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            }
        }
    });

    frame.setTitle(Messages.getString("AppWindow.0") + " " + Messages.getString("AppWindow.version.code")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    frame.setLocationRelativeTo(null);
    JMenuBar menuBar = new JMenuBar();
    frame.setJMenuBar(menuBar);

    JMenu mnFile = new JMenu(Messages.getString("AppWindow.1")); //$NON-NLS-1$
    menuBar.add(mnFile);

    JMenuItem mntmExit = new JMenuItem(Messages.getString("AppWindow.3")); //$NON-NLS-1$
    mntmExit.setIcon(Icons.IC_LOGOUT_SMALL);
    mntmExit.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            WindowEvent wev = new WindowEvent(frame, WindowEvent.WINDOW_CLOSING);
            Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(wev);

        }
    });
    mnFile.add(mntmExit);

    JMenu mnEdit = new JMenu(Messages.getString("AppWindow.4")); //$NON-NLS-1$
    menuBar.add(mnEdit);

    JMenuItem mntmOptions = new JMenuItem(Messages.getString("AppWindow.5")); //$NON-NLS-1$
    mntmOptions.setIcon(Icons.IC_PREFERENCES_SYSTEM_SMALL);
    mntmOptions.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new OptionsDialog(frame);
        }
    });
    mnEdit.add(mntmOptions);

    JMenu mnTools = new JMenu(Messages.getString("AppWindow.mnTools.text")); //$NON-NLS-1$
    menuBar.add(mnTools);

    JMenuItem mntmPostprocessing = new JMenuItem(Messages.getString("AppWindow.mntmPostprocessing.text")); //$NON-NLS-1$
    mntmPostprocessing.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            // TODO Auto-generated method stub
        }
    });
    mnTools.add(mntmPostprocessing);

    JMenuItem mntmPlot = new JMenuItem(Messages.getString("AppWindow.mntmPlot.text")); //$NON-NLS-1$
    mntmPlot.setIcon(Icons.IC_TOOL_PLOT_SMALL);
    mntmPlot.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            DialogUtil.getInstance().showPlotTypeSelection();
        }
    });

    mnTools.add(mntmPlot);

    JMenu mnHelp = new JMenu(Messages.getString("AppWindow.6")); //$NON-NLS-1$
    menuBar.add(mnHelp);

    JMenuItem mntmAbout = new JMenuItem(Messages.getString("AppWindow.7")); //$NON-NLS-1$
    mntmAbout.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            try {
                new AboutDialog(frame);
            } catch (URISyntaxException e) {
                // TODO Auto-generated catch block

                e.printStackTrace();
            }
        }
    });
    mnHelp.add(mntmAbout);

    createContent();

    DialogUtil.getInstance().setMainFrame(frame);

}

From source file:com.frostwire.gui.bittorrent.PartialFilesDialog.java

public PartialFilesDialog(JFrame frame, TOTorrent torrent, String name) throws TOTorrentException {
    super(frame, I18n.tr("Select files to download"));

    this._torrent = torrent;

    this._name = name;
    _model = new TorrentTableModel(_torrent);

    addWindowListener(new WindowAdapter() {
        @Override//w w w .jav  a 2 s  .  com
        public void windowOpened(WindowEvent e) {
            GUIMediator.instance().setRemoteDownloadsAllowed(false);
        }

        @Override
        public void windowClosing(WindowEvent e) {
            GUIMediator.instance().setRemoteDownloadsAllowed(true);
        }
    });

    setupUI();
    setLocationRelativeTo(frame);
}