View Javadoc

1   
2   package org.catacomb.graph.gui;
3   
4   import org.catacomb.interlish.structure.Repaintable;
5   import org.catacomb.report.E;
6   
7   import java.awt.*;
8   
9   
10  
11  public class BaseCanvas extends BasePanel implements Repaintable {
12      static final long serialVersionUID = 1001;
13  
14      int prefw;
15      int prefh;
16  
17  
18      Color bgColor;
19      Color fgColor;
20  
21      BasicStroke bs1 = new BasicStroke((float)1.0);
22  
23  
24  
25  
26      public BaseCanvas(int w, int h) {
27          super();
28          bgColor = Color.black;
29          fgColor = Color.white;
30  
31          setPreferredSize(new Dimension(w, h));
32          prefw = w;
33          prefh = h;
34  
35          setBackground(bgColor);
36          setFont(new Font("sansserif", Font.PLAIN, 12));
37      }
38  
39      public void setPreferredSize(int w, int h) {
40          prefw = w;
41          prefh = h;
42          setPreferredSize(new Dimension(prefw, prefh));
43      }
44  
45      public void setBg(Color c) {
46          bgColor = c;
47          setBackground(bgColor);
48      }
49  
50  
51      public void setCursor(String type) {
52          if (type.equals("default") || type.equals("pointer")) {
53              setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
54  
55          } else if (type.equals("cross")) {
56              setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
57  
58          } else {
59              E.warning("unrecognized cursor " + type);
60          }
61      }
62  
63  
64      public void setDataBackground(Color c) {
65          bgColor = c;
66      }
67  
68      public Color getDataBackground() {
69          return bgColor;
70      }
71  
72  
73      public Color getNormalForeground() {
74          return fgColor;
75      }
76  
77  
78      public void paintComponent(Graphics g0) {
79  
80          g0.setColor(bgColor);
81          g0.fillRect(0, 0, getWidth(), getHeight());
82          Graphics2D g = (Graphics2D)g0;
83  
84          g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
85                             RenderingHints.VALUE_ANTIALIAS_ON);
86  
87  
88          simpleStroke(g);
89  
90          paint2D(g);
91  
92      }
93  
94  
95      final void simpleStroke(Graphics2D g) {
96          g.setStroke(bs1);
97      }
98  
99  
100     public void paint2D(Graphics2D g) {
101 
102     }
103 
104 
105     public void requestRepaint() {
106         repaint();
107     }
108 
109 
110 
111     /*
112       is this ever necessary now??
113 
114     public int[][] getIntegerImage() {
115        Image im = createImage(imw, imh);
116        Graphics gg = im.getGraphics();
117        printAll (gg);
118        int[] pix = new int[imw * imh];
119        PixelGrabber grabber = new PixelGrabber(im, 0, 0, imw,imh,
120     				      pix, 0, imw);
121        try {
122      grabber.grabPixels();
123        } catch (Exception e) {
124      S.p ("pixel grabbing interrupted");
125        }
126        int[][] ret = new int[imh][imw];
127 
128        for (int i = 0; i < imh; i++) {
129            for (int j = 0; j < imw; j++) {
130               int pi = pix[i*imw + j];
131               int ir = ((pi  >> 16) & 0xFF);
132               int ig = ((pi >> 8) & 0xFF);
133               int ib = (pi & 0xFF);
134          ret[i][j] = (ir << 16) + (ig << 8) + ib;
135            }
136         }
137         return ret;
138     }
139 
140     */
141 
142 }
143 
144