Search in sources :

Example 61 with Attribute

use of org.openmuc.jasn1.compiler.pkix1explicit88.Attribute in project JMRI by JMRI.

the class PaneProgPane method newVariable.

/**
     * Add the representation of a single variable. The variable is defined by a
     * JDOM variable Element from the XML file.
     *
     * @param var         element containing variable
     * @param col         column to insert label into
     * @param g           panel layout manager
     * @param cs          constraints on layout manager
     * @param showStdName show the name following the rules for the
     * <em>nameFmt</em> element
     */
public void newVariable(Element var, JComponent col, GridBagLayout g, GridBagConstraints cs, boolean showStdName) {
    // get the name
    String name = var.getAttribute("item").getValue();
    // if it doesn't exist, do nothing
    int i = _varModel.findVarIndex(name);
    if (i < 0) {
        log.trace("Variable \"{}\" not found, omitted", name);
        return;
    }
    //        Leave here for now. Need to track pre-existing corner-case issue
    //        log.info("Entry item="+name+";cs.gridx="+cs.gridx+";cs.gridy="+cs.gridy+";cs.anchor="+cs.anchor+";cs.ipadx="+cs.ipadx);
    // check label orientation
    Attribute attr;
    // this default is also set in the DTD
    String layout = "left";
    if ((attr = var.getAttribute("layout")) != null && attr.getValue() != null) {
        layout = attr.getValue();
    }
    // load label if specified, else use name
    String label = name;
    if (!showStdName) {
        // get name attribute from variable, as that's the mfg name
        label = _varModel.getLabel(i);
    }
    String temp = LocaleSelector.getAttribute(var, "label");
    if (temp != null) {
        label = temp;
    }
    // get representation; store into the list to be programmed
    JComponent rep = getRepresentation(name, var);
    varList.add(i);
    // create the paired label
    JLabel l = new WatchingLabel(label, rep);
    int spaceWidth = getFontMetrics(l.getFont()).stringWidth(" ");
    // assemble v from label, rep
    switch(layout) {
        case "left":
            cs.anchor = GridBagConstraints.EAST;
            cs.ipadx = spaceWidth;
            g.setConstraints(l, cs);
            col.add(l);
            cs.ipadx = 0;
            cs.gridx++;
            cs.anchor = GridBagConstraints.WEST;
            g.setConstraints(rep, cs);
            col.add(rep);
            break;
        //        log.info("Exit item="+name+";cs.gridx="+cs.gridx+";cs.gridy="+cs.gridy+";cs.anchor="+cs.anchor+";cs.ipadx="+cs.ipadx);
        case "right":
            cs.anchor = GridBagConstraints.EAST;
            g.setConstraints(rep, cs);
            col.add(rep);
            cs.gridx++;
            cs.anchor = GridBagConstraints.WEST;
            cs.ipadx = spaceWidth;
            g.setConstraints(l, cs);
            col.add(l);
            cs.ipadx = 0;
            break;
        case "below":
            // variable in center of upper line
            cs.anchor = GridBagConstraints.CENTER;
            g.setConstraints(rep, cs);
            col.add(rep);
            // label aligned like others
            cs.gridy++;
            cs.anchor = GridBagConstraints.WEST;
            cs.ipadx = spaceWidth;
            g.setConstraints(l, cs);
            col.add(l);
            cs.ipadx = 0;
            break;
        case "above":
            // label aligned like others
            cs.anchor = GridBagConstraints.WEST;
            cs.ipadx = spaceWidth;
            g.setConstraints(l, cs);
            col.add(l);
            cs.ipadx = 0;
            // variable in center of lower line
            cs.gridy++;
            cs.anchor = GridBagConstraints.CENTER;
            g.setConstraints(rep, cs);
            col.add(rep);
            break;
        default:
            log.error("layout internally inconsistent: " + layout);
    }
}
Also used : Attribute(org.jdom2.Attribute) JComponent(javax.swing.JComponent) JLabel(javax.swing.JLabel)

Example 62 with Attribute

use of org.openmuc.jasn1.compiler.pkix1explicit88.Attribute in project JMRI by JMRI.

the class WiThrottlePreferences method load.

@Override
public void load(Element child) {
    Attribute a;
    if ((a = child.getAttribute("isUseEStop")) != null) {
        setUseEStop(a.getValue().equalsIgnoreCase("true"));
        this.asLoadedUseEStop = this.isUseEStop();
    }
    if ((a = child.getAttribute("getEStopDelay")) != null) {
        try {
            setEStopDelay(Integer.valueOf(a.getValue()));
            this.asLoadedEStopDelay = this.getEStopDelay();
        } catch (NumberFormatException e) {
            log.debug(e.getLocalizedMessage(), e);
        }
    }
    if ((a = child.getAttribute("isUseMomF2")) != null) {
        setUseMomF2(a.getValue().equalsIgnoreCase("true"));
        this.asLoadedUseMomF2 = this.isUseMomF2();
    }
    if ((a = child.getAttribute("getPort")) != null) {
        try {
            setPort(a.getIntValue());
        } catch (DataConversionException ex) {
            log.error("Port {} is invalid.", a.getValue());
        }
        this.asLoadedPort = this.getPort();
    }
    if ((a = child.getAttribute("isAllowTrackPower")) != null) {
        setAllowTrackPower(a.getValue().equalsIgnoreCase("true"));
        this.asLoadedAllowTrackPower = this.isAllowTrackPower();
    }
    if ((a = child.getAttribute("isAllowTurnout")) != null) {
        setAllowTurnout(a.getValue().equalsIgnoreCase("true"));
        this.asLoadedAllowTurnout = this.isAllowTurnout();
    }
    if ((a = child.getAttribute("isAllowRoute")) != null) {
        setAllowRoute(a.getValue().equalsIgnoreCase("true"));
        this.asLoadedAllowRoute = this.isAllowRoute();
    }
    if ((a = child.getAttribute("isAllowConsist")) != null) {
        setAllowConsist(a.getValue().equalsIgnoreCase("true"));
        this.asLoadedAllowConsist = this.isAllowConsist();
    }
    if ((a = child.getAttribute("isUseWiFiConsist")) != null) {
        setUseWiFiConsist(a.getValue().equalsIgnoreCase("true"));
        this.asLoadedUseWiFiConsist = this.isUseWiFiConsist();
    }
}
Also used : Attribute(org.jdom2.Attribute) DataConversionException(org.jdom2.DataConversionException)

Example 63 with Attribute

use of org.openmuc.jasn1.compiler.pkix1explicit88.Attribute 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 64 with Attribute

use of org.openmuc.jasn1.compiler.pkix1explicit88.Attribute in project sis by apache.

the class DecoderWrapper method numericValue.

/**
 * Returns the value of the attribute of the given name as a number, or {@code null} if none.
 *
 * @param  name  the name of the attribute to search, or {@code null}.
 * @return the attribute value, or {@code null} if none or unparsable or if the given name was null.
 */
@Override
public Number numericValue(final String name) {
    if (name != null) {
        for (final Group group : groups) {
            final Attribute attribute = findAttribute(group, name);
            if (attribute != null) {
                final Number value = attribute.getNumericValue();
                if (value != null) {
                    return value;
                }
                String asString = attribute.getStringValue();
                if (asString != null && !(asString = asString.trim()).isEmpty()) {
                    return parseNumber(asString);
                }
            }
        }
    }
    return null;
}
Also used : Group(ucar.nc2.Group) Attribute(ucar.nc2.Attribute)

Example 65 with Attribute

use of org.openmuc.jasn1.compiler.pkix1explicit88.Attribute in project sis by apache.

the class VariableWrapper method getAttributeValues.

/**
 * Returns the sequence of values for the given attribute, or an empty array if none.
 * The elements will be of class {@link String} if {@code numeric} is {@code false},
 * or {@link Number} if {@code numeric} is {@code true}.
 */
@Override
public Object[] getAttributeValues(final String attributeName, final boolean numeric) {
    final Attribute attribute = variable.findAttributeIgnoreCase(attributeName);
    if (attribute != null) {
        boolean hasValues = false;
        final Object[] values = new Object[attribute.getLength()];
        for (int i = 0; i < values.length; i++) {
            if (numeric) {
                if ((values[i] = attribute.getNumericValue(i)) != null) {
                    hasValues = true;
                }
            } else {
                Object value = attribute.getValue(i);
                if (value != null) {
                    String text = value.toString().trim();
                    if (!text.isEmpty()) {
                        values[i] = text;
                        hasValues = true;
                    }
                }
            }
        }
        if (hasValues) {
            return values;
        }
    }
    return new Object[0];
}
Also used : Attribute(ucar.nc2.Attribute)

Aggregations

Attribute (org.jdom2.Attribute)148 Element (org.jdom2.Element)104 Document (org.jdom2.Document)18 ArrayList (java.util.ArrayList)17 DataConversionException (org.jdom2.DataConversionException)16 Editor (jmri.jmrit.display.Editor)15 Test (org.junit.Test)15 IOException (java.io.IOException)14 NamedIcon (jmri.jmrit.catalog.NamedIcon)13 Attribute (org.bouncycastle.asn1.x509.Attribute)11 HashMap (java.util.HashMap)10 List (java.util.List)9 HashSet (java.util.HashSet)7 Map (java.util.Map)7 LayoutEditor (jmri.jmrit.display.layoutEditor.LayoutEditor)7 Attribute (ucar.nc2.Attribute)7 Asn1Integer (com.android.hotspot2.asn1.Asn1Integer)5 Asn1Object (com.android.hotspot2.asn1.Asn1Object)5 Asn1Oid (com.android.hotspot2.asn1.Asn1Oid)5 OidMappings (com.android.hotspot2.asn1.OidMappings)5