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