Esempio n. 1
0
  public void fillAsWeightMerge() {

    ConnectivityMatrixList<ConnectivityMatrix> cms =
        new ConnectivityMatrixList<ConnectivityMatrix>();
    Iterator<LWMap> i = getMapList().iterator();
    Iterator<Boolean> ci = null;
    if (getActiveFileList() != null) ci = getActiveFileList().iterator();
    while (i.hasNext()) {
      LWMap m = i.next();
      if (DEBUG_LOCAL) {
        System.out.println("LWMergeMap, computing matrix array next map is: " + m.getLabel());
      }
      Boolean b = Boolean.TRUE;
      if (ci != null && ci.hasNext()) {
        b = ci.next();
      }
      if (b.booleanValue()) // || (m==getBaseMap()))
      {
        if (DEBUG_LOCAL) {
          System.out.println("LWMergeMap, computing matrix array actually adding: " + m.getLabel());
        }
        cms.add(new ConnectivityMatrix(m));
      } else {
        if (DEBUG_LOCAL) {
          System.out.println(
              "LWMergeMap, computing matrix array not adding due to check box or base map (already added):"
                  + " (label, m == getBaseMap()) ("
                  + m.getLabel()
                  + ","
                  + (m == getBaseMap())
                  + ")");
        }
      }
    }

    ArrayList<Style> nodeStyles = new ArrayList<Style>();
    ArrayList<Style> linkStyles = new ArrayList<Style>();

    for (int si = 0; si < 5; si++) {
      nodeStyles.add(StyleMap.getStyle("node.w" + (si + 1)));
    }

    for (int lsi = 0; lsi < 5; lsi++) {
      linkStyles.add(StyleMap.getStyle("link.w" + (lsi + 1)));
    }

    WeightAggregate weightAggregate = new WeightAggregate(cms);

    if (!excludeNodesFromBaseMap && baseMapIsActive()) {
      addMergeNodesForMap(getBaseMap(), weightAggregate, nodeStyles);
    }

    if (!getFilterOnBaseMap()) {
      Iterator<LWMap> maps = getMapList().iterator();
      ci = null;
      if (getActiveFileList() != null) ci = getActiveFileList().iterator();
      while (maps.hasNext()) {
        LWMap m = maps.next();
        if (DEBUG_LOCAL) {
          System.out.println("LWMergeMap: next map - " + m.getLabel());
        }
        Boolean b = Boolean.TRUE;
        if (ci != null && ci.hasNext()) {
          b = ci.next();
        }
        if (m != baseMap && b.booleanValue()) {
          if (DEBUG_LOCAL) {
            System.out.println("LWMergeMap: actually adding - " + m.getLabel());
          }
          addMergeNodesForMap(m, weightAggregate, nodeStyles);
        } else {
          if (DEBUG_LOCAL) {
            System.out.println("LWMergeMap: not adding - " + m.getLabel());
          }
        }
      }
    }

    // todo: use applyCSS(style) -- need to plug in formatting panel
    Iterator children = getAllDescendents(LWComponent.ChildKind.PROPER).iterator();

    while (children.hasNext()) {
      LWComponent comp = (LWComponent) children.next();
      if (DEBUG_LOCAL) {
        System.out.println("LWMergeMap, computing colors, next component - " + comp.getLabel());
      }
      if (comp instanceof LWNode) {
        LWNode node = (LWNode) comp;
        double score =
            100
                * weightAggregate.getNodeCount(Util.getMergeProperty(node))
                / weightAggregate.getCount();
        if (score > 100) {
          score = 100;
        }
        if (score < 0) {
          score = 0;
        }
        Style currStyle = nodeStyles.get(getNodeInterval(score) - 1);
        // todo: applyCss here instead.
        node.setFillColor(Style.hexToColor(currStyle.getAttribute("background")));

        java.awt.Color strokeColor = null;
        if (currStyle.getAttribute("font-color") != null) {
          strokeColor = Style.hexToColor(currStyle.getAttribute("font-color"));
        }
        if (strokeColor != null) {
          node.setTextColor(strokeColor);
        }
      }
    }

    // compute and create links in Merge Map
    Iterator<LWComponent> children1 = getAllDescendents(LWComponent.ChildKind.PROPER).iterator();
    while (children1.hasNext()) {
      LWComponent comp1 = children1.next();
      // if(comp1 instanceof LWImage)
      //    continue;
      // LWNode node1 = (LWNode)comp1;
      LWComponent node1 = comp1;
      Iterator<LWComponent> children2 =
          getAllDescendents(LWComponent.ChildKind.PROPER).iterator(); // getNodeIterator();
      LWComponent node2 = null;
      while (children2.hasNext()) {
        /*LWComponent*/ node2 = /*(LWNode)*/ children2.next();
        if (!((node2 instanceof LWNode) || (node2 instanceof LWImage))) {
          continue;
        }
        if (node2 != node1) {
          int c =
              weightAggregate.getConnection(
                  Util.getMergeProperty(node1), Util.getMergeProperty(node2));
          int c2 =
              weightAggregate.getConnection(
                  Util.getMergeProperty(node2), Util.getMergeProperty(node1));
          if (c > 0) {
            double score = 100 * c / weightAggregate.getCount();

            // are either of these ever happenning? If so, why?
            if (score > 100) {
              score = 100;
            }
            if (score < 0) {
              score = 0;
            }

            Style currLinkStyle = linkStyles.get(getLinkInterval(score) - 1);
            LWLink link = new LWLink(node1, node2);
            if (c2 > 0 && !getFilterOnBaseMap()) {
              link.setArrowState(LWLink.ARROW_BOTH);
              weightAggregate.setConnection(
                  Util.getMergeProperty(node2), Util.getMergeProperty(node1), 0);
            }
            // todo: applyCSS here
            link.setStrokeColor(Style.hexToColor(currLinkStyle.getAttribute("background")));
            addLink(link);

            cms.addLinkSourceMapMetadata(
                Util.getMergeProperty(node1), Util.getMergeProperty(node2), link);

            // edu.tufts.vue.metadata.VueMetadataElement vme = new
            // edu.tufts.vue.metadata.VueMetadataElement();
            // vme.setType(edu.tufts.vue.metadata.VueMetadataElement.OTHER);
            // vme.setObject("source: " + comp.getMap().getLabel() + "," + sourceLabel);
            // link.getMetadataList().getMetadata().add(vme);
          }
        }
      }
    }
  }
Esempio n. 2
0
  public void fillAsVoteMerge() {

    HashMap<String, LWNode> nodes = new HashMap<String, LWNode>();

    ConnectivityMatrixList<ConnectivityMatrix> cms =
        new ConnectivityMatrixList<ConnectivityMatrix>();

    Iterator<LWMap> i = getMapList().iterator();
    Iterator<Boolean> ci = null;
    if (getActiveFileList() != null) ci = getActiveFileList().iterator();
    while (i.hasNext()) {
      Boolean b = Boolean.TRUE;

      LWMap next = i.next();

      if (ci != null && ci.hasNext()) {
        b = ci.next();
      }
      if (b.booleanValue() /*&& (next != getBaseMap())*/) cms.add(new ConnectivityMatrix(next));
    }
    VoteAggregate voteAggregate = new VoteAggregate(cms);

    voteAggregate.setNodeThreshold((double) getNodeThresholdSliderValue() / 100.0);
    voteAggregate.setLinkThreshold((double) getLinkThresholdSliderValue() / 100.0);

    // compute and create nodes in Merge Map

    if (!excludeNodesFromBaseMap && baseMapIsActive()) {
      addMergeNodesFromSourceMap(baseMap, voteAggregate, nodes);
    }

    if (!getFilterOnBaseMap()) {
      Iterator<LWMap> maps = getMapList().iterator();
      ci = null;
      if (getActiveFileList() != null) ci = getActiveFileList().iterator();
      while (maps.hasNext()) {
        LWMap m = maps.next();
        Boolean b = Boolean.TRUE;
        if (ci != null && ci.hasNext()) {
          b = ci.next();
        }
        if (m != baseMap && b.booleanValue()) {
          addMergeNodesFromSourceMap(m, voteAggregate, nodes);
        }
      }
    }

    // compute and create links in Merge Map
    Iterator<LWComponent> children1 =
        getAllDescendents(LWComponent.ChildKind.PROPER).iterator(); // getNodeIterator();
    while (children1.hasNext()) {
      /*LWNode*/ LWComponent node1 = /*(LWNode)*/ children1.next();
      Iterator<LWComponent> children2 =
          getAllDescendents(LWComponent.ChildKind.PROPER).iterator(); // getNodeIterator();
      while (children2.hasNext()) {

        /*LWNode*/ LWComponent node2 = /*(LWNode)*/ children2.next();

        if (!((node1 instanceof LWNode || node1 instanceof LWImage)
            && (node2 instanceof LWNode || node2 instanceof LWImage))) {
          continue;
        }

        if (node2 != node1) {
          boolean addLink =
              voteAggregate.isLinkVoteAboveThreshold(
                  Util.getMergeProperty(node1), Util.getMergeProperty(node2));
          if (addLink) {
            LWLink link = new LWLink(node1, node2);
            addLink(link);
            cms.addLinkSourceMapMetadata(
                Util.getMergeProperty(node1), Util.getMergeProperty(node2), link);
          }
        }
      }
    }
  }