< prev index next >

src/java.desktop/share/classes/javax/swing/plaf/basic/BasicLabelUI.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 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 || "graphicsConfiguration" == 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 


   1 /*
   2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 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                 || "graphicsConfiguration" == 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 


< prev index next >