Example usage for javax.swing JWindow setLocation

List of usage examples for javax.swing JWindow setLocation

Introduction

In this page you can find the example usage for javax.swing JWindow setLocation.

Prototype

@Override
public void setLocation(Point p) 

Source Link

Document

The method changes the geometry-related data.

Usage

From source file:org.apache.log4j.chainsaw.LogUI.java

/**
 * Shutsdown by ensuring the Appender gets a chance to close.
 *///  ww w . ja  v  a  2  s  .com
public boolean shutdown() {
    if (getApplicationPreferenceModel().isConfirmExit()) {
        if (JOptionPane.showConfirmDialog(LogUI.this, "Are you sure you want to exit Chainsaw?", "Confirm Exit",
                JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) != JOptionPane.YES_OPTION) {
            return false;
        }

    }

    final JWindow progressWindow = new JWindow();
    final ProgressPanel panel = new ProgressPanel(1, 3, "Shutting down");
    progressWindow.getContentPane().add(panel);
    progressWindow.pack();

    Point p = new Point(getLocation());
    p.move((int) getSize().getWidth() >> 1, (int) getSize().getHeight() >> 1);
    progressWindow.setLocation(p);
    progressWindow.setVisible(true);

    Runnable runnable = new Runnable() {
        public void run() {
            try {
                int progress = 1;
                final int delay = 25;

                handler.close();
                panel.setProgress(progress++);

                Thread.sleep(delay);

                pluginRegistry.stopAllPlugins();
                panel.setProgress(progress++);

                Thread.sleep(delay);

                panel.setProgress(progress++);
                Thread.sleep(delay);
            } catch (Exception e) {
                e.printStackTrace();
            }

            fireShutdownEvent();
            performShutdownAction();
            progressWindow.setVisible(false);
        }
    };

    if (OSXIntegration.IS_OSX) {
        /**
         * or OSX we do it in the current thread because otherwise returning
         * will exit the process before it's had a chance to save things
         * 
         */
        runnable.run();
    } else {
        new Thread(runnable).start();
    }
    return true;
}