Exemplo n.º 1
0
 private void doRename(Element node) {
   if (imageDefaults == null) {
     imageDefaults = getImageDefaults();
   }
   if (!node.hasAttribute(ATTR_NAME)) return;
   JLabel label = new JLabel("New name: ");
   JTextField nameFld = new JTextField("", 20);
   JComponent contents =
       GuiUtils.doLayout(
           new Component[] {
             GuiUtils.rLabel("New name: "), nameFld,
           },
           2,
           GuiUtils.WT_N,
           GuiUtils.WT_N);
   contents = GuiUtils.center(contents);
   contents = GuiUtils.inset(contents, 10);
   if (!GuiUtils.showOkCancelDialog(
       null, "Rename \"" + node.getAttribute("name") + "\"", contents, null)) return;
   String newName = nameFld.getText().trim();
   String tagName = node.getTagName();
   Element root = imageDefaultsRoot;
   if (tagName.equals("default")) {
     root = (Element) node.getParentNode();
   }
   Element exists = XmlUtil.findElement(root, tagName, ATTR_NAME, newName);
   if (!(exists == null)) {
     if (!GuiUtils.askYesNo(
         "Name Already Exists",
         "Do you want to replace " + node.getAttribute("name") + " with" + "\"" + newName + "\"?"))
       return;
   }
   node.removeAttribute(ATTR_NAME);
   node.setAttribute(ATTR_NAME, newName);
   makeXmlTree();
   try {
     imageDefaults.writeWritable();
   } catch (Exception e) {
     logger.error("write error!", e);
   }
   imageDefaults.setWritableDocument(imageDefaultsDocument, imageDefaultsRoot);
 }
Exemplo n.º 2
0
  public Element saveParameterSet() {
    if (imageDefaults == null) {
      imageDefaults = getImageDefaults();
    }
    if (newCompName.length() == 0) {
      newComponentError("parameter set");
      return null;
    }
    Element newChild = imageDefaultsDocument.createElement(TAG_DEFAULT);
    newChild.setAttribute(ATTR_NAME, newCompName);

    if (datachoice == null) {
      datachoice = getDataChoice();
    }
    dataSource = getDataSource();
    if (!(dataSource.getClass().isInstance(new AddeImageParameterDataSource()))) {
      return newChild;
    }
    AddeImageParameterDataSource testDataSource = (AddeImageParameterDataSource) dataSource;
    List imageList = testDataSource.getDescriptors(datachoice, this.dataSelection);
    int numImages = imageList.size();
    List dateTimes = new ArrayList();
    DateTime thisDT = null;
    if (!(imageList == null)) {
      AddeImageDescriptor aid = null;
      for (int imageNo = 0; imageNo < numImages; imageNo++) {
        aid = (AddeImageDescriptor) (imageList.get(imageNo));
        thisDT = aid.getImageTime();
        if (!(dateTimes.contains(thisDT))) {
          if (thisDT != null) {
            dateTimes.add(thisDT);
          }
        }
      }
      String dateS = "";
      String timeS = "";
      if (!(dateTimes.isEmpty())) {
        thisDT = (DateTime) dateTimes.get(0);
        dateS = thisDT.dateString();
        timeS = thisDT.timeString();
        if (dateTimes.size() > 1) {
          for (int img = 1; img < dateTimes.size(); img++) {
            thisDT = (DateTime) dateTimes.get(img);
            String str = ',' + thisDT.dateString();
            String newString = new String(dateS + str);
            dateS = newString;
            str = ',' + thisDT.timeString();
            newString = new String(timeS + str);
            timeS = newString;
          }
        }
      }
      if (aid != null) {
        String displayUrl = testDataSource.getDisplaySource();
        ImageParameters ip = new ImageParameters(displayUrl);
        List props = ip.getProperties();
        List vals = ip.getValues();
        String server = ip.getServer();
        newChild.setAttribute(ATTR_SERVER, server);
        int num = props.size();
        if (num > 0) {
          String attr = "";
          String val = "";
          for (int i = 0; i < num; i++) {
            attr = (String) (props.get(i));
            if (attr.equals(ATTR_POS)) {
              val = new Integer(numImages - 1).toString();
            } else if (attr.equals(ATTR_DAY)) {
              val = dateS;
            } else if (attr.equals(ATTR_TIME)) {
              val = timeS;
            } else {
              val = (String) (vals.get(i));
            }
            newChild.setAttribute(attr, val);
          }
        }
      }
    }
    Element parent = xmlTree.getSelectedElement();
    if (parent == null) {
      parent = (Element) lastCat;
    }
    if (parent != null) {
      Element exists = XmlUtil.findElement(parent, "default", ATTR_NAME, newCompName);
      if (!(exists == null)) {
        JLabel label = new JLabel("Replace \"" + newCompName + "\"?");
        JPanel contents = GuiUtils.top(GuiUtils.inset(label, newCompName.length() + 12));
        if (!GuiUtils.showOkCancelDialog(null, "Parameter Set Exists", contents, null)) {
          return newChild;
        }
        parent.removeChild(exists);
      }
      parent.appendChild(newChild);
      makeXmlTree();
    }
    try {
      imageDefaults.writeWritable();
    } catch (Exception e) {
      logger.error("write error!", e);
    }
    imageDefaults.setWritableDocument(imageDefaultsDocument, imageDefaultsRoot);
    return newChild;
  }