1 /* 2 * Copyright (c) 2014, 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 23 * questions. 24 */ 25 package javafx.scene.control; 26 27 import com.sun.javafx.scene.control.skin.resources.ControlResources; 28 29 import javafx.beans.NamedArg; 30 import javafx.scene.control.Button; 31 import javafx.scene.control.ButtonBar.ButtonData; 32 33 /** 34 * The ButtonType class is used as part of the JavaFX {@link Dialog} API (more 35 * specifically, the {@link DialogPane} API) to specify which buttons should be 36 * shown to users in the dialogs. Refer to the {@link DialogPane} class javadoc 37 * for more information on how to use this class. 38 * 39 * @see Alert 40 * @see Dialog 41 * @see DialogPane 42 * @since JavaFX 8u40 43 */ 44 public final class ButtonType { 45 46 /** 47 * A pre-defined {@link ButtonType} that displays "Apply" and has a 48 * {@link ButtonData} of {@link ButtonData#APPLY}. 49 */ 50 public static final ButtonType APPLY = new ButtonType( 51 ControlResources.getString("Dialog.apply.button"), ButtonData.APPLY); 52 53 /** 54 * A pre-defined {@link ButtonType} that displays "OK" and has a 55 * {@link ButtonData} of {@link ButtonData#OK_DONE}. 56 */ 57 public static final ButtonType OK = new ButtonType( 58 ControlResources.getString("Dialog.ok.button"), ButtonData.OK_DONE); 59 60 /** 61 * A pre-defined {@link ButtonType} that displays "Cancel" and has a 62 * {@link ButtonData} of {@link ButtonData#CANCEL_CLOSE}. 63 */ 64 public static final ButtonType CANCEL = new ButtonType( 65 ControlResources.getString("Dialog.cancel.button"), ButtonData.CANCEL_CLOSE); 66 67 /** 68 * A pre-defined {@link ButtonType} that displays "Close" and has a 69 * {@link ButtonData} of {@link ButtonData#CANCEL_CLOSE}. 70 */ 71 public static final ButtonType CLOSE = new ButtonType( 72 ControlResources.getString("Dialog.close.button"), ButtonData.CANCEL_CLOSE); 73 74 /** 75 * A pre-defined {@link ButtonType} that displays "Yes" and has a 76 * {@link ButtonData} of {@link ButtonData#YES}. 77 */ 78 public static final ButtonType YES = new ButtonType( 79 ControlResources.getString("Dialog.yes.button"), ButtonData.YES); 80 81 /** 82 * A pre-defined {@link ButtonType} that displays "No" and has a 83 * {@link ButtonData} of {@link ButtonData#NO}. 84 */ 85 public static final ButtonType NO = new ButtonType( 86 ControlResources.getString("Dialog.no.button"), ButtonData.NO); 87 88 /** 89 * A pre-defined {@link ButtonType} that displays "Finish" and has a 90 * {@link ButtonData} of {@link ButtonData#FINISH}. 91 */ 92 public static final ButtonType FINISH = new ButtonType( 93 ControlResources.getString("Dialog.finish.button"), ButtonData.FINISH); 94 95 /** 96 * A pre-defined {@link ButtonType} that displays "Next" and has a 97 * {@link ButtonData} of {@link ButtonData#NEXT_FORWARD}. 98 */ 99 public static final ButtonType NEXT = new ButtonType( 100 ControlResources.getString("Dialog.next.button"), ButtonData.NEXT_FORWARD); 101 102 /** 103 * A pre-defined {@link ButtonType} that displays "Previous" and has a 104 * {@link ButtonData} of {@link ButtonData#BACK_PREVIOUS}. 105 */ 106 public static final ButtonType PREVIOUS = new ButtonType( 107 ControlResources.getString("Dialog.previous.button"), ButtonData.BACK_PREVIOUS); 108 109 private final String text; 110 private final ButtonData buttonData; 111 112 113 /** 114 * Creates a ButtonType instance with the given text, and the ButtonData set 115 * as {@link ButtonData#OTHER}. 116 * 117 * @param text The string to display in the text property of controls such 118 * as {@link Button#textProperty() Button}. 119 */ 120 public ButtonType(@NamedArg("text") String text) { 121 this(text, ButtonData.OTHER); 122 } 123 124 /** 125 * Creates a ButtonType instance with the given text, and the ButtonData set 126 * as specified. 127 * 128 * @param text The string to display in the text property of controls such 129 * as {@link Button#textProperty() Button}. 130 * @param buttonData The type of button that should be created from this ButtonType. 131 */ 132 public ButtonType(@NamedArg("text") String text, 133 @NamedArg("buttonData") ButtonData buttonData) { 134 this.text = text; 135 this.buttonData = buttonData; 136 } 137 138 /** 139 * Returns the ButtonData specified for this ButtonType in the constructor. 140 */ 141 public final ButtonData getButtonData() { return this.buttonData; } 142 143 /** 144 * Returns the text specified for this ButtonType in the constructor; 145 */ 146 public final String getText() { return text; } 147 148 /** {@inheritDoc} */ 149 @Override public String toString() { 150 return "ButtonType [text=" + getText() + ", buttonData=" + getButtonData() + "]"; 151 } 152 }