Ejemplo n.º 1
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();
  }
Ejemplo n.º 2
0
 private void deletePath() {
   OPath path = _pathList.getSelectedValue();
   if (path == null) {
     // check that name was typed in and not selected
     path = _block.getPathByName(_pathName.getText());
   }
   if (path == null) {
     return;
   }
   _pathChange = false;
   _block.removePath(path);
   _pathListModel.dataChange();
   // Get icons for path
   _pathGroup = makePathGroup(path);
   clearPath();
 }
Ejemplo n.º 3
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();
  }