Search in sources :

Example 31 with Element

use of org.neo4j.ogm.domain.gh806.Element in project JMRI by JMRI.

the class AbstractSensorManagerConfigXML method store.

public Element store(Object o, Element sensors) {
    setStoreElementClass(sensors);
    SensorManager tm = (SensorManager) o;
    if (tm.getDefaultSensorDebounceGoingActive() > 0 || tm.getDefaultSensorDebounceGoingInActive() > 0) {
        Element elem = new Element("globalDebounceTimers");
        elem.addContent(new Element("goingActive").addContent(String.valueOf(tm.getDefaultSensorDebounceGoingActive())));
        elem.addContent(new Element("goingInActive").addContent(String.valueOf(tm.getDefaultSensorDebounceGoingInActive())));
        sensors.addContent(elem);
    }
    java.util.Iterator<String> iter = tm.getSystemNameList().iterator();
    // don't return an element if there are not sensors to include
    if (!iter.hasNext()) {
        return null;
    }
    // store the sensors
    while (iter.hasNext()) {
        String sname = iter.next();
        log.debug("system name is " + sname);
        Sensor s = tm.getBySystemName(sname);
        String inverted = s.getInverted() ? "true" : "false";
        Element elem = new Element("sensor").setAttribute("inverted", inverted);
        elem.addContent(new Element("systemName").addContent(sname));
        log.debug("store sensor " + sname);
        if (s.useDefaultTimerSettings()) {
            elem.addContent(new Element("useGlobalDebounceTimer").addContent("yes"));
        } else {
            if (s.getSensorDebounceGoingActiveTimer() > 0 || s.getSensorDebounceGoingInActiveTimer() > 0) {
                Element timer = new Element("debounceTimers");
                timer.addContent(new Element("goingActive").addContent(String.valueOf(s.getSensorDebounceGoingActiveTimer())));
                timer.addContent(new Element("goingInActive").addContent(String.valueOf(s.getSensorDebounceGoingInActiveTimer())));
                elem.addContent(timer);
            }
        }
        if (tm.isPullResistanceConfigurable()) {
            // store the sensor's value for pull resistance.
            elem.addContent(new Element("pullResistance").addContent(s.getPullResistance().getShortName()));
        }
        // store common part
        storeCommon(s, elem);
        sensors.addContent(elem);
    }
    return sensors;
}
Also used : SensorManager(jmri.SensorManager) Element(org.jdom2.Element) Sensor(jmri.Sensor)

Example 32 with Element

use of org.neo4j.ogm.domain.gh806.Element in project JMRI by JMRI.

the class AbstractNamedBeanManagerConfigXML method loadProperties.

/**
     * Load all key/value properties
     *
     * @param t    The NamedBean being loaded
     * @param elem The existing Element
     */
void loadProperties(NamedBean t, Element elem) {
    Element p = elem.getChild("properties");
    if (p == null) {
        return;
    }
    for (Object next : p.getChildren("property")) {
        Element e = (Element) next;
        try {
            Class<?> cl;
            Constructor<?> ctor;
            // create key string
            String key = e.getChild("key").getText();
            // constructed from Strings, similar to the value code below.
            if (!(e.getChild("key").getAttributeValue("class") == null || e.getChild("key").getAttributeValue("class").equals("") || e.getChild("key").getAttributeValue("class").equals("java.lang.String"))) {
                log.warn("NamedBean {} property key of invalid non-String type {} not supported", t.getSystemName(), e.getChild("key").getAttributeValue("class"));
            }
            // create value object
            Object value = null;
            if (e.getChild("value") != null) {
                cl = Class.forName(e.getChild("value").getAttributeValue("class"));
                ctor = cl.getConstructor(new Class<?>[] { String.class });
                value = ctor.newInstance(new Object[] { e.getChild("value").getText() });
            }
            // store
            t.setProperty(key, value);
        } catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | java.lang.reflect.InvocationTargetException ex) {
            log.error("Error loading properties", ex);
        }
    }
}
Also used : Element(org.jdom2.Element)

Example 33 with Element

use of org.neo4j.ogm.domain.gh806.Element in project JMRI by JMRI.

the class JmriJTablePersistenceManager method savePreferences.

@Override
public synchronized void savePreferences(Profile profile) {
    log.debug("Saving preferences (dirty={})...", this.dirty);
    Element element = new Element(TABLES_ELEMENT, TABLES_NAMESPACE);
    if (!this.columns.isEmpty()) {
        this.columns.entrySet().stream().map((entry) -> {
            Element table = new Element("table").setAttribute("name", entry.getKey());
            Element columnsElement = new Element("columns");
            entry.getValue().entrySet().stream().map((column) -> {
                Element columnElement = new Element("column").setAttribute("name", column.getKey());
                if (column.getValue().getOrder() != -1) {
                    columnElement.setAttribute("order", Integer.toString(column.getValue().getOrder()));
                }
                if (column.getValue().getWidth() != -1) {
                    columnElement.setAttribute("width", Integer.toString(column.getValue().getWidth()));
                }
                columnElement.setAttribute("hidden", Boolean.toString(column.getValue().getHidden()));
                return columnElement;
            }).forEach((columnElement) -> {
                columnsElement.addContent(columnElement);
            });
            table.addContent(columnsElement);
            List<SortKey> keys = this.sortKeys.get(entry.getKey());
            if (keys != null) {
                Element sorter = new Element(SORT_ORDER);
                keys.stream().forEach((key) -> {
                    sorter.addContent(new Element("sortKey").setAttribute("column", Integer.toString(key.getColumn())).setAttribute(SORT_ORDER, key.getSortOrder().name()));
                });
                table.addContent(sorter);
            }
            return table;
        }).forEach((table) -> {
            element.addContent(table);
        });
    }
    try {
        ProfileUtils.getUserInterfaceConfiguration(ProfileManager.getDefault().getActiveProfile()).putConfigurationFragment(JDOMUtil.toW3CElement(element), false);
    } catch (JDOMException ex) {
        log.error("Unable to save user preferences", ex);
    }
    this.dirty = false;
}
Also used : Arrays(java.util.Arrays) TableColumnModel(javax.swing.table.TableColumnModel) Enumeration(java.util.Enumeration) SortKey(javax.swing.RowSorter.SortKey) XTableColumnModel(jmri.util.swing.XTableColumnModel) AbstractPreferencesManager(jmri.util.prefs.AbstractPreferencesManager) LoggerFactory(org.slf4j.LoggerFactory) ProfileManager(jmri.profile.ProfileManager) HashMap(java.util.HashMap) Timer(java.util.Timer) InitializationException(jmri.util.prefs.InitializationException) ArrayList(java.util.ArrayList) JDOMException(org.jdom2.JDOMException) JDOMUtil(jmri.util.jdom.JDOMUtil) ProfileUtils(jmri.profile.ProfileUtils) Map(java.util.Map) Profile(jmri.profile.Profile) TableColumnModelEvent(javax.swing.event.TableColumnModelEvent) RowSorter(javax.swing.RowSorter) TimerTask(java.util.TimerTask) ListSelectionEvent(javax.swing.event.ListSelectionEvent) Nonnull(javax.annotation.Nonnull) PropertyChangeEvent(java.beans.PropertyChangeEvent) ChangeEvent(javax.swing.event.ChangeEvent) Logger(org.slf4j.Logger) TableColumn(javax.swing.table.TableColumn) RowSorterListener(javax.swing.event.RowSorterListener) Set(java.util.Set) Objects(java.util.Objects) SortOrder(javax.swing.SortOrder) List(java.util.List) TableColumnModelListener(javax.swing.event.TableColumnModelListener) PropertyChangeListener(java.beans.PropertyChangeListener) JTable(javax.swing.JTable) DataConversionException(org.jdom2.DataConversionException) CheckForNull(javax.annotation.CheckForNull) RowSorterEvent(javax.swing.event.RowSorterEvent) Element(org.jdom2.Element) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) List(java.util.List) JDOMException(org.jdom2.JDOMException)

Example 34 with Element

use of org.neo4j.ogm.domain.gh806.Element in project JMRI by JMRI.

the class JMenuUtil method jMenuFromElement.

@Nonnull
static JMenu jMenuFromElement(@CheckForNull Element main, WindowInterface wi, Object context) {
    boolean addSep = false;
    String name = "<none>";
    if (main == null) {
        log.warn("Menu from element called without an element");
        return new JMenu(name);
    }
    name = LocaleSelector.getAttribute(main, "name");
    //Next statement left in if the xml file hasn't been converted
    if ((name == null) || (name.equals(""))) {
        if (main.getChild("name") != null) {
            name = main.getChild("name").getText();
        }
    }
    JMenu menu = new JMenu(name);
    ArrayList<Integer> mnemonicList = new ArrayList<Integer>();
    for (Object item : main.getChildren("node")) {
        JMenuItem menuItem = null;
        Element child = (Element) item;
        if (child.getChildren("node").size() == 0) {
            // leaf
            if ((child.getText().trim()).equals("separator")) {
                addSep = true;
            } else {
                if (!(SystemType.isMacOSX() && UIManager.getLookAndFeel().isNativeLookAndFeel() && ((child.getChild("adapter") != null && child.getChild("adapter").getText().equals("apps.gui3.TabbedPreferencesAction")) || (child.getChild("current") != null && child.getChild("current").getText().equals("quit"))))) {
                    if (addSep) {
                        menu.addSeparator();
                        addSep = false;
                    }
                    Action act = actionFromNode(child, wi, context);
                    menu.add(menuItem = new JMenuItem(act));
                }
            }
        } else {
            if (addSep) {
                menu.addSeparator();
                addSep = false;
            }
            if (child.getChild("group") != null && child.getChild("group").getText().equals("yes")) {
                //A seperate method is required for creating radio button groups
                menu.add(createMenuGroupFromElement(child, wi, context));
            } else {
                // not leaf
                menu.add(menuItem = jMenuFromElement(child, wi, context));
            }
        }
        if (menuItem != null && child.getChild("current") != null) {
            setMenuItemInterAction(context, child.getChild("current").getText(), menuItem);
        }
        if (menuItem != null && child.getChild("mnemonic") != null) {
            int mnemonic = convertStringToKeyEvent(child.getChild("mnemonic").getText());
            if (mnemonicList.contains(mnemonic)) {
                log.error("Menu Item '" + menuItem.getText() + "' Mnemonic '" + child.getChild("mnemonic").getText() + "' has already been assigned");
            } else {
                menuItem.setMnemonic(mnemonic);
                mnemonicList.add(mnemonic);
            }
        }
    }
    return menu;
}
Also used : Action(javax.swing.Action) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu) Nonnull(javax.annotation.Nonnull)

Example 35 with Element

use of org.neo4j.ogm.domain.gh806.Element in project JMRI by JMRI.

the class JMenuUtil method loadMenu.

public static JMenu[] loadMenu(String path, WindowInterface wi, Object context) {
    Element root = rootFromName(path);
    int n = root.getChildren("node").size();
    JMenu[] retval = new JMenu[n];
    int i = 0;
    ArrayList<Integer> mnemonicList = new ArrayList<Integer>();
    for (Object child : root.getChildren("node")) {
        JMenu menuItem = jMenuFromElement((Element) child, wi, context);
        retval[i++] = menuItem;
        if (((Element) child).getChild("mnemonic") != null) {
            int mnemonic = convertStringToKeyEvent(((Element) child).getChild("mnemonic").getText());
            if (mnemonicList.contains(mnemonic)) {
                log.error("Menu item '" + menuItem.getText() + "' Mnemonic '" + ((Element) child).getChild("mnemonic").getText() + "' has already been assigned");
            } else {
                menuItem.setMnemonic(mnemonic);
                mnemonicList.add(mnemonic);
            }
        }
    }
    return retval;
}
Also used : Element(org.jdom2.Element) ArrayList(java.util.ArrayList) JMenu(javax.swing.JMenu)

Aggregations

Element (org.jdom2.Element)3327 Document (org.jdom2.Document)502 Test (org.junit.Test)457 ArrayList (java.util.ArrayList)327 IOException (java.io.IOException)268 Attribute (org.jdom2.Attribute)207 JDOMException (org.jdom2.JDOMException)202 Element (org.osate.aadl2.Element)143 Namespace (org.jdom2.Namespace)136 Test (org.junit.jupiter.api.Test)131 List (java.util.List)130 SAXBuilder (org.jdom2.input.SAXBuilder)125 File (java.io.File)124 HashMap (java.util.HashMap)117 XMLOutputter (org.jdom2.output.XMLOutputter)103 XConfiguration (org.apache.oozie.util.XConfiguration)98 Configuration (org.apache.hadoop.conf.Configuration)96 NamedElement (org.osate.aadl2.NamedElement)77 StringReader (java.io.StringReader)67 Iterator (java.util.Iterator)63