< prev index next >

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

Print this page
rev 9280 : 8088397: [Dialog] ButtonType text not updated when Locale changes

@@ -46,68 +46,69 @@
     /**
      * A pre-defined {@link ButtonType} that displays "Apply" and has a 
      * {@link ButtonData} of {@link ButtonData#APPLY}.
      */
     public static final ButtonType APPLY = new ButtonType(
-            ControlResources.getString("Dialog.apply.button"), ButtonData.APPLY);
+            "Dialog.apply.button", null, ButtonData.APPLY);
     
     /**
      * A pre-defined {@link ButtonType} that displays "OK" and has a 
      * {@link ButtonData} of {@link ButtonData#OK_DONE}.
      */
     public static final ButtonType OK = new ButtonType(
-            ControlResources.getString("Dialog.ok.button"), ButtonData.OK_DONE);
+            "Dialog.ok.button", null, ButtonData.OK_DONE);
     
     /**
      * A pre-defined {@link ButtonType} that displays "Cancel" and has a 
      * {@link ButtonData} of {@link ButtonData#CANCEL_CLOSE}.
      */
     public static final ButtonType CANCEL = new ButtonType(
-            ControlResources.getString("Dialog.cancel.button"), ButtonData.CANCEL_CLOSE);
+            "Dialog.cancel.button", null, ButtonData.CANCEL_CLOSE);
     
     /**
      * A pre-defined {@link ButtonType} that displays "Close" and has a 
      * {@link ButtonData} of {@link ButtonData#CANCEL_CLOSE}.
      */
     public static final ButtonType CLOSE = new ButtonType(
-            ControlResources.getString("Dialog.close.button"), ButtonData.CANCEL_CLOSE);
+            "Dialog.close.button", null, ButtonData.CANCEL_CLOSE);
     
     /**
      * A pre-defined {@link ButtonType} that displays "Yes" and has a 
      * {@link ButtonData} of {@link ButtonData#YES}.
      */
     public static final ButtonType YES = new ButtonType(
-            ControlResources.getString("Dialog.yes.button"), ButtonData.YES);
+            "Dialog.yes.button", null, ButtonData.YES);
     
     /**
      * A pre-defined {@link ButtonType} that displays "No" and has a 
      * {@link ButtonData} of {@link ButtonData#NO}.
      */
     public static final ButtonType NO = new ButtonType(
-            ControlResources.getString("Dialog.no.button"), ButtonData.NO);
+            "Dialog.no.button", null, ButtonData.NO);
     
     /**
      * A pre-defined {@link ButtonType} that displays "Finish" and has a 
      * {@link ButtonData} of {@link ButtonData#FINISH}.
      */
     public static final ButtonType FINISH = new ButtonType(
-            ControlResources.getString("Dialog.finish.button"), ButtonData.FINISH);
+            "Dialog.finish.button", null, ButtonData.FINISH);
     
     /**
      * A pre-defined {@link ButtonType} that displays "Next" and has a 
      * {@link ButtonData} of {@link ButtonData#NEXT_FORWARD}.
      */
     public static final ButtonType NEXT = new ButtonType(
-            ControlResources.getString("Dialog.next.button"), ButtonData.NEXT_FORWARD);
+            "Dialog.next.button", null, ButtonData.NEXT_FORWARD);
     
     /**
      * A pre-defined {@link ButtonType} that displays "Previous" and has a 
      * {@link ButtonData} of {@link ButtonData#BACK_PREVIOUS}.
      */
     public static final ButtonType PREVIOUS = new ButtonType(
-            ControlResources.getString("Dialog.previous.button"), ButtonData.BACK_PREVIOUS);
+            "Dialog.previous.button", null, ButtonData.BACK_PREVIOUS);
     
+    private final String key;
     private final String text;
     private final ButtonData buttonData;
     
 
     /**

@@ -129,10 +130,18 @@
      *      as {@link Button#textProperty() Button}.
      * @param buttonData The type of button that should be created from this ButtonType.
      */ 
     public ButtonType(@NamedArg("text") String text, 
                         @NamedArg("buttonData") ButtonData buttonData) {
+        this(null, text, buttonData);
+    }
+
+    /**
+     * Provide key or text. The other one should be null.
+     */
+    private ButtonType(String key, String text, ButtonData buttonData) {
+        this.key = key;
         this.text = text;
         this.buttonData = buttonData;
     }
 
     /**

@@ -141,11 +150,17 @@
     public final ButtonData getButtonData() { return this.buttonData; }
     
     /**
      * Returns the text specified for this ButtonType in the constructor;
      */
-    public final String getText() { return text;    }
+    public final String getText() {
+        if (text == null && key != null) {
+            return ControlResources.getString(key);
+        } else {
+            return text;
+        }
+    }
 
     /** {@inheritDoc} */
     @Override public String toString() {
         return "ButtonType [text=" + getText() + ", buttonData=" + getButtonData() + "]";
     } 
< prev index next >