public class KeyboardDrawingCanvas extends DrawingCanvas
1:
2: package draw3;
3:
4: import java.awt.*;
5: import java.awt.event.*;
6: import java.util.EventListener;
7: import draw1.*;
8:
9: public class KeyboardDrawingCanvas extends DrawingCanvas {
10:
11: public KeyboardDrawingCanvas() {
12: addKeyListener((KeyListener) listener);
13: font = new Font(fontFamily, fontStyle, fontSize);
14: }
15:
16: public Font getFont() {
17: return font;
18: }
19:
20: public String getFontFamily() {
21: return fontFamily;
22: }
23:
24: public void setFontFamily(String fontFamily) {
25: if (fontFamily != null &&
26: !fontFamily.equals(this.fontFamily)) {
27: this.fontFamily =fontFamily;
28: font = new Font(fontFamily, fontStyle, fontSize);
29: }
30: }
31:
32: public int getFontSize() {
33: return fontSize;
34: }
35:
36: public void setFontSize(int fontSize) {
37: if (fontSize > 0 &&
38: fontSize != this.fontSize) {
39: this.fontSize = fontSize;
40: font = new Font(fontFamily, fontStyle, fontSize);
41: }
42: }
43:
44: public int getFontStyle() {
45: return fontStyle;
46: }
47:
48: public void setFontStyle(int fontStyle) {
49: if (fontStyle != this.fontStyle) {
50: this.fontStyle = fontStyle;
51: font = new Font(fontFamily, fontStyle, fontSize);
52: }
53: }
54:
55: // necessary for keyboard input
56: // public boolean isFocusTraversable() { // pre 1.4
57: public boolean isFocusable() { // 1.4
58: return true;
59: }
60:
61: // factory method
62: protected EventListener makeCanvasListener() {
63: return (drawingCanvasListener = new KeyboardDrawingCanvasListener(this));
64: }
65:
66: protected String fontFamily = "Serif";
67: protected int fontSize = 24;
68: protected int fontStyle = Font.PLAIN;
69: protected Font font;
70:
71: }