Search in sources :

Example 76 with Element

use of com.zhan_dui.utils.m3u8.Element in project JMRI by JMRI.

the class PaneProgPane method newRow.

/**
     * Create a single row from the JDOM column Element
     *
     * @param element     element containing row contents
     * @param showStdName show the name following the rules for the
     * <em>nameFmt</em> element
     * @param modelElem   element containing the decoder model
     * @return a panel containing the group
     */
public JPanel newRow(Element element, boolean showStdName, Element modelElem) {
    // create a panel to add as a new column or row
    final JPanel c = new JPanel();
    panelList.add(c);
    GridBagLayout g = new GridBagLayout();
    GridBagConstraints cs = new GridBagConstraints();
    c.setLayout(g);
    // handle the xml definition
    // for all elements in the column or row
    List<Element> elemList = element.getChildren();
    log.trace("newRow starting with {} elements", elemList.size());
    for (int i = 0; i < elemList.size(); i++) {
        // update the grid position
        cs.gridy = 0;
        cs.gridx++;
        Element e = elemList.get(i);
        String name = e.getName();
        log.trace("newRow processing {} element", name);
        // decode the type
        if (name.equals("display")) {
            // its a variable
            // load the variable
            newVariable(e, c, g, cs, showStdName);
        } else if (name.equals("separator")) {
            // its a separator
            JSeparator j = new JSeparator(javax.swing.SwingConstants.VERTICAL);
            cs.fill = GridBagConstraints.BOTH;
            cs.gridheight = GridBagConstraints.REMAINDER;
            g.setConstraints(j, cs);
            c.add(j);
            cs.fill = GridBagConstraints.NONE;
            cs.gridheight = 1;
        } else if (name.equals("label")) {
            cs.gridheight = GridBagConstraints.REMAINDER;
            makeLabel(e, c, g, cs);
        } else if (name.equals("soundlabel")) {
            cs.gridheight = GridBagConstraints.REMAINDER;
            makeSoundLabel(e, c, g, cs);
        } else if (name.equals("cvtable")) {
            makeCvTable(cs, g, c);
        } else if (name.equals("indxcvtable")) {
            log.debug("starting to build IndexedCvTable pane");
            JTable indxcvTable = new JTable(_indexedCvModel);
            JScrollPane cvScroll = new JScrollPane(indxcvTable);
            indxcvTable.setDefaultRenderer(JTextField.class, new ValueRenderer());
            indxcvTable.setDefaultRenderer(JButton.class, new ValueRenderer());
            indxcvTable.setDefaultEditor(JTextField.class, new ValueEditor());
            indxcvTable.setDefaultEditor(JButton.class, new ValueEditor());
            indxcvTable.setRowHeight(new JButton("X").getPreferredSize().height);
            indxcvTable.setPreferredScrollableViewportSize(new Dimension(700, indxcvTable.getRowHeight() * 14));
            cvScroll.setColumnHeaderView(indxcvTable.getTableHeader());
            // don't want a horizontal scroll bar
            // Need to see the whole row at one time
            //                indxcvTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
            cs.gridwidth = GridBagConstraints.REMAINDER;
            g.setConstraints(cvScroll, cs);
            c.add(cvScroll);
            cs.gridwidth = 1;
            // remember which indexed CVs to read/write
            for (int j = 0; j < _indexedCvModel.getRowCount(); j++) {
                String sz = "CV" + _indexedCvModel.getName(j);
                int in = _varModel.findVarIndex(sz);
                indexedCvList.add(in);
            }
            _cvTable = true;
            log.debug("end of building IndexedCvTable pane");
        } else if (name.equals("fnmapping")) {
            pickFnMapPanel(c, g, cs, modelElem);
        } else if (name.equals("dccaddress")) {
            JPanel l = addDccAddressPanel(e);
            if (l.getComponentCount() > 0) {
                cs.gridheight = GridBagConstraints.REMAINDER;
                g.setConstraints(l, cs);
                c.add(l);
                cs.gridheight = 1;
            }
        } else if (name.equals("column")) {
            // nested "column" elements ...
            cs.gridheight = GridBagConstraints.REMAINDER;
            JPanel l = newColumn(e, showStdName, modelElem);
            if (l.getComponentCount() > 0) {
                panelList.add(l);
                g.setConstraints(l, cs);
                c.add(l);
                cs.gridheight = 1;
            }
        } else if (name.equals("row")) {
            // nested "row" elements ...
            cs.gridwidth = GridBagConstraints.REMAINDER;
            JPanel l = newRow(e, showStdName, modelElem);
            if (l.getComponentCount() > 0) {
                panelList.add(l);
                g.setConstraints(l, cs);
                c.add(l);
                cs.gridwidth = 1;
            }
        } else if (name.equals("grid")) {
            // nested "grid" elements ...
            cs.gridwidth = GridBagConstraints.REMAINDER;
            JPanel l = newGrid(e, showStdName, modelElem);
            if (l.getComponentCount() > 0) {
                panelList.add(l);
                g.setConstraints(l, cs);
                c.add(l);
                cs.gridwidth = 1;
            }
        } else if (name.equals("group")) {
            // nested "group" elements ...
            JPanel l = newGroup(e, showStdName, modelElem);
            if (l.getComponentCount() > 0) {
                panelList.add(l);
                g.setConstraints(l, cs);
                c.add(l);
            }
        } else if (!name.equals("qualifier")) {
            // its a mistake
            log.error("No code to handle element of type " + e.getName() + " in newRow");
        }
    }
    // add glue to the bottom to allow resize
    if (c.getComponentCount() > 0) {
        c.add(Box.createVerticalGlue());
    }
    // handle qualification if any
    QualifierAdder qa = new QualifierAdder() {

        @Override
        protected Qualifier createQualifier(VariableValue var, String relation, String value) {
            return new JComponentQualifier(c, var, Integer.parseInt(value), relation);
        }

        @Override
        protected void addListener(java.beans.PropertyChangeListener qc) {
            c.addPropertyChangeListener(qc);
        }
    };
    qa.processModifierElements(element, _varModel);
    return c;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) GridBagLayout(java.awt.GridBagLayout) VariableValue(jmri.jmrit.symbolicprog.VariableValue) Element(org.jdom2.Element) JButton(javax.swing.JButton) ValueEditor(jmri.jmrit.symbolicprog.ValueEditor) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField) JSeparator(javax.swing.JSeparator) ValueRenderer(jmri.jmrit.symbolicprog.ValueRenderer) JTable(javax.swing.JTable) QualifierAdder(jmri.jmrit.symbolicprog.QualifierAdder)

Example 77 with Element

use of com.zhan_dui.utils.m3u8.Element in project JMRI by JMRI.

the class AddressPanel method getXml.

/**
     * Create an Element of this object's preferences.
     * <ul>
     * <li> Window Preferences
     * <li> Address value
     * </ul>
     *
     * @return org.jdom2.Element for this objects preferences. Defined in
     *         DTD/throttle-config
     */
public Element getXml() {
    Element me = new Element("AddressPanel");
    //Element window = new Element("window");
    java.util.ArrayList<Element> children = new java.util.ArrayList<Element>(1);
    children.add(WindowPreferences.getPreferences(this));
    children.add((new jmri.configurexml.LocoAddressXml()).store(addrSelector.getAddress()));
    children.add((new jmri.configurexml.LocoAddressXml()).store(consistAddress));
    me.setContent(children);
    return me;
}
Also used : Element(org.jdom2.Element) ArrayList(java.util.ArrayList)

Example 78 with Element

use of com.zhan_dui.utils.m3u8.Element in project JMRI by JMRI.

the class ButtonTrigger method getXml.

@Override
public Element getXml() {
    Element me = new Element("Trigger");
    log.debug("Bool Trigger getXml():");
    log.debug("  trigger_name = " + this.getName());
    log.debug("  event_name = " + this.event_name);
    log.debug("  target_name = " + target.getName());
    log.debug("  match = " + Boolean.valueOf(match_value).toString());
    log.debug("  action = " + this.getTriggerType().toString());
    me.setAttribute("name", this.getName());
    me.setAttribute("type", "BOOLEAN");
    me.addContent(new Element("event-name").addContent(event_name));
    me.addContent(new Element("target-name").addContent(target.getName()));
    me.addContent(new Element("match").addContent(Boolean.valueOf(match_value).toString()));
    me.addContent(new Element("action").addContent(this.getTriggerType().toString()));
    return (me);
}
Also used : Element(org.jdom2.Element)

Example 79 with Element

use of com.zhan_dui.utils.m3u8.Element in project JMRI by JMRI.

the class WindowPreferences method getPreferences.

/**
     * Collect container preferences.
     *
     * @param c The container being XMLed.
     * @return An Element containing the following prefs:
     * <ul>
     * <li> x location
     * <li> y location
     * <li> width
     * <li> height
     * </ul>
     */
public static Element getPreferences(Container c) {
    Element window = new Element("window");
    window.setAttribute("x", String.valueOf(c.getLocation().x));
    window.setAttribute("y", String.valueOf(c.getLocation().y));
    Dimension size = c.getSize();
    window.setAttribute("width", String.valueOf(size.width));
    window.setAttribute("height", String.valueOf(size.height));
    window.setAttribute("isVisible", String.valueOf(c.isVisible()));
    return window;
}
Also used : Element(org.jdom2.Element) Dimension(java.awt.Dimension)

Example 80 with Element

use of com.zhan_dui.utils.m3u8.Element in project JMRI by JMRI.

the class WindowPreferences method getPreferences.

/**
     * Collect JInternalFrame preferences.
     *
     * @param c The JInternalFrame being XMLed.
     * @return An Element containing the following prefs:
     * <ul>
     * <li> x location
     * <li> y location
     * <li> width
     * <li> height
     * <li> isIcon
     * </ul>
     */
public static Element getPreferences(JInternalFrame c) {
    Element window = getPreferences((Container) c);
    window.setAttribute("isIconified", String.valueOf(c.isIcon()));
    return window;
}
Also used : Element(org.jdom2.Element)

Aggregations

Element (org.jdom2.Element)673 Attribute (org.jdom2.Attribute)73 Document (org.jdom2.Document)58 File (java.io.File)49 ArrayList (java.util.ArrayList)36 NamedIcon (jmri.jmrit.catalog.NamedIcon)27 IOException (java.io.IOException)26 JDOMException (org.jdom2.JDOMException)26 XmlFile (jmri.jmrit.XmlFile)24 Test (org.junit.Test)24 Turnout (jmri.Turnout)20 DataConversionException (org.jdom2.DataConversionException)20 DocType (org.jdom2.DocType)19 Editor (jmri.jmrit.display.Editor)18 Point (java.awt.Point)15 HashMap (java.util.HashMap)15 Dimension (java.awt.Dimension)14 FileNotFoundException (java.io.FileNotFoundException)13 SignalHead (jmri.SignalHead)13 List (java.util.List)12