3fafe3a03e8e96d44da4e79f6e6d3a3610a9e49b
[jalviewjs.git] / site / swingjs / j2s / javax / swing / text / ComponentView.js
1 Clazz.declarePackage ("javax.swing.text");\r
2 Clazz.load (["java.awt.Container", "java.beans.PropertyChangeListener", "javax.swing.text.View"], "javax.swing.text.ComponentView", ["java.lang.IllegalArgumentException", "java.awt.Dimension", "$.Rectangle", "javax.swing.SwingUtilities", "javax.swing.text.AbstractDocument", "$.BadLocationException", "$.Position", "$.StyleConstants"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.createdC = null;\r
5 this.c = null;\r
6 if (!Clazz.isClassDefined ("javax.swing.text.ComponentView.Invalidator")) {\r
7 javax.swing.text.ComponentView.$ComponentView$Invalidator$ ();\r
8 }\r
9 Clazz.instantialize (this, arguments);\r
10 }, javax.swing.text, "ComponentView", javax.swing.text.View);\r
11 Clazz.defineMethod (c$, "createComponent", \r
12 function () {\r
13 var attr = this.getElement ().getAttributes ();\r
14 var comp = javax.swing.text.StyleConstants.getComponent (attr);\r
15 return comp;\r
16 });\r
17 Clazz.defineMethod (c$, "getComponent", \r
18 function () {\r
19 return this.createdC;\r
20 });\r
21 Clazz.overrideMethod (c$, "paint", \r
22 function (g, a) {\r
23 if (this.c != null) {\r
24 var alloc = (Clazz.instanceOf (a, java.awt.Rectangle)) ? a : a.getBounds ();\r
25 this.c.setBounds (alloc.x, alloc.y, alloc.width, alloc.height);\r
26 }}, "java.awt.Graphics,java.awt.Shape");\r
27 Clazz.overrideMethod (c$, "getPreferredSpan", \r
28 function (axis) {\r
29 if ((axis != 0) && (axis != 1)) {\r
30 throw  new IllegalArgumentException ("Invalid axis: " + axis);\r
31 }if (this.c != null) {\r
32 var size = this.c.getPreferredSize ();\r
33 if (axis == 0) {\r
34 return size.width;\r
35 } else {\r
36 return size.height;\r
37 }}return 0;\r
38 }, "~N");\r
39 Clazz.overrideMethod (c$, "getMinimumSpan", \r
40 function (axis) {\r
41 if ((axis != 0) && (axis != 1)) {\r
42 throw  new IllegalArgumentException ("Invalid axis: " + axis);\r
43 }if (this.c != null) {\r
44 var size = this.c.getMinimumSize ();\r
45 if (axis == 0) {\r
46 return size.width;\r
47 } else {\r
48 return size.height;\r
49 }}return 0;\r
50 }, "~N");\r
51 Clazz.overrideMethod (c$, "getMaximumSpan", \r
52 function (axis) {\r
53 if ((axis != 0) && (axis != 1)) {\r
54 throw  new IllegalArgumentException ("Invalid axis: " + axis);\r
55 }if (this.c != null) {\r
56 var size = this.c.getMaximumSize ();\r
57 if (axis == 0) {\r
58 return size.width;\r
59 } else {\r
60 return size.height;\r
61 }}return 0;\r
62 }, "~N");\r
63 Clazz.defineMethod (c$, "getAlignment", \r
64 function (axis) {\r
65 if (this.c != null) {\r
66 switch (axis) {\r
67 case 0:\r
68 return this.c.getAlignmentX ();\r
69 case 1:\r
70 return this.c.getAlignmentY ();\r
71 }\r
72 }return Clazz.superCall (this, javax.swing.text.ComponentView, "getAlignment", [axis]);\r
73 }, "~N");\r
74 Clazz.defineMethod (c$, "setParent", \r
75 function (p) {\r
76 Clazz.superCall (this, javax.swing.text.ComponentView, "setParent", [p]);\r
77 if (javax.swing.SwingUtilities.isEventDispatchThread ()) {\r
78 this.setComponentParent ();\r
79 } else {\r
80 var callSetComponentParent = ((Clazz.isClassDefined ("javax.swing.text.ComponentView$1") ? 0 : javax.swing.text.ComponentView.$ComponentView$1$ ()), Clazz.innerTypeInstance (javax.swing.text.ComponentView$1, this, null));\r
81 javax.swing.SwingUtilities.invokeLater (callSetComponentParent);\r
82 }}, "javax.swing.text.View");\r
83 Clazz.defineMethod (c$, "setComponentParent", \r
84 function () {\r
85 var p = this.getParent ();\r
86 if (p != null) {\r
87 var parent = this.getContainer ();\r
88 if (parent != null) {\r
89 if (this.c == null) {\r
90 var comp = this.createComponent ();\r
91 if (comp != null) {\r
92 this.createdC = comp;\r
93 this.c = Clazz.innerTypeInstance (javax.swing.text.ComponentView.Invalidator, this, null, comp);\r
94 }}if (this.c != null) {\r
95 if (this.c.getParent () == null) {\r
96 parent.add (this.c, this);\r
97 parent.addPropertyChangeListener ("enabled", this.c);\r
98 }}}} else {\r
99 if (this.c != null) {\r
100 var parent = this.c.getParent ();\r
101 if (parent != null) {\r
102 parent.remove (this.c);\r
103 parent.removePropertyChangeListener ("enabled", this.c);\r
104 }}}});\r
105 Clazz.defineMethod (c$, "modelToView", \r
106 function (pos, a, b) {\r
107 var p0 = this.getStartOffset ();\r
108 var p1 = this.getEndOffset ();\r
109 if ((pos >= p0) && (pos <= p1)) {\r
110 var r = a.getBounds ();\r
111 if (pos == p1) {\r
112 r.x += r.width;\r
113 }r.width = 0;\r
114 return r;\r
115 }throw  new javax.swing.text.BadLocationException (pos + " not in range " + p0 + "," + p1, pos);\r
116 }, "~N,java.awt.Shape,javax.swing.text.Position.Bias");\r
117 Clazz.defineMethod (c$, "viewToModel", \r
118 function (x, y, a, bias) {\r
119 var alloc = a;\r
120 if (x < alloc.x + (Clazz.doubleToInt (alloc.width / 2))) {\r
121 bias[0] = javax.swing.text.Position.Bias.Forward;\r
122 return this.getStartOffset ();\r
123 }bias[0] = javax.swing.text.Position.Bias.Backward;\r
124 return this.getEndOffset ();\r
125 }, "~N,~N,java.awt.Shape,~A");\r
126 c$.$ComponentView$Invalidator$ = function () {\r
127 Clazz.pu$h(self.c$);\r
128 c$ = Clazz.decorateAsClass (function () {\r
129 Clazz.prepareCallback (this, arguments);\r
130 this.min = null;\r
131 this.pref = null;\r
132 this.max = null;\r
133 this.yalign = 0;\r
134 this.xalign = 0;\r
135 Clazz.instantialize (this, arguments);\r
136 }, javax.swing.text.ComponentView, "Invalidator", java.awt.Container, java.beans.PropertyChangeListener);\r
137 Clazz.makeConstructor (c$, \r
138 function (a) {\r
139 Clazz.superConstructor (this, javax.swing.text.ComponentView.Invalidator, []);\r
140 this.setLayout (null);\r
141 this.add (a);\r
142 this.cacheChildSizes ();\r
143 }, "java.awt.Component");\r
144 Clazz.defineMethod (c$, "invalidate", \r
145 function () {\r
146 Clazz.superCall (this, javax.swing.text.ComponentView.Invalidator, "invalidate", []);\r
147 if (this.getParent () != null) {\r
148 this.b$["javax.swing.text.ComponentView"].preferenceChanged (null, true, true);\r
149 }});\r
150 Clazz.overrideMethod (c$, "doLayout", \r
151 function () {\r
152 this.cacheChildSizes ();\r
153 });\r
154 Clazz.defineMethod (c$, "setBounds", \r
155 function (a, b, c, d) {\r
156 Clazz.superCall (this, javax.swing.text.ComponentView.Invalidator, "setBounds", [a, b, c, d]);\r
157 if (this.getComponentCount () > 0) {\r
158 this.getComponent (0).setSize (c, d);\r
159 }this.cacheChildSizes ();\r
160 }, "~N,~N,~N,~N");\r
161 Clazz.defineMethod (c$, "validateIfNecessary", \r
162 function () {\r
163 if (!this.isValid ()) {\r
164 this.validate ();\r
165 }});\r
166 Clazz.defineMethod (c$, "cacheChildSizes", \r
167  function () {\r
168 if (this.getComponentCount () > 0) {\r
169 var a = this.getComponent (0);\r
170 this.min = a.getMinimumSize ();\r
171 this.pref = a.getPreferredSize ();\r
172 this.max = a.getMaximumSize ();\r
173 this.yalign = a.getAlignmentY ();\r
174 this.xalign = a.getAlignmentX ();\r
175 } else {\r
176 this.min = this.pref = this.max =  new java.awt.Dimension (0, 0);\r
177 }});\r
178 Clazz.defineMethod (c$, "setVisible", \r
179 function (a) {\r
180 Clazz.superCall (this, javax.swing.text.ComponentView.Invalidator, "setVisible", [a]);\r
181 if (this.getComponentCount () > 0) {\r
182 this.getComponent (0).setVisible (a);\r
183 }}, "~B");\r
184 Clazz.overrideMethod (c$, "isShowing", \r
185 function () {\r
186 return true;\r
187 });\r
188 Clazz.overrideMethod (c$, "getMinimumSize", \r
189 function () {\r
190 this.validateIfNecessary ();\r
191 return this.min;\r
192 });\r
193 Clazz.overrideMethod (c$, "getPreferredSize", \r
194 function () {\r
195 this.validateIfNecessary ();\r
196 return this.pref;\r
197 });\r
198 Clazz.overrideMethod (c$, "getMaximumSize", \r
199 function () {\r
200 this.validateIfNecessary ();\r
201 return this.max;\r
202 });\r
203 Clazz.overrideMethod (c$, "getAlignmentX", \r
204 function () {\r
205 this.validateIfNecessary ();\r
206 return this.xalign;\r
207 });\r
208 Clazz.overrideMethod (c$, "getAlignmentY", \r
209 function () {\r
210 this.validateIfNecessary ();\r
211 return this.yalign;\r
212 });\r
213 Clazz.overrideMethod (c$, "propertyChange", \r
214 function (a) {\r
215 var b = a.getNewValue ();\r
216 if (this.getComponentCount () > 0) {\r
217 this.getComponent (0).setEnabled ((b).booleanValue ());\r
218 }}, "java.beans.PropertyChangeEvent");\r
219 c$ = Clazz.p0p ();\r
220 };\r
221 c$.$ComponentView$1$ = function () {\r
222 Clazz.pu$h(self.c$);\r
223 c$ = Clazz.declareAnonymous (javax.swing.text, "ComponentView$1", null, Runnable);\r
224 Clazz.overrideMethod (c$, "run", \r
225 function () {\r
226 var doc = this.b$["javax.swing.text.ComponentView"].getDocument ();\r
227 try {\r
228 if (Clazz.instanceOf (doc, javax.swing.text.AbstractDocument)) {\r
229 (doc).readLock ();\r
230 }this.b$["javax.swing.text.ComponentView"].setComponentParent ();\r
231 var host = this.b$["javax.swing.text.ComponentView"].getContainer ();\r
232 if (host != null) {\r
233 this.b$["javax.swing.text.ComponentView"].preferenceChanged (null, true, true);\r
234 host.repaint ();\r
235 }} finally {\r
236 if (Clazz.instanceOf (doc, javax.swing.text.AbstractDocument)) {\r
237 (doc).readUnlock ();\r
238 }}\r
239 });\r
240 c$ = Clazz.p0p ();\r
241 };\r
242 });\r