455 *
456 * @param c a component
457 * @return an instance of {@code BasicLabelUI}
458 */
459 public static ComponentUI createUI(JComponent c) {
460 if (System.getSecurityManager() != null) {
461 AppContext appContext = AppContext.getAppContext();
462 BasicLabelUI safeBasicLabelUI =
463 (BasicLabelUI) appContext.get(BASIC_LABEL_UI_KEY);
464 if (safeBasicLabelUI == null) {
465 safeBasicLabelUI = new BasicLabelUI();
466 appContext.put(BASIC_LABEL_UI_KEY, safeBasicLabelUI);
467 }
468 return safeBasicLabelUI;
469 }
470 return labelUI;
471 }
472
473 public void propertyChange(PropertyChangeEvent e) {
474 String name = e.getPropertyName();
475 if (name == "text" || "font" == name || "foreground" == name) {
476 // remove the old html view client property if one
477 // existed, and install a new one if the text installed
478 // into the JLabel is html source.
479 JLabel lbl = ((JLabel) e.getSource());
480 String text = lbl.getText();
481 BasicHTML.updateRenderer(lbl, text);
482 }
483 else if (name == "labelFor" || name == "displayedMnemonic") {
484 installKeyboardActions((JLabel) e.getSource());
485 }
486 }
487
488 // When the accelerator is pressed, temporarily make the JLabel
489 // focusTraversable by registering a WHEN_FOCUSED action for the
490 // release of the accelerator. Then give it focus so it can
491 // prevent unwanted keyTyped events from getting to other components.
492 private static class Actions extends UIAction {
493 private static final String PRESS = "press";
494 private static final String RELEASE = "release";
495
|
455 *
456 * @param c a component
457 * @return an instance of {@code BasicLabelUI}
458 */
459 public static ComponentUI createUI(JComponent c) {
460 if (System.getSecurityManager() != null) {
461 AppContext appContext = AppContext.getAppContext();
462 BasicLabelUI safeBasicLabelUI =
463 (BasicLabelUI) appContext.get(BASIC_LABEL_UI_KEY);
464 if (safeBasicLabelUI == null) {
465 safeBasicLabelUI = new BasicLabelUI();
466 appContext.put(BASIC_LABEL_UI_KEY, safeBasicLabelUI);
467 }
468 return safeBasicLabelUI;
469 }
470 return labelUI;
471 }
472
473 public void propertyChange(PropertyChangeEvent e) {
474 String name = e.getPropertyName();
475 if (name == "text" || "font" == name || "foreground" == name ||
476 "ancestor" == name || "graphicsConfig" == name) {
477 // remove the old html view client property if one
478 // existed, and install a new one if the text installed
479 // into the JLabel is html source.
480 JLabel lbl = ((JLabel) e.getSource());
481 String text = lbl.getText();
482 BasicHTML.updateRenderer(lbl, text);
483 }
484 else if (name == "labelFor" || name == "displayedMnemonic") {
485 installKeyboardActions((JLabel) e.getSource());
486 }
487 }
488
489 // When the accelerator is pressed, temporarily make the JLabel
490 // focusTraversable by registering a WHEN_FOCUSED action for the
491 // release of the accelerator. Then give it focus so it can
492 // prevent unwanted keyTyped events from getting to other components.
493 private static class Actions extends UIAction {
494 private static final String PRESS = "press";
495 private static final String RELEASE = "release";
496
|