예제 #1
0
파일: Z.java 프로젝트: adamldavis/z
  protected void addFieldLinks() {
    log.info("addFieldLinks()");
    final Map<String, ZNode> nodeMap = new HashMap<String, ZNode>();
    final Pattern patt = Pattern.compile("(private |protected |public |final |static )+\\s*(\\w+)");

    // TODO redo this to actually include packages
    for (ZNode node : selectedNode.getSubmodules()) {
      if (node.getNodeType() == ZNodeType.CLASS) {
        nodeMap.put(node.getName(), node);
      }
    }
    log.info("nodeMap={}", nodeMap);
    for (ZNode node : selectedNode.getSubmodules()) {
      for (String line : node.getCodeLines()) {
        final Matcher matcher = patt.matcher(line);
        if (matcher.find()) {
          log.info("group2={}", matcher.group(2));
          if (nodeMap.containsKey(matcher.group(2))) {
            links.add(new ZNodeLink(node, nodeMap.get(matcher.group(2)), LinkType.HAS_A));
          }
        }
      }
    }
    // just add 1 so there's at least 1
    links.add(new ZNodeLink(selectedNode, selectedNode, LinkType.HAS_A));
  }
예제 #2
0
파일: Z.java 프로젝트: adamldavis/z
  private void updateSubLocations(ZNode node, boolean immediate, Point2D loc) {
    final Point center = new Point((int) Math.round(loc.getX()), (int) Math.round(loc.getY()));
    // make bigger when more nodes
    final float factor =
        selectedNode == node ? (1.3f + logSize(node.getSubmodules().size()) / 2.2f) : 1.2f;
    int size = Math.round(sizeMap.get(node) * factor);
    final float xRatio = display.getWidth() / display.getHeight();
    Map<ZNode, Point2D> map =
        new PixelZNodePositioner(
                center,
                new Dimension((int) (size * xRatio), size),
                new DirectionZNodePositioner(direction, makeNodePositioner()))
            .getNewPositions(node);

    for (ZNode sub : node.getSubmodules()) {
      pointMap.put(sub, map.get(sub));
      if (immediate) sub.setLocation((java.awt.geom.Point2D.Float) map.get(sub));

      updateSubLocations(sub, immediate, map.get(sub));
    }
    if (node == selectedNode)
      for (ZNode dep : node.getDependencies()) {
        pointMap.put(dep, map.get(dep));
        if (immediate) dep.setLocation((java.awt.geom.Point2D.Float) map.get(dep));
      }
  }
예제 #3
0
파일: Z.java 프로젝트: adamldavis/z
 public void createSubNode(Point point) {
   if (selectedNode != null) {
     // create sub-module
     final ZNodeType subtype;
     switch (selectedNode.getNodeType()) {
       case METHOD:
         subtype = ZNodeType.CALLEE;
         break;
       case CLASS:
         subtype = ZNodeType.METHOD;
         break;
       case PACKAGE:
         subtype = ZNodeType.CLASS;
         break;
       case CALLEE:
       case CALLER:
       case DEPENDENCY:
         return;
       default:
         subtype = ZNodeType.PACKAGE;
     }
     ZNode sub = createNewZ(point, subtype);
     if (sub != null) selectedNode.getSubmodules().add(sub);
   }
 }
예제 #4
0
파일: Z.java 프로젝트: adamldavis/z
 private ZNode createNewZNode(Point point, ZNodeType type, String name) {
   if (name == null) {
     return null;
   }
   final Point2D.Float zp = translateToZNodePoint(point);
   final ZNode zNode = new ZNode(zp.x, zp.y, name.trim());
   zNode.setNodeType(type);
   zNode.setParentFile(selectedNode.getParentFile());
   if (type == ZNodeType.DEPENDENCY) {
     zNode.setCode(asList("artifactId=" + name, "groupId=" + name));
   }
   synchronized (zNodes) {
     zNodes.add(zNode);
   }
   if (type == ZNodeType.METHOD) {
     zNode.setParentFile(
         new File(
             selectedNode.getParentFile(),
             selectedNode.getName() + "." + selectedNode.getExtension()));
     int end = selectedNode.getEndLineNumber(apiFactory.getLanguageParser());
     for (ZNode method : selectedNode.getSubmodules()) {
       end += method.getCodeLineSize();
     }
     zNode.setExtension(String.valueOf(end));
     System.err.println("ext=" + zNode.getExtension());
   } else if (type == ZNodeType.CALLEE) {
     selectedNode.addCodeLine(zNode.getName());
   }
   new ZCodeSaver(apiFactory).save(zNode);
   return zNode;
 }
예제 #5
0
파일: Z.java 프로젝트: adamldavis/z
  protected void clicked(ZNode node) {
    log.info("selected: " + node);
    selectedNode = new ZCodeLoader(apiFactory).load(node);
    synchronized (zNodes) {
      zNodes.clear();
      zNodes.add(selectedNode);
      zNodes.addAll(selectedNode.getDependencies());
      zNodes.addAll(selectedNode.getSubmodules());
    }
    count.set(0);

    state = State.ANIMATING;
    aniCount.set(0);
    final Dimension dim = display.getDimension();
    sortNodes();
    float selSize = (float) Math.min(dim.getWidth(), dim.getHeight()) / 2.2f;
    sizeMap.put(selectedNode, selSize);
    float shrinkFactor = 0.2f;
    float size = (float) (selSize * shrinkFactor);

    for (ZNode dep : selectedNode.getDependencies()) {
      sizeMap.put(dep, size);
    }
    for (ZNode sub : selectedNode.getSubmodules()) {
      sub = new ZCodeLoader(apiFactory).load(sub);
      sizeMap.put(sub, size + logSize(sub.getSubmodules().size()));
      synchronized (zNodes) {
        zNodes.addAll(sub.getSubmodules());
      }
      for (ZNode sub2 : sub.getSubmodules()) {
        sizeMap.put(sub2, size * shrinkFactor + logSize(sub2.getCodeLineSize()));
      }
    }
    Point2D.Float center = new Point2D.Float(selSize * 1.25f, selSize);
    pointMap.put(node, center);
    updateSubLocations(selectedNode, false, center);
  }
예제 #6
0
파일: Z.java 프로젝트: adamldavis/z
  private void addMethodLinks() {
    log.info("addMethodLinks()");
    final Map<String, ZNode> nodeMap = new HashMap<String, ZNode>();
    final Pattern patt = Pattern.compile("(\\w+)\\(");

    for (ZNode method : selectedNode.getSubmodules()) {
      final Matcher matcher = patt.matcher(method.getName());
      if (matcher.find()) {
        final String name = matcher.group(1);
        nodeMap.put(name, method);
      }
    }
    log.info("nodeMap={}", nodeMap);
    for (ZNode method : selectedNode.getSubmodules()) {
      for (ZNode call : method.getSubmodules()) {
        // TODO fix
        if (nodeMap.containsKey(call.getName())) {
          links.add(new ZNodeLink(method, nodeMap.get(call.getName()), LinkType.METHOD_CALL));
        }
      }
    }
    // just add 1 so there's at least 1
    links.add(new ZNodeLink(selectedNode, selectedNode, LinkType.HAS_A));
  }
예제 #7
0
파일: Z.java 프로젝트: adamldavis/z
  private void sortNodes() {
    Collections.sort(
        selectedNode.getSubmodules(),
        new Comparator<ZNode>() {

          @Override
          public int compare(ZNode node1, ZNode node2) {
            switch (order) {
              case ALPHA:
                return node1.getName().compareTo(node2.getName());
              case SIZE:
                return node1.getCodeLineSize() - node2.getCodeLineSize();
              case TIME:
                return (int) (node1.getLastModified() - node2.getLastModified());
              default:
                return 0;
            }
          }
        });
  }