Search in sources :

Example 6 with CloseMainFrameAdapter

use of com.ramussoft.gui.common.event.CloseMainFrameAdapter in project ramus by Vitaliy-Yakovchuk.

the class Runner method openInNewWindows.

@SuppressWarnings("unchecked")
public JFrame openInNewWindows(final Engine engine, final AccessRules rules, final File file, final boolean recovered) {
    List<GUIPlugin> list = new ArrayList<GUIPlugin>();
    FilePlugin filePlugin = new FilePlugin((FileIEngineImpl) engine.getDeligate(), engine, rules, file, this);
    list.add(filePlugin);
    list.add(new UndoRedoPlugin(engine));
    initAdditionalGUIPlugins(list, engine, rules);
    final AbstractGUIPluginFactory factory = createGUIPluginFactory(engine, rules, list);
    final JFrame frame = factory.getMainFrame();
    engine.setPluginProperty(CORE, "MainFrame", frame);
    String title = getApplicationTitle();
    if (file != null)
        title += " - " + file.getName();
    frame.setTitle(title);
    factory.getFramework().addCloseMainFrameListener(new CloseMainFrameAdapter() {

        @Override
        public void afterClosed() {
            List<JFrame> list = (List<JFrame>) engine.getPluginProperty(CORE, "AdditionalWindows");
            if (list != null) {
                JFrame[] frames = list.toArray(new JFrame[list.size()]);
                for (JFrame frame : frames) {
                    frame.setVisible(false);
                    frame.dispose();
                }
            }
            FileIEngineImpl impl = (FileIEngineImpl) engine.getDeligate();
            try {
                impl.getTemplate().getConnection().close();
                if (engine instanceof Journaled)
                    ((Journaled) engine).close();
                impl.close();
                impl.clear();
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
    });
    Object changed = engine.getPluginProperty(CORE, "Changed");
    if (changed != null)
        filePlugin.changed();
    InputStream is = engine.getInputStream("/user/gui/session.binary");
    if (is != null) {
        try {
            ObjectInputStream ois = new ObjectInputStream(is);
            try {
                final List<ActionEvent> session = (List<ActionEvent>) ois.readObject();
                SwingUtilities.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        for (ActionEvent e : session) if (e != null)
                            factory.getFramework().propertyChanged(e);
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                is.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    beforeMainFrameShow(frame);
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            frame.setVisible(true);
            if (recovered) {
                factory.getFramework().propertyChanged("FileRecovered");
            } else
                factory.getFramework().propertyChanged("FileOpened", file);
            postShowVisibaleMainFrame(engine, factory.getFramework());
        }
    });
    return frame;
}
Also used : FileIEngineImpl(com.ramussoft.core.impl.FileIEngineImpl) ObjectInputStream(java.io.ObjectInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ActionEvent(com.ramussoft.gui.common.event.ActionEvent) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ZipException(java.util.zip.ZipException) FileMinimumVersionException(com.ramussoft.core.impl.FileMinimumVersionException) IOException(java.io.IOException) UndoRedoPlugin(com.ramussoft.gui.common.UndoRedoPlugin) Journaled(com.ramussoft.common.journal.Journaled) CloseMainFrameAdapter(com.ramussoft.gui.common.event.CloseMainFrameAdapter) JFrame(javax.swing.JFrame) List(java.util.List) ArrayList(java.util.ArrayList) GUIPlugin(com.ramussoft.gui.common.GUIPlugin) AbstractGUIPluginFactory(com.ramussoft.gui.common.AbstractGUIPluginFactory) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

CloseMainFrameAdapter (com.ramussoft.gui.common.event.CloseMainFrameAdapter)6 AbstractGUIPluginFactory (com.ramussoft.gui.common.AbstractGUIPluginFactory)3 GUIPlugin (com.ramussoft.gui.common.GUIPlugin)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 JFrame (javax.swing.JFrame)3 UndoRedoPlugin (com.ramussoft.gui.common.UndoRedoPlugin)2 ActionEvent (com.ramussoft.gui.common.event.ActionEvent)2 ActionListener (com.ramussoft.gui.common.event.ActionListener)2 AccessRules (com.ramussoft.common.AccessRules)1 Engine (com.ramussoft.common.Engine)1 PluginFactory (com.ramussoft.common.PluginFactory)1 PluginProvider (com.ramussoft.common.PluginProvider)1 QualifierAdapter (com.ramussoft.common.event.QualifierAdapter)1 QualifierEvent (com.ramussoft.common.event.QualifierEvent)1 QualifierListener (com.ramussoft.common.event.QualifierListener)1 Journaled (com.ramussoft.common.journal.Journaled)1 SimpleAttributePluginSuit (com.ramussoft.core.attribute.simple.SimpleAttributePluginSuit)1 FileIEngineImpl (com.ramussoft.core.impl.FileIEngineImpl)1