⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 workflow_fileimportgxl.java

📁 用java实现的工作流
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                if (!getIcon(node).equals(null)) {
                  Icon icon1 = new ImageIcon(getIcon(node));
                  GraphConstants.setIcon(node_attrs, icon1);
                }

                attributes.put(vertex, node_attrs);

                // Add Vertex to new Cells

                newCells.add(vertex);

              }

              // Create Edge
            }
            else if (type.equals("edge")) {
              Element edge_node = (Element) node;
              // Fetch Source ID Node
              Node tmp = node.getAttributes().getNamedItem("from");
              // Fetch Source ID Value
              String source = null;
              if (tmp != null) {
                source = tmp.getNodeValue();
                // Fetch Target ID Node
              }
              tmp = node.getAttributes().getNamedItem("to");
              // Fetch Target ID Value
              String target = null;
              if (tmp != null) {
                target = tmp.getNodeValue();
                // Create Edge with label
              }
              DefaultEdge edge = new DefaultEdge(new GPUserObject(label));
              // Find Source Port
              if (source != null) {
                // Fetch Vertex for Source ID
                DefaultGraphCell vertex =
                    (DefaultGraphCell) ids.get(source);
                if (vertex != null) {

                  // Connect to Source Port
                  cs.connect(edge, vertex.getChildAt(0), true);

                }
              }
              // Find Target Port
              if (target != null) {
                // Fetch Vertex for Target ID
                DefaultGraphCell vertex =
                    (DefaultGraphCell) ids.get(target);
                if (vertex != null) {

                  // Connect to Target Port
                  cs.connect(edge, vertex.getChildAt(0), false);
                }
              }

              boolean edge_directed = ("true".equals(edge_node.getAttribute(
                  "isdirected")) || defaultDirected)
                  && ! ("false".equals(edge_node.getAttribute("isdirected")));
              AttributeMap map = new AttributeMap();

              if (edge_directed) {
                GraphConstants.setLineEnd(map, GraphConstants.ARROW_SIMPLE);
                GraphConstants.setEndFill(map, true);
                GraphConstants.setLabelAlongEdge(map, true);
              }

              fetchEdgeViewProperties(edge_node, map);
              attributes.put(edge, map);

              // Add Edge to new Cells
              newCells.add(edge);
            }
            else if (type.equals("view")) { // Graph view attributes
              // Currently defined: defaultlayout
              defaultLayout = ( (Element) node).getAttribute("defaultlayout");
            }
          }
        }
      }
    }
    // Insert the cells (View stores attributes)
    model.insert(newCells.toArray(), attributes, cs, null, null);
    //   if (defaultLayout != null) {
    //   applyLayout(graph, defaultLayout);
    //  }
  }

  /**
   * Applies the layout given by name in <code>layout</code>.
   * Searches LayoutRegistry for the layout controller with string representation
   * equals to the <code>layout</code> and performs its algorithm on the imported
   * graph.
   */
  static void applyLayout(JGraph graph, String layout) {
    if (layout == null) {
      return;
    }
    Iterator controllers = JGraphLayoutRegistry.getSharedJGraphLayoutRegistry().
        getLayouts().iterator();
    while (controllers.hasNext()) {
      JGraphLayoutAlgorithm controller = (JGraphLayoutAlgorithm) controllers.
          next();
      if (layout.equals(controller.toString())) {
        Object[] cells = JGraphUtilities.getAll(graph);
        if (cells != null && cells.length > 0) {
          JGraphLayoutAlgorithm.applyLayout(graph, cells, controller);
        }
        return;
      }
    }
  }

  /**
   * Returns an GPAttributeMap for the specified position and color.
   */
  public Map createDefaultAttributes() {
    // Create an GPAttributeMap
    AttributeMap map = new AttributeMap();
    // Set a Black Line Border (the Border-Attribute must be Null!)
    //  GraphConstants.setBorderColor(map, Color.black);
    //   GraphConstants.setBackground(map, Color.LIGHT_GRAY);
    GraphConstants.setOpaque(map, true);

    //   GraphConstants.setBorder(map, BorderFactory.createRaisedBevelBorder());

    //  GraphConstants.setValue(map,"新节点");


    // Return the Map
    return map;
  }

  // Fetch Cell Label from Node
  protected static String getLabel(Node node) {
    String lab = null;
    NodeList children = node.getChildNodes();
    for (int j = 0; j < children.getLength(); j++) {
      Node attr = children.item(j);
      if (attr.getNodeName().equals("attr")
          && attr
          .getAttributes()
          .getNamedItem("name")
          .getNodeValue()
          .equals(
          "Label")) {
        NodeList values = attr.getChildNodes();
        for (int k = 0; k < values.getLength(); k++) {
          if (values.item(k).getNodeName().equals("string")) {
            Node labelNode = values.item(k).getFirstChild();

            if (labelNode != null) {
              lab = labelNode.getNodeValue();
            }
          }
        }
      }
    }
    return (lab != null) ? lab : new String("");
  }

  protected Vector getBound(Node node) {

    Vector vec = new Vector();
    NodeList children = node.getChildNodes();
    for (int j = 0; j < children.getLength(); j++) {
      Node attr = children.item(j);
      if (attr.getNodeName().equals("attr")
          && attr
          .getAttributes()
          .getNamedItem("name")
          .getNodeValue()
          .equals(
          "Bounds")) {
        NodeList values = attr.getChildNodes();
        for (int k = 0; k < values.getLength(); k++) {
          if (values.item(k).getNodeName().equals("tup")) {
            NodeList tup = values.item(k).getChildNodes();
            for (int i = 0; i < tup.getLength(); i++) {
              if (tup.item(i).getNodeName().equals("int")) {
                Node Bounds = tup.item(i).getFirstChild();
                vec.add(Bounds.getNodeValue());

              }

            }

          }
        }

      }
    }
    return vec;
  }

// 添加获得ICON的方法 //comsci
  protected String getIcon(Node node) {

    String iconname = null;

    NodeList children = node.getChildNodes();
    for (int jl = 0; jl < children.getLength(); jl++) {
      Node attr = children.item(jl);
      if (attr.getNodeName().equals("attr")
          && attr
          .getAttributes()
          .getNamedItem("name")
          .getNodeValue()
          .equals(
          "Icon")) {

        NodeList values = attr.getChildNodes();
        for (int kl = 0; kl < values.getLength(); kl++) {
          if (values.item(kl).getNodeName().equals("tup")) {

            NodeList tup = values.item(kl).getChildNodes();
            for (int il = 0; il < tup.getLength(); il++) {

              if (tup.item(il).getNodeName().equals("string")) {

                Node icon1 = tup.item(il).getFirstChild();
                if (! (icon1.getNodeValue().equals(""))) {
                  iconname = (String) icon1.getNodeValue();

                }

              }

            }

          }

        }

      }

    }

    return iconname;

  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -