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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142 }
143
144