Search in sources :

Example 1 with EditorPanel

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();
}
Also used : App(org.suikasoft.jOptions.app.App) SpecsSystem(pt.up.fe.specs.util.SpecsSystem) LaraIException(org.lara.interpreter.exception.LaraIException) App(org.suikasoft.jOptions.app.App) AppPersistence(org.suikasoft.jOptions.app.AppPersistence) ArrayList(java.util.ArrayList) WindowsFocusGainedListener(org.lara.interpreter.joptions.panels.editor.listeners.WindowsFocusGainedListener) SimpleGui(org.suikasoft.jOptions.gui.SimpleGui) EditorPanel(org.lara.interpreter.joptions.panels.editor.EditorPanel) WeaverEngine(org.lara.interpreter.weaver.interf.WeaverEngine) DataStore(org.suikasoft.jOptions.Interfaces.DataStore) AppKernel(org.suikasoft.jOptions.app.AppKernel) JTabbedPane(javax.swing.JTabbedPane) CommandLine(org.apache.commons.cli.CommandLine) XmlPersistence(org.suikasoft.jOptions.persistence.XmlPersistence) StoreDefinition(org.suikasoft.jOptions.storedefinition.StoreDefinition) JFrame(javax.swing.JFrame) LaraiKeys(org.lara.interpreter.joptions.config.interpreter.LaraiKeys) Frame(java.awt.Frame) TabProvider(org.suikasoft.jOptions.gui.panels.app.TabProvider) ProgramPanel(org.suikasoft.jOptions.gui.panels.app.ProgramPanel) File(java.io.File) StringListPanel(org.suikasoft.jOptions.gui.panels.option.StringListPanel) Dimension(java.awt.Dimension) List(java.util.List) OptionsParser(org.lara.interpreter.cli.OptionsParser) DefaultWeaver(org.lara.interpreter.weaver.defaultweaver.DefaultWeaver) SpecsLogs(pt.up.fe.specs.util.SpecsLogs) SearchUtils(org.lara.interpreter.joptions.panels.editor.utils.SearchUtils) LaraI(larai.LaraI) Optional(java.util.Optional) WindowConstants(javax.swing.WindowConstants) AppKernel(org.suikasoft.jOptions.app.AppKernel) JTabbedPane(javax.swing.JTabbedPane) ArrayList(java.util.ArrayList) TabProvider(org.suikasoft.jOptions.gui.panels.app.TabProvider) ProgramPanel(org.suikasoft.jOptions.gui.panels.app.ProgramPanel) JFrame(javax.swing.JFrame) StoreDefinition(org.suikasoft.jOptions.storedefinition.StoreDefinition) SimpleGui(org.suikasoft.jOptions.gui.SimpleGui) WindowsFocusGainedListener(org.lara.interpreter.joptions.panels.editor.listeners.WindowsFocusGainedListener) StringListPanel(org.suikasoft.jOptions.gui.panels.option.StringListPanel) XmlPersistence(org.suikasoft.jOptions.persistence.XmlPersistence) EditorPanel(org.lara.interpreter.joptions.panels.editor.EditorPanel) Dimension(java.awt.Dimension)

Aggregations

Dimension (java.awt.Dimension)1 Frame (java.awt.Frame)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 JFrame (javax.swing.JFrame)1 JTabbedPane (javax.swing.JTabbedPane)1 WindowConstants (javax.swing.WindowConstants)1 LaraI (larai.LaraI)1 CommandLine (org.apache.commons.cli.CommandLine)1 OptionsParser (org.lara.interpreter.cli.OptionsParser)1 LaraIException (org.lara.interpreter.exception.LaraIException)1 LaraiKeys (org.lara.interpreter.joptions.config.interpreter.LaraiKeys)1 EditorPanel (org.lara.interpreter.joptions.panels.editor.EditorPanel)1 WindowsFocusGainedListener (org.lara.interpreter.joptions.panels.editor.listeners.WindowsFocusGainedListener)1 SearchUtils (org.lara.interpreter.joptions.panels.editor.utils.SearchUtils)1 DefaultWeaver (org.lara.interpreter.weaver.defaultweaver.DefaultWeaver)1 WeaverEngine (org.lara.interpreter.weaver.interf.WeaverEngine)1 DataStore (org.suikasoft.jOptions.Interfaces.DataStore)1