1 /* |
1 /* |
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
78 /** |
78 /** |
79 * Forwards the call to SwingUtilities.layoutCompoundLabel(). |
79 * Forwards the call to SwingUtilities.layoutCompoundLabel(). |
80 * This method is here so that a subclass could do Label specific |
80 * This method is here so that a subclass could do Label specific |
81 * layout and to shorten the method name a little. |
81 * layout and to shorten the method name a little. |
82 * |
82 * |
|
83 * @param label an instance of {@code JLabel} |
|
84 * @param fontMetrics a font metrics |
|
85 * @param text a text |
|
86 * @param icon an icon |
|
87 * @param viewR a bounding rectangle to lay out label |
|
88 * @param iconR a bounding rectangle to lay out icon |
|
89 * @param textR a bounding rectangle to lay out text |
|
90 * @return a possibly clipped version of the compound labels string |
83 * @see SwingUtilities#layoutCompoundLabel |
91 * @see SwingUtilities#layoutCompoundLabel |
84 */ |
92 */ |
85 protected String layoutCL( |
93 protected String layoutCL( |
86 JLabel label, |
94 JLabel label, |
87 FontMetrics fontMetrics, |
95 FontMetrics fontMetrics, |
107 } |
115 } |
108 |
116 |
109 /** |
117 /** |
110 * Paint clippedText at textX, textY with the labels foreground color. |
118 * Paint clippedText at textX, textY with the labels foreground color. |
111 * |
119 * |
|
120 * @param l an instance of {@code JLabel} |
|
121 * @param g an instance of {@code Graphics} |
|
122 * @param s a text |
|
123 * @param textX an X coordinate |
|
124 * @param textY an Y coordinate |
112 * @see #paint |
125 * @see #paint |
113 * @see #paintDisabledText |
126 * @see #paintDisabledText |
114 */ |
127 */ |
115 protected void paintEnabledText(JLabel l, Graphics g, String s, int textX, int textY) |
128 protected void paintEnabledText(JLabel l, Graphics g, String s, int textX, int textY) |
116 { |
129 { |
123 |
136 |
124 /** |
137 /** |
125 * Paint clippedText at textX, textY with background.lighter() and then |
138 * Paint clippedText at textX, textY with background.lighter() and then |
126 * shifted down and to the right by one pixel with background.darker(). |
139 * shifted down and to the right by one pixel with background.darker(). |
127 * |
140 * |
|
141 * @param l an instance of {@code JLabel} |
|
142 * @param g an instance of {@code Graphics} |
|
143 * @param s a text |
|
144 * @param textX an X coordinate |
|
145 * @param textY an Y coordinate |
128 * @see #paint |
146 * @see #paint |
129 * @see #paintEnabledText |
147 * @see #paintEnabledText |
130 */ |
148 */ |
131 protected void paintDisabledText(JLabel l, Graphics g, String s, int textX, int textY) |
149 protected void paintDisabledText(JLabel l, Graphics g, String s, int textX, int textY) |
132 { |
150 { |
327 installKeyboardActions((JLabel)c); |
345 installKeyboardActions((JLabel)c); |
328 } |
346 } |
329 |
347 |
330 |
348 |
331 public void uninstallUI(JComponent c) { |
349 public void uninstallUI(JComponent c) { |
332 uninstallDefaults((JLabel)c); |
350 uninstallDefaults((JLabel) c); |
333 uninstallComponents((JLabel)c); |
351 uninstallComponents((JLabel) c); |
334 uninstallListeners((JLabel)c); |
352 uninstallListeners((JLabel) c); |
335 uninstallKeyboardActions((JLabel)c); |
353 uninstallKeyboardActions((JLabel) c); |
336 } |
354 } |
337 |
355 |
338 protected void installDefaults(JLabel c){ |
356 /** |
339 LookAndFeel.installColorsAndFont(c, "Label.background", "Label.foreground", "Label.font"); |
357 * Installs default properties. |
340 LookAndFeel.installProperty(c, "opaque", Boolean.FALSE); |
358 * |
341 } |
359 * @param c an instance of {@code JLabel} |
342 |
360 */ |
|
361 protected void installDefaults(JLabel c){ |
|
362 LookAndFeel.installColorsAndFont(c, "Label.background", "Label.foreground", "Label.font"); |
|
363 LookAndFeel.installProperty(c, "opaque", Boolean.FALSE); |
|
364 } |
|
365 |
|
366 /** |
|
367 * Registers listeners. |
|
368 * |
|
369 * @param c an instance of {@code JLabel} |
|
370 */ |
343 protected void installListeners(JLabel c){ |
371 protected void installListeners(JLabel c){ |
344 c.addPropertyChangeListener(this); |
372 c.addPropertyChangeListener(this); |
345 } |
373 } |
346 |
374 |
|
375 /** |
|
376 * Registers components. |
|
377 * |
|
378 * @param c an instance of {@code JLabel} |
|
379 */ |
347 protected void installComponents(JLabel c){ |
380 protected void installComponents(JLabel c){ |
348 BasicHTML.updateRenderer(c, c.getText()); |
381 BasicHTML.updateRenderer(c, c.getText()); |
349 c.setInheritsPopupMenu(true); |
382 c.setInheritsPopupMenu(true); |
350 } |
383 } |
351 |
384 |
|
385 /** |
|
386 * Registers keyboard actions. |
|
387 * |
|
388 * @param l an instance of {@code JLabel} |
|
389 */ |
352 protected void installKeyboardActions(JLabel l) { |
390 protected void installKeyboardActions(JLabel l) { |
353 int dka = l.getDisplayedMnemonic(); |
391 int dka = l.getDisplayedMnemonic(); |
354 Component lf = l.getLabelFor(); |
392 Component lf = l.getLabelFor(); |
355 if ((dka != 0) && (lf != null)) { |
393 if ((dka != 0) && (lf != null)) { |
356 LazyActionMap.installLazyActionMap(l, BasicLabelUI.class, |
394 LazyActionMap.installLazyActionMap(l, BasicLabelUI.class, |
372 inputMap.clear(); |
410 inputMap.clear(); |
373 } |
411 } |
374 } |
412 } |
375 } |
413 } |
376 |
414 |
|
415 /** |
|
416 * Uninstalls default properties. |
|
417 * |
|
418 * @param c an instance of {@code JLabel} |
|
419 */ |
377 protected void uninstallDefaults(JLabel c){ |
420 protected void uninstallDefaults(JLabel c){ |
378 } |
421 } |
379 |
422 |
|
423 /** |
|
424 * Unregisters listeners. |
|
425 * |
|
426 * @param c an instance of {@code JLabel} |
|
427 */ |
380 protected void uninstallListeners(JLabel c){ |
428 protected void uninstallListeners(JLabel c){ |
381 c.removePropertyChangeListener(this); |
429 c.removePropertyChangeListener(this); |
382 } |
430 } |
383 |
431 |
|
432 /** |
|
433 * Unregisters components. |
|
434 * |
|
435 * @param c an instance of {@code JLabel} |
|
436 */ |
384 protected void uninstallComponents(JLabel c){ |
437 protected void uninstallComponents(JLabel c){ |
385 BasicHTML.updateRenderer(c, ""); |
438 BasicHTML.updateRenderer(c, ""); |
386 } |
439 } |
387 |
440 |
|
441 /** |
|
442 * Unregisters keyboard actions. |
|
443 * |
|
444 * @param c an instance of {@code JLabel} |
|
445 */ |
388 protected void uninstallKeyboardActions(JLabel c) { |
446 protected void uninstallKeyboardActions(JLabel c) { |
389 SwingUtilities.replaceUIInputMap(c, JComponent.WHEN_FOCUSED, null); |
447 SwingUtilities.replaceUIInputMap(c, JComponent.WHEN_FOCUSED, null); |
390 SwingUtilities.replaceUIInputMap(c, JComponent.WHEN_IN_FOCUSED_WINDOW, |
448 SwingUtilities.replaceUIInputMap(c, JComponent.WHEN_IN_FOCUSED_WINDOW, |
391 null); |
449 null); |
392 SwingUtilities.replaceUIActionMap(c, null); |
450 SwingUtilities.replaceUIActionMap(c, null); |
393 } |
451 } |
394 |
452 |
|
453 /** |
|
454 * Returns an instance of {@code BasicLabelUI}. |
|
455 * |
|
456 * @param c a component |
|
457 * @return an instance of {@code BasicLabelUI} |
|
458 */ |
395 public static ComponentUI createUI(JComponent c) { |
459 public static ComponentUI createUI(JComponent c) { |
396 if (System.getSecurityManager() != null) { |
460 if (System.getSecurityManager() != null) { |
397 AppContext appContext = AppContext.getAppContext(); |
461 AppContext appContext = AppContext.getAppContext(); |
398 BasicLabelUI safeBasicLabelUI = |
462 BasicLabelUI safeBasicLabelUI = |
399 (BasicLabelUI) appContext.get(BASIC_LABEL_UI_KEY); |
463 (BasicLabelUI) appContext.get(BASIC_LABEL_UI_KEY); |