Пример #1
0
 @Override
 public void keyPressed(KeyEvent e) {
   if (!links.isEmpty()) return;
   switch (e.getKeyChar()) {
     case 's':
       // TODO: Search!!!!
       String name = display.showInputDialog("Search", "Z");
       ZTask activeTask = taskList.getActiveTask();
       for (ZNode node : getZNodes()) {
         if (node.getName().startsWith(name)) {
           log.info("found {}", node.getName());
           if (activeTask != null) {
             activeTask.add(node);
           }
         }
       }
       break;
     case 'm':
       if (selectedNode.getNodeType() == ZNodeType.CLASS) {
         addMethodLinks();
       }
       break;
     case 'p':
       // TODO: add polymorphic links
     case 'i':
     case 'r':
       // TODO: add import/require links
     case 'h':
     case 'f':
       addFieldLinks();
   }
 }
Пример #2
0
 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;
 }
Пример #3
0
  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));
  }
Пример #4
0
  public void activateGoUp() {
    File pFile = selectedNode.getParentFile();

    if (selectedNode.getNodeType() == ZNodeType.PACKAGE) {
      for (int i = 0; i < selectedNode.getName().split("\\.").length; i++) {
        pFile = pFile.getParentFile();
      }
    } else if (selectedNode.getNodeType() == ZNodeType.MODULE) {
      pFile = pFile.getParentFile();
    }
    selectedNode = new ZCodeLoader(apiFactory).load(pFile);
    clicked(selectedNode);
  }
Пример #5
0
  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));
  }
Пример #6
0
 @Override
 public void mouseMoved(MouseEvent e) {
   final ZNode node = findZNodeAt(e.getPoint());
   if (node == selectedNode) {
     return;
   }
   if (hoveredNode != node && hoveredNode != null) {
     hoveredNode.setSize(hoveredNode.getSize() * 1f / 1.1f);
   }
   if (node != null && hoveredNode != node) {
     node.setSize(node.getSize() * 1.1f);
   }
   hoveredNode = node;
   hoverText = node == null ? null : node.getName();
   mouseLocation = e.getPoint();
 }