Пример #1
0
  public void clearAllElements() {

    // this deletion code was copied from an old version of LWComponent deletion code
    // todo: probably should sync this up with whatever the menu action does.

    Iterator li = getAllDescendents().iterator();

    while (li.hasNext()) {
      LWComponent c = (LWComponent) li.next();

      LWContainer parent = c.getParent();
      if (parent == null) {
        // System.out.println("DELETE: " + c + " skipping: null parent (already deleted)");
      } else if (c.isDeleted()) {
        // System.out.println("DELETE: " + c + " skipping (already deleted)");
      } else if (parent.isDeleted()) { // after prior check, this case should be impossible now
        // System.out.println("DELETE: " + c + " skipping (parent already deleted)"); // parent will
        // call deleteChildPermanently
      } else if (parent.isSelected()) { // if parent selected, it will delete it's children
        // System.out.println("DELETE: " + c + " skipping - parent selected & will be deleting");
      } else {
        parent.deleteChildPermanently(c);
      }
    }
  }
Пример #2
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);
          }
        }
      }
    }
  }
Пример #3
0
    private PrintJob(MapViewer viewer, boolean viewerPrint) {
      super("PrintJob#" + JobCount++);
      this.map = viewer.getMap();
      this.focal = viewerPrint ? viewer.getFocal() : map;
      this.jobName = map.getDisplayLabel();
      this.isPrintingView = viewerPrint;

      // be sure to grab bounds info now -- sometimes it's possible
      // that the viewer bounds go negative once the model print dialog
      // boxes go active and VUE is hung without being able to reshape
      // or repaint itself.  (That's not a problem when we run this
      // in a thread, but there's a java bug with that right now, tho
      // it's safer to do it this way anyway).
      if (isPrintingView()) {
        if (focal == map) this.bounds = viewer.getVisibleMapBounds();
        else this.bounds = focal.getBorderBounds();
      } else this.bounds = map.getBounds();
      out(viewerPrint ? "printing: viewer contents" : "printing: whole map");
      out("requested map bounds: " + bounds);
    }
Пример #4
0
  public boolean nodeAlreadyPresent(LWComponent node) {

    if (DEBUG_LOCAL) {
      System.out.println("nodeAlreadyPresent -- getParent() " + node.getParent());
    }

    // also need to check if parent *will* be visible
    // if(! (node.getParent() instanceof LWMap ) )
    if (!node.atTopLevel()) return true;
    if (node == null) {
      return false;
    }
    // if(node.getParent() instanceof LWNode && (LWNode.isImageNode((LWNode)(node.getParent()))) )
    //     return true;
    //        Iterator<LWComponent> i = this.getAllDescendents(ChildKind.PROPER).iterator();
    //        Iterator<LWComponent> i = this. getChildList().iterator();
    for (LWComponent c : getAllDescendents(ChildKind.PROPER)) {
      if (Util.getMergeProperty(node) != null && Util.getMergeProperty(c) != null) {
        if (Util.getMergeProperty(node).equals(Util.getMergeProperty(c))) {
          if (DEBUG_LOCAL) {
            System.out.println(
                "LWMergeMap - returning true in nodeAlreadyPresent - for (node,c) ("
                    + Util.getMergeProperty(node)
                    + ","
                    + Util.getMergeProperty(c)
                    + ")");
          }
          // TODO: not sure why this code is here and what it is doing. should be refactored.
          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);
          vme.setObject("source: " + node.getMap().getLabel() + "," + sourceLabel);
          c.getMetadataList().getMetadata().add(vme);

          return true;
        }
      }
    }
    return false;
  }
Пример #5
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);
          }
        }
      }
    }
  }
Пример #6
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);
          }
        }
      }
    }
  }
Пример #7
0
    public int print(Graphics gc, PageFormat format, int pageIndex)
        throws java.awt.print.PrinterException {
      if (pageIndex > 0) {
        out("page " + pageIndex + " requested, ending print job.");
        return Printable.NO_SUCH_PAGE;
      }

      Dimension page =
          new Dimension(
              (int) format.getImageableWidth() - 1, (int) format.getImageableHeight() - 1);

      Graphics2D g = (Graphics2D) gc;

      out(
          "asked to render page "
              + pageIndex
              + " in "
              + outpf(format)
              + " w/transform "
              + g.getTransform());

      // note: supposedly, perhaps on Windows with JVM's 1.5 and newer, the
      // transform scale provided can actually allow us to derive the DPI of the
      // print device, which we could use for image rendering optimization's
      // during prints.  Mac OS X Snow Leopard w/JVM 1.6 always reports a 1.0
      // scale though.  And operations like "print preview" or "print to PDF"
      // wouldn't have a fixed DPI anyway.

      if (DEBUG.CONTAINMENT) {
        g.setColor(Color.lightGray);
        g.fillRect(0, 0, 9999, 9999);
      }

      g.translate(format.getImageableX(), format.getImageableY());

      // Don't need to clip if printing whole map, as computed zoom
      // should have made sure everything is within page size
      // if (!isPrintingView())
      // g.clipRect(0, 0, page.width, page.height);

      if (DEBUG.CONTAINMENT) {
        // g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
        // draw border outline of page
        g.setColor(Color.gray);
        g.setStroke(VueConstants.STROKE_TWO);
        g.drawRect(0, 0, page.width, page.height);
        // g.setComposite(AlphaComposite.Src);
      }

      // compute zoom & offset for visible map components
      Point2D.Float offset = new Point2D.Float();
      // center vertically only if landscape mode
      // if (format.getOrientation() == PageFormat.LANDSCAPE)
      // TODO: allow horizontal centering, but not vertical centering (handle in computeZoomFit)
      double scale = ZoomTool.computeZoomFit(page, 5, bounds, offset, true);
      out("rendering at scale " + scale);
      // set up the DrawContext
      DrawContext dc =
          new DrawContext(
              g, scale, -offset.x, -offset.y,
              null, // frame would be the PageFormat offset & size rectangle
              focal, false); // todo: absolute links shouldn't be spec'd here

      dc.setMapDrawing();
      dc.setPrintQuality();

      if (isPrintingView() && map == focal)
        g.clipRect(
            (int) Math.floor(bounds.getX()),
            (int) Math.floor(bounds.getY()),
            (int) Math.ceil(bounds.getWidth()),
            (int) Math.ceil(bounds.getHeight()));

      if (DEBUG.CONTAINMENT) {
        g.setColor(Color.red);
        g.setStroke(VueConstants.STROKE_TWO);
        g.draw(bounds);
      }

      // render the map
      if (map == focal) map.draw(dc);
      else focal.draw(dc);

      out("page " + pageIndex + " rendered.");
      return Printable.PAGE_EXISTS;
    }