示例#1
0
  private Element writeXMLUnitElement(UnitElement unit, Element unitElement) {
    Element unitID = new Element("UnitID");
    unitID.addContent(unit.getUnitID() + "");
    unitElement.addContent(unitID);

    // unit description analog to the Unit-XML
    Element unitDescription = new Element("UnitDescription");
    unitElement.addContent(unitDescription);

    Element general = new Element("General");
    unitDescription.addContent(general);

    Element unitName = new Element("UnitName");
    unitName.addContent(unit.getUnitName());
    general.addContent(unitName);
    Element pathToIcon = new Element("PathToIcon");
    pathToIcon.addContent(unit.getIconPath());
    general.addContent(pathToIcon);
    Element imageJSyntax = new Element("ImageJSyntax");
    imageJSyntax.addContent(((MacroElement) unit.getObject()).getImageJSyntax());
    general.addContent(imageJSyntax);
    Element color = new Element("Color");
    String colorHex = Integer.toHexString(unit.getColor().getRGB());
    color.addContent("0x" + colorHex.substring(2));
    general.addContent(color);
    Element iconSize = new Element("IconSize");
    iconSize.addContent(unit.getCompontentSize().toString());
    general.addContent(iconSize);
    Element helpStringU = new Element("HelpString");
    helpStringU.addContent(unit.getHelpString());
    general.addContent(helpStringU);
    Element doDisplayU = new Element("DoDisplay");
    doDisplayU.addContent(unit.isDisplay() ? "true" : "false");
    general.addContent(doDisplayU);

    // deal with all parameters
    Element parameters = new Element("Parameters");
    unitDescription.addContent(parameters);
    for (Parameter parameter : unit.getParameters()) {
      Element parameterElement = new Element("Parameter");
      parameters.addContent(parameterElement);

      Element name = new Element("Name");
      name.addContent(parameter.getDisplayName());
      parameterElement.addContent(name);

      Element dataType = new Element("DataType");
      dataType.addContent(parameter.getParaType());
      parameterElement.addContent(dataType);

      Element value = new Element("Value");
      value.addContent(parameter.getValue() + "");

      Element helpStringP = new Element("HelpString");
      helpStringP.addContent(parameter.getHelpString());
      parameterElement.addContent(helpStringP);

      // special parameters

      if (parameter instanceof ChoiceParameter) {

        value = new Element("Value");
        ChoiceParameter choiceParameter = (ChoiceParameter) parameter;
        String choiceString = choiceParameter.getChoicesString();
        value.addContent(choiceString);

        Element choiceNumber = new Element("ChoiceNumber");
        choiceNumber.addContent(choiceParameter.getChoiceIndex() + "");
        parameterElement.addContent(choiceNumber);
      }
      parameterElement.addContent(value);

      if (parameter instanceof BooleanParameter) {
        Element trueString = new Element("TrueString");
        trueString.addContent(((BooleanParameter) parameter).getTrueString());
        parameterElement.addContent(trueString);
      }
    }

    // deal with inputs
    Element inputs = new Element("Inputs");
    unitDescription.addContent(inputs);
    for (Input input : unit.getInputs()) {
      writeXMLInput(inputs, input);
    }

    // deal with outputs
    Element outputs = new Element("Outputs");
    unitDescription.addContent(outputs);
    for (Output output : unit.getOutputs()) {
      writeXMLOutput(outputs, output);
    }
    return unitDescription;
  }
示例#2
0
  private Node readUnit(final Element actualUnitElement, URL url) {
    Node node;
    int xPos = Integer.parseInt(actualUnitElement.getChild("XPos").getValue());
    int yPos = Integer.parseInt(actualUnitElement.getChild("YPos").getValue());
    String label = "";
    if (actualUnitElement.getChild("Label") != null)
      label = actualUnitElement.getChild("Label").getValue();

    System.out.println("Read unit: " + label);

    Element unitDescriptionElement = actualUnitElement.getChild("UnitDescription");
    if (actualUnitElement.getChild("UnitID") != null && unitDescriptionElement != null) {

      int unitID = Integer.parseInt(actualUnitElement.getChild("UnitID").getValue());
      UnitDescription unitDescription = new UnitDescription(url, unitDescriptionElement);

      UnitElement unitElement;

      Element unitsElement = unitDescriptionElement.getChild("Units");
      Element internalConnectionsElement = unitDescriptionElement.getChild("InternalConnections");
      Element externalConnectionsElement = unitDescriptionElement.getChild("ExternalConnections");
      Element originalConnectionsElement = unitDescriptionElement.getChild("OriginalConnections");
      if (internalConnectionsElement != null
          && originalConnectionsElement != null
          && unitsElement != null) {

        /*
         * GroupUnit
         */

        System.out.println("Process group..");

        unitElement = new GroupUnitElement(new Point(xPos, yPos), label);
        HashMap<Integer, UnitElement> embeddedNodes = new HashMap<Integer, UnitElement>();

        unitElement.setHelpString(unitDescription.helpString);
        newNodes.put(unitID, unitElement);
        groupUnits.add((GroupUnitElement) unitElement);

        /*for (int i = 0; i < unitDescription.numInputs; i++) {
        	unitElement.addInput(UnitFactory.createInput(unitDescription.input[i+1], unitElement, i+1));
        }

        for (int i = 0; i < unitDescription.numOutputs; i++) {
        	unitElement.addOutput(UnitFactory.createOutput(unitDescription.output[i+1], unitElement, i+1));
        }*/

        if (unitsElement != null) {

          List<Element> unitsList = unitsElement.getChildren();
          Iterator<Element> unitsIterator = unitsList.iterator();

          // loop over all Units
          while (unitsIterator.hasNext()) {
            Element actualEmbeddedUnitElement = unitsIterator.next();
            Node embeddedNode = readUnit(actualEmbeddedUnitElement, url);
            ((GroupUnitElement) unitElement).getNodes().add(embeddedNode);
            if (embeddedNode instanceof UnitElement) {
              System.out.println(
                  "put in embeddedNodes: "
                      + embeddedNode
                      + " unitid: "
                      + ((UnitElement) embeddedNode).getUnitID());
              newNodes.put(((UnitElement) embeddedNode).getUnitID(), (UnitElement) embeddedNode);
              embeddedNodes.put(
                  ((UnitElement) embeddedNode).getUnitID(), (UnitElement) embeddedNode);
            }
          }
        }

        if (internalConnectionsElement != null) {
          List<Element> connectionsList = internalConnectionsElement.getChildren();
          Iterator<Element> connectionsIterator = connectionsList.iterator();

          // internal connections require the hashmap with all embedded units
          while (connectionsIterator.hasNext()) {
            Element actualConnectionElement = connectionsIterator.next();

            /*Connection connection = readConnection(newNodes, actualConnectionElement);
            ((GroupUnitElement)unitElement).getInternalConnections().add(connection);*/
            ConnectionDelegate conDelegate =
                new ConnectionDelegate(
                    actualConnectionElement,
                    ((GroupUnitElement) unitElement).getInternalConnections());
            connectionDelegates.add(conDelegate);
          }
        }

        if (originalConnectionsElement != null) {
          List<Element> connectionsList = internalConnectionsElement.getChildren();
          Iterator<Element> connectionsIterator = connectionsList.iterator();

          while (connectionsIterator.hasNext()) {
            Element actualConnectionElement = connectionsIterator.next();
            ConnectionDelegate conDelegate =
                new ConnectionDelegate(
                    actualConnectionElement,
                    ((GroupUnitElement) unitElement).getOriginalConnections());
            connectionDelegates.add(conDelegate);
          }
        }

        if (externalConnectionsElement != null) {
          List<Element> connectionsList = externalConnectionsElement.getChildren();
          Iterator<Element> connectionsIterator = connectionsList.iterator();

          // external connections require the hashmap with all embedded and existing units
          // we need all units of the workflow :/
          while (connectionsIterator.hasNext()) {
            Element actualConnectionElement = connectionsIterator.next();
            //						Connection connection = readConnection(embeddedNodes, actualConnectionElement);
            //						((GroupUnitElement)unitElement).getInternalConnections().add(connection);
            ConnectionDelegate conDelegate =
                new ConnectionDelegate(
                    actualConnectionElement,
                    ((GroupUnitElement) unitElement).getExternalConnections());
            connectionDelegates.add(conDelegate);
          }
        }

      } else {
        // create UnitElement
        unitElement = UnitFactory.createProcessingUnit(unitDescription, new Point(xPos, yPos));
        unitElement.setDisplay(unitDescription.getIsDisplayUnit());
        unitElement.setHelpString(unitDescription.helpString);
        unitElement.setLabel(label);
        newNodes.put(unitID, unitElement);
      }

      node = unitElement;

    } else {
      CommentNode comment = new CommentNode(new Point(xPos, yPos), label);
      node = comment;
    }

    return node;
  }