|
Spec-Zone .ru
спецификации, руководства, описания, API
|
Some types are value types. Value types have the following characteristics:
Currently, the only value types are String, Integer, Number, Boolean, and Duration. These types have built-in support in the language:
String, Integer, Number, Boolean, and Duration are discussed in this section.
String represents character strings. The default value for the String type is the empty string ("").
StringLiteral:
OneStringLiteral
StringLiteral OneStringLiteral
OneStringLiteral:
" DoubleQuoteStringCharactersopt "
' SingleQuoteStringCharactersopt '
DoubleQuoteStringCharacters:
DoubleQuoteStringCharacter
DoubleQuoteStringCharacters DoubleQuoteStringCharacter
DoubleQuoteStringCharacter:
InputCharacter but not ", {, } or \
\ InputCharacter
SingleQuoteStringCharacters:
SingleQuoteStringCharacter
SingleQuoteStringCharacters SingleQuoteStringCharacter
SingleQuoteStringCharacter:
InputCharacter but not ', {, } or \
\ InputCharacter
Literals are bracketed in either single or double quotes. That is, a double quote followed by a sequence of characters (here "sequence" does not refer to the cardinality) and ending with a double quote. For example:
"brown cow"
Or a single quote followed by a sequence of characters and ending with a single quote. For example:
'This is so %#@*^ exciting!'
If the sequence of characters includes braces ('{' or '}') it is a string-expression. Any character may be escaped with the backslash character ('\') -- this is useful for including the brace, quote, and backslash characters. Note that single quotes may be included in double quoted strings without being escaped, and visa versa. For example:
"Then she said 'shazam', and abruptly left"
The sequence of characters must not include carriage-return or linefeed. Two adjacent strings are automatically merged at compile-time -- this is convenient for making multiple line strings. Thus:
def greeting = "Hello " 'there'; println( greeting );
will print:
Hello there
When an application displays some text to a user, you'd like the text to be in the user's own language. "Localization" is a mechanism to be able to replace a string literal by a translation selected at run-time.
If a double hash sign ## is prefixed to a string literal,
JavaFX substitutes the string literal with a localized one at
run-time, if JavaFX finds appropriate localization in JavaFX properties files
on the classpath. A JavaFX properties file contains localized strings for a
locale as "key" = "value" pairs.
Localized strings are searched using the original string literals as keys.
If no localized string is found, the original string literal is used as a default.
Optionally, explicit keys can be specified with square brackets
([]). For example:
def mon = ##"Monday"; def about = ##[ABOUT]"JavaFX is a cool scripting language!"; println( mon ); println( about );
Suppose this script is Foo.fx, and there is a JavaFX
properties file for French Foo_fr.fxproperties, which contains the
following localization:
"Monday" = "Lundi" "ABOUT" = "JavaFX est un langage de script cool !"
The script will print:
Lundi JavaFX est un langage de script cool !
in French locale. You can also provide layered properties files
for finer grained control. For example, you can provide localized texts that
are France specific in Foo_fr_FR.fxproperties, and keep
other French localized texts that are country independent in
Foo_fr.fxproperties. Then the JavaFX searches the
appropriate localized texts by attempting the following fallback
search in French France (fr_FR) locale:
Foo_fr_FR.fxproperties Foo_fr.fxproperties (original string)
For more information on the locale and how the JavaFX properties
file is located, refer to java.util.Locale and
java.util.ResourceBundle classes of the Java platform.
The encoding of a JavaFX properties file is
UTF-8. Other encodings can be specified with
the @charset directive. For example:
@charset "ISO-8859-1";
is specified in the first line of the JavaFX properties file, the
file is read in ISO-8859-1 encoding. If the string literal contains string-expressions,
corresponding properties
should only contain the FORMAT_STRING_LITERAL parts
of the string expressions, without curly braces and expression parts. For
example:
def gCal = new GregorianCalendar(1995, Calendar.MAY, 23);
def bday = ##"The birthday of Duke is {%1$tB gCal} {%2$te gCal}, {%3$tY gCal}.";
Then a JavaFX properties file that contains the localized text for
"bday" should look like (e.g., for French):
"The birthday of Duke is %1$tB %2$te, %3$tY." = "L'anniversaire du duc est le %2$te %1$tB %3$tY."
Note that the position of those FORMAT_STRING_LITERAL parts
(indicated by [argument_index]$) may change in localized texts.
String-expressions are of String type -- see the Expressions chapter
IntegerLiteral:
DecimalIntegerLiteral
HexIntegerLiteral
OctalIntegerLiteral
DecimalIntegerLiteral:
0
NonZeroDigit Digitsopt
Digits:
Digit
Digits Digit
Digit:
0
NonZeroDigit
NonZeroDigit: one of
1 2 3 4 5 6 7 8 9
HexIntegerLiteral:
0 x HexDigits
0 X HexDigits
HexDigits:
HexDigit
HexDigit HexDigits
HexDigit: one of
0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F
OctalIntegerLiteral:
0 OctalDigits
OctalDigits:
OctalDigit
OctalDigit OctalDigits
OctalDigit: one of
0 1 2 3 4 5 6 7
The Integer type represents integers in the range -2147483648 to 2147483647, inclusive. The default value for the Integer type is zero (0).
Integers may be represented in decimal, octal, or hexidecimal formats. Decimal format is the digit 1 through 9 followed by digits in the range 0 through 9, or simply 0 by itself. Octal format is the digit 0 followed by digits in the range 0 through 7. Hexidecimal format is the digit 0 following by 'x' or 'X' then followed by digits in the range 0 through 9 or A through F (upper or lower case). These are all valid Integer literals:
145 0 012 0xFF
The Number type represents floating-point numbers.
NumberLiteral:
Digits . Digitsopt ExponentPartopt
. Digits ExponentPartopt
Digits ExponentPartopt
ExponentPart:
ExponentIndicator SignedInteger
ExponentIndicator: one of
e E
SignedInteger:
Signopt Digits
Sign: one of
+ -
The following are valid Number literals:
12.3 0.629 3.9e4 1.7662E-34
Boolean represents the values true and false.
BooleanLiteral: one of
true false
The two, and only, Boolean literals are:
true false