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;
}
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");
}
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);
});
}
}
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.");
});
}
}
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;
}
Aggregations