本文整理汇总了Java中java.util.Locale.Category类的典型用法代码示例。如果您正苦于以下问题:Java Category类的具体用法?Java Category怎么用?Java Category使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Category类属于java.util.Locale包,在下文中一共展示了Category类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: formatLocaleTest
import java.util.Locale.Category; //导入依赖的package包/类
static void formatLocaleTest() {
StringBuilder sb = new StringBuilder();
IntStream.range(0, src.size()).forEach(i -> {
sb.setLength(0);
Locale.setDefault(Locale.Category.FORMAT, formatLocale.get(i));
new Formatter(sb).format(conversions.get(i), src.get(i));
if (!sb.toString().equals(expected.get(i))) {
throw new RuntimeException(
"Wrong uppercasing with Formatter.format(" +
"\"" + conversions.get(i) + "\"" +
") in locale "
+ formatLocale.get(i) +
". Expected: " + expected.get(i) +
" Returned: " + sb.toString());
}
});
}
示例2: getTextField
import java.util.Locale.Category; //导入依赖的package包/类
protected TextField getTextField(Parameter<?> param, int cols) {
TextField tf = new TextField();
Object defaultVal = param.getValueOrDefault();
if (defaultVal instanceof Number)
tf.setText(NumberFormat.getInstance().format(defaultVal));
else if (defaultVal != null)
tf.setText(defaultVal.toString());
if (cols > 0)
tf.setPrefColumnCount(cols);
// tf.addActionListener(new ParameterActionListener(tf, param));
tf.textProperty().addListener((v, o, n) -> {
if (n != null && param.setStringLastValue(Locale.getDefault(Category.FORMAT), n)) {
fireParameterChangedEvent(param, false);
}
});
// onKeyTyped wasn't causing property synchronisation of parameter values
// tf.setOnKeyTyped(e -> {
// if (param.setStringLastValue(tf.getText()))
// fireParameterChangedEvent(param, false);
// });
return tf;
}
示例3: PodcastImpl
import java.util.Locale.Category; //导入依赖的package包/类
public PodcastImpl(String title, String subtitle, String autor,
String copyright, String summary, URL feed, URL link, URL imageUrl,
Category category, Set<String> keywords)
throws MalformedURLException {
this.title = title;
this.subtitle = subtitle;
this.copyright = copyright;
this.summary = summary;
this.feed = feed;
this.imageUrl = imageUrl; // get Image!
this.category = category;
this.author = autor;
this.keywords = keywords;
this.link = link;
this.episodes = new TreeSet<Episode>();
this.image = downloadImage(this.imageUrl);
}
示例4: printLocale
import java.util.Locale.Category; //导入依赖的package包/类
private static void printLocale() {
Locale locale = Locale.getDefault();
ostream.println(LOCALE_SETTINGS);
ostream.println(INDENT + "default locale = " +
locale.getDisplayLanguage());
ostream.println(INDENT + "default display locale = " +
Locale.getDefault(Category.DISPLAY).getDisplayName());
ostream.println(INDENT + "default format locale = " +
Locale.getDefault(Category.FORMAT).getDisplayName());
printLocales();
ostream.println();
}
示例5: main
import java.util.Locale.Category; //导入依赖的package包/类
public static void main(String [] args) {
IntStream.range(0, formatLocale.size()).forEach(i -> {
Locale.setDefault(Locale.Category.FORMAT, formatLocale.get(i));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new PrintStream(baos).format("%.2f", src);
if (!baos.toString().equals(expected.get(i))) {
throw new RuntimeException(
"Wrong conversion with PrintStream.format() in locale "
+ formatLocale.get(i) +
". Expected: " + expected.get(i) +
" Returned: " + baos.toString());
}
});
}
示例6: createPersistentPreference
import java.util.Locale.Category; //导入依赖的package包/类
/**
* Create a preference for storing Locales.
*
* This provides a more persistnt way of setting the Locale than doing so directly.
*
* @param name
* @param category
* @param defaultValue
* @return
*/
private static ObjectProperty<Locale> createPersistentPreference(final String name, final Category category, final Locale defaultValue) {
ObjectProperty<Locale> property = new SimpleObjectProperty<>(defaultValue);
logger.debug("Default Locale {} set to: {}", category, defaultValue);
// Try to read a set value for the preference
// Locale.US is (I think) the only one we're guaranteed to have - so use it to get the displayed name
String currentValue = getUserPreferences().get(name, defaultValue.getDisplayName(Locale.US));
if (currentValue != null) {
boolean localeFound = false;
for (Locale locale : Locale.getAvailableLocales()) {
if (currentValue.equals(locale.getDisplayName(Locale.US))) {
// System.err.println("Default for " + category + " is set to: " + currentValue);
Locale.setDefault(category, locale);
property.set(locale);
logger.info("Locale {} set to {}", category, locale);
localeFound = true;
break;
}
}
if (!localeFound)
logger.info("Could not find Locale {} for {} - value remains ", currentValue, category, Locale.getDefault(category));
}
property.addListener((v, o, n) -> {
try {
logger.debug("Setting Locale {} to: {}", category, n);
if (n == null) {
getUserPreferences().remove(name);
Locale.setDefault(category, defaultValue);
} else {
getUserPreferences().put(name, n.getDisplayName(Locale.US));
Locale.setDefault(category, n);
}
} catch (Exception e) {
logger.error("Unable to set Locale for {} to {}", category, n);
}
});
// Triggered when reset is called
resetProperty.addListener((c, o, v) -> property.setValue(defaultValue));
return property;
}
示例7: printLocale
import java.util.Locale.Category; //导入依赖的package包/类
private static void printLocale(PrintStream ostream) {
Locale locale = Locale.getDefault();
ostream.println(LOCALE_SETTINGS);
ostream.println(INDENT + "default locale = " +
locale.getDisplayLanguage());
ostream.println(INDENT + "default display locale = " +
Locale.getDefault(Category.DISPLAY).getDisplayName());
ostream.println(INDENT + "default format locale = " +
Locale.getDefault(Category.FORMAT).getDisplayName());
printLocales(ostream);
ostream.println();
}
示例8: getDefaultLocale
import java.util.Locale.Category; //导入依赖的package包/类
public static Locale getDefaultLocale(final Category category) {
return defaultLocaleProperty(category).get();
}
示例9: setDefaultLocale
import java.util.Locale.Category; //导入依赖的package包/类
public static void setDefaultLocale(final Category category, final Locale locale) {
defaultLocaleProperty(category).set(locale);
}
示例10: toString
import java.util.Locale.Category; //导入依赖的package包/类
@Override
public String toString() {
return name + ": " + arrayAsString(Locale.getDefault(Category.FORMAT));
}
示例11: writeImageDataSerialized
import java.util.Locale.Category; //导入依赖的package包/类
private static boolean writeImageDataSerialized(final File file, final ImageData<?> imageData) {
if (file == null)
return false;
File backup = null;
try {
long startTime = System.currentTimeMillis();
// Backup any existing file... just in case of disaster
if (file.exists()) {
File fileCopy = new File(file.toURI());
backup = new File(fileCopy.getAbsolutePath() + ".backup");
fileCopy.renameTo(backup);
}
FileOutputStream fileOutMain = new FileOutputStream(file);
OutputStream outputStream = new BufferedOutputStream(fileOutMain);
// Could enable compression - however need to consider writing data file version number first
// if (compress) {
// Deflater deflater = new Deflater(Deflater.BEST_SPEED);
// deflater.setStrategy(Deflater.HUFFMAN_ONLY); // More modest compression, but a bit faster
// outputStream = new DeflaterOutputStream(fileOutMain, deflater, 1024*1024*8);
// } else {
outputStream = new BufferedOutputStream(fileOutMain);
// }
ObjectOutputStream outStream = new ObjectOutputStream(outputStream);
// Write the identifier
// Version 1.0 was the first...
// Version 2 switched to integers, and includes Locale information
outStream.writeUTF("Data file version 2");
// Write the image path
outStream.writeObject("Image path: " + imageData.getServerPath());
// Write the current locale
outStream.writeObject(Locale.getDefault(Category.FORMAT));
// Write the rest of the main image metadata
outStream.writeObject(imageData.getImageType());
outStream.writeObject(imageData.getColorDeconvolutionStains());
outStream.writeObject(imageData.getHistoryWorkflow());
// Write the rest of the main image metadata
PathObjectHierarchy hierarchy = imageData.getHierarchy();
logger.info(String.format("Writing object hierarchy with %d object(s)...", hierarchy.nObjects()));
outStream.writeObject(hierarchy);
// Write any remaining (serializable) properties
Map<String, Object> map = new HashMap<>();
for (Entry<String, Object> entry : imageData.getProperties().entrySet()) {
if (entry.getValue() instanceof Serializable)
map.put(entry.getKey(), entry.getValue());
else
logger.error("Property not serializable and will not be saved! Key: " + entry.getKey() + ", Value: " + entry.getValue());
}
if (map != null)
outStream.writeObject(map);
// Write EOF marker
outStream.writeObject("EOF");
// Remember the saved path
imageData.setLastSavedPath(file.getAbsolutePath(), true);
outputStream.close();
// Delete the backup file
if (backup != null && !backup.equals(file))
backup.delete();
long endTime = System.currentTimeMillis();
logger.info(String.format("Image data written to %s in %.2f seconds", file.getAbsolutePath(), (endTime - startTime)/1000.));
} catch (IOException e) {
logger.error("Error writing Image data to " + file.getAbsolutePath(), e);
return false;
}
return true;
}
示例12: SettingsModel
import java.util.Locale.Category; //导入依赖的package包/类
SettingsModel() {
// Insert default values
map.put(HIDDEN_START, "false");
map.put(AUTOSTART, "true");
map.put(AUTOUPDATE, "true");
map.put(LOCALE, Locale.getDefault(Category.DISPLAY).getLanguage());
map.put(VERSION, Starter.getClientVersion());
map.put(NOTIFICATION_ENABLED, "true");
map.put(NOTIFICATION_DELETE_TIME, "5");
map.put(NOTIFICATION_MAX_COUNT, "3");
map.put(NOTIFICATION_ORIENTATION, NotificationOrientation.BOTTOM.toString());
map.put(NOTIFICATION_PADDING_BOTTOM, "15");
map.put(NOTIFICATION_PADDING_TOP, "45");
map.put(INSTALL_FOLDER, "");
map.put(INSTALL_ID, "1");
rootPref = Preferences.userNodeForPackage(Starter.class);
// Load from prefs if possible
try {
String[] allKeys = rootPref.keys();
for (String key : allKeys) {
String value = rootPref.get(key, "");
if (!value.equals("")) {
map.put(key, value);
}
}
} catch (BackingStoreException e) {
logger.warn("BackingStore is not available -> switched to default settings");
}
if(!updateShortcut()){
map.put(AUTOSTART, "false");
}
if (map.get(INSTALL_ID).equals("1")) {
map.put(INSTALL_ID, UUID.randomUUID().toString());
save();
}
}
示例13: interpolate
import java.util.Locale.Category; //导入依赖的package包/类
@Override
public String interpolate ( final String message, final Context context )
{
return interpolate ( message, context, Locale.getDefault ( Category.DISPLAY ) );
}
示例14: parseLocale
import java.util.Locale.Category; //导入依赖的package包/类
/**
* Shamelessly copied from: http://stackoverflow.com/questions/6824157/parse-accept-language-header-in-java
*/
public static Locale parseLocale( final String header )
{
// String header = "en-ca,en;q=0.8,en-us;q=0.6,de-de;q=0.4,de;q=0.2";
if ( header == null || header.trim()
.length() < 1 )
{
return Locale.getDefault( Category.FORMAT );
}
final Map<Double, String> prefs = parseQualityHeader( header );
final List<Double> sortedKeys = new ArrayList<Double>( prefs.keySet() );
Collections.sort( sortedKeys );
Collections.reverse( sortedKeys );
final Locale[] available = Locale.getAvailableLocales();
Locale result = null;
for ( final Double key : sortedKeys )
{
final String[] parts = prefs.get( key )
.split( "_" );
for ( final Locale l : available )
{
if ( !parts[0].equals( l.getISO3Language() ) )
{
continue;
}
if ( parts.length > 1 && !parts[1].equals( l.getISO3Country() ) )
{
continue;
}
if ( parts.length > 2 && !parts[2].equals( l.getVariant() ) )
{
continue;
}
result = l;
}
}
return result == null ? Locale.getDefault( Category.FORMAT ) : result;
}
示例15: categorys
import java.util.Locale.Category; //导入依赖的package包/类
@Override
public Category categorys() {
return category;
}