Search in sources :

Example 31 with WindowAdapter

use of java.awt.event.WindowAdapter in project ACS by ACS-Community.

the class SysPropEditor method openFrame.

public static JFrame openFrame(final SysPropEditor inst) {
    // frame
    final JFrame f = new JFrame(SysPropEditor.class.getName());
    f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    f.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent evt) {
            int answer = JOptionPane.showConfirmDialog(f, "Really close?", "Close Window", JOptionPane.YES_NO_OPTION);
            if (answer == JOptionPane.YES_OPTION) {
                f.setVisible(false);
                f.dispose();
            }
        }
    });
    f.getContentPane().add(inst);
    f.pack();
    f.setVisible(true);
    return f;
}
Also used : JFrame(javax.swing.JFrame) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter)

Example 32 with WindowAdapter

use of java.awt.event.WindowAdapter in project ACS by ACS-Community.

the class LogManagerGui method openFrame.

//
// =============  Stand-Alone Launch==================
//
public static JFrame openFrame(final LogManagerGui inst) {
    // frame
    final JFrame f = new JFrame(LogManagerGui.class.getName());
    f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    f.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent evt) {
            int answer = JOptionPane.showConfirmDialog(f, "Really close?", "Close Window", JOptionPane.YES_NO_OPTION);
            if (answer == JOptionPane.YES_OPTION) {
                f.setVisible(false);
                f.dispose();
            }
        }
    });
    f.getContentPane().add(inst);
    f.pack();
    f.setVisible(true);
    return f;
}
Also used : JFrame(javax.swing.JFrame) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter)

Example 33 with WindowAdapter

use of java.awt.event.WindowAdapter in project jdk8u_jdk by JetBrains.

the class NoResizeEventOnDMChangeTest method testFSWindow.

private static void testFSWindow(final GraphicsDevice gd, final DisplayMode[] dms, final Window fsWin) {
    System.out.println("Testing FS window: " + fsWin);
    Component c = new Canvas() {

        @Override
        public void paint(Graphics g) {
            g.setColor(Color.blue);
            g.fillRect(0, 0, getWidth(), getHeight());
            g.setColor(Color.magenta);
            g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
            g.setColor(Color.red);
            g.drawString("FS Window   : " + fsWin, 50, 50);
            DisplayMode dm = getGraphicsConfiguration().getDevice().getDisplayMode();
            g.drawString("Display Mode: " + dm.getWidth() + "x" + dm.getHeight(), 50, 75);
        }
    };
    fsWin.add("Center", c);
    fsWin.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            fsWin.dispose();
            if (fsWin.getOwner() != null) {
                fsWin.getOwner().dispose();
            }
        }
    });
    try {
        EventQueue.invokeAndWait(new Runnable() {

            public void run() {
                gd.setFullScreenWindow(fsWin);
            }
        });
    } catch (Exception ex) {
    }
    sleep(1000);
    final ResizeEventChecker r1 = new ResizeEventChecker();
    final ResizeEventChecker r2 = new ResizeEventChecker();
    if (gd.isDisplayChangeSupported()) {
        fsWin.addComponentListener(r1);
        c.addComponentListener(r2);
        for (final DisplayMode dm1 : dms) {
            try {
                EventQueue.invokeAndWait(new Runnable() {

                    public void run() {
                        System.err.printf("----------- Setting DM %dx%d:\n", dm1.getWidth(), dm1.getHeight());
                        try {
                            gd.setDisplayMode(dm1);
                            r1.incDmChanges();
                            r2.incDmChanges();
                        } catch (IllegalArgumentException iae) {
                        }
                    }
                });
            } catch (Exception ex) {
            }
            for (int i = 0; i < 3; i++) {
                fsWin.repaint();
                sleep(1000);
            }
        }
        fsWin.removeComponentListener(r1);
        c.removeComponentListener(r2);
    }
    try {
        EventQueue.invokeAndWait(new Runnable() {

            public void run() {
                gd.setFullScreenWindow(null);
                fsWin.dispose();
                if (fsWin.getOwner() != null) {
                    fsWin.getOwner().dispose();
                }
            }
        });
    } catch (Exception ex) {
    }
    System.out.printf("FS Window: resizes=%d, dm changes=%d\n", r1.getResizes(), r1.getDmChanges());
    System.out.printf("Component: resizes=%d, dm changes=%d\n", r2.getResizes(), r2.getDmChanges());
    if (r1.getResizes() < r1.getDmChanges()) {
        throw new RuntimeException("FS Window didn't receive all resizes!");
    }
    if (r2.getResizes() < r2.getDmChanges()) {
        throw new RuntimeException("Component didn't receive all resizes!");
    }
}
Also used : Canvas(java.awt.Canvas) WindowAdapter(java.awt.event.WindowAdapter) Graphics(java.awt.Graphics) DisplayMode(java.awt.DisplayMode) WindowEvent(java.awt.event.WindowEvent) Component(java.awt.Component)

Example 34 with WindowAdapter

use of java.awt.event.WindowAdapter in project jdk8u_jdk by JetBrains.

the class TooMuchWheelRotationEventsTest method createUI.

private static void createUI() {
    final JFrame mainFrame = new JFrame("Trackpad scrolling test");
    GridBagLayout layout = new GridBagLayout();
    JPanel mainControlPanel = new JPanel(layout);
    JPanel resultButtonPanel = new JPanel(layout);
    GridBagConstraints gbc = new GridBagConstraints();
    JPanel testPanel = createTestPanel();
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    mainControlPanel.add(testPanel, gbc);
    JTextArea instructionTextArea = new JTextArea();
    instructionTextArea.setText(INSTRUCTIONS);
    instructionTextArea.setEditable(false);
    instructionTextArea.setBackground(Color.white);
    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    mainControlPanel.add(instructionTextArea, gbc);
    JButton passButton = new JButton("Pass");
    passButton.setActionCommand("Pass");
    passButton.addActionListener((ActionEvent e) -> {
        testResult = true;
        mainFrame.dispose();
        countDownLatch.countDown();
    });
    JButton failButton = new JButton("Fail");
    failButton.setActionCommand("Fail");
    failButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            mainFrame.dispose();
            countDownLatch.countDown();
        }
    });
    gbc.gridx = 0;
    gbc.gridy = 0;
    resultButtonPanel.add(passButton, gbc);
    gbc.gridx = 1;
    gbc.gridy = 0;
    resultButtonPanel.add(failButton, gbc);
    gbc.gridx = 0;
    gbc.gridy = 2;
    mainControlPanel.add(resultButtonPanel, gbc);
    mainFrame.add(mainControlPanel);
    mainFrame.pack();
    mainFrame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            mainFrame.dispose();
            countDownLatch.countDown();
        }
    });
    mainFrame.setVisible(true);
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) JTextArea(javax.swing.JTextArea) GridBagLayout(java.awt.GridBagLayout) ActionListener(java.awt.event.ActionListener) JFrame(javax.swing.JFrame) ActionEvent(java.awt.event.ActionEvent) WindowEvent(java.awt.event.WindowEvent) JButton(javax.swing.JButton) WindowAdapter(java.awt.event.WindowAdapter)

Example 35 with WindowAdapter

use of java.awt.event.WindowAdapter in project jdk8u_jdk by JetBrains.

the class TexturePaintPrintingTest method doTest.

private static void doTest(Runnable action) {
    String description = " A TexturePaint graphics will be shown on console.\n" + " The same graphics is sent to printer.\n" + " Please verify if TexturePaint shading is printed.\n" + " If none is printed, press FAIL else press PASS";
    final JDialog dialog = new JDialog();
    dialog.setTitle("printSelectionTest");
    JTextArea textArea = new JTextArea(description);
    textArea.setEditable(false);
    final JButton testButton = new JButton("Start Test");
    final JButton passButton = new JButton("PASS");
    passButton.setEnabled(false);
    passButton.addActionListener((e) -> {
        f.dispose();
        dialog.dispose();
        pass();
    });
    final JButton failButton = new JButton("FAIL");
    failButton.setEnabled(false);
    failButton.addActionListener((e) -> {
        f.dispose();
        dialog.dispose();
        fail();
    });
    testButton.addActionListener((e) -> {
        testButton.setEnabled(false);
        action.run();
        passButton.setEnabled(true);
        failButton.setEnabled(true);
    });
    JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(textArea, BorderLayout.CENTER);
    JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.add(testButton);
    buttonPanel.add(passButton);
    buttonPanel.add(failButton);
    mainPanel.add(buttonPanel, BorderLayout.SOUTH);
    dialog.add(mainPanel);
    dialog.pack();
    dialog.setVisible(true);
    dialog.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            System.out.println("main dialog closing");
            testGeneratedInterrupt = false;
            mainThread.interrupt();
        }
    });
}
Also used : JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) FlowLayout(java.awt.FlowLayout) BorderLayout(java.awt.BorderLayout) WindowEvent(java.awt.event.WindowEvent) JButton(javax.swing.JButton) WindowAdapter(java.awt.event.WindowAdapter) JDialog(javax.swing.JDialog)

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