コード例 #1
0
  /**
   * Load, starting with the memoryComboIcon element, then all the value-icon pairs
   *
   * @param element Top level Element to unpack.
   * @param o an Editor as an Object
   */
  public void load(Element element, Object o) {
    // create the objects
    Editor p = (Editor) o;

    Element elem = element.getChild("itemList");
    List<Element> list = elem.getChildren("item");
    String[] items = new String[list.size()];
    for (int i = 0; i < list.size(); i++) {
      Element e = list.get(i);
      String item = e.getText();
      //            int idx = 0;
      //            try {
      //                idx = e.getAttribute("index").getIntValue();
      //            } catch ( org.jdom2.DataConversionException ex) {
      //                log.error("failed to convert ComboBoxIcon index attribute");
      //                idx = i;
      //            }
      items[i] = item;
    }

    MemoryComboIcon l = new MemoryComboIcon(p, items);

    loadTextInfo(l, element);
    String name;
    Attribute attr = element.getAttribute("memory");
    if (attr == null) {
      log.error("incorrect information for a memory location; must use memory name");
      p.loadFailed();
      return;
    } else {
      name = attr.getValue();
    }

    Memory m = jmri.InstanceManager.memoryManagerInstance().getMemory(name);

    if (m != null) {
      l.setMemory(name);
    } else {
      log.error("Memory named '" + attr.getValue() + "' not found.");
      p.loadFailed();
      return;
    }

    p.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.MEMORIES, element);
  }
コード例 #2
0
  /**
   * Load, starting with the memoryInputIcon element, then all the value-icon pairs
   *
   * @param element Top level Element to unpack.
   * @param o an Editor as an Object
   */
  public void load(Element element, Object o) {
    // create the objects
    Editor p = (Editor) o;

    int nCol = 2;
    try {
      nCol = element.getAttribute("colWidth").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
      log.error("failed to convert colWidth attribute");
    }

    MemoryInputIcon l = new MemoryInputIcon(nCol, p);

    loadTextInfo(l, element);
    String name;
    Attribute attr = element.getAttribute("memory");
    if (attr == null) {
      log.error("incorrect information for a memory location; must use memory name");
      p.loadFailed();
      return;
    } else {
      name = attr.getValue();
    }

    Memory m = jmri.InstanceManager.memoryManagerInstance().getMemory(name);

    if (m != null) {
      l.setMemory(name);
    } else {
      log.error("Memory named '" + attr.getValue() + "' not found.");
      p.loadFailed();
      return;
    }

    p.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.MEMORIES, element);

    javax.swing.JComponent textField = l.getTextComponent();
    jmri.jmrit.display.PositionablePopupUtil util = l.getPopupUtility();
    if (util.hasBackground()) {
      textField.setBackground(util.getBackground());
    } else {
      textField.setBackground(null);
      textField.setOpaque(false);
    }
  }
コード例 #3
0
ファイル: TurnoutIconXml.java プロジェクト: JMRI/jmri-test
 private NamedIcon loadTurnoutIcon(
     String state, int rotation, TurnoutIcon l, Element element, String name, Editor ed) {
   NamedIcon icon = null;
   if (element.getAttribute(state) != null) {
     String iconName = element.getAttribute(state).getValue();
     icon = NamedIcon.getIconByName(iconName);
     if (icon == null) {
       icon = ed.loadFailed("Turnout \"" + name + "\" icon \"" + state + "\" ", iconName);
       if (icon == null) {
         log.info("Turnout \"" + name + "\" icon \"" + state + "\" removed for url= " + iconName);
       }
     } else {
       icon.setRotation(rotation, l);
     }
   } else {
     log.warn("did not locate " + state + " icon file for Turnout " + name);
   }
   if (icon == null) {
     log.info("Turnout Icon \"" + name + "\": icon \"" + state + "\" removed");
   } else {
     l.setIcon(_nameMap.get(state), icon);
   }
   return icon;
 }
コード例 #4
0
ファイル: TurnoutIconXml.java プロジェクト: JMRI/jmri-test
  /**
   * Create a PositionableLabel, then add to a target JLayeredPane
   *
   * @param element Top level Element to unpack.
   * @param o Editor as an Object
   */
  @SuppressWarnings("null")
  public void load(Element element, Object o) {
    // create the objects
    Editor p = (Editor) o;

    TurnoutIcon l = new TurnoutIcon(p);

    String name;
    try {
      name = element.getAttribute("turnout").getValue();
    } catch (NullPointerException e) {
      log.error("incorrect information for turnout; must use turnout name");
      p.loadFailed();
      return;
    }
    l.setTurnout(name);

    Attribute a = element.getAttribute("tristate");
    if ((a == null) || ((a != null) && a.getValue().equals("true"))) {
      l.setTristate(true);
    } else {
      l.setTristate(false);
    }

    a = element.getAttribute("momentary");
    if ((a != null) && a.getValue().equals("true")) {
      l.setMomentary(true);
    } else {
      l.setMomentary(false);
    }

    a = element.getAttribute("directControl");
    if ((a != null) && a.getValue().equals("true")) {
      l.setDirectControl(true);
    } else {
      l.setDirectControl(false);
    }

    List<Element> states = element.getChildren();
    if (states.size() > 0) {
      if (log.isDebugEnabled()) {
        log.debug("Main element has" + states.size() + " items");
      }
      Element elem = element; // the element containing the icons
      Element icons = element.getChild("icons");
      if (icons != null) {
        List<Element> s = icons.getChildren();
        states = s;
        elem = icons; // the element containing the icons
        if (log.isDebugEnabled()) {
          log.debug("icons element has" + states.size() + " items");
        }
      }
      for (int i = 0; i < states.size(); i++) {
        String state = states.get(i).getName();
        if (log.isDebugEnabled()) {
          log.debug("setIcon for state \"" + state + "\" and " + _nameMap.get(state));
        }
        NamedIcon icon =
            loadIcon(l, state, elem, "TurnoutIcon \"" + name + "\": icon \"" + state + "\" ", p);
        if (icon != null) {
          l.setIcon(_nameMap.get(state), icon);
        } else {
          log.info("TurnoutIcon \"" + name + "\": icon \"" + state + "\" removed");
          return;
        }
      }
      log.debug(states.size() + " icons loaded for " + l.getNameString());
    } else { // case when everything was attributes
      int rotation = 0;
      try {
        rotation = element.getAttribute("rotate").getIntValue();
      } catch (org.jdom2.DataConversionException e) {
      } catch (NullPointerException e) { // considered normal if the attributes are not present
      }
      if (loadTurnoutIcon("thrown", rotation, l, element, name, p) == null) {
        return;
      }
      if (loadTurnoutIcon("closed", rotation, l, element, name, p) == null) {
        return;
      }
      if (loadTurnoutIcon("unknown", rotation, l, element, name, p) == null) {
        return;
      }
      if (loadTurnoutIcon("inconsistent", rotation, l, element, name, p) == null) {
        return;
      }
    }
    Element elem = element.getChild("iconmaps");
    if (elem != null) {
      Attribute attr = elem.getAttribute("family");
      if (attr != null) {
        l.setFamily(attr.getValue());
      }
    }

    p.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.TURNOUTS, element);
  }