< prev index next >

modules/controls/src/main/java/javafx/scene/control/TextInputControl.java

Print this page




  52 import javafx.css.CssMetaData;
  53 import javafx.css.FontCssMetaData;
  54 import javafx.css.PseudoClass;
  55 import javafx.css.StyleOrigin;
  56 import javafx.css.Styleable;
  57 import javafx.css.StyleableObjectProperty;
  58 import javafx.css.StyleableProperty;
  59 import javafx.scene.AccessibleAction;
  60 import javafx.scene.AccessibleAttribute;
  61 import javafx.scene.input.Clipboard;
  62 import javafx.scene.input.ClipboardContent;
  63 import javafx.scene.text.Font;
  64 
  65 import java.text.BreakIterator;
  66 import java.util.ArrayList;
  67 import java.util.Collections;
  68 import java.util.List;
  69 
  70 import com.sun.javafx.util.Utils;
  71 import com.sun.javafx.binding.ExpressionHelper;

  72 import javafx.util.StringConverter;
  73 
  74 /**
  75  * Abstract base class for text input controls.
  76  * @since JavaFX 2.0
  77  */
  78 @DefaultProperty("text")
  79 public abstract class TextInputControl extends Control {
  80     /**
  81      * Interface representing a text input's content. Since it is an ObservableStringValue,
  82      * you can also bind to, or observe the content.
  83      * @since JavaFX 2.0
  84      */
  85     protected interface Content extends ObservableStringValue {
  86         /**
  87          * Retrieves a subset of the content.
  88          *
  89          * @param start
  90          * @param end
  91          */


 186      **************************************************************************/
 187 
 188     /**
 189      * The default font to use for text in the TextInputControl. If the TextInputControl's text is
 190      * rich text then this font may or may not be used depending on the font
 191      * information embedded in the rich text, but in any case where a default
 192      * font is required, this font will be used.
 193      * @since JavaFX 8.0
 194      */
 195     public final ObjectProperty<Font> fontProperty() {
 196         if (font == null) {
 197             font = new StyleableObjectProperty<Font>(Font.getDefault()) {
 198 
 199 
 200                 private boolean fontSetByCss = false;
 201 
 202                 @Override
 203                 public void applyStyle(StyleOrigin newOrigin, Font value) {
 204 
 205                     //
 206                     // RT-20727 - if CSS is setting the font, then make sure invalidate doesn't call impl_reapplyCSS
 207                     //
 208                     try {
 209                         // super.applyStyle calls set which might throw if value is bound.
 210                         // Have to make sure fontSetByCss is reset.
 211                         fontSetByCss = true;
 212                         super.applyStyle(newOrigin, value);
 213                     } catch(Exception e) {
 214                         throw e;
 215                     } finally {
 216                         fontSetByCss = false;
 217                     }
 218 
 219                 }
 220 
 221 
 222                 @Override
 223                 public void set(Font value) {
 224                     final Font oldValue = get();
 225                     if (value == null ? oldValue == null : value.equals(oldValue)) {
 226                         return;
 227                     }
 228                     super.set(value);
 229                 }
 230 
 231                 @Override
 232                 protected void invalidated() {
 233                     // RT-20727 - if font is changed by calling setFont, then
 234                     // css might need to be reapplied since font size affects
 235                     // calculated values for styles with relative values
 236                     if(fontSetByCss == false) {
 237                         TextInputControl.this.impl_reapplyCSS();
 238                     }
 239                 }
 240 
 241                 @Override
 242                 public CssMetaData<TextInputControl,Font> getCssMetaData() {
 243                     return StyleableProperties.FONT;
 244                 }
 245 
 246                 @Override
 247                 public Object getBean() {
 248                     return TextInputControl.this;
 249                 }
 250 
 251                 @Override
 252                 public String getName() {
 253                     return "font";
 254                 }
 255             };
 256         }
 257         return font;




  52 import javafx.css.CssMetaData;
  53 import javafx.css.FontCssMetaData;
  54 import javafx.css.PseudoClass;
  55 import javafx.css.StyleOrigin;
  56 import javafx.css.Styleable;
  57 import javafx.css.StyleableObjectProperty;
  58 import javafx.css.StyleableProperty;
  59 import javafx.scene.AccessibleAction;
  60 import javafx.scene.AccessibleAttribute;
  61 import javafx.scene.input.Clipboard;
  62 import javafx.scene.input.ClipboardContent;
  63 import javafx.scene.text.Font;
  64 
  65 import java.text.BreakIterator;
  66 import java.util.ArrayList;
  67 import java.util.Collections;
  68 import java.util.List;
  69 
  70 import com.sun.javafx.util.Utils;
  71 import com.sun.javafx.binding.ExpressionHelper;
  72 import com.sun.javafx.scene.NodeHelper;
  73 import javafx.util.StringConverter;
  74 
  75 /**
  76  * Abstract base class for text input controls.
  77  * @since JavaFX 2.0
  78  */
  79 @DefaultProperty("text")
  80 public abstract class TextInputControl extends Control {
  81     /**
  82      * Interface representing a text input's content. Since it is an ObservableStringValue,
  83      * you can also bind to, or observe the content.
  84      * @since JavaFX 2.0
  85      */
  86     protected interface Content extends ObservableStringValue {
  87         /**
  88          * Retrieves a subset of the content.
  89          *
  90          * @param start
  91          * @param end
  92          */


 187      **************************************************************************/
 188 
 189     /**
 190      * The default font to use for text in the TextInputControl. If the TextInputControl's text is
 191      * rich text then this font may or may not be used depending on the font
 192      * information embedded in the rich text, but in any case where a default
 193      * font is required, this font will be used.
 194      * @since JavaFX 8.0
 195      */
 196     public final ObjectProperty<Font> fontProperty() {
 197         if (font == null) {
 198             font = new StyleableObjectProperty<Font>(Font.getDefault()) {
 199 
 200 
 201                 private boolean fontSetByCss = false;
 202 
 203                 @Override
 204                 public void applyStyle(StyleOrigin newOrigin, Font value) {
 205 
 206                     //
 207                     // RT-20727 - if CSS is setting the font, then make sure invalidate doesn't call NodeHelper.reapplyCSS
 208                     //
 209                     try {
 210                         // super.applyStyle calls set which might throw if value is bound.
 211                         // Have to make sure fontSetByCss is reset.
 212                         fontSetByCss = true;
 213                         super.applyStyle(newOrigin, value);
 214                     } catch(Exception e) {
 215                         throw e;
 216                     } finally {
 217                         fontSetByCss = false;
 218                     }
 219 
 220                 }
 221 
 222 
 223                 @Override
 224                 public void set(Font value) {
 225                     final Font oldValue = get();
 226                     if (value == null ? oldValue == null : value.equals(oldValue)) {
 227                         return;
 228                     }
 229                     super.set(value);
 230                 }
 231 
 232                 @Override
 233                 protected void invalidated() {
 234                     // RT-20727 - if font is changed by calling setFont, then
 235                     // css might need to be reapplied since font size affects
 236                     // calculated values for styles with relative values
 237                     if(fontSetByCss == false) {
 238                         NodeHelper.reapplyCSS(TextInputControl.this);
 239                     }
 240                 }
 241 
 242                 @Override
 243                 public CssMetaData<TextInputControl,Font> getCssMetaData() {
 244                     return StyleableProperties.FONT;
 245                 }
 246 
 247                 @Override
 248                 public Object getBean() {
 249                     return TextInputControl.this;
 250                 }
 251 
 252                 @Override
 253                 public String getName() {
 254                     return "font";
 255                 }
 256             };
 257         }
 258         return font;


< prev index next >