1 package org.catacomb.druid.xtext.base;
2
3
4
5 import org.catacomb.druid.color.StandardPalette;
6 import org.catacomb.druid.xtext.canvas.FontStore;
7 import org.catacomb.interlish.content.BasicTouchTime;
8
9 import java.util.ArrayList;
10
11 import java.awt.Font;
12 import java.awt.Color;
13
14 public class Guise {
15
16
17 public String id;
18 public ArrayList<Slot> slots;
19
20
21 String fontFamily;
22 String fontSize;
23 String fontStyle;
24 Color fontColor;
25
26 boolean bUnderline;
27
28 BasicTouchTime touchTime;
29
30 BasicTouchTime cacheTime;
31
32
33 Font cachedFont;
34
35 static int icolor = 0;
36
37 public Guise() {
38 fontFamily = "serif";
39 fontSize = "12";
40 fontColor = Color.black;
41 fontStyle = "plain";
42 bUnderline = false;
43
44 slots = new ArrayList<Slot>();
45 cacheTime = new BasicTouchTime();
46 touchTime = new BasicTouchTime();
47 }
48
49
50 public void setNextPaletteColor() {
51 setFontColor(StandardPalette.getColor(icolor));
52 icolor += 1;
53 }
54
55
56 public void touch() {
57 touchTime.now();
58 }
59
60
61
62 public Font getFont() {
63 if (cachedFont == null || cacheTime.isBefore(touchTime)) {
64 updateCache();
65 }
66 return cachedFont;
67 }
68
69 public Color getColor() {
70 return fontColor;
71 }
72
73 private void updateCache() {
74 cachedFont = FontStore.instance().getFont(fontFamily, fontStyle, "" + fontSize);
75
76
77 cacheTime.now();
78 }
79
80
81
82 public void setID(String s) {
83 id = s;
84 }
85
86
87 public String getID() {
88 return id;
89 }
90
91
92 public Color getFontColor() {
93 return fontColor;
94 }
95
96
97 public void setFontColor(Color c) {
98 if (fontColor == null) {
99 fontColor = Color.black;
100 }
101 fontColor = c;
102 }
103
104
105 public String getFontFamily() {
106 return fontFamily;
107 }
108
109
110
111 public void setFontFamily(String fontFamily) {
112 this.fontFamily = fontFamily;
113 touch();
114 }
115
116
117
118 public String getFontSize() {
119 return fontSize;
120 }
121
122
123
124 public void setFontSize(String fs) {
125 this.fontSize = fs;
126 touch();
127 }
128
129
130
131 public String getFontStyle() {
132 return fontStyle;
133
134 }
135
136
137
138 public void setFontStyle(String fontStyle) {
139 this.fontStyle = fontStyle;
140 touch();
141 }
142
143
144 public void setBoldFont() {
145 setFontStyle("bold");
146 touch();
147 }
148
149
150 public void setColorBlack() {
151 setFontColor(Color.black);
152 }
153
154
155 public void setUnderline(boolean b) {
156 bUnderline = b;
157 }
158
159
160 public boolean underline() {
161 return bUnderline;
162 }
163
164
165 public void setColorDarkGreen() {
166 setFontColor(new Color(0, 160, 0));
167
168 }
169
170
171
172
173
174
175 }