1 Clazz.declarePackage ("java.awt");
\r
2 Clazz.load (null, "java.awt.Font", ["java.awt.font.TextAttribute", "java.awt.geom.AffineTransform", "swingjs.JSToolkit"], function () {
\r
3 c$ = Clazz.decorateAsClass (function () {
\r
9 this.$hasLayoutAttributes = false;
\r
10 this.nonIdentityTx = false;
\r
12 Clazz.instantialize (this, arguments);
\r
13 }, java.awt, "Font");
\r
14 Clazz.makeConstructor (c$,
\r
15 function (name, style, size) {
\r
16 this.name = (name != null) ? name : "Default";
\r
17 this.style = (style & -4) == 0 ? style : 0;
\r
19 this.pointSize = size;
\r
21 Clazz.makeConstructor (c$,
\r
22 function (name, style, sizePts) {
\r
23 this.name = (name != null) ? name : "Default";
\r
24 this.style = (style & -4) == 0 ? style : 0;
\r
25 this.size = Clazz.doubleToInt (sizePts + 0.5);
\r
26 this.pointSize = sizePts;
\r
28 Clazz.makeConstructor (c$,
\r
30 this.name = font.name;
\r
31 this.style = font.style;
\r
32 this.size = font.size;
\r
33 this.pointSize = font.pointSize;
\r
34 }, "java.awt.Font");
\r
35 Clazz.defineMethod (c$, "getTransform",
\r
37 return new java.awt.geom.AffineTransform ();
\r
39 Clazz.defineMethod (c$, "getFamily",
\r
41 return (this.family == null ? this.family = swingjs.JSToolkit.getFontFamily (this) : this.family);
\r
43 Clazz.defineMethod (c$, "getName",
\r
47 Clazz.defineMethod (c$, "getFontName",
\r
51 Clazz.defineMethod (c$, "getStyle",
\r
55 Clazz.defineMethod (c$, "getSize",
\r
59 Clazz.defineMethod (c$, "getSize2D",
\r
61 return this.pointSize;
\r
63 Clazz.defineMethod (c$, "isPlain",
\r
65 return this.style == 0;
\r
67 Clazz.defineMethod (c$, "isBold",
\r
69 return (this.style & 1) != 0;
\r
71 Clazz.defineMethod (c$, "isItalic",
\r
73 return (this.style & 2) != 0;
\r
75 Clazz.defineMethod (c$, "isTransformed",
\r
77 return this.nonIdentityTx;
\r
79 Clazz.defineMethod (c$, "hasLayoutAttributes",
\r
81 return this.$hasLayoutAttributes;
\r
83 c$.getFont = Clazz.defineMethod (c$, "getFont",
\r
85 return java.awt.Font.getFont (nm, null);
\r
87 c$.decode = Clazz.defineMethod (c$, "decode",
\r
94 return new java.awt.Font ("Dialog", fontStyle, fontSize);
\r
95 }var lastHyphen = str.lastIndexOf ('-');
\r
96 var lastSpace = str.lastIndexOf (' ');
\r
97 var sepChar = (lastHyphen > lastSpace) ? '-' : ' ';
\r
98 var sizeIndex = str.lastIndexOf (sepChar);
\r
99 var styleIndex = str.lastIndexOf (sepChar, sizeIndex - 1);
\r
100 var strlen = str.length;
\r
101 if (sizeIndex > 0 && sizeIndex + 1 < strlen) {
\r
103 fontSize = Integer.$valueOf (str.substring (sizeIndex + 1)).intValue ();
\r
104 if (fontSize <= 0) {
\r
107 if (Clazz.exceptionOf (e, NumberFormatException)) {
\r
108 styleIndex = sizeIndex;
\r
109 sizeIndex = strlen;
\r
110 if (str.charAt (sizeIndex - 1) == sepChar) {
\r
116 }if (styleIndex >= 0 && styleIndex + 1 < strlen) {
\r
117 styleName = str.substring (styleIndex + 1, sizeIndex);
\r
118 styleName = styleName.toLowerCase ();
\r
119 if (styleName.equals ("bolditalic")) {
\r
121 } else if (styleName.equals ("italic")) {
\r
123 } else if (styleName.equals ("bold")) {
\r
125 } else if (styleName.equals ("plain")) {
\r
128 styleIndex = sizeIndex;
\r
129 if (str.charAt (styleIndex - 1) == sepChar) {
\r
131 }}fontName = str.substring (0, styleIndex);
\r
133 var fontEnd = strlen;
\r
134 if (styleIndex > 0) {
\r
135 fontEnd = styleIndex;
\r
136 } else if (sizeIndex > 0) {
\r
137 fontEnd = sizeIndex;
\r
138 }if (fontEnd > 0 && str.charAt (fontEnd - 1) == sepChar) {
\r
140 }fontName = str.substring (0, fontEnd);
\r
141 }return new java.awt.Font (fontName, fontStyle, fontSize);
\r
143 c$.getFont = Clazz.defineMethod (c$, "getFont",
\r
144 function (nm, font) {
\r
147 str = System.getProperty (nm);
\r
149 if (Clazz.exceptionOf (e, SecurityException)) {
\r
156 }return java.awt.Font.decode (str);
\r
157 }, "~S,java.awt.Font");
\r
158 Clazz.overrideMethod (c$, "hashCode",
\r
160 if (this.hash == 0) {
\r
161 this.hash = this.name.hashCode () ^ this.style ^ this.size;
\r
164 Clazz.overrideMethod (c$, "equals",
\r
166 if (obj === this) {
\r
168 }if (obj != null) {
\r
171 if (this.size == font.size && this.style == font.style && this.nonIdentityTx == font.nonIdentityTx && this.$hasLayoutAttributes == font.$hasLayoutAttributes && this.pointSize == font.pointSize && this.name.equals (font.name)) {
\r
174 if (Clazz.exceptionOf (e, ClassCastException)) {
\r
181 Clazz.overrideMethod (c$, "toString",
\r
184 if (this.isBold ()) {
\r
185 strStyle = this.isItalic () ? "bolditalic" : "bold";
\r
187 strStyle = this.isItalic () ? "italic" : "plain";
\r
188 }return this.getClass ().getName () + "[family=" + this.getFamily () + ",name=" + this.name + ",style=" + strStyle + ",size=" + this.size + "]";
\r
190 Clazz.defineMethod (c$, "getAvailableAttributes",
\r
192 var attributes = Clazz.newArray (-1, [java.awt.font.TextAttribute.FAMILY, java.awt.font.TextAttribute.WEIGHT, java.awt.font.TextAttribute.WIDTH, java.awt.font.TextAttribute.SIZE, java.awt.font.TextAttribute.UNDERLINE, java.awt.font.TextAttribute.STRIKETHROUGH]);
\r
195 Clazz.defineMethod (c$, "deriveFont",
\r
196 function (style, size) {
\r
197 return new java.awt.Font (this.name, style, size);
\r
199 Clazz.defineMethod (c$, "deriveFont",
\r
201 return new java.awt.Font (this.name, this.style, size);
\r
203 Clazz.defineMethod (c$, "deriveFont",
\r
205 return new java.awt.Font (this.name, style, this.size);
\r
207 Clazz.defineMethod (c$, "hasUniformLineMetrics",
\r
211 Clazz.overrideMethod (c$, "finalize",
\r
214 Clazz.defineStatics (c$,
\r
215 "DIALOG", "Dialog",
\r
216 "DIALOG_INPUT", "DialogInput",
\r
217 "SANS_SERIF", "SansSerif",
\r
219 "MONOSPACED", "Monospaced",
\r
223 "ROMAN_BASELINE", 0,
\r
224 "CENTER_BASELINE", 1,
\r
225 "HANGING_BASELINE", 2,
\r
226 "TRUETYPE_FONT", 0,
\r
228 "LAYOUT_LEFT_TO_RIGHT", 0,
\r
229 "LAYOUT_RIGHT_TO_LEFT", 1,
\r
230 "LAYOUT_NO_START_CONTEXT", 2,
\r
231 "LAYOUT_NO_LIMIT_CONTEXT", 4);
\r