pl.xoft.saf.finder.ui.MainApp.java
package pl.xoft.saf.finder.ui;

import java.awt.Component;
import java.util.EventObject;
import javax.swing.JOptionPane;
import org.jdesktop.application.*;

/**
 * Main application class, responsible for application lifecycle management.
 * @author Piotr Kochanski, http://www.xoft.pl
 */
public class MainApp extends Application {

    ResourceMap resource;
    ApplicationContext ctxt;

    @Override
    protected void startup() {
        FrameView view = new MainViewFrame(this);
        view.setFrame(new MainFrame());
        show(view);
        
        addExitListener(new ExitListener() {
            public boolean canExit(EventObject e) {
                Object[] options = {resource.getString("label.yes"), 
                        resource.getString("label.no")};
                
                Object source = (e != null) ? e.getSource() : null;
                Component owner = (source instanceof Component) ? (Component)source : null;
                
                boolean mayExit = JOptionPane.showOptionDialog(owner,
                        resource.getString("label.exit"),
                        resource.getString("Application.name"),
                        JOptionPane.YES_NO_OPTION,
                        JOptionPane.QUESTION_MESSAGE,
                        null,
                        options,
                        options[1]) == JOptionPane.YES_OPTION;

                return mayExit;
            }

            public void willExit(EventObject event) {
                //do nothing
            }
        });
    }

    @Override
    protected void initialize(String[] args) {
        System.out.println("Inicjalizacja... ");
        this.ctxt = getContext();
        ResourceManager mgr = ctxt.getResourceManager();
        resource = mgr.getResourceMap(MainApp.class);
    }

    @Override
    protected void shutdown() {
        System.out.println("Koniec pracy!! Czyƛcimy");
    }

    public static void main(String[] args) {
        Application.launch(MainApp.class, args);
    }
}