Esempio n. 1
0
  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;
  }
Esempio n. 2
0
  /**
   * Construct the array of icons that displays the path
   *
   * @param path
   */
  private ArrayList<Positionable> makePathGroup(OPath path) {
    Portal fromPortal = path.getFromPortal();
    Portal toPortal = path.getToPortal();
    String name = path.getName();

    java.util.List<Positionable> list = _parent.getCircuitGroup();
    if (log.isDebugEnabled()) {
      log.debug("makePathGroup for " + name + " CircuitGroup size= " + list.size());
    }
    ArrayList<Positionable> pathGroup = new ArrayList<Positionable>();
    for (int i = 0; i < list.size(); i++) {
      Positionable pos = list.get(i);
      if (pos instanceof IndicatorTrack) {
        ArrayList<String> paths = ((IndicatorTrack) pos).getPaths();
        if (paths != null) {
          for (int j = 0; j < paths.size(); j++) {
            if (name.equals(paths.get(j))) {
              ((IndicatorTrack) pos).setControlling(true);
              pathGroup.add(pos);
            }
          }
        }
      } else {
        PortalIcon icon = (PortalIcon) pos;
        Portal portal = icon.getPortal();
        if (portal.equals(fromPortal)) {
          pathGroup.add(icon);
        } else if (portal.equals(toPortal)) {
          pathGroup.add(icon);
        }
      }
    }
    return pathGroup;
  }
Esempio n. 3
0
 private static Element storePath(OPath path) {
   Element elem = new Element("path");
   elem.setAttribute("pathName", path.getName());
   elem.setAttribute("blockName", "" + path.getBlock().getSystemName());
   Portal portal = path.getFromPortal();
   if (portal != null) {
     elem.setAttribute("fromPortal", portal.getName());
   }
   portal = path.getToPortal();
   if (portal != null) {
     elem.setAttribute("toPortal", portal.getName());
   }
   List<BeanSetting> list = path.getSettings();
   for (int i = 0; i < list.size(); i++) {
     BeanSetting bs = list.get(i);
     Element e = new Element("setting");
     // Turnout to = (Turnout)bs.getBean();
     e.setAttribute("turnout", bs.getBeanName());
     e.setAttribute("set", "" + bs.getSetting());
     elem.addContent(e);
   }
   elem.setAttribute("fromDirection", "" + path.getFromBlockDirection());
   elem.setAttribute("toDirection", "" + path.getToBlockDirection());
   elem.setAttribute("length", "" + path.getLengthMm());
   return elem;
 }
Esempio n. 4
0
  private void changePathName() {
    String name = _pathName.getText();
    OPath path = _pathList.getSelectedValue();
    if (name == null || name.trim().length() == 0 || path == null) {
      JOptionPane.showMessageDialog(
          this,
          Bundle.getMessage("changePathName"),
          Bundle.getMessage("makePath"),
          JOptionPane.INFORMATION_MESSAGE);
      return;
    }
    String oldName = path.getName();
    OPath oldPath = _block.getPathByName(name);
    if (oldPath != null) {
      JOptionPane.showMessageDialog(
          this,
          Bundle.getMessage("duplicatePathName", name, _block.getDisplayName()),
          Bundle.getMessage("makePath"),
          JOptionPane.INFORMATION_MESSAGE);
      return;
    }
    path.setName(name);

    // Change the path name in the track icons
    java.util.List<Positionable> list = _parent.getCircuitGroup();
    // cannot do remove/add path on the fly due to conncurrent access with Iterator
    ArrayList<IndicatorTrack> changeGroup = new ArrayList<IndicatorTrack>();
    for (int i = 0; i < list.size(); i++) {
      if (list.get(i) instanceof IndicatorTrack) {
        IndicatorTrack icon = (IndicatorTrack) list.get(i);
        ArrayList<String> paths = icon.getPaths();
        if (paths != null) {
          for (int j = 0; j < paths.size(); j++) {
            if (oldName.equals(paths.get(j))) {
              changeGroup.add(icon);
            }
          }
        }
      }
    }
    for (int i = 0; i < changeGroup.size(); i++) {
      IndicatorTrack track = changeGroup.get(i);
      track.removePath(oldName);
      track.addPath(name);
    }
    _pathChange = false;
    _pathListModel.dataChange();
  }
Esempio n. 5
0
 public void valueChanged(ListSelectionEvent e) {
   clearPath();
   OPath path = _pathList.getSelectedValue();
   if (path != null) {
     _pathName.setText(path.getName());
     if (_units.isSelected()) {
       _length.setText(Float.toString(path.getLengthIn()));
     } else {
       _length.setText(Float.toString(path.getLengthCm()));
     }
     showPath(path);
   } else {
     checkForSavePath();
     _pathName.setText(null);
     _length.setText("");
   }
   int state = _block.getState() | OBlock.ALLOCATED;
   _block.pseudoPropertyChange("state", Integer.valueOf(0), Integer.valueOf(state));
 }
Esempio n. 6
0
 private boolean findErrors() {
   boolean error = false;
   if (checkForSavePath()) {
     return true;
   }
   java.util.List<Path> list = _block.getPaths();
   if (list.size() == 0) {
     JOptionPane.showMessageDialog(
         this,
         Bundle.getMessage("noPaths", _block.getDisplayName()),
         Bundle.getMessage("makePath"),
         JOptionPane.INFORMATION_MESSAGE);
   }
   for (int i = 0; i < list.size(); i++) {
     OPath path = (OPath) list.get(i);
     ArrayList<Positionable> pathGp = makePathGroup(path);
     if (pathGp.size() == 0) {
       error = true;
       break;
     }
     OPath p = makeOPath(path.getName(), pathGp, false);
     if (p == null) {
       error = true;
       break;
     }
   }
   if (error) {
     int result =
         JOptionPane.showConfirmDialog(
             this,
             Bundle.getMessage("hasPathErrors"),
             Bundle.getMessage("makePath"),
             JOptionPane.YES_NO_OPTION,
             JOptionPane.QUESTION_MESSAGE);
     if (result == JOptionPane.YES_OPTION) {
       error = false;
     }
   }
   return error;
 }
Esempio n. 7
0
  private static boolean pathsEqual(OPath p1, OPath p2) {
    Portal toPortal1 = p1.getToPortal();
    Portal fromPortal1 = p1.getFromPortal();
    Portal toPortal2 = p2.getToPortal();
    Portal fromPortal2 = p2.getFromPortal();
    boolean testSettings = false;
    if (toPortal1 != null) {
      if ((toPortal1.equals(toPortal2) || toPortal1.equals(fromPortal2))) {
        if (fromPortal1 != null) {
          if (fromPortal1.equals(fromPortal2) || fromPortal1.equals(toPortal2)) {
            testSettings = true;
          }
        } else {
          if (toPortal2 == null || fromPortal2 == null) {
            testSettings = true;
          }
        }
      }
    } else if (toPortal2 == null) { // i.e. toPortal2 matches toPortal1==null
      if (fromPortal1 != null && fromPortal1.equals(fromPortal2)) {
        testSettings = true;
      }
    } else if (fromPortal2 == null) { // i.e. fromPortal2 matches toPortal1==null
      if (fromPortal1 != null && fromPortal1.equals(toPortal2)) {
        testSettings = true;
      }
    }

    if (testSettings) {
      java.util.List<BeanSetting> setting1 = p1.getSettings();
      java.util.List<BeanSetting> setting2 = p2.getSettings();
      if (setting1.size() != setting2.size()) {
        return false;
      }
      if (setting1.size() == 0) { // no turnouts in paths, but portals the same
        return true;
      }
      Iterator<BeanSetting> it = setting1.iterator();
      while (it.hasNext()) {
        BeanSetting bs1 = it.next();
        Iterator<BeanSetting> iter = setting2.iterator();
        while (iter.hasNext()) {
          BeanSetting bs2 = iter.next();
          if (bs1.getBean().equals(bs2.getBean()) && bs1.getSetting() == bs2.getSetting()) {
            return true;
          }
        }
      }
    }
    return false;
  }
Esempio n. 8
0
 public Component getListCellRendererComponent(
     JList<? extends OPath> list, // the list
     OPath value, // value to display
     int index, // cell index
     boolean isSelected, // is the cell selected
     boolean cellHasFocus) // does the cell have focus
     {
   String s = value.getDescription();
   setText(s);
   if (isSelected) {
     setBackground(list.getSelectionBackground());
     setForeground(list.getSelectionForeground());
   } else {
     setBackground(list.getBackground());
     setForeground(list.getForeground());
   }
   setEnabled(list.isEnabled());
   setFont(list.getFont());
   setOpaque(true);
   return this;
 }
Esempio n. 9
0
  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;
  }
Esempio n. 10
0
 /**
  * Key is sufficient to mark the Portal's knowledge of the path. Full path info will get loaded
  * from the HashMap
  */
 private static Element storePathKey(OPath path) {
   Element elem = new Element("path");
   elem.setAttribute("pathName", path.getName());
   elem.setAttribute("blockName", "" + path.getBlock().getSystemName());
   return elem;
 }
Esempio n. 11
0
  /**
   * Create or update the selected path named in the text field Checks that icons have been selected
   * for the path
   */
  private void addPath() {
    String name = _pathName.getText();
    if (name == null || name.trim().length() == 0) {
      JOptionPane.showMessageDialog(
          this,
          Bundle.getMessage("TooltipPathName"),
          Bundle.getMessage("makePath"),
          JOptionPane.INFORMATION_MESSAGE);
      return;
    }
    OPath otherPath = _block.getPathByName(name);
    boolean sameName = false;
    if (otherPath != null) {
      _pathList.setSelectedValue(otherPath, true);
      sameName = true;
      if (!_pathChange) {
        // check portals OK
        Portal p = otherPath.getFromPortal();
        if (p != null && !p.isValidPath(otherPath)) {
          p.addPath(otherPath);
        }
        p = otherPath.getToPortal();
        if (p != null && !p.isValidPath(otherPath)) {
          p.addPath(otherPath);
        }
        setPathLength(otherPath);
        return;
      }
    }
    OPath path = makeOPath(name, _pathGroup, true);
    if (path == null) {
      return; // proper OPath cannot be made
    }
    if (otherPath == null) {
      // is this path already defined?
      Iterator<Path> iter = _block.getPaths().iterator();
      while (iter.hasNext()) {
        OPath p = (OPath) iter.next();
        if (pathsEqual(path, p)) {
          otherPath = p;
          break;
        }
      }
    }
    // match icons to current selections
    changePathNameInIcons(name, path);

    if (otherPath != null) { // same path
      if (!sameName) {
        int result =
            JOptionPane.showConfirmDialog(
                this,
                Bundle.getMessage("samePath", otherPath.getName(), name),
                Bundle.getMessage("makePath"),
                JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE);
        if (result == JOptionPane.YES_OPTION) {
          changePathName();
        }
      }
      _pathList.setSelectedValue(otherPath, true);
    }
    Portal toPortal = path.getToPortal();
    Portal fromPortal = path.getFromPortal();
    if (fromPortal != null && fromPortal.equals(toPortal)) {
      int result =
          JOptionPane.showConfirmDialog(
              this,
              Bundle.getMessage("balloonTrack", name, fromPortal.getDescription()),
              Bundle.getMessage("makePath"),
              JOptionPane.YES_NO_OPTION,
              JOptionPane.QUESTION_MESSAGE);
      if (result == JOptionPane.NO_OPTION) {
        fromPortal = null;
      }
    }
    _pathChange = false;
    // If the name is the same as a Path already in the block, don't add.
    // Just update OPath changes
    if (sameName) {
      OPath oldPath = _block.getPathByName(name);
      oldPath.setToPortal(toPortal);
      oldPath.setFromPortal(fromPortal);
      setPathLength(oldPath);
      oldPath.clearSettings();
      Iterator<BeanSetting> it = path.getSettings().iterator();
      while (it.hasNext()) {
        oldPath.addSetting(it.next());
      }
      toPortal.addPath(oldPath);
      if (fromPortal != null) {
        fromPortal.addPath(oldPath);
      }
    } else {
      _block.addPath(path); // OBlock adds path to portals and checks for duplicate path names
      setPathLength(path);
    }
    _pathList.setSelectedValue(path, true);
    _pathListModel.dataChange();
  }
Esempio n. 12
0
 private void showPath(OPath path) {
   path.setTurnouts(0, true, 0, false);
   _pathGroup = makePathGroup(path);
   updatePath(false);
 }