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:org.obiba.onyx.jade.instrument.summitdoppler.VantageABIInstrumentRunner.java

protected void buildGUI() {

    appWindow.setAlwaysOnTop(true);/*from  ww w. ja  v a  2 s  . com*/
    appWindow.setResizable(false);
    appWindow.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

    appWindow.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            confirmOnExit();
        }
    });

    appWindow.add(buildMainPanel(), BorderLayout.CENTER);

    appWindow.pack();
    appWindow.setSize(appWindowWidth, appWindowHeight);

    // Display the GUI in the middle of the screen.
    Dimension SCREEN_SIZE = Toolkit.getDefaultToolkit().getScreenSize();
    appWindow.setLocation(SCREEN_SIZE.width / 2 - appWindowWidth / 2,
            SCREEN_SIZE.height / 2 - appWindowHeight / 2);

    appWindow.setVisible(true);
}

From source file:com.isecpartners.gizmo.FourthIdea.java

private void init(final BlobScroller scroller, String str, final AbstractAction action) {
    this.scroller = scroller;
    this.reqText = str;
    if (System.getProperty("os.name").toUpperCase().contains("WINDOWS")) {
        defaultShellField.setText("cmd.exe /c");
    } else {/*w ww .  ja v  a2  s . c  o m*/
        defaultShellField.setText("sh -c");
    }
    this.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            action.actionPerformed(null);
        }
    });

    command_translation = new Properties();
    try {
        command_translation.load(new FileInputStream(command_map_file_name));
    } catch (IOException ex) {
        try {
            FileOutputStream fout = new FileOutputStream(command_map_file_name);
            fout.write("".getBytes());
            fout.close();
        } catch (IOException ex1) {
        }

        GizmoView.log("couldn't find " + command_map_file_name + ".. turning off macro translation");
    }
    jTextPane1.setText(str);
    jTextPane1.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            "esc");
    jTextPane1.getActionMap().put("esc", action);

}

From source file:MyJava3D.java

public MyJava3D() {
    // load the object file
    Scene scene = null;/*from  ww w  . jav  a2s.  c  o  m*/
    Shape3D shape = null;

    // read in the geometry information from the data file
    ObjectFile objFileloader = new ObjectFile(ObjectFile.RESIZE);

    try {
        scene = objFileloader.load("hand1.obj");
    } catch (Exception e) {
        scene = null;
        System.err.println(e);
    }

    if (scene == null)
        System.exit(1);

    // retrieve the Shape3D object from the scene
    BranchGroup branchGroup = scene.getSceneGroup();
    shape = (Shape3D) branchGroup.getChild(0);

    GeometryArray geometryArray = (GeometryArray) shape.getGeometry();

    // add the geometry to the rendering engine...
    renderingEngine.addGeometry(geometryArray);

    // create a rendering surface and bind the rendering engine
    renderingSurface = new RenderingSurface(renderingEngine, geometryUpdater);

    // start the rendering surface and add it to the content panel
    renderingSurface.start();
    getContentPane().add(renderingSurface);

    // disable automatic close support for Swing frame.
    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);

    // adds the window listener
    addWindowListener(new WindowAdapter() {
        // handles the system exit window message
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
}

From source file:com.sshtools.sshterm.SshTermFullScreenWindowContainer.java

public void init(final SshToolsApplication application, SshToolsApplicationPanel panel)
        throws SshToolsApplicationException {
    //    getContentPane().invalidate();
    invalidate();/* w  w w  .  j av  a2 s  . c om*/
    try {
        Method m = getClass().getMethod("setUndecorated", new Class[] { boolean.class });
        m.invoke(this, new Object[] { Boolean.TRUE });
    } catch (Exception e) {
        e.printStackTrace();
    }
    this.panel = panel;
    this.application = application;
    // We dont want the status bar, menu bar or tool bar showing in full screen mode by default
    ((SshTerminalPanel) panel).setToolsVisible(false);
    panel.registerActionMenu(new SshToolsApplicationPanel.ActionMenu("File", "File", 'f', 0));
    panel.registerAction(exitAction = new ExitAction(application, this));
    panel.registerAction(newWindowAction = new NewWindowAction(application));
    panel.registerAction(aboutAction = new AboutAction(this, application));
    panel.registerAction(changelogAction = new ChangelogAction(this, application));
    panel.registerAction(faqAction = new FAQAction());
    panel.registerAction(beginnerAction = new BeginnerAction());
    panel.registerAction(advancedAction = new AdvancedAction());
    panel.registerAction(fullScreenAction = new FullScreenActionImpl(application, this));
    getApplicationPanel().rebuildActionComponents();
    JPanel p = new JPanel(new BorderLayout());
    if (panel.getToolBar() != null) {
        JPanel t = new JPanel(new BorderLayout());
        t.add(panel.getToolBar(), BorderLayout.NORTH);
        t.add(toolSeperator = new JSeparator(JSeparator.HORIZONTAL), BorderLayout.SOUTH);
        final SshToolsApplicationPanel pnl = panel;
        panel.getToolBar().addComponentListener(new ComponentAdapter() {
            public void componentHidden(ComponentEvent evt) {
                log.debug("Tool separator is now " + pnl.getToolBar().isVisible());
                toolSeperator.setVisible(pnl.getToolBar().isVisible());
            }
        });
        p.add(t, BorderLayout.NORTH);
    }
    p.add(panel, BorderLayout.CENTER);
    if (panel.getStatusBar() != null) {
        p.add(panel.getStatusBar(), BorderLayout.SOUTH);
    }
    JPanel x = new JPanel(new BorderLayout());
    x.add(((SshTerminalPanel) panel).getJMenuBar(), BorderLayout.NORTH);
    x.add(p, BorderLayout.CENTER);
    getContentPane().setLayout(new GridLayout(1, 1));
    getContentPane().add(x);
    // Watch for the frame closing
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent evt) {
            application.closeContainer(SshTermFullScreenWindowContainer.this);
        }
    });
    validate();
}

From source file:MemoryMonitor.java

public static void main(String s[]) {
    final MemoryMonitor demo = new MemoryMonitor();
    WindowListener l = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);/*w  w  w.j a  v a 2s . co  m*/
        }

        public void windowDeiconified(WindowEvent e) {
            demo.surf.start();
        }

        public void windowIconified(WindowEvent e) {
            demo.surf.stop();
        }
    };
    JFrame f = new JFrame("MemoryMonitor");
    f.addWindowListener(l);
    f.getContentPane().add("Center", demo);
    f.pack();
    f.setSize(new Dimension(400, 500));
    f.setVisible(true);
    demo.surf.start();
    Thread thr = new Thread(new Memeater());
    thr.start();
}

From source file:es.emergya.ui.gis.popups.ListaCapas.java

private ListaCapas(CustomMapView mapView, final IMapViewer historyMapViewer) {
    super();//from  ww w. ja va  2 s .  c o m
    setTitle(i18n.getString("window.gpx.titleBar"));
    setLocationRelativeTo(getBasicWindow().getFrame());
    setResizable(false);
    setAlwaysOnTop(true);
    this.mapView = mapView;
    this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
    setIconImage(getBasicWindow().getFrame().getIconImage());
    JPanel dialogo = new JPanel(new BorderLayout());
    dialogo.setBackground(Color.WHITE);
    dialogo.setBorder(new EmptyBorder(10, 10, 10, 10));

    capasGpx = new JPanel();
    capasGpx.setBackground(Color.WHITE);
    capasGpx.setLayout(new BoxLayout(capasGpx, BoxLayout.Y_AXIS));

    JScrollPane lista = new JScrollPane(capasGpx);
    lista.setOpaque(false);
    lista.setBorder(new TitledBorder(i18n.getString("window.gpx.title")));
    dialogo.add(lista, BorderLayout.CENTER);

    JPanel boton = new JPanel(new FlowLayout());
    boton.setOpaque(false);
    JButton cargar = getCargarGPXButton();
    boton.add(cargar, FlowLayout.LEFT);
    dialogo.add(boton, BorderLayout.SOUTH);

    add(dialogo);
    setPreferredSize(new Dimension(400, 250));
    pack();
    setLocationRelativeTo((Component) mapView);

    this.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            super.windowClosed(e);
            // historyMapViewer.getGPXButton().setSelected(false);
        }
    });

}

From source file:com.igormaznitsa.sciareto.ui.MainFrame.java

public MainFrame(@Nonnull @MustNotContainNull final String... args) {
    super();//from  www. ja v  a 2s. c  om
    initComponents();

    this.stackPanel = new JPanel();
    this.stackPanel.setFocusable(false);
    this.stackPanel.setOpaque(false);
    this.stackPanel.setBorder(BorderFactory.createEmptyBorder(32, 32, 16, 32));
    this.stackPanel.setLayout(new BoxLayout(this.stackPanel, BoxLayout.Y_AXIS));

    final JPanel glassPanel = (JPanel) this.getGlassPane();
    glassPanel.setOpaque(false);

    this.setGlassPane(glassPanel);

    glassPanel.setLayout(new BorderLayout(8, 8));
    glassPanel.add(Box.createGlue(), BorderLayout.CENTER);

    final JPanel ppanel = new JPanel(new BorderLayout(0, 0));
    ppanel.setFocusable(false);
    ppanel.setOpaque(false);
    ppanel.setCursor(null);
    ppanel.add(this.stackPanel, BorderLayout.SOUTH);

    glassPanel.add(ppanel, BorderLayout.EAST);

    this.stackPanel.add(Box.createGlue());

    glassPanel.setVisible(false);

    this.setTitle("Scia Reto");

    setIconImage(UiUtils.loadImage("logo256x256.png"));

    this.stateless = args.length > 0;

    final MainFrame theInstance = this;

    this.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(@Nonnull final WindowEvent e) {
            if (doClosing()) {
                dispose();
            }
        }
    });

    this.tabPane = new EditorTabPane(this);

    this.explorerTree = new ExplorerTree(this);

    final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    splitPane.setOneTouchExpandable(true);
    splitPane.setDividerLocation(250);
    splitPane.setResizeWeight(0.0d);
    splitPane.setLeftComponent(this.explorerTree);
    splitPane.setRightComponent(this.tabPane);

    add(splitPane, BorderLayout.CENTER);

    this.menuOpenRecentProject.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            final File[] lastOpenedProjects = FileHistoryManager.getInstance().getLastOpenedProjects();
            if (lastOpenedProjects.length > 0) {
                for (final File folder : lastOpenedProjects) {
                    final JMenuItem item = new JMenuItem(folder.getName());
                    item.setToolTipText(folder.getAbsolutePath());
                    item.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            openProject(folder, false);
                        }
                    });
                    menuOpenRecentProject.add(item);
                }
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {
            menuOpenRecentProject.removeAll();
        }

        @Override
        public void menuCanceled(MenuEvent e) {
        }
    });

    this.menuOpenRecentFile.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            final File[] lastOpenedFiles = FileHistoryManager.getInstance().getLastOpenedFiles();
            if (lastOpenedFiles.length > 0) {
                for (final File file : lastOpenedFiles) {
                    final JMenuItem item = new JMenuItem(file.getName());
                    item.setToolTipText(file.getAbsolutePath());
                    item.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            openFileAsTab(file);
                        }
                    });
                    menuOpenRecentFile.add(item);
                }
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {
            menuOpenRecentFile.removeAll();
        }

        @Override
        public void menuCanceled(MenuEvent e) {
        }
    });

    if (!this.stateless) {
        restoreState();
    } else {
        boolean openedProject = false;
        for (final String filePath : args) {
            final File file = new File(filePath);
            if (file.isDirectory()) {
                openedProject = true;
                openProject(file, true);
            } else if (file.isFile()) {
                openFileAsTab(file);
            }
        }
        if (!openedProject) {
            //TODO try to hide project panel!
        }
    }

    final LookAndFeel current = UIManager.getLookAndFeel();
    final ButtonGroup lfGroup = new ButtonGroup();
    final String currentLFClassName = current.getClass().getName();
    for (final UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        final JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(info.getName());
        lfGroup.add(menuItem);
        if (currentLFClassName.equals(info.getClassName())) {
            menuItem.setSelected(true);
        }
        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(@Nonnull final ActionEvent e) {
                try {
                    UIManager.setLookAndFeel(info.getClassName());
                    SwingUtilities.updateComponentTreeUI(theInstance);
                    PreferencesManager.getInstance().getPreferences().put(Main.PROPERTY_LOOKANDFEEL,
                            info.getClassName());
                    PreferencesManager.getInstance().flush();
                } catch (Exception ex) {
                    LOGGER.error("Can't change LF", ex);
                }
            }
        });
        this.menuLookAndFeel.add(menuItem);
    }
}

From source file:com.diversityarrays.kdxplore.curate.fieldview.InterceptFieldLayoutView.java

public void openFieldLayoutView(Component trigger, String title,
        @SuppressWarnings("rawtypes") MutableComboBoxModel comboBoxModel, CurationData curationData,
        CurationTableModel curationTableModel, SelectedValueStore selectedValueStore,
        PlotCellChoicesPanel plotCellChoicesPanel, JPopupMenu popuMenu, Font smallFont,
        Action curationHelpAction, MessagePrinter messages, Closure<String> selectionClosure,
        CurationContext curationContext, CurationMenuProvider curationMenuProvider,

        FieldLayoutTableModel fieldLayoutTableModel, CellSelectableTable fieldLayoutTable,
        FieldViewSelectionModel fieldViewSelectionModel,

        JButton undockButton) {/*from  w w w . ja  v  a  2 s . co m*/
    if (fieldLayoutFrame != null) {
        fieldLayoutFrame.toFront();
        return;
    }

    JCheckBox alwaysOnTopOption = new JCheckBox(Msg.OPTION_KEEP_ON_TOP(), true);

    viewPanel = new FieldLayoutViewPanel(comboBoxModel, alwaysOnTopOption, curationData, curationTableModel,
            selectedValueStore, plotCellChoicesPanel, popuMenu, smallFont, curationHelpAction, messages,
            selectionClosure, curationContext, curationMenuProvider,

            fieldLayoutTableModel, fieldLayoutTable, fieldViewSelectionModel,

            undockButton);

    viewPanel.addRefreshListener(refreshListener);

    viewPanel.addTraitInstanceSelectionListener(itemListener);
    viewPanel.addCellSelectionListener(cellSelectionListener);

    fieldLayoutFrame = new JFrame(title);
    fieldLayoutFrame.setAlwaysOnTop(alwaysOnTopOption.isSelected());
    fieldLayoutFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    fieldLayoutFrame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowOpened(WindowEvent e) {
            viewPanel.doPostOpenActions();
        }

        @Override
        public void windowClosed(WindowEvent e) {
            try {
                viewPanel.removeCellSelectionListener(cellSelectionListener);
            } finally {
                fieldLayoutFrame.removeWindowListener(this);
                fieldLayoutFrame = null;
            }
        }
    });
    fieldLayoutFrame.setContentPane(viewPanel);
    fieldLayoutFrame.pack();
    fieldLayoutFrame.setLocationRelativeTo(trigger);
    fieldLayoutFrame.setVisible(true);
    fieldLayoutFrame.toFront();

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

From source file:com.sshtools.appframework.ui.SshToolsApplicationFrame.java

/**
 * @param application//w  w  w. ja  v  a2  s.  c  om
 * @param panel
 * 
 * @throws SshToolsApplicationException
 */

public void init(final SshToolsApplication application, SshToolsApplicationPanel panel)
        throws SshToolsApplicationException {
    log.debug("Initialising frame");
    this.panel = panel;
    this.application = application;
    if (application != null) {
        setTitle(application.getApplicationName() + " - " + application.getApplicationVersion());
    }
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    // Register the File menu
    panel.registerActionMenu(new ActionMenu("File", "File", 'f', 0));
    // Register the Exit action
    if (showExitAction && application != null) {
        panel.registerAction(exitAction = new ExitAction(application, this));
        // Register the New Window Action
    }
    if (showNewWindowAction && application != null) {
        panel.registerAction(newWindowAction = new NewWindowAction(application));
        // Register the Help menu
    }
    panel.registerActionMenu(new ActionMenu("Help", "Help", 'h', 99));
    // Register the About box action
    if (showAboutBox && application != null) {
        panel.registerAction(aboutAction = new AboutAction(this, application));
    }

    getApplicationPanel().rebuildActionComponents();
    // JPanel p = new JPanel(new ToolBarLayout());
    JPanel p = new JPanel(new BorderLayout(0, 0));
    JPanel center = new JPanel(new BorderLayout(0, 0));
    if (panel.getJMenuBar() != null) {
        setJMenuBar(panel.getJMenuBar());
    }

    if (panel.getToolBar() != null) {
        // center.add(toolSeparator = new JSeparator(JSeparator.HORIZONTAL),
        // BorderLayout.NORTH);
        // toolSeparator.setVisible(panel.getToolBar().isVisible());
        // panel.getToolBar().addComponentListener(new ComponentAdapter() {
        // public void componentShown(ComponentEvent e) {
        // toolSeparator.setVisible(SshToolsApplicationFrame.this.panel.getToolBar().isVisible());
        // }
        //
        // public void componentHidden(ComponentEvent e) {
        // toolSeparator.setVisible(SshToolsApplicationFrame.this.panel.getToolBar().isVisible());
        // }
        //
        // });
        final SshToolsApplicationPanel pnl = panel;
        panel.getToolBar().addComponentListener(new ComponentAdapter() {

            public void componentHidden(ComponentEvent evt) {
                // toolSeparator.setVisible(pnl.getToolBar().isVisible());

            }

        });
        p.add(panel.getToolBar(), BorderLayout.NORTH);
    }
    center.add(panel, BorderLayout.CENTER);
    p.add(center, BorderLayout.CENTER);
    getContentPane().setLayout(new GridLayout(1, 1, 0, 0));
    getContentPane().add(p);
    // Watch for the frame closing
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent evt) {
            if (application != null) {
                application.closeContainer(SshToolsApplicationFrame.this);
            } else {
                int confirm = JOptionPane.showOptionDialog(SshToolsApplicationFrame.this,
                        "Close " + getTitle() + "?", "Close Operation", JOptionPane.YES_NO_OPTION,
                        JOptionPane.QUESTION_MESSAGE, null, null, null);
                if (confirm == 0) {
                    hide();
                }
            }

        }

    });
    // If this is the first frame, center the window on the screen
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    boolean found = false;
    if (application != null && application.getContainerCount() != 0) {
        for (int i = 0; (i < application.getContainerCount()) && !found; i++) {
            SshToolsApplicationContainer c = application.getContainerAt(i);
            if (c instanceof SshToolsApplicationFrame) {
                SshToolsApplicationFrame f = (SshToolsApplicationFrame) c;
                setSize(f.getSize());
                Point newLocation = new Point(f.getX(), f.getY());
                newLocation.x += 48;
                newLocation.y += 48;
                if (newLocation.x > (screenSize.getWidth() - 64)) {
                    newLocation.x = 0;
                }
                if (newLocation.y > (screenSize.getHeight() - 64)) {
                    newLocation.y = 0;
                }
                setLocation(newLocation);
                found = true;
            }
        }
    }
    if (!found) {
        // Is there a previous stored geometry we can use?
        if (PreferencesStore.preferenceExists(PREF_LAST_FRAME_GEOMETRY)) {
            setBounds(PreferencesStore.getRectangle(PREF_LAST_FRAME_GEOMETRY, getBounds()));
        } else {
            pack();
            setSize(800, 600);
            UIUtil.positionComponent(SwingConstants.CENTER, this);
        }
    }
    log.debug("Initialisation of frame complete");
}

From source file:cloud.gui.CloudGUI.java

private void addWindowListener() {
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            while (model.getRowCount() != 0) {
                instances.getSelectionModel().setSelectionInterval(0, 0);
                killSelectedInstances();
            }//from  w w w.  jav  a2 s . c o  m
            System.exit(0); //
        }
    });
}