202c41e8bb101a5bdf40209fd498c5bb08039859
[jalviewjs.git] / site / swingjs / j2s / jssun / swing / SwingUtilities2.js
1 Clazz.declarePackage ("jssun.swing");
2 Clazz.load (["java.lang.Enum", "java.awt.font.FontRenderContext", "jssun.swing.StringUIClientPropertyKey"], "jssun.swing.SwingUtilities2", ["java.lang.Boolean", "$.StringBuffer", "java.awt.Graphics2D", "$.RenderingHints", "javax.swing.SwingUtilities", "$.UIManager"], function () {
3 c$ = Clazz.declareType (jssun.swing, "SwingUtilities2");
4 c$.drawTextAntialiased = Clazz.defineMethod (c$, "drawTextAntialiased", 
5 function (c) {
6 if (c != null) {
7 return c.getClientProperty (jssun.swing.SwingUtilities2.AA_TEXT_PROPERTY_KEY);
8 }return null;
9 }, "javax.swing.JComponent");
10 c$.getLeftSideBearing = Clazz.defineMethod (c$, "getLeftSideBearing", 
11 function (c, fm, string) {
12 if ((string == null) || (string.length == 0)) {
13 return 0;
14 }return jssun.swing.SwingUtilities2.getLeftSideBearing (c, fm, string.charAt (0));
15 }, "javax.swing.JComponent,java.awt.FontMetrics,~S");
16 c$.getLeftSideBearing = Clazz.defineMethod (c$, "getLeftSideBearing", 
17 function (c, fm, firstChar) {
18 return 0;
19 }, "javax.swing.JComponent,java.awt.FontMetrics,~S");
20 c$.getRightSideBearing = Clazz.defineMethod (c$, "getRightSideBearing", 
21 function (c, fm, string) {
22 if ((string == null) || (string.length == 0)) {
23 return 0;
24 }return jssun.swing.SwingUtilities2.getRightSideBearing (c, fm, string.charAt (string.length - 1));
25 }, "javax.swing.JComponent,java.awt.FontMetrics,~S");
26 c$.getRightSideBearing = Clazz.defineMethod (c$, "getRightSideBearing", 
27 function (c, fm, lastChar) {
28 return 0;
29 }, "javax.swing.JComponent,java.awt.FontMetrics,~S");
30 c$.getFontMetrics = Clazz.defineMethod (c$, "getFontMetrics", 
31 function (c, g) {
32 return jssun.swing.SwingUtilities2.getFontMetrics (c, g, g.getFont ());
33 }, "javax.swing.JComponent,java.awt.Graphics");
34 c$.getFontMetrics = Clazz.defineMethod (c$, "getFontMetrics", 
35 function (c, g, font) {
36 if (c != null) {
37 return c.getFontMetrics (font);
38 }return null;
39 }, "javax.swing.JComponent,java.awt.Graphics,java.awt.Font");
40 c$.stringWidth = Clazz.defineMethod (c$, "stringWidth", 
41 function (c, fm, string) {
42 if (string == null || string.equals ("")) {
43 return 0;
44 }return fm.stringWidth (string);
45 }, "javax.swing.JComponent,java.awt.FontMetrics,~S");
46 c$.drawString = Clazz.defineMethod (c$, "drawString", 
47 function (c, g, text, x, y) {
48 if (text == null || text.length <= 0) {
49 return;
50 }var info = jssun.swing.SwingUtilities2.drawTextAntialiased (c);
51 if (info != null && (Clazz.instanceOf (g, java.awt.Graphics2D))) {
52 var g2 = g;
53 var oldContrast = null;
54 var oldAAValue = g2.getRenderingHint (java.awt.RenderingHints.KEY_TEXT_ANTIALIASING);
55 if (info.aaHint !== oldAAValue) {
56 g2.setRenderingHint (java.awt.RenderingHints.KEY_TEXT_ANTIALIASING, info.aaHint);
57 } else {
58 oldAAValue = null;
59 }if (info.lcdContrastHint != null) {
60 oldContrast = g2.getRenderingHint (java.awt.RenderingHints.KEY_TEXT_LCD_CONTRAST);
61 if (info.lcdContrastHint.equals (oldContrast)) {
62 oldContrast = null;
63 } else {
64 g2.setRenderingHint (java.awt.RenderingHints.KEY_TEXT_LCD_CONTRAST, info.lcdContrastHint);
65 }}g.drawString (text, x, y);
66 if (oldAAValue != null) {
67 g2.setRenderingHint (java.awt.RenderingHints.KEY_TEXT_ANTIALIASING, oldAAValue);
68 }if (oldContrast != null) {
69 g2.setRenderingHint (java.awt.RenderingHints.KEY_TEXT_LCD_CONTRAST, oldContrast);
70 }} else {
71 g.drawString (text, x, y);
72 }}, "javax.swing.JComponent,java.awt.Graphics,~S,~N,~N");
73 c$.loc2IndexFileList = Clazz.defineMethod (c$, "loc2IndexFileList", 
74 function (list, point) {
75 var index = list.locationToIndex (point);
76 if (index != -1) {
77 var bySize = list.getClientProperty ("List.isFileList");
78 if (Clazz.instanceOf (bySize, Boolean) && (bySize).booleanValue () && !jssun.swing.SwingUtilities2.pointIsInActualBounds (list, index, point)) {
79 index = -1;
80 }}return index;
81 }, "javax.swing.JList,java.awt.Point");
82 c$.pointIsInActualBounds = Clazz.defineMethod (c$, "pointIsInActualBounds", 
83  function (list, index, point) {
84 var renderer = list.getCellRenderer ();
85 var dataModel = list.getModel ();
86 var value = dataModel.getElementAt (index);
87 var item = renderer.getListCellRendererComponent (list, value, index, false, false);
88 var itemSize = item.getPreferredSize ();
89 var cellBounds = list.getCellBounds (index, index);
90 if (!item.getComponentOrientation ().isLeftToRight ()) {
91 cellBounds.x += (cellBounds.width - itemSize.width);
92 }cellBounds.width = itemSize.width;
93 return cellBounds.contains (point);
94 }, "javax.swing.JList,~N,java.awt.Point");
95 c$.pointOutsidePrefSize = Clazz.defineMethod (c$, "pointOutsidePrefSize", 
96 function (table, row, column, p) {
97 if (table.convertColumnIndexToModel (column) != 0 || row == -1) {
98 return true;
99 }var tcr = table.getCellRenderer (row, column);
100 var value = table.getValueAt (row, column);
101 var cell = tcr.getTableCellRendererComponent (table, value, false, false, row, column);
102 var itemSize = cell.getPreferredSize ();
103 var cellBounds = table.getCellRect (row, column, false);
104 cellBounds.width = itemSize.width;
105 cellBounds.height = itemSize.height;
106 if (p.x > cellBounds.x + cellBounds.width || p.y > cellBounds.y + cellBounds.height) {
107 return true;
108 }return false;
109 }, "javax.swing.JTable,~N,~N,java.awt.Point");
110 c$.setLeadAnchorWithoutSelection = Clazz.defineMethod (c$, "setLeadAnchorWithoutSelection", 
111 function (model, lead, anchor) {
112 if (anchor == -1) {
113 anchor = lead;
114 }if (lead == -1) {
115 model.setAnchorSelectionIndex (-1);
116 model.setLeadSelectionIndex (-1);
117 } else {
118 if (model.isSelectedIndex (lead)) {
119 model.addSelectionInterval (lead, lead);
120 } else {
121 model.removeSelectionInterval (lead, lead);
122 }model.setAnchorSelectionIndex (anchor);
123 }}, "javax.swing.ListSelectionModel,~N,~N");
124 c$.shouldIgnore = Clazz.defineMethod (c$, "shouldIgnore", 
125 function (me, c) {
126 return c == null || !c.isEnabled () || !javax.swing.SwingUtilities.isLeftMouseButton (me) || me.isConsumed ();
127 }, "java.awt.event.MouseEvent,javax.swing.JComponent");
128 c$.adjustFocus = Clazz.defineMethod (c$, "adjustFocus", 
129 function (c) {
130 if (!c.hasFocus () && c.isRequestFocusEnabled ()) {
131 c.requestFocus ();
132 }}, "javax.swing.JComponent");
133 c$.getGraphics2D = Clazz.defineMethod (c$, "getGraphics2D", 
134 function (g) {
135 if (Clazz.instanceOf (g, java.awt.Graphics2D)) {
136 return g;
137 } else {
138 return null;
139 }}, "java.awt.Graphics");
140 c$.isPrinting = Clazz.defineMethod (c$, "isPrinting", 
141 function (g) {
142 return false;
143 }, "java.awt.Graphics");
144 c$.useSelectedTextColor = Clazz.defineMethod (c$, "useSelectedTextColor", 
145 function (h, c) {
146 var painter = h.getPainter ();
147 var painterClass = painter.getClass ().getName ();
148 if (painterClass.indexOf ("javax.swing.text.DefaultHighlighter") != 0 && painterClass.indexOf ("com.sun.java.swing.plaf.windows.WindowsTextUI") != 0) {
149 return false;
150 }try {
151 var defPainter = painter;
152 if (defPainter.getColor () != null && !defPainter.getColor ().equals (c.getSelectionColor ())) {
153 return false;
154 }} catch (e) {
155 if (Clazz.exceptionOf (e, ClassCastException)) {
156 return false;
157 } else {
158 throw e;
159 }
160 }
161 return true;
162 }, "javax.swing.text.Highlighter.Highlight,javax.swing.text.JTextComponent");
163 c$.canAccessSystemClipboard = Clazz.defineMethod (c$, "canAccessSystemClipboard", 
164 function () {
165 var canAccess = false;
166 return canAccess;
167 });
168 c$.canCurrentEventAccessSystemClipboard = Clazz.defineMethod (c$, "canCurrentEventAccessSystemClipboard", 
169 function () {
170 return false;
171 });
172 c$.displayPropertiesToCSS = Clazz.defineMethod (c$, "displayPropertiesToCSS", 
173 function (font, fg) {
174 var rule =  new StringBuffer ("body {");
175 if (font != null) {
176 rule.append (" font-family: ");
177 rule.append (font.getFamily ());
178 rule.append (" ; ");
179 rule.append (" font-size: ");
180 rule.append ("" + font.getSize ());
181 rule.append ("pt ;");
182 if (font.isBold ()) {
183 rule.append (" font-weight: 700 ; ");
184 }if (font.isItalic ()) {
185 rule.append (" font-style: italic ; ");
186 }}if (fg != null) {
187 rule.append (" color: #");
188 if (fg.getRed () < 16) {
189 rule.append ('0');
190 }rule.append (Integer.toHexString (fg.getRed ()));
191 if (fg.getGreen () < 16) {
192 rule.append ('0');
193 }rule.append (Integer.toHexString (fg.getGreen ()));
194 if (fg.getBlue () < 16) {
195 rule.append ('0');
196 }rule.append (Integer.toHexString (fg.getBlue ()));
197 rule.append (" ; ");
198 }rule.append (" }");
199 return rule.toString ();
200 }, "java.awt.Font,java.awt.Color");
201 c$.makeIcon = Clazz.defineMethod (c$, "makeIcon", 
202 function (baseClass, rootClass, imageFile) {
203 return null;
204 }, "Class,Class,~S");
205 c$.isLocalDisplay = Clazz.defineMethod (c$, "isLocalDisplay", 
206 function () {
207 return true;
208 });
209 c$.getUIDefaultsInt = Clazz.defineMethod (c$, "getUIDefaultsInt", 
210 function (key) {
211 return jssun.swing.SwingUtilities2.getUIDefaultsInt (key, 0);
212 }, "~O");
213 c$.getUIDefaultsInt = Clazz.defineMethod (c$, "getUIDefaultsInt", 
214 function (key, l) {
215 return jssun.swing.SwingUtilities2.getUIDefaultsInt (key, l, 0);
216 }, "~O,java.util.Locale");
217 c$.getUIDefaultsInt = Clazz.defineMethod (c$, "getUIDefaultsInt", 
218 function (key, defaultValue) {
219 return jssun.swing.SwingUtilities2.getUIDefaultsInt (key, null, defaultValue);
220 }, "~O,~N");
221 c$.getUIDefaultsInt = Clazz.defineMethod (c$, "getUIDefaultsInt", 
222 function (key, l, defaultValue) {
223 var value = javax.swing.UIManager.get (key, l);
224 if (Clazz.instanceOf (value, Integer)) {
225 return (value).intValue ();
226 }if (Clazz.instanceOf (value, String)) {
227 try {
228 return Integer.parseInt (value);
229 } catch (nfe) {
230 if (Clazz.exceptionOf (nfe, NumberFormatException)) {
231 } else {
232 throw nfe;
233 }
234 }
235 }return defaultValue;
236 }, "~O,java.util.Locale,~N");
237 c$.liesIn = Clazz.defineMethod (c$, "liesIn", 
238  function (rect, p, horizontal, ltr, three) {
239 var p0;
240 var pComp;
241 var length;
242 var forward;
243 if (horizontal) {
244 p0 = rect.x;
245 pComp = p.x;
246 length = rect.width;
247 forward = ltr;
248 } else {
249 p0 = rect.y;
250 pComp = p.y;
251 length = rect.height;
252 forward = true;
253 }if (three) {
254 var boundary = (length >= 30) ? 10 : Clazz.doubleToInt (length / 3);
255 if (pComp < p0 + boundary) {
256 return forward ? jssun.swing.SwingUtilities2.Section.LEADING : jssun.swing.SwingUtilities2.Section.TRAILING;
257 } else if (pComp >= p0 + length - boundary) {
258 return forward ? jssun.swing.SwingUtilities2.Section.TRAILING : jssun.swing.SwingUtilities2.Section.LEADING;
259 }return jssun.swing.SwingUtilities2.Section.MIDDLE;
260 } else {
261 var middle = p0 + Clazz.doubleToInt (length / 2);
262 if (forward) {
263 return pComp >= middle ? jssun.swing.SwingUtilities2.Section.TRAILING : jssun.swing.SwingUtilities2.Section.LEADING;
264 } else {
265 return pComp < middle ? jssun.swing.SwingUtilities2.Section.TRAILING : jssun.swing.SwingUtilities2.Section.LEADING;
266 }}}, "java.awt.Rectangle,java.awt.Point,~B,~B,~B");
267 c$.liesInHorizontal = Clazz.defineMethod (c$, "liesInHorizontal", 
268 function (rect, p, ltr, three) {
269 return jssun.swing.SwingUtilities2.liesIn (rect, p, true, ltr, three);
270 }, "java.awt.Rectangle,java.awt.Point,~B,~B");
271 c$.liesInVertical = Clazz.defineMethod (c$, "liesInVertical", 
272 function (rect, p, three) {
273 return jssun.swing.SwingUtilities2.liesIn (rect, p, false, false, three);
274 }, "java.awt.Rectangle,java.awt.Point,~B");
275 Clazz.pu$h(self.c$);
276 c$ = Clazz.declareType (jssun.swing.SwingUtilities2, "Section", Enum);
277 Clazz.defineEnumConstant (c$, "LEADING", 0, []);
278 Clazz.defineEnumConstant (c$, "MIDDLE", 1, []);
279 Clazz.defineEnumConstant (c$, "TRAILING", 2, []);
280 c$ = Clazz.p0p ();
281 Clazz.pu$h(self.c$);
282 c$ = Clazz.decorateAsClass (function () {
283 this.aaHint = null;
284 this.lcdContrastHint = null;
285 this.frc = null;
286 Clazz.instantialize (this, arguments);
287 }, jssun.swing.SwingUtilities2, "AATextInfo");
288 c$.getAATextInfo = Clazz.defineMethod (c$, "getAATextInfo", 
289 function (a) {
290 return null;
291 }, "~B");
292 c$ = Clazz.p0p ();
293 c$.LAF_STATE_KEY = c$.prototype.LAF_STATE_KEY =  new Clazz._O ();
294 c$.DEFAULT_FRC = c$.prototype.DEFAULT_FRC =  new java.awt.font.FontRenderContext (null, false, false);
295 c$.AA_TEXT_PROPERTY_KEY = c$.prototype.AA_TEXT_PROPERTY_KEY =  new Clazz._O ();
296 c$.SKIP_CLICK_COUNT = c$.prototype.SKIP_CLICK_COUNT =  new Clazz._O ();
297 c$.COMPONENT_UI_PROPERTY_KEY = c$.prototype.COMPONENT_UI_PROPERTY_KEY =  new Clazz._O ();
298 c$.BASICMENUITEMUI_MAX_TEXT_OFFSET = c$.prototype.BASICMENUITEMUI_MAX_TEXT_OFFSET =  new jssun.swing.StringUIClientPropertyKey ("maxTextOffset");
299 });