Пример #1
0
  public void paint(Graphics g) {
    System.out.println("paint");
    Graphics2D g2d = (Graphics2D) g;

    Point1 p1, p2;

    n = paintInfo.size();

    if (toolFlag == 2) g2d.clearRect(0, 0, getSize().width - 100, getSize().height - 100); // 清除

    for (int i = 0; i < n - 1; i++) {
      p1 = (Point1) paintInfo.elementAt(i);
      p2 = (Point1) paintInfo.elementAt(i + 1);
      size = new BasicStroke(p1.boarder, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);

      g2d.setColor(p1.col);
      g2d.setStroke(size);

      if (p1.tool == p2.tool) {
        switch (p1.tool) {
          case 0: // 画笔
            Line2D line1 = new Line2D.Double(p1.x, p1.y, p2.x, p2.y);
            g2d.draw(line1);
            break;

          case 1: // 橡皮
            g.clearRect(p1.x, p1.y, p1.boarder, p1.boarder);
            break;

          case 3: // 画直线
            Line2D line2 = new Line2D.Double(p1.x, p1.y, p2.x, p2.y);
            g2d.draw(line2);
            break;

          case 4: // 画圆
            Ellipse2D ellipse =
                new Ellipse2D.Double(p1.x, p1.y, Math.abs(p2.x - p1.x), Math.abs(p2.y - p1.y));
            g2d.draw(ellipse);
            break;

          case 5: // 画矩形
            Rectangle2D rect =
                new Rectangle2D.Double(p1.x, p1.y, Math.abs(p2.x - p1.x), Math.abs(p2.y - p1.y));
            g2d.draw(rect);
            break;

          case 6: // 截断,跳过
            i = i + 1;
            break;

          default:
        } // end switch
      } // end if
    } // end for
  }
Пример #2
0
 /** Determines if this subtree contains the given vertex */
 public boolean containsTreeVertex(TreeVertex vertex) {
   if (vertex == null) return false;
   for (int i = 0; i < m_vertexList.size(); i++) {
     if ((TreeVertex) m_vertexList.elementAt(i) == vertex) return true;
   }
   for (int i = 0; i < m_edgeList.size(); i++) {
     TreeEdge edge = (TreeEdge) m_edgeList.elementAt(i);
     if (edge.getSourceVertex() == vertex || edge.getDestVertex() == vertex) {
       return true;
     }
   }
   return false;
 }
Пример #3
0
 private void recurseSelectEdges(TreeVertex root) {
   Vector edges = root.getEdgeList();
   for (int i = 0; i < edges.size(); i++) {
     TreeEdge edge = (TreeEdge) edges.elementAt(i);
     TreeVertex dest = edge.getDestVertex();
     if (m_vertexList.contains(dest)) {
       edge.setSelected(true);
       recurseSelectEdges(dest);
     }
   }
 }
Пример #4
0
 public TreeVertex findRoot() {
   if (m_root != null) return m_root;
   int rootLayer = 1000;
   TreeVertex root = null;
   for (int i = 0; i < m_vertexList.size(); i++) {
     TreeVertex vertex = (TreeVertex) m_vertexList.elementAt(i);
     if (vertex.getLayer() < rootLayer) {
       rootLayer = vertex.getLayer();
       root = vertex;
     }
   }
   return root;
 }