Example usage for java.awt.event WindowEvent getWindow

List of usage examples for java.awt.event WindowEvent getWindow

Introduction

In this page you can find the example usage for java.awt.event WindowEvent getWindow.

Prototype

public Window getWindow() 

Source Link

Document

Returns the originator of the event.

Usage

From source file:es.emergya.ui.plugins.admin.aux1.SummaryAction.java

private JFrame createJDialog(final String titulo) {
    final JFrame d = new JFrame(titulo);
    d.setResizable(false);/*  ww w  .  j a v a2s .  c  o  m*/
    d.setAlwaysOnTop(true);
    d.setIconImage(window.getIconImage());
    d.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    d.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            super.windowClosing(e);
            if (cambios) {
                int res = JOptionPane.showConfirmDialog(d,
                        "Existen cambios sin guardar. Seguro que desea cerrar la ventana?",
                        "Cambios sin guardar", JOptionPane.OK_CANCEL_OPTION);
                if (res != JOptionPane.CANCEL_OPTION) {
                    e.getWindow().dispose();
                }
            } else {
                e.getWindow().dispose();
            }
        }
    });
    d.setLayout(new BorderLayout(5, 5));
    d.setBackground(Color.WHITE);
    d.getContentPane().setBackground(Color.WHITE);
    return d;
}

From source file:at.becast.youploader.gui.FrmMain.java

/**
 * Creates new form frmMain//from   ww  w  . j a va2 s. c  om
 */
public FrmMain() {
    self = this;
    this.tos = false;
    this.setMinimumSize(new Dimension(900, 580));
    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            LOG.info(Main.APP_NAME + " " + Main.VERSION + " closing.", FrmMain.class);
            Main.s.put("left", String.valueOf(getX()));
            Main.s.put("top", String.valueOf(getY()));
            Main.s.put("width", String.valueOf(getWidth()));
            Main.s.put("height", String.valueOf(getHeight()));
            LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
            loggerContext.stop();
            e.getWindow().dispose();
        }
    });
    UploadMgr = UploadManager.getInstance();
    TemplateMgr = TemplateManager.getInstance();
    UploadMgr.setParent(this);
    String sspeed = Main.s.setting.get("speed");
    if (sspeed != null) {
        speed = Integer.parseInt(sspeed);
    } else {
        speed = 0;
    }
    initComponents();
    initMenuBar();
    loadAccounts();
    this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/yp.png")));
    try {
        loadQueue();
    } catch (SQLException | IOException e) {
        LOG.error("Error: ", e);
    }
    this.setVisible(true);
    if (Main.firstlaunch) {
        int n = JOptionPane.showConfirmDialog(null, LANG.getString("frmMain.initialAccount.Message"),
                LANG.getString("frmMain.initialAccount.title"), JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE);
        if (n == JOptionPane.YES_OPTION) {
            mntmAddAccountActionPerformed();
        }
    } else {
        PlaylistUpdater pu = new PlaylistUpdater(this);
        Thread updater = new Thread(pu);
        updater.start();
        AccountUpdater au = new AccountUpdater(this);
        Thread aupdater = new Thread(au);
        aupdater.start();
    }
    EditPanel edit = (EditPanel) ss1.contentPane;
    if (edit.getCmbTemplate().getModel().getSize() > 0) {
        edit.getCmbTemplate().setSelectedIndex(0);
    }
    tray = new TrayManager(this);
    addWindowStateListener(new WindowStateListener() {
        public void windowStateChanged(WindowEvent e) {
            if (e.getNewState() == ICONIFIED) {
                tray.add();
                setVisible(false);
            }
            if (e.getNewState() == 7) {
                tray.add();
                setVisible(false);
            }
            if (e.getNewState() == MAXIMIZED_BOTH) {
                tray.remove();
                setVisible(true);
            }
            if (e.getNewState() == NORMAL) {
                tray.remove();
                setVisible(true);
            }
        }
    });
}

From source file:com.projity.pm.graphic.frames.GraphicManager.java

public void windowClosed(WindowEvent evt) {
    if (evt.getWindow() == assignResourcesDialog)
        assignResourcesDialog = null;
}

From source file:org.geoserver.wms.WMSTestSupport.java

/**
 * Shows <code>image</code> in a Frame.
 * //  ww w  .j av a2s .c  o m
 * @param frameName
 * @param timeOut
 * @param image
 */
public static void showImage(String frameName, long timeOut, final BufferedImage image) {
    int width = image.getWidth();
    int height = image.getHeight();

    if (((System.getProperty("java.awt.headless") == null)
            || !System.getProperty("java.awt.headless").equals("true")) && INTERACTIVE) {
        Frame frame = new Frame(frameName);
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                e.getWindow().dispose();
            }
        });

        Panel p = new Panel(null) { // no layout manager so it respects
                                    // setSize
            public void paint(Graphics g) {
                g.drawImage(image, 0, 0, this);
            }
        };

        frame.add(p);
        p.setSize(width, height);
        frame.pack();
        frame.setVisible(true);

        try {
            Thread.sleep(timeOut);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        frame.dispose();
    }
}

From source file:org.jets3t.apps.cockpitlite.CockpitLite.java

/**
 * Runs Cockpit as a stand-alone application.
 * @param args// w w  w . j  a v a2 s  .c om
 * @throws Exception
 */
public static void main(String args[]) throws Exception {
    JFrame ownerFrame = new JFrame("JetS3t Cockpit-Lite");
    ownerFrame.addWindowListener(new WindowListener() {
        public void windowOpened(WindowEvent e) {
        }

        public void windowClosing(WindowEvent e) {
            e.getWindow().dispose();
        }

        public void windowClosed(WindowEvent e) {
        }

        public void windowIconified(WindowEvent e) {
        }

        public void windowDeiconified(WindowEvent e) {
        }

        public void windowActivated(WindowEvent e) {
        }

        public void windowDeactivated(WindowEvent e) {
        }
    });

    // Read arguments as properties of the form: <propertyName>'='<propertyValue>
    Properties argumentProperties = new Properties();
    if (args.length > 0) {
        for (int i = 0; i < args.length; i++) {
            String arg = args[i];
            int delimIndex = arg.indexOf("=");
            if (delimIndex >= 0) {
                String name = arg.substring(0, delimIndex);
                String value = arg.substring(delimIndex + 1);
                argumentProperties.put(name, value);
            } else {
                System.out.println("Ignoring property argument with incorrect format: " + arg);
            }
        }
    }

    new CockpitLite(ownerFrame, argumentProperties);
}

From source file:org.spoutcraft.launcher.skin.ConsoleFrame.java

/**
 * Construct the frame./*ww  w.  java  2s .com*/
 * 
 * @param numLines number of lines to show at a time
 * @param colorEnabled true to enable a colored console
 * @param trackProc process to track
 * @param killProcess true to kill the process on console close
 */
public ConsoleFrame(int numLines, boolean colorEnabled, final Process trackProc, final boolean killProcess) {
    super("Console");
    this.numLines = numLines;
    this.colorEnabled = colorEnabled;
    this.trackProc = trackProc;

    this.highlightedAttributes = new SimpleAttributeSet();
    StyleConstants.setForeground(highlightedAttributes, Color.BLACK);
    StyleConstants.setBackground(highlightedAttributes, Color.YELLOW);

    this.errorAttributes = new SimpleAttributeSet();
    StyleConstants.setForeground(errorAttributes, new Color(200, 0, 0));
    this.infoAttributes = new SimpleAttributeSet();
    StyleConstants.setForeground(infoAttributes, new Color(200, 0, 0));
    this.debugAttributes = new SimpleAttributeSet();
    StyleConstants.setForeground(debugAttributes, Color.DARK_GRAY);

    setSize(new Dimension(650, 400));
    buildUI();

    Compatibility.setIconImage(this, Toolkit.getDefaultToolkit().getImage(LoginFrame.spoutcraftIcon));

    if (trackProc != null) {
        track(trackProc);
    }

    addMouseListener(this);

    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent event) {
            if (trackProc != null && killProcess) {
                trackProc.destroy();
                if (loggerHandler != null) {
                    rootLogger.removeHandler(loggerHandler);
                }
                event.getWindow().dispose();
            }
        }
    });
}

From source file:org.squidy.designer.Designer.java

/**
 * @param view//from  w w  w.j  av a 2  s  .c o m
 */
private void initializeView(PFrame view) {
    view.setTitle(VIEW_TITLE);
    view.setDefaultCloseOperation(PFrame.DO_NOTHING_ON_CLOSE);

    view.addWindowListener(new WindowAdapter() {

        /*
         * (non-Javadoc)
         * 
         * @see java.awt.event.WindowAdapter#windowClosing(java.awt
         * .event.WindowEvent)
         */
        @Override
        public void windowClosing(WindowEvent e) {
            super.windowClosing(e);

            // Remove view.
            PFrame view = (PFrame) e.getWindow();
            views.remove(view);
            view.dispose();

            if (LOG.isDebugEnabled()) {
                LOG.debug("Closing view. View count " + views.size());
            }

            // Store data if last view has been closed.
            if (views.size() == 0) {
                store(data);
                System.exit(0);
            }
        }
    });

    view.getCanvas().addInputEventListener(new PBasicInputEventHandler() {
        @Override
        public void mouseClicked(PInputEvent event) {
            super.mouseClicked(event);

            final PCamera camera = event.getCamera();

            if (!event.isHandled() && event.isLeftMouseButton() && event.getClickCount() == 2) {

                Rectangle bounds = getCanvas().getBounds();
                bounds.setBounds((int) (bounds.getX() - 30), ((int) bounds.getY() - 30),
                        ((int) bounds.getWidth() + 30), ((int) bounds.getHeight() + 30));

                camera.animateViewToCenterBounds(bounds, true, 1000);

                // Set all children of current node as draggable.
                for (Object child : getCanvas().getLayer().getChildrenReference()) {
                    if (child instanceof Draggable) {
                        ((Draggable) child).setDraggable(true);
                    }
                }
            }
        }
    });

    view.getCanvas().getCamera().addInputEventListener(new PBasicInputEventHandler() {

        /*
        * (non-Javadoc)
        * 
        * @see
        * edu.umd.cs.piccolo.event.PBasicInputEventHandler#mouseClicked
        * (edu.umd.cs.piccolo.event.PInputEvent)
        */
        @Override
        public void mouseClicked(PInputEvent event) {
            super.mouseClicked(event);

            if (event.isRightMouseButton() && event.getClickCount() > 1) {

                PLayer layer = getCanvas().getLayer();

                PCamera camera = new PCamera();
                camera.addLayer(layer);
                layer.getRoot().addChild(camera);

                PCanvas canvas = new PSwingCanvas();
                canvas.setCamera(camera);

                PFrame view = new PFrame("", false, canvas);
                views.add(view);
                initializeView(view);
                // view.setVisible(true);

                if (LOG.isDebugEnabled()) {
                    LOG.debug("Created view. View count " + views.size());
                }
            }
        }
    });
}