Search in sources :

Example 21 with ConfigureManager

use of jmri.ConfigureManager in project JMRI by JMRI.

the class FileLocationPaneXml method load.

@Override
public boolean load(Element shared, Element perNode) {
    boolean result = true;
    //Attribute scriptLocation = shared.getAttribute("defaultScriptLocation");
    //if (scriptLocation!=null)
    //FileUtil.setPythonScriptsPath(scriptLocation.getValue());
    /*Attribute userLocation = shared.getAttribute("defaultUserLocation");
         if (userLocation!=null)
         FileUtil.setUserFilesPath(userLocation.getValue());*/
    String value = loadUserLocations(shared, "defaultUserLocation");
    if (value != null) {
        FileUtil.setUserFilesPath(value);
    }
    value = loadUserLocations(shared, "defaultScriptLocation");
    if (value != null) {
        FileUtil.setScriptsPath(value);
    }
    ConfigureManager cm = jmri.InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
    if (cm != null) {
        cm.registerPref(new FileLocationPane());
    }
    return result;
}
Also used : ConfigureManager(jmri.ConfigureManager) FileLocationPane(apps.FileLocationPane)

Example 22 with ConfigureManager

use of jmri.ConfigureManager in project JMRI by JMRI.

the class ControlPanelEditor method init.

@Override
protected void init(String name) {
    setVisible(false);
    java.awt.Container contentPane = this.getContentPane();
    contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
    // make menus
    setGlobalSetsLocalFlag(false);
    setUseGlobalFlag(false);
    _menuBar = new JMenuBar();
    _circuitBuilder = new CircuitBuilder(this);
    _shapeDrawer = new ShapeDrawer(this);
    makeDrawMenu();
    makeWarrantMenu(false);
    makeIconMenu();
    makeZoomMenu();
    makeMarkerMenu();
    makeOptionMenu();
    makeEditMenu();
    makeFileMenu();
    setJMenuBar(_menuBar);
    addHelpMenu("package.jmri.jmrit.display.ControlPanelEditor", true);
    super.setTargetPanel(null, null);
    super.setTargetPanelSize(300, 300);
    makeDataFlavors();
    // set scrollbar initial state
    setScroll(SCROLL_BOTH);
    scrollBoth.setSelected(true);
    super.setDefaultToolTip(new ToolTip(null, 0, 0, new Font("Serif", Font.PLAIN, 12), Color.black, new Color(255, 250, 210), Color.black));
    // register the resulting panel for later configuration
    ConfigureManager cm = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
    if (cm != null) {
        cm.registerUser(this);
    }
    pack();
    setVisible(true);
    class makeCatalog extends SwingWorker<CatalogPanel, Object> {

        @Override
        public CatalogPanel doInBackground() {
            return CatalogPanel.makeDefaultCatalog();
        }
    }
    (new makeCatalog()).execute();
    log.debug("Init SwingWorker launched");
}
Also used : ToolTip(jmri.jmrit.display.ToolTip) BoxLayout(javax.swing.BoxLayout) Color(java.awt.Color) Font(java.awt.Font) ShapeDrawer(jmri.jmrit.display.controlPanelEditor.shape.ShapeDrawer) ConfigureManager(jmri.ConfigureManager) SwingWorker(javax.swing.SwingWorker) Container(java.awt.Container) JMenuBar(javax.swing.JMenuBar)

Example 23 with ConfigureManager

use of jmri.ConfigureManager in project JMRI by JMRI.

the class AppConfigBase method registerWithConfigureManager.

private void registerWithConfigureManager(PreferencesPanel panel) {
    if (panel.isPersistant()) {
        ConfigureManager cm = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
        if (cm != null) {
            cm.registerPref(panel);
        }
    }
    if (panel instanceof ManagingPreferencesPanel) {
        log.debug("Iterating over managed panels within {}/{}", panel.getPreferencesItemText(), panel.getTabbedPreferencesTitle());
        ((ManagingPreferencesPanel) panel).getPreferencesPanels().stream().forEach((managed) -> {
            log.debug("Registering {} with the ConfigureManager", managed.getClass().getName());
            this.registerWithConfigureManager(managed);
        });
    }
}
Also used : ConfigureManager(jmri.ConfigureManager) ManagingPreferencesPanel(jmri.swing.ManagingPreferencesPanel)

Example 24 with ConfigureManager

use of jmri.ConfigureManager in project JMRI by JMRI.

the class AppsBase method setAndLoadPreferenceFile.

/**
     * Invoked to load the preferences information, and in the process
     * configure the system.
     * The high-level steps are:
     *<ul>
     *  <li>Locate the preferences file based through
     *      {@link FileUtil#getFile(String)}
     *  <li>See if the preferences file exists, and handle it if it doesn't
     *  <li>Obtain a {@link jmri.ConfigureManager} from the {@link jmri.InstanceManager}
     *  <li>Ask that ConfigureManager to load the file, in the process loading information into existing and new managers.
     *  <li>Do any deferred loads that are needed
     *  <li>If needed, migrate older formats
     *</ul>
     * (There's additional handling for shared configurations)
     */
protected void setAndLoadPreferenceFile() {
    FileUtil.createDirectory(FileUtil.getUserFilesPath());
    final File file;
    File sharedConfig = null;
    try {
        sharedConfig = FileUtil.getFile(FileUtil.PROFILE + Profile.SHARED_CONFIG);
        if (!sharedConfig.canRead()) {
            sharedConfig = null;
        }
    } catch (FileNotFoundException ex) {
    // ignore - this only means that sharedConfig does not exist.
    }
    if (sharedConfig != null) {
        file = sharedConfig;
    } else if (!new File(getConfigFileName()).isAbsolute()) {
        // must be relative, but we want it to 
        // be relative to the preferences directory
        file = new File(FileUtil.getUserFilesPath() + getConfigFileName());
    } else {
        file = new File(getConfigFileName());
    }
    // don't try to load if doesn't exist, but mark as not OK
    if (!file.exists()) {
        preferenceFileExists = false;
        configOK = false;
        log.info("No pre-existing config file found, searched for '" + file.getPath() + "'");
        return;
    }
    preferenceFileExists = true;
    try {
        ConfigureManager cm = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
        if (cm != null) {
            configOK = cm.load(file);
        } else {
            configOK = false;
        }
        log.debug("end load config file {}, OK={}", file.getName(), configOK);
    } catch (JmriException e) {
        configOK = false;
    }
    if (sharedConfig != null) {
        // sharedConfigs do not need deferred loads
        configDeferredLoadOK = true;
    } else if (SwingUtilities.isEventDispatchThread()) {
        // To avoid possible locks, deferred load should be
        // performed on the Swing thread
        configDeferredLoadOK = doDeferredLoad(file);
    } else {
        try {
            // Use invokeAndWait method as we don't want to
            // return until deferred load is completed
            SwingUtilities.invokeAndWait(() -> {
                configDeferredLoadOK = doDeferredLoad(file);
            });
        } catch (InterruptedException | InvocationTargetException ex) {
            log.error("Exception creating system console frame: " + ex);
        }
    }
    if (sharedConfig == null && configOK == true && configDeferredLoadOK == true) {
        log.info("Migrating preferences to new format...");
        // migrate preferences
        InstanceManager.getOptionalDefault(TabbedPreferences.class).ifPresent(tp -> {
            tp.init();
            tp.saveContents();
            InstanceManager.getOptionalDefault(ConfigureManager.class).ifPresent(cm -> {
                cm.storePrefs();
            });
            log.info("Preferences have been migrated to new format.");
            log.info("New preferences format will be used after JMRI is restarted.");
        });
    }
}
Also used : ConfigureManager(jmri.ConfigureManager) FileNotFoundException(java.io.FileNotFoundException) JmriException(jmri.JmriException) BlockValueFile(jmri.jmrit.display.layoutEditor.BlockValueFile) File(java.io.File) TabbedPreferences(apps.gui3.TabbedPreferences)

Example 25 with ConfigureManager

use of jmri.ConfigureManager in project JMRI by JMRI.

the class AppsBase method doDeferredLoad.

//abstract protected void addToActionModel();
private boolean doDeferredLoad(File file) {
    boolean result;
    log.debug("start deferred load from config file {}", file.getName());
    try {
        ConfigureManager cm = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
        if (cm != null) {
            result = cm.loadDeferred(file);
        } else {
            log.error("Failed to get default configure manager");
            result = false;
        }
    } catch (JmriException e) {
        log.error("Unhandled problem loading deferred configuration: " + e);
        result = false;
    }
    log.debug("end deferred load from config file {}, OK={}", file.getName(), result);
    return result;
}
Also used : ConfigureManager(jmri.ConfigureManager) JmriException(jmri.JmriException)

Aggregations

ConfigureManager (jmri.ConfigureManager)37 Color (java.awt.Color)7 Attribute (org.jdom2.Attribute)6 Element (org.jdom2.Element)6 JmriException (jmri.JmriException)4 AbstractXmlAdapter (jmri.configurexml.AbstractXmlAdapter)4 XmlAdapter (jmri.configurexml.XmlAdapter)4 Font (java.awt.Font)3 Point (java.awt.Point)3 File (java.io.File)3 BoxLayout (javax.swing.BoxLayout)3 JMenuBar (javax.swing.JMenuBar)3 ToolTip (jmri.jmrit.display.ToolTip)3 Container (java.awt.Container)2 Dimension (java.awt.Dimension)2 FlowLayout (java.awt.FlowLayout)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 HashMap (java.util.HashMap)2 OverridingMethodsMustInvokeSuper (javax.annotation.OverridingMethodsMustInvokeSuper)2