Search in sources :

Example 31 with ConfigureManager

use of jmri.ConfigureManager in project JMRI by JMRI.

the class PanelEditorXml method load.

/**
     * Create a PanelEditor object, then register and fill it, then pop it in a
     * JFrame
     *
     * @param shared Top level Element to unpack.
     * @return true if successful
     */
@Override
public boolean load(Element shared, Element perNode) {
    boolean result = true;
    // find coordinates
    int x = 0;
    int y = 0;
    int height = 400;
    int width = 300;
    try {
        x = shared.getAttribute("x").getIntValue();
        y = shared.getAttribute("y").getIntValue();
        height = shared.getAttribute("height").getIntValue();
        width = shared.getAttribute("width").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert PanelEditor's attribute");
        result = false;
    }
    // find the name
    String name = "Panel";
    if (shared.getAttribute("name") != null) {
        name = shared.getAttribute("name").getValue();
    }
    // confirm that panel hasn't already been loaded
    if (jmri.jmrit.display.PanelMenu.instance().isPanelNameUsed(name)) {
        log.warn("File contains a panel with the same name (" + name + ") as an existing panel");
        result = false;
    }
    PanelEditor panel = new PanelEditor(name);
    //panel.makeFrame(name);
    jmri.jmrit.display.PanelMenu.instance().addEditorPanel(panel);
    panel.getTargetFrame().setLocation(x, y);
    panel.getTargetFrame().setSize(width, height);
    panel.setTitle();
    // Load editor option flags. This has to be done before the content 
    // items are loaded, to preserve the individual item settings
    Attribute a;
    boolean value = true;
    if ((a = shared.getAttribute("editable")) != null && a.getValue().equals("no")) {
        value = false;
    }
    panel.setAllEditable(value);
    value = true;
    if ((a = shared.getAttribute("positionable")) != null && a.getValue().equals("no")) {
        value = false;
    }
    panel.setAllPositionable(value);
    /*
         value = false;
         if ((a = element.getAttribute("showcoordinates"))!=null && a.getValue().equals("yes"))
         value = true;
         panel.setShowCoordinates(value);
         */
    value = true;
    if ((a = shared.getAttribute("showtooltips")) != null && a.getValue().equals("no")) {
        value = false;
    }
    panel.setAllShowTooltip(value);
    value = true;
    if ((a = shared.getAttribute("controlling")) != null && a.getValue().equals("no")) {
        value = false;
    }
    panel.setAllControlling(value);
    value = false;
    if ((a = shared.getAttribute("hide")) != null && a.getValue().equals("yes")) {
        value = true;
    }
    panel.setShowHidden(value);
    value = true;
    if ((a = shared.getAttribute("panelmenu")) != null && a.getValue().equals("no")) {
        value = false;
    }
    panel.setPanelMenuVisible(value);
    String state = "both";
    if ((a = shared.getAttribute("scrollable")) != null) {
        state = a.getValue();
    }
    panel.setScroll(state);
    // set color if needed
    try {
        int red = shared.getAttribute("redBackground").getIntValue();
        int blue = shared.getAttribute("blueBackground").getIntValue();
        int green = shared.getAttribute("greenBackground").getIntValue();
        panel.setBackgroundColor(new Color(red, green, blue));
    } catch (org.jdom2.DataConversionException e) {
        log.warn("Could not parse color attributes!");
    } catch (NullPointerException e) {
    // considered normal if the attributes are not present
    }
    //set the (global) editor display widgets to their flag settings
    panel.initView();
    // load the contents with their individual option settings
    List<Element> items = shared.getChildren();
    for (int i = 0; i < items.size(); i++) {
        // get the class, hence the adapter object to do loading
        Element item = items.get(i);
        String adapterName = item.getAttribute("class").getValue();
        log.debug("load via " + adapterName);
        try {
            XmlAdapter adapter = (XmlAdapter) Class.forName(adapterName).newInstance();
            // and do it
            adapter.load(item, panel);
            if (!panel.loadOK()) {
                result = false;
            }
        } catch (Exception e) {
            log.error("Exception while loading " + item.getName() + ":" + e);
            result = false;
            e.printStackTrace();
        }
    }
    // dispose of url correction data
    panel.disposeLoadData();
    // display the results, with the editor in back
    panel.pack();
    panel.setAllEditable(panel.isEditable());
    // we don't pack the target frame here, because size was specified
    // TODO: Work out why, when calling this method, panel size is increased
    // vertically (at least on MS Windows)
    // always show the panel
    panel.getTargetFrame().setVisible(true);
    // register the resulting panel for later configuration
    ConfigureManager cm = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
    if (cm != null) {
        cm.registerUser(panel);
    }
    // reset the size and position, in case the display caused it to change
    panel.getTargetFrame().setLocation(x, y);
    panel.getTargetFrame().setSize(width, height);
    return result;
}
Also used : Attribute(org.jdom2.Attribute) Color(java.awt.Color) Element(org.jdom2.Element) PanelEditor(jmri.jmrit.display.panelEditor.PanelEditor) Point(java.awt.Point) ConfigureManager(jmri.ConfigureManager) AbstractXmlAdapter(jmri.configurexml.AbstractXmlAdapter) XmlAdapter(jmri.configurexml.XmlAdapter)

Example 32 with ConfigureManager

use of jmri.ConfigureManager in project JMRI by JMRI.

the class SystemConsoleConfigPanelXml method load.

@Override
public boolean load(Element shared, Element perNode) throws Exception {
    boolean result = true;
    String value;
    SystemConsolePreferencesManager manager = InstanceManager.getDefault(SystemConsolePreferencesManager.class);
    try {
        if ((value = shared.getAttributeValue("scheme")) != null) {
            manager.setScheme(Integer.parseInt(value));
        }
        if ((value = shared.getAttributeValue("fontfamily")) != null) {
            manager.setFontFamily(value);
        }
        if ((value = shared.getAttributeValue("fontsize")) != null) {
            manager.setFontSize(Integer.parseInt(value));
        }
        if ((value = shared.getAttributeValue("fontstyle")) != null) {
            manager.setFontStyle(Integer.parseInt(value));
        }
        if ((value = shared.getAttributeValue("wrapstyle")) != null) {
            manager.setWrapStyle(Integer.parseInt(value));
        }
    } catch (NumberFormatException ex) {
        log.error("NumberFormatException while setting System Console parameters: " + ex);
        result = false;
    }
    // As we've had a load request, register the system console with the
    // preference manager
    ConfigureManager cm = jmri.InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
    if (cm != null) {
        cm.registerPref(new SystemConsoleConfigPanel());
    }
    return result;
}
Also used : ConfigureManager(jmri.ConfigureManager) SystemConsoleConfigPanel(apps.SystemConsoleConfigPanel) SystemConsolePreferencesManager(apps.systemconsole.SystemConsolePreferencesManager)

Example 33 with ConfigureManager

use of jmri.ConfigureManager in project JMRI by JMRI.

the class StoreXmlAllAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    java.io.File file = getFileName(getAllFileChooser());
    if (file == null) {
        return;
    }
    // and finally store
    ConfigureManager cm = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
    if (cm == null) {
        log.error("Failed to get default configure manager");
    } else {
        boolean results = cm.storeAll(file);
        log.debug(results ? "store was successful" : "store failed");
        if (!results) {
            JOptionPane.showMessageDialog(null, rb.getString("PanelStoreHasErrors") + "\n" + rb.getString("PanelStoreIncomplete") + "\n" + rb.getString("ConsoleWindowHasInfo"), rb.getString("PanelStoreError"), JOptionPane.ERROR_MESSAGE);
        }
    }
}
Also used : ConfigureManager(jmri.ConfigureManager)

Example 34 with ConfigureManager

use of jmri.ConfigureManager in project JMRI by JMRI.

the class StoreXmlConfigAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    File file = getFileName(getConfigFileChooser());
    if (file == null) {
        return;
    }
    // and finally store
    ConfigureManager cm = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
    if (cm == null) {
        log.error("Failed to get default configure manager");
    } else {
        boolean results = cm.storeConfig(file);
        System.out.println(results);
        log.debug(results ? "store was successful" : "store failed");
        if (!results) {
            JOptionPane.showMessageDialog(null, rb.getString("StoreHasErrors") + "\n" + rb.getString("StoreIncomplete") + "\n" + rb.getString("ConsoleWindowHasInfo"), rb.getString("StoreError"), JOptionPane.ERROR_MESSAGE);
        }
    }
}
Also used : ConfigureManager(jmri.ConfigureManager) File(java.io.File)

Example 35 with ConfigureManager

use of jmri.ConfigureManager in project JMRI by JMRI.

the class BlockBossLogic method setup.

private static void setup() {
    if (bblList == null) {
        bblList = new ArrayList<BlockBossLogic>();
        ConfigureManager cm = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
        if (cm != null) {
            cm.registerConfig(new BlockBossLogic(), jmri.Manager.BLOCKBOSS);
        }
    }
}
Also used : ConfigureManager(jmri.ConfigureManager)

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