Esempio n. 1
0
  public void addMergeNodesForMap(LWMap map, WeightAggregate weightAggregate, List<Style> styles) {

    Iterator<LWComponent> children =
        map.getAllDescendents(LWComponent.ChildKind.PROPER).iterator(); // map.getNodeIterator();
    while (children.hasNext()) {
      LWComponent component = children.next();
      if (component instanceof LWPortal) continue;

      if (component instanceof LWNode || component instanceof LWImage) {
        boolean repeat = false;
        if (nodeAlreadyPresent(component)) {
          repeat = true;
        }
        LWComponent node = component.duplicate();
        edu.tufts.vue.metadata.VueMetadataElement vme =
            new edu.tufts.vue.metadata.VueMetadataElement();
        vme.setType(edu.tufts.vue.metadata.VueMetadataElement.OTHER);
        String sourceLabel = node.getLabel();
        if (sourceLabel == null) sourceLabel = "";
        String sourceMap = component.getMap().getLabel();

        if (sourceMap == null) sourceMap = "";

        vme.setObject("source: " + sourceMap + "," + sourceLabel);
        node.getMetadataList().getMetadata().add(vme);
        if (!repeat) {
          if (!excludeNodesFromBaseMap || !nodePresentOnBaseMap(node)) {
            add(node);
          }
        }
      }
    }
  }
Esempio n. 2
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. 3
0
  public void addMergeNodesFromSourceMap(
      LWMap map, VoteAggregate voteAggregate, HashMap<String, LWNode> nodes) {
    Iterator<LWComponent> children =
        map.getAllDescendents(LWComponent.ChildKind.PROPER).iterator(); // map.getNodeIterator();
    while (children.hasNext()) {
      // LWNode comp = (LWNode)children.next();
      LWComponent comp = children.next();

      if (comp instanceof LWPortal) continue;

      boolean repeat = false;
      if (nodeAlreadyPresent(comp)) {
        repeat = true;
        /*if(RECORD_SOURCE_NODES)
        {
          LWNode node = nodes.get(Util.getMergeProperty(comp));
          if(node.getNotes() !=null)
          {
            node.setNotes(node.getNotes()+"\n" + map.getLabel());
          }
          else
          {
            node.setNotes(map.getLabel());
          }
        }*/
      }

      if (voteAggregate.isNodeVoteAboveThreshold(Util.getMergeProperty(comp))) {
        // LWNode node = (LWNode)comp.duplicate();
        LWComponent node = comp.duplicate();

        String sourceLabel = node.getLabel();

        if (sourceLabel == null) sourceLabel = "";

        edu.tufts.vue.metadata.VueMetadataElement vme =
            new edu.tufts.vue.metadata.VueMetadataElement();
        vme.setType(edu.tufts.vue.metadata.VueMetadataElement.OTHER);

        // todo: looks like this may be needed in future -- may be an issue
        // of map list in merge maps panel -- or otherwise might require
        // more generic approach (certainly a seperate method either here or in
        // merge maps panel or in VueMetadataElement is in order)
        /*String mapLabel = comp.getMap().getLabel();

        if(mapLabel != null)
        {
            if(mapLabel.contains(".vue"))
            {
                mapLabel = mapLabel.substring(0,mapLabel.indexOf(".vue"));
            }
        }
        else
        {
            mapLabel = "";
        }*/

        vme.setObject("source: " + comp.getMap().getLabel() + "," + sourceLabel);
        node.getMetadataList().getMetadata().add(vme);

        if (!repeat) {
          /*if(RECORD_SOURCE_NODES)
          {
            if(node.getNotes() !=null)
            {
              node.setNotes(node.getNotes()+"\n" + map.getLabel());
            }
            else
            {
              node.setNotes(map.getLabel());
            }
            nodes.put(Util.getMergeProperty(comp),node);
          }*/
          // addNode(node);
          if (!excludeNodesFromBaseMap || !nodePresentOnBaseMap(node)) {
            add(node);
          }
        }
      }
    }
  }