JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / site / j2s / javax / swing / text / IconView.js
1 Clazz.declarePackage ("javax.swing.text");\r
2 Clazz.load (["javax.swing.text.View"], "javax.swing.text.IconView", ["java.lang.IllegalArgumentException", "javax.swing.text.BadLocationException", "$.Position", "$.StyleConstants"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.c = null;\r
5 Clazz.instantialize (this, arguments);\r
6 }, javax.swing.text, "IconView", javax.swing.text.View);\r
7 Clazz.makeConstructor (c$, \r
8 function (elem) {\r
9 Clazz.superConstructor (this, javax.swing.text.IconView, [elem]);\r
10 var attr = elem.getAttributes ();\r
11 this.c = javax.swing.text.StyleConstants.getIcon (attr);\r
12 }, "javax.swing.text.Element");\r
13 Clazz.overrideMethod (c$, "paint", \r
14 function (g, a) {\r
15 var alloc = a.getBounds ();\r
16 this.c.paintIcon (this.getContainer (), g, alloc.x, alloc.y);\r
17 }, "java.awt.Graphics,java.awt.Shape");\r
18 Clazz.overrideMethod (c$, "getPreferredSpan", \r
19 function (axis) {\r
20 switch (axis) {\r
21 case 0:\r
22 return this.c.getIconWidth ();\r
23 case 1:\r
24 return this.c.getIconHeight ();\r
25 default:\r
26 throw  new IllegalArgumentException ("Invalid axis: " + axis);\r
27 }\r
28 }, "~N");\r
29 Clazz.defineMethod (c$, "getAlignment", \r
30 function (axis) {\r
31 switch (axis) {\r
32 case 1:\r
33 return 1;\r
34 default:\r
35 return Clazz.superCall (this, javax.swing.text.IconView, "getAlignment", [axis]);\r
36 }\r
37 }, "~N");\r
38 Clazz.defineMethod (c$, "modelToView", \r
39 function (pos, a, b) {\r
40 var p0 = this.getStartOffset ();\r
41 var p1 = this.getEndOffset ();\r
42 if ((pos >= p0) && (pos <= p1)) {\r
43 var r = a.getBounds ();\r
44 if (pos == p1) {\r
45 r.x += r.width;\r
46 }r.width = 0;\r
47 return r;\r
48 }throw  new javax.swing.text.BadLocationException (pos + " not in range " + p0 + "," + p1, pos);\r
49 }, "~N,java.awt.Shape,javax.swing.text.Position.Bias");\r
50 Clazz.defineMethod (c$, "viewToModel", \r
51 function (x, y, a, bias) {\r
52 var alloc = a;\r
53 if (x < alloc.x + (Clazz.doubleToInt (alloc.width / 2))) {\r
54 bias[0] = javax.swing.text.Position.Bias.Forward;\r
55 return this.getStartOffset ();\r
56 }bias[0] = javax.swing.text.Position.Bias.Backward;\r
57 return this.getEndOffset ();\r
58 }, "~N,~N,java.awt.Shape,~A");\r
59 });\r