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;
}
Aggregations