Example #1
0
    /**
     * Filters a list of vertices out of an array of JGraph GraphCell objects. Other objects are
     * thrown away.
     *
     * @param cells Array of cells to be filtered.
     * @return a list of vertices.
     */
    private List<Object> filterVertices(Object[] cells) {
      List<Object> jVertices = new ArrayList<Object>();

      for (int i = 0; i < cells.length; i++) {
        Object cell = cells[i];

        if (cell instanceof org.jgraph.graph.Edge) {
          // ignore -- we don't care about edges.
        } else if (cell instanceof Port) {
          // ignore -- we don't care about ports.
        } else if (cell instanceof DefaultGraphCell) {
          DefaultGraphCell graphCell = (DefaultGraphCell) cell;

          // If a DefaultGraphCell has a Port as a child, it is a
          // vertex.
          // Note: do not change the order of following conditions;
          // the code uses the short-circuit evaluation of ||.
          if (graphCell.isLeaf() || (graphCell.getFirstChild() instanceof Port)) {
            jVertices.add(cell);
          }
        } else if (cell instanceof GraphCell) {
          // If it is not a DefaultGraphCell, it doesn't have
          // children.
          jVertices.add(cell);
        }
      }

      return jVertices;
    }