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()); } }); }
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; }
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); }
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(); }
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()); } }); }
/** * 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; }
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(); }
public static Locale getDefaultLocale(final Category category) { return defaultLocaleProperty(category).get(); }
public static void setDefaultLocale(final Category category, final Locale locale) { defaultLocaleProperty(category).set(locale); }
@Override public String toString() { return name + ": " + arrayAsString(Locale.getDefault(Category.FORMAT)); }
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; }
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(); } }
@Override public String interpolate ( final String message, final Context context ) { return interpolate ( message, context, Locale.getDefault ( Category.DISPLAY ) ); }
/** * 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; }
@Override public Category categorys() { return category; }
/** * Get a property for setting the default Locale for a specified Category. * * Setting this property also results in the Locale being changed to match. * * @param category * @return */ public static ObjectProperty<Locale> defaultLocaleProperty(final Category category) { if (category == Category.FORMAT) return defaultLocaleFormat; if (category == Category.DISPLAY) return defaultLocaleDisplay; return null; }
/** * Format a value with a maximum number of decimal places, using the default Locale. * * @param value * @param nDecimalPlaces * @return */ public synchronized static String formatNumber(final double value, final int maxDecimalPlaces) { return formatNumber(Locale.getDefault(Category.FORMAT), value, maxDecimalPlaces); }
/** * Create a new ExtendedMessageFormat for the default locale. * * @param pattern the pattern to use, not null * @throws IllegalArgumentException in case of a bad pattern. */ public ExtendedMessageFormat(final String pattern) { this(pattern, Locale.getDefault(Category.FORMAT)); }
/** * Create a new ExtendedMessageFormat for the default locale. * * @param pattern the pattern to use, not null * @param registry the registry of format factories, may be null * @throws IllegalArgumentException in case of a bad pattern. */ public ExtendedMessageFormat(final String pattern, final Map<String, ? extends FormatFactory> registry) { this(pattern, Locale.getDefault(Category.FORMAT), registry); }
public Category categorys();