Search in sources :

Example 36 with WindowEvent

use of java.awt.event.WindowEvent in project zaproxy by zaproxy.

the class AbstractDialog method initialize.

/**
	 * This method initializes this
	 */
private void initialize() {
    this.setVisible(false);
    this.setIconImages(DisplayUtils.getZapIconImages());
    this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    if (Model.getSingleton().getOptionsParam().getViewParam().getWmUiHandlingOption() == 0) {
        this.setSize(300, 200);
    }
    this.setTitle(Constant.PROGRAM_NAME);
    //  Handle escape key to close the dialog    
    KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
    AbstractAction escapeAction = new AbstractAction() {

        private static final long serialVersionUID = 3516424501887406165L;

        @Override
        public void actionPerformed(ActionEvent e) {
            dispatchEvent(new WindowEvent(AbstractDialog.this, WindowEvent.WINDOW_CLOSING));
        }
    };
    getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, "ESCAPE");
    getRootPane().getActionMap().put("ESCAPE", escapeAction);
}
Also used : ActionEvent(java.awt.event.ActionEvent) WindowEvent(java.awt.event.WindowEvent) KeyStroke(javax.swing.KeyStroke) AbstractAction(javax.swing.AbstractAction)

Example 37 with WindowEvent

use of java.awt.event.WindowEvent 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 38 with WindowEvent

use of java.awt.event.WindowEvent 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 39 with WindowEvent

use of java.awt.event.WindowEvent 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)

Example 40 with WindowEvent

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

the class TestSafeCanvas method main.

public static void main(String[] args) throws InterruptedException {
    AppSettings settings = new AppSettings(true);
    settings.setWidth(640);
    settings.setHeight(480);
    final TestSafeCanvas app = new TestSafeCanvas();
    app.setPauseOnLostFocus(false);
    app.setSettings(settings);
    app.createCanvas();
    app.startCanvas(true);
    JmeCanvasContext context = (JmeCanvasContext) app.getContext();
    Canvas canvas = context.getCanvas();
    canvas.setSize(settings.getWidth(), settings.getHeight());
    Thread.sleep(3000);
    JFrame frame = new JFrame("Test");
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            app.stop();
        }
    });
    frame.getContentPane().add(canvas);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    Thread.sleep(3000);
    frame.getContentPane().remove(canvas);
    Thread.sleep(3000);
    frame.getContentPane().add(canvas);
}
Also used : JmeCanvasContext(com.jme3.system.JmeCanvasContext) AppSettings(com.jme3.system.AppSettings) JFrame(javax.swing.JFrame) Canvas(java.awt.Canvas) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter)

Aggregations

WindowEvent (java.awt.event.WindowEvent)201 WindowAdapter (java.awt.event.WindowAdapter)140 JPanel (javax.swing.JPanel)44 JButton (javax.swing.JButton)40 JFrame (javax.swing.JFrame)40 BorderLayout (java.awt.BorderLayout)36 ActionEvent (java.awt.event.ActionEvent)34 Dimension (java.awt.Dimension)32 JLabel (javax.swing.JLabel)30 JScrollPane (javax.swing.JScrollPane)26 ActionListener (java.awt.event.ActionListener)25 GridBagConstraints (java.awt.GridBagConstraints)19 GridBagLayout (java.awt.GridBagLayout)19 FlowLayout (java.awt.FlowLayout)18 Frame (java.awt.Frame)15 Insets (java.awt.Insets)15 JDialog (javax.swing.JDialog)13 JTextArea (javax.swing.JTextArea)13 Container (java.awt.Container)12 WindowListener (java.awt.event.WindowListener)10