Search in sources :

Example 1 with GuiLafConfigPane

use of apps.GuiLafConfigPane in project JMRI by JMRI.

the class GuiLafConfigPaneXml method load.

@Override
public boolean load(Element shared, Element perNode) {
    boolean result = true;
    UIManager.LookAndFeelInfo[] plafs = UIManager.getInstalledLookAndFeels();
    java.util.Hashtable<String, String> installedLAFs = new java.util.Hashtable<String, String>(plafs.length);
    for (int i = 0; i < plafs.length; i++) {
        installedLAFs.put(plafs[i].getName(), plafs[i].getClassName());
    }
    String name = shared.getAttribute("LAFclass").getValue();
    String className = installedLAFs.get(name);
    log.debug("GUI selection: " + name + " class name: " + className);
    // set the GUI
    if (className != null) {
        InstanceManager.getDefault(GuiLafPreferencesManager.class).setLookAndFeel(name);
        try {
            if (!className.equals(UIManager.getLookAndFeel().getClass().getName())) {
                log.debug("set GUI to " + name + "," + className);
                updateLookAndFeel(name, className);
            } else {
                log.debug("skip updateLAF as already has className==" + className);
            }
        } catch (Exception ex) {
            log.error("Exception while setting GUI look & feel: " + ex);
            result = false;
        }
    }
    Attribute langAttr = shared.getAttribute("LocaleLanguage");
    Attribute countryAttr = shared.getAttribute("LocaleCountry");
    Attribute varAttr = shared.getAttribute("LocaleVariant");
    if (countryAttr != null && langAttr != null && varAttr != null) {
        Locale locale = new Locale(langAttr.getValue(), countryAttr.getValue(), varAttr.getValue());
        Locale.setDefault(locale);
        InstanceManager.getDefault(GuiLafPreferencesManager.class).setLocale(locale);
    }
    Attribute clickAttr = shared.getAttribute("nonStandardMouseEvent");
    if (clickAttr != null) {
        boolean nonStandardMouseEvent = clickAttr.getValue().equals("yes");
        jmri.util.swing.SwingSettings.setNonStandardMouseEvent(nonStandardMouseEvent);
        InstanceManager.getDefault(GuiLafPreferencesManager.class).setNonStandardMouseEvent(nonStandardMouseEvent);
    }
    Attribute graphicAttr = shared.getAttribute("graphicTableState");
    if (graphicAttr != null) {
        boolean graphicTableState = graphicAttr.getValue().equals("yes");
        InstanceManager.getDefault(GuiLafPreferencesManager.class).setGraphicTableState(graphicTableState);
    }
    GuiLafConfigPane g = new GuiLafConfigPane();
    ConfigureManager cm = jmri.InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
    if (cm != null) {
        cm.registerPref(g);
    }
    Attribute fontsize = shared.getAttribute("fontsize");
    if (fontsize != null) {
        int size = Integer.parseInt(fontsize.getValue());
        InstanceManager.getDefault(GuiLafPreferencesManager.class).setFontSize(size);
        this.setUIFontSize(size);
    }
    return result;
}
Also used : Locale(java.util.Locale) GuiLafPreferencesManager(apps.gui.GuiLafPreferencesManager) Attribute(org.jdom2.Attribute) GuiLafConfigPane(apps.GuiLafConfigPane) UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException) ConfigureManager(jmri.ConfigureManager)

Example 2 with GuiLafConfigPane

use of apps.GuiLafConfigPane in project JMRI by JMRI.

the class GuiLafConfigPaneXml method store.

/**
     * Default implementation for storing the static contents of the Swing LAF
     *
     * @param o Object to store, of type GuiLafConfigPane
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    Element e = new Element("gui");
    GuiLafConfigPane g = (GuiLafConfigPane) o;
    String lafClassName = g.getClassName();
    e.setAttribute("LAFclass", lafClassName);
    e.setAttribute("class", this.getClass().getName());
    Locale l = g.getLocale();
    e.setAttribute("LocaleLanguage", l.getLanguage());
    e.setAttribute("LocaleCountry", l.getCountry());
    e.setAttribute("LocaleVariant", l.getVariant());
    GuiLafPreferencesManager manager = InstanceManager.getDefault(GuiLafPreferencesManager.class);
    if (manager.getFontSize() != manager.getDefaultFontSize()) {
        e.setAttribute("fontsize", Integer.toString(manager.getFontSize()));
    }
    e.setAttribute("nonStandardMouseEvent", (g.mouseEvent.isSelected() ? "yes" : "no"));
    e.setAttribute("graphicTableState", (g.graphicStateDisplay.isSelected() ? "yes" : "no"));
    return e;
}
Also used : Locale(java.util.Locale) GuiLafPreferencesManager(apps.gui.GuiLafPreferencesManager) Element(org.jdom2.Element) GuiLafConfigPane(apps.GuiLafConfigPane)

Aggregations

GuiLafConfigPane (apps.GuiLafConfigPane)2 GuiLafPreferencesManager (apps.gui.GuiLafPreferencesManager)2 Locale (java.util.Locale)2 UnsupportedLookAndFeelException (javax.swing.UnsupportedLookAndFeelException)1 ConfigureManager (jmri.ConfigureManager)1 Attribute (org.jdom2.Attribute)1 Element (org.jdom2.Element)1