Exemple #1
0
 private void addEdgeToNode(Edge edge, Node node) {
   Set<Edge> edges = this.nodeEdges.get(node.getPoint());
   if (edges == null) {
     this.nodeEdges.put(node.getPoint(), edges = new HashSet<>());
   }
   edges.add(edge);
 }
Exemple #2
0
 public void add(Node node, int weight) {
   if (node == null) {
     return;
   }
   Node known = this.knownNodes.get(node.getPoint());
   if (known == null) {
     known = node;
     this.knownNodes.put(node.getPoint(), node);
   }
   if (this.last == null) {
     this.last = known;
     return;
   }
   Edge edge = new Edge(this.last, known, weight);
   this.edges.add(edge);
   this.addEdgeToNode(edge, node);
   this.addEdgeToNode(edge, this.last);
   this.last = node;
 }
  /**
   * 描画を行う。ここで全ての全体図を書いてしまう。スクロールに関してはViewで行う。
   *
   * @param aGraphics グラフィックス
   */
  public void paintComponent(Graphics aGraphics) {
    super.paintComponent(aGraphics);
    ForestModel aModel = (ForestModel) this.getModel();

    Font aFont = new Font(Font.Serif, Font.PLAIN, 12);
    FontMetrics aMetrics = new FontMetrics(aFont); // stringのwidthを知るために使用する
    aGraphics.setColor(Color.black);
    aGraphics.setFont(aFont);
    int fontHeight = aFont.getSize();

    /*
    drawRectで四角を描く
    Nodeの座標を得て、width,height分の大きさを描く
    drawlineでNode同士を結ぶ
    ここですべて描いちゃう。未完成
    */
    aGraphics.setColor(Color.black);

    for (Branch aBranch : aModel.getBranch()) {

      aGraphics.drawLine(
          aBranch.getStartPoint().getX(),
          aBranch.getStartPoint().getY() + fontHeight / 2,
          aBranch.getEndPoint().getX(),
          aBranch.getEndPoint().getY() + fontHeight / 2);

      Node aChildNode = aBranch.getChildNode();
      aGraphics.drawString(
          aChildNode.getLabel(), aChildNode.getPoint().getX(), aChildNode.getPoint().getY());
      int width = aMetrics.stringWidth(aChildNode.getLabel());
      aGraphics.drawRect(
          aChildNode.getPoint().getX(), aChildNode.getPoint().getY(), width, fontHeight);

      Node aParentNode = aBranch.getParentNode();
      aGraphics.drawString(
          aParentNode.getLabel(), aParentNode.getPoint().getX(), aParentNode.getPoint().getY());
      width = aMetrics.stringWidth(aParentNode.getLabel());
      aGraphics.drawRect(
          aParentNode.getPoint().getX(), aParentNode.getPoint().getY(), width, fontHeight);
    }
    return;
  }
Exemple #4
0
 public Set<Edge> getEdges(Node node) {
   if (node == null) {
     return null;
   }
   return this.nodeEdges.get(node.getPoint());
 }