Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/port80/graph/dot/impl/DotBox.java


1   //
2   // Copyright(c) 2002, Chris Leung
3   //
4   
5   package com.port80.graph.dot.impl;
6   
7   import com.port80.util.msg;
8   
9   public class DotBox {
10    
11    private static final String NAME="DotBox";
12    
13    int llx, lly, urx, ury;
14    public DotBox() {};
15    public DotBox(int llx, int lly, int urx, int ury) {
16      this.llx = llx;
17      this.lly = lly;
18      this.urx = urx;
19      this.ury = ury;
20    }
21    public DotBox(DotBox box) {
22      this.llx = box.llx;
23      this.lly = box.lly;
24      this.urx = box.urx;
25      this.ury = box.ury;
26    }
27  
28    public void set(int llx, int lly, int urx, int ury) {
29      this.llx = llx;
30      this.lly = lly;
31      this.urx = urx;
32      this.ury = ury;
33    }
34    public void set(DotBox box) {
35      this.llx = box.llx;
36      this.lly = box.lly;
37      this.urx = box.urx;
38      this.ury = box.ury;
39    }
40    public DotBox dup() {
41      DotBox ret=new DotBox(llx,lly,urx,ury);
42      return ret;
43    }
44    public String toString() {
45      return llx + "," + lly + "," + urx + "," + ury;
46    }
47    public String toGeneralPath() {
48      StringBuffer ret = new StringBuffer();
49      ret.append(
50        "<l closed=\"true\">"
51          + llx
52          + ".0f,"
53          + ury
54          + ".0f "
55          + llx
56          + ".0f,"
57          + lly
58          + ".0f "
59          + urx
60          + ".0f,"
61          + lly
62          + ".0f "
63          + urx
64          + ".0f,"
65          + ury
66          + ".0f</l>\n");
67      return ret.toString();
68    }
69  
70    /** 
71     * Break box into smaller boxes vertically.
72     */
73    public int subDivide(int max,DotBox[] ret) {
74      int y = lly - ury;
75      int nsub = Math.min(max, y);
76      for (int i = 0; i < nsub; ++i) {
77        ret[i] = new DotBox(this);
78        ret[i].ury = ury + (y * i) / nsub;
79        ret[i].lly = ury + (y * (i + 1)) / nsub;
80        if (ret[i].ury == ret[i].lly)
81          msg.fatal(NAME + ".subDivide(): ret[i].ury==ret[i].lly");
82      }
83      return nsub;
84    }
85  
86  }