use of org.lara.interpreter.joptions.panels.editor.EditorPanel in project lara-framework by specs-feup.
the class LaraLauncher method launchGUI.
public static void launchGUI(WeaverEngine engine, Optional<File> configFile) {
long time = System.currentTimeMillis();
AppKernel kernel = new LaraiLauncherKernel(engine);
// replace this with a splash screen
SpecsLogs.msgInfo("Starting GUI...");
StoreDefinition laraiDefinition = OptionsParser.getLaraStoreDefinition(engine);
String appName = engine.getNameAndBuild();
// String appName = engine.getName();
//
// var implVersion = SpecsSystem.getBuildNumber();
// if (implVersion != null) {
// appName += " (build " + implVersion + ")";
// }
List<TabProvider> otherTabs = new ArrayList<>();
XmlPersistence persistence = OptionsParser.getXmlPersistence(laraiDefinition);
otherTabs.add(dataStore -> EditorPanel.newInstance(dataStore, persistence, engine));
App app = App.newInstance(appName, laraiDefinition, persistence, kernel).setOtherTabs(otherTabs).setNodeClass(engine.getClass()).setIcon(engine.getIcon());
SimpleGui gui = new SimpleGui(app);
JFrame guiFrame = gui.getFrame();
// <- prevent closing
guiFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
guiFrame.setPreferredSize(new Dimension(1200, 750));
guiFrame.setExtendedState(guiFrame.getExtendedState() | Frame.MAXIMIZED_BOTH);
guiFrame.addWindowFocusListener(new WindowsFocusGainedListener(e -> refreshCurrentTab(guiFrame)));
guiFrame.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent windowEvent) {
EditorPanel editorPanel = SearchUtils.findFirstComponentOfType(guiFrame, EditorPanel.class);
JTabbedPane parent = (JTabbedPane) editorPanel.getParent();
parent.setSelectedComponent(editorPanel);
boolean success = editorPanel.getTabsContainer().getMainTab().saveBeforeClose();
if (!success) {
return;
}
success = editorPanel.closingProgram();
// success = editorPanel.getTabsContainer().closeAll();
if (!success) {
return;
}
// guiFrame.dispose(); <-- this does not close the JVM instance, i.e., the window is closed but the
// process is still executing
// TODO - replace with correct close method
System.exit(0);
}
});
if (configFile.isPresent()) {
ProgramPanel programPanel = SearchUtils.findFirstComponentOfType(guiFrame, ProgramPanel.class);
programPanel.getFilenameTextField().setSelectedItem(configFile.get());
}
// Initialize External Dependencies predefined values
var externalDependenciesPanel = (StringListPanel) gui.getAppFrame().getTabbedPane().getOptionsPanel().getPanel(LaraiKeys.EXTERNAL_DEPENDENCIES);
externalDependenciesPanel.setPredefinedValues(engine.getPredefinedExternalDependencies());
// externalDependencies.getDefaultSeparator()
// System.out.println("NAME: " + LaraiKeys.EXTERNAL_DEPENDENCIES.getName());
// var externalDependenciesPanel = (StringListPanel) LaraiKeys.EXTERNAL_DEPENDENCIES.getPanel(null);
// externalDependenciesPanel.setPredefinedValues(engine.getPredefinedExternalDependencies());
// guiFrame.revalidate();
// guiFrame.repaint();
SpecsLogs.debug("Lara GUI load time: " + (System.currentTimeMillis() - time));
// This code is making the console area to use all window
// JTabbedPane tabbedPane = SearchUtils.findFirstComponentOfType(guiFrame, JTabbedPane.class);
// tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1); // So it opens in the editor tab
gui.execute();
}
Aggregations