コード例 #1
0
ファイル: EditCircuitPaths.java プロジェクト: NomDInet/JMRI
  private boolean setPathLength(OPath path) {
    float f = 0.0f;
    try {
      String num = _length.getText();
      if (num == null || num.length() == 0) {
        num = "0.0";
      }
      f = Float.parseFloat(num);
      if (_units.isSelected()) {
        path.setLength(f * 25.4f);
      } else {
        path.setLength(f * 10f);
      }
    } catch (NumberFormatException nfe) {
      f = -1.0f;
    }
    if (f < 0.0f) {
      JOptionPane.showMessageDialog(
          this,
          Bundle.getMessage("MustBeFloat", _length.getText()),
          Bundle.getMessage("makePath"),
          JOptionPane.INFORMATION_MESSAGE);
      return false;
    }

    return true;
  }
コード例 #2
0
ファイル: OBlockManagerXml.java プロジェクト: dpharris/JMRI
  OPath loadPath(Element elem, OBlock block) {
    String pName = elem.getAttribute("pathName").getValue();
    OPath path = getPath(block, pName);
    try {
      Attribute attr = elem.getAttribute("fromDirection");
      if (attr != null) {
        path.setFromBlockDirection(attr.getIntValue());
      }
      attr = elem.getAttribute("toDirection");
      if (attr != null) {
        path.setToBlockDirection(attr.getIntValue());
      }
      attr = elem.getAttribute("length");
      if (attr != null) {
        path.setLength(attr.getFloatValue());
      }
    } catch (org.jdom2.DataConversionException e) {
      log.error(
          "Could not parse attribute of path ("
              + pName
              + ") block ("
              + block.getSystemName()
              + ")");
    }

    Attribute attr = elem.getAttribute("fromPortal");
    if (attr != null) {
      Portal portal = getPortal(attr.getValue());
      if (portal != null) {
        path.setFromPortal(portal);
        portal.addPath(path);
      }
    }
    attr = elem.getAttribute("toPortal");
    if (attr != null) {
      Portal portal = getPortal(attr.getValue());
      if (portal != null) {
        path.setToPortal(portal);
        portal.addPath(path);
      }
    }

    List<Element> settings = elem.getChildren("setting");
    if (log.isDebugEnabled()) {
      log.debug("Path (" + pName + ") has " + settings.size() + " settings.");
    }
    java.util.HashSet<String> turnouts = new java.util.HashSet<String>();
    int dups = 0;
    for (int i = 0; i < settings.size(); i++) {
      Element setElem = settings.get(i);
      int setting = 0;
      try {
        setting = setElem.getAttribute("set").getIntValue();
      } catch (org.jdom2.DataConversionException e) {
        log.error(
            "Could not parse 'set' attribute for path ("
                + pName
                + ") block ("
                + block.getSystemName()
                + ")");
      }
      String sysName = setElem.getAttribute("turnout").getValue();
      if (!turnouts.contains(sysName)) {
        Turnout to = InstanceManager.turnoutManagerInstance().provideTurnout(sysName);
        turnouts.add(sysName);
        BeanSetting bs = new BeanSetting(to, sysName, setting);
        path.addSetting(bs);
      } else {
        dups++;
      }
    }
    if (dups > 0) {
      log.warn(dups + " duplicate settings not loaded for path \"" + pName + "\"");
    }
    return path;
  }