Search in sources :

Example 81 with WindowAdapter

use of java.awt.event.WindowAdapter in project gephi by gephi.

the class DataLaboratoryHelper method executeManipulator.

/**
     * Prepares the dialog UI of a manipulator if it has one and executes the manipulator in a separate
     * Thread when the dialog is accepted or directly if there is no UI.
     * @param m Manipulator to execute
     */
public void executeManipulator(final Manipulator m) {
    if (m.canExecute()) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                final ManipulatorUI ui = m.getUI();
                //Show a dialog for the manipulator UI if it provides one. If not, execute the manipulator directly:
                if (ui != null) {
                    final JButton okButton = new JButton(NbBundle.getMessage(DataLaboratoryHelper.class, "DataLaboratoryHelper.ui.okButton.text"));
                    DialogControls dialogControls = new DialogControlsImpl(okButton);
                    ui.setup(m, dialogControls);
                    JPanel settingsPanel = ui.getSettingsPanel();
                    DialogDescriptor dd = new DialogDescriptor(settingsPanel, NbBundle.getMessage(DataLaboratoryHelper.class, "SettingsPanel.title", ui.getDisplayName()), ui.isModal(), new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            if (e.getSource().equals(okButton)) {
                                ui.unSetup();
                                executeManipulatorInOtherThread(m);
                            } else {
                                ui.unSetup();
                            }
                        }
                    });
                    dd.setOptions(new Object[] { okButton, DialogDescriptor.CANCEL_OPTION });
                    //All options close
                    dd.setClosingOptions(null);
                    Dialog dialog = DialogDisplayer.getDefault().createDialog(dd);
                    dialog.addWindowListener(new WindowAdapter() {

                        @Override
                        public void windowClosing(WindowEvent e) {
                            ui.unSetup();
                        }
                    });
                    dialog.setVisible(true);
                } else {
                    executeManipulatorInOtherThread(m);
                }
            }
        });
    }
}
Also used : JPanel(javax.swing.JPanel) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) WindowAdapter(java.awt.event.WindowAdapter) ActionListener(java.awt.event.ActionListener) AttributeColumnsManipulatorUI(org.gephi.datalab.spi.columns.AttributeColumnsManipulatorUI) ManipulatorUI(org.gephi.datalab.spi.ManipulatorUI) Dialog(java.awt.Dialog) WindowEvent(java.awt.event.WindowEvent) DialogDescriptor(org.openide.DialogDescriptor) DialogControls(org.gephi.datalab.spi.DialogControls)

Example 82 with WindowAdapter

use of java.awt.event.WindowAdapter in project jmonkeyengine by jMonkeyEngine.

the class JoglDisplay method applySettings.

protected void applySettings(AppSettings settings) {
    final boolean isDisplayModeModified;
    final GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    // Get the current display mode
    final DisplayMode previousDisplayMode = gd.getDisplayMode();
    // Handle full screen mode if requested.
    if (settings.isFullscreen()) {
        frame.setUndecorated(true);
        // Check if the full-screen mode is supported by the OS
        boolean isFullScreenSupported = gd.isFullScreenSupported();
        if (isFullScreenSupported) {
            gd.setFullScreenWindow(frame);
            // Check if display mode changes are supported by the OS
            if (gd.isDisplayChangeSupported()) {
                // Get all available display modes
                final DisplayMode[] displayModes = gd.getDisplayModes();
                DisplayMode multiBitsDepthSupportedDisplayMode = null;
                DisplayMode refreshRateUnknownDisplayMode = null;
                DisplayMode multiBitsDepthSupportedAndRefreshRateUnknownDisplayMode = null;
                DisplayMode matchingDisplayMode = null;
                DisplayMode currentDisplayMode;
                // that matches exactly with your parameters
                for (int i = 0; i < displayModes.length && matchingDisplayMode == null; i++) {
                    currentDisplayMode = displayModes[i];
                    if (currentDisplayMode.getWidth() == settings.getWidth() && currentDisplayMode.getHeight() == settings.getHeight()) {
                        if (currentDisplayMode.getBitDepth() == settings.getBitsPerPixel()) {
                            if (currentDisplayMode.getRefreshRate() == settings.getFrequency()) {
                                matchingDisplayMode = currentDisplayMode;
                            } else if (currentDisplayMode.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN) {
                                refreshRateUnknownDisplayMode = currentDisplayMode;
                            }
                        } else if (currentDisplayMode.getBitDepth() == DisplayMode.BIT_DEPTH_MULTI) {
                            if (currentDisplayMode.getRefreshRate() == settings.getFrequency()) {
                                multiBitsDepthSupportedDisplayMode = currentDisplayMode;
                            } else if (currentDisplayMode.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN) {
                                multiBitsDepthSupportedAndRefreshRateUnknownDisplayMode = currentDisplayMode;
                            }
                        }
                    }
                }
                DisplayMode nextDisplayMode = null;
                if (matchingDisplayMode != null) {
                    nextDisplayMode = matchingDisplayMode;
                } else if (multiBitsDepthSupportedDisplayMode != null) {
                    nextDisplayMode = multiBitsDepthSupportedDisplayMode;
                } else if (refreshRateUnknownDisplayMode != null) {
                    nextDisplayMode = refreshRateUnknownDisplayMode;
                } else if (multiBitsDepthSupportedAndRefreshRateUnknownDisplayMode != null) {
                    nextDisplayMode = multiBitsDepthSupportedAndRefreshRateUnknownDisplayMode;
                } else {
                    isFullScreenSupported = false;
                }
                // with the input parameters, use it
                if (nextDisplayMode != null) {
                    gd.setDisplayMode(nextDisplayMode);
                    isDisplayModeModified = true;
                } else {
                    isDisplayModeModified = false;
                }
            } else {
                isDisplayModeModified = false;
                // Resize the canvas if the display mode cannot be changed
                // and the screen size is not equal to the canvas size
                final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
                if (screenSize.width != settings.getWidth() || screenSize.height != settings.getHeight()) {
                    canvas.setSize(screenSize);
                }
            }
        } else {
            isDisplayModeModified = false;
        }
        // Software windowed full-screen mode
        if (!isFullScreenSupported) {
            final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            // Resize the canvas
            canvas.setSize(screenSize);
            // Resize the frame so that it occupies the whole screen
            frame.setSize(screenSize);
            // Set its location at the top left corner
            frame.setLocation(0, 0);
        }
    } else // Otherwise, center the window on the screen.
    {
        isDisplayModeModified = false;
        frame.pack();
        int x, y;
        x = (Toolkit.getDefaultToolkit().getScreenSize().width - settings.getWidth()) / 2;
        y = (Toolkit.getDefaultToolkit().getScreenSize().height - settings.getHeight()) / 2;
        frame.setLocation(x, y);
    }
    frame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent evt) {
            // If required, restore the previous display mode
            if (isDisplayModeModified) {
                gd.setDisplayMode(previousDisplayMode);
            }
            // If required, get back to the windowed mode
            if (gd.getFullScreenWindow() == frame) {
                gd.setFullScreenWindow(null);
            }
            windowCloseRequest.set(true);
        }

        @Override
        public void windowActivated(WindowEvent evt) {
            active.set(true);
        }

        @Override
        public void windowDeactivated(WindowEvent evt) {
            active.set(false);
        }
    });
    logger.log(Level.FINE, "Selected display mode: {0}x{1}x{2} @{3}", new Object[] { gd.getDisplayMode().getWidth(), gd.getDisplayMode().getHeight(), gd.getDisplayMode().getBitDepth(), gd.getDisplayMode().getRefreshRate() });
}
Also used : DisplayMode(java.awt.DisplayMode) GraphicsDevice(java.awt.GraphicsDevice) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter) Dimension(java.awt.Dimension)

Example 83 with WindowAdapter

use of java.awt.event.WindowAdapter in project groovy-core by groovy.

the class Main method doTreeAction.

public static void doTreeAction(String f, AST t, String[] tokenNames) {
    if (t == null)
        return;
    if (showTree) {
        CommonAST.setVerboseStringConversion(true, tokenNames);
        ASTFactory factory = new ASTFactory();
        AST r = factory.create(0, "AST ROOT");
        r.setFirstChild(t);
        final ASTFrame frame = new ASTFrame("Groovy AST", r);
        frame.setVisible(true);
        frame.addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent e) {
                // hide the Frame
                frame.setVisible(false);
                frame.dispose();
                System.exit(0);
            }
        });
        if (verbose)
            System.out.println(t.toStringList());
    }
/*if ( xml ) {
            ((CommonAST)t).setVerboseStringConversion(true, tokenNames);
            ASTFactory factory = new ASTFactory();
            AST r = factory.create(0,"AST ROOT");
            r.setFirstChild(t);
            XStream xstream = new XStream();
            xstream.alias("ast", CommonAST.class);
            try {
                xstream.toXML(r,new FileWriter(f + ".xml"));
                System.out.println("Written AST to " + f + ".xml");
            } catch (Exception e) {
                System.out.println("couldn't write to " + f + ".xml");
                e.printStackTrace();
            }
            //if (verbose)  System.out.println(t.toStringList());
        }*/
/*@todo
        GroovyTreeParser tparse = new GroovyTreeParser();
        try {
            tparse.compilationUnit(t);
            if (verbose)  System.out.println("successful walk of result AST for "+f);
        }
        catch (RecognitionException e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
        }
    @todo*/
}
Also used : AST(antlr.collections.AST) CommonAST(antlr.CommonAST) ASTFrame(antlr.debug.misc.ASTFrame) ASTFactory(antlr.ASTFactory) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter)

Example 84 with WindowAdapter

use of java.awt.event.WindowAdapter in project gradle by gradle.

the class Application method setupUI.

private void setupUI() {
    frame = new JFrame("Gradle");
    JPanel mainPanel = new JPanel(new BorderLayout());
    frame.getContentPane().add(mainPanel);
    mainPanel.add(singlePaneUIInstance.getComponent());
    mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    singlePaneUIInstance.aboutToShow();
    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    frame.addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent e) {
            close();
        }
    });
    frame.setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
    frame.setLocationByPlatform(true);
}
Also used : WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter)

Example 85 with WindowAdapter

use of java.awt.event.WindowAdapter in project gradle by gradle.

the class ProjectAndTaskFilterDialog method setupUI.

private void setupUI() {
    mainPanel = new JPanel(new BorderLayout());
    dialog.getContentPane().add(mainPanel);
    mainPanel.add(createOptionsPanel(), BorderLayout.NORTH);
    mainPanel.add(createCenterPanel(), BorderLayout.CENTER);
    mainPanel.add(createOkCancelPanel(), BorderLayout.SOUTH);
    mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    dialog.addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent e) {
            close(false);
        }
    });
    dialog.setSize(600, 750);
    dialog.setLocationRelativeTo(dialog.getParent());
}
Also used : WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter)

Aggregations

WindowAdapter (java.awt.event.WindowAdapter)143 WindowEvent (java.awt.event.WindowEvent)140 JPanel (javax.swing.JPanel)40 JButton (javax.swing.JButton)36 JFrame (javax.swing.JFrame)34 BorderLayout (java.awt.BorderLayout)32 Dimension (java.awt.Dimension)30 JLabel (javax.swing.JLabel)26 JScrollPane (javax.swing.JScrollPane)25 ActionEvent (java.awt.event.ActionEvent)22 ActionListener (java.awt.event.ActionListener)20 FlowLayout (java.awt.FlowLayout)18 GridBagConstraints (java.awt.GridBagConstraints)18 GridBagLayout (java.awt.GridBagLayout)18 Insets (java.awt.Insets)14 Frame (java.awt.Frame)13 Container (java.awt.Container)12 JTextArea (javax.swing.JTextArea)12 JDialog (javax.swing.JDialog)11 IOException (java.io.IOException)9