Example usage for java.util Locale Locale

List of usage examples for java.util Locale Locale

Introduction

In this page you can find the example usage for java.util Locale Locale.

Prototype

public Locale(String language, String country) 

Source Link

Document

Construct a locale from language and country.

Usage

From source file:ChoiceFormatDemo.java

static public void main(String[] args) {
    displayMessages(new Locale("en", "US"));
    System.out.println();/*from   w  ww  .  j  a v  a  2  s  .  c  o  m*/
    displayMessages(new Locale("fr", "FR"));
}

From source file:KeysDemo.java

static public void main(String[] args) {

    Collator enUSCollator = Collator.getInstance(new Locale("en", "US"));

    String[] words = { "peach", "apricot", "grape", "lemon" };

    CollationKey[] keys = new CollationKey[words.length];

    for (int k = 0; k < keys.length; k++) {
        keys[k] = enUSCollator.getCollationKey(words[k]);
    }//  ww  w .  j a v  a2  s.  c o m

    sortArray(keys);
    displayWords(keys);
}

From source file:SimpleDateFormatDemo.java

static public void main(String[] args) {

    Locale[] locales = { new Locale("fr", "FR"), new Locale("de", "DE"), new Locale("en", "US") };

    for (int i = 0; i < locales.length; i++) {
        displayDate(locales[i]);//from   ww  w.  j a  v a2s.  c  o m
        System.out.println();
    }

    String[] patterns = { "dd.MM.yy", "yyyy.MM.dd G 'at' hh:mm:ss z", "EEE, MMM d, ''yy", "h:mm a", "H:mm",
            "H:mm:ss:SSS", "K:mm a,z", "yyyy.MMMMM.dd GGG hh:mm aaa" };

    for (int k = 0; k < patterns.length; k++) {
        displayPattern(patterns[k], new Locale("en", "US"));
        System.out.println();
    }

    System.out.println();
}

From source file:DecimalFormatDemo.java

static public void main(String[] args) {

    customFormat("###,###.###", 123456.789);
    customFormat("###.##", 123456.789);
    customFormat("000000.000", 123.78);
    customFormat("$###,###.###", 12345.67);
    customFormat("\u00a5###,###.###", 12345.67);

    Locale currentLocale = new Locale("en", "US");

    DecimalFormatSymbols unusualSymbols = new DecimalFormatSymbols(currentLocale);
    unusualSymbols.setDecimalSeparator('|');
    unusualSymbols.setGroupingSeparator('^');
    String strange = "#,##0.###";
    DecimalFormat weirdFormatter = new DecimalFormat(strange, unusualSymbols);
    weirdFormatter.setGroupingSize(4);/*from  w  w w  .ja va2s  . c  o m*/
    String bizarre = weirdFormatter.format(12345.678);
    System.out.println(bizarre);

    Locale[] locales = { new Locale("en", "US"), new Locale("de", "DE"), new Locale("fr", "FR") };

    for (int i = 0; i < locales.length; i++) {
        localizedFormat("###,###.###", 123456.789, locales[i]);
    }

}

From source file:NumberFormatDemo.java

static public void main(String[] args) {

    Locale[] locales = { new Locale("fr", "FR"), new Locale("de", "DE"), new Locale("en", "US") };

    for (int i = 0; i < locales.length; i++) {
        System.out.println();//w  w w .j a  v a  2s  . c  o  m
        displayNumber(locales[i]);
        displayCurrency(locales[i]);
        displayPercent(locales[i]);
    }
}

From source file:com.talkdesk.geo.PhoneNumberGeoMap.java

/**
 * @param args/*from  w  w  w  .jav  a 2 s.c  om*/
 * @throws IOException
 * @throws SQLException
 * @throws ClassNotFoundException
 * @throws GeoResolverException
 */
public static void main(String[] args) throws GeoResolverException {
    // create Options object
    DBConnector connector = new DBConnector();
    GeoCodeResolver resolver = new GeoCodeResolver(connector.getDefaultDBconnection());
    ArrayList list = new ArrayList(Arrays.asList(args));
    Hashtable<String, Double> infoTable = new Hashtable<String, Double>();

    if (list.contains("--populate-data")) {
        GeoCodeRepositoryBuilder repositoryBuilder = new GeoCodeRepositoryBuilder();
        if (list.contains("--country"))
            repositoryBuilder.populateCountryData();
        else if (list.contains("--geo"))
            repositoryBuilder.populateGeoData();
        else {
            repositoryBuilder.populateCountryData();
            repositoryBuilder.populateGeoData();
        }

    } else if (list.contains("--same-country-only")) {
        list.remove("--same-country-only");
        infoTable = resolver.buildInfoTable(list, true);
    } else {
        infoTable = resolver.buildInfoTable(list, false);
    }

    String phoneNumber = resolver.getClosestNumber(infoTable);

    if (phoneNumber != null) {
        System.out.println("-----------------------");
        System.out.println(phoneNumber);
        Locale locale = new Locale("en", phoneNumber.split(":")[0]);
        System.out.println(locale.getDisplayCountry());
    } else {
        System.out.println("-----------------------");
        System.out.println("No Result ..!!!");
    }

}

From source file:RedPenRunner.java

public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption("h", "help", false, "help");
    options.addOption("v", "version", false, "print the version information and exit");

    OptionBuilder.withLongOpt("port");
    OptionBuilder.withDescription("port number");
    OptionBuilder.hasArg();//from w  ww . ja v  a 2s. c  o m
    OptionBuilder.withArgName("PORT");
    options.addOption(OptionBuilder.create("p"));

    OptionBuilder.withLongOpt("key");
    OptionBuilder.withDescription("stop key");
    OptionBuilder.hasArg();
    OptionBuilder.withArgName("STOP_KEY");
    options.addOption(OptionBuilder.create("k"));

    OptionBuilder.withLongOpt("conf");
    OptionBuilder.withDescription("configuration file");
    OptionBuilder.hasArg();
    OptionBuilder.withArgName("CONFIG_FILE");
    options.addOption(OptionBuilder.create("c"));

    OptionBuilder.withLongOpt("lang");
    OptionBuilder.withDescription("Language of error messages");
    OptionBuilder.hasArg();
    OptionBuilder.withArgName("LANGUAGE");
    options.addOption(OptionBuilder.create("L"));

    CommandLineParser parser = new BasicParser();
    CommandLine commandLine = null;

    try {
        commandLine = parser.parse(options, args);
    } catch (Exception e) {
        printHelp(options);
        System.exit(-1);
    }

    int portNum = 8080;
    String language = "en";
    if (commandLine.hasOption("h")) {
        printHelp(options);
        System.exit(0);
    }
    if (commandLine.hasOption("v")) {
        System.out.println(RedPen.VERSION);
        System.exit(0);
    }
    if (commandLine.hasOption("p")) {
        portNum = Integer.parseInt(commandLine.getOptionValue("p"));
    }
    if (commandLine.hasOption("L")) {
        language = commandLine.getOptionValue("L");
    }
    if (isPortTaken(portNum)) {
        System.err.println("port is taken...");
        System.exit(1);
    }

    // set language
    if (language.equals("ja")) {
        Locale.setDefault(new Locale("ja", "JA"));
    } else {
        Locale.setDefault(new Locale("en", "EN"));
    }

    final String contextPath = System.getProperty("redpen.home", "/");

    Server server = new Server(portNum);
    ProtectionDomain domain = RedPenRunner.class.getProtectionDomain();
    URL location = domain.getCodeSource().getLocation();

    HandlerList handlerList = new HandlerList();
    if (commandLine.hasOption("key")) {
        // Add Shutdown handler only when STOP_KEY is specified
        ShutdownHandler shutdownHandler = new ShutdownHandler(commandLine.getOptionValue("key"));
        handlerList.addHandler(shutdownHandler);
    }

    WebAppContext webapp = new WebAppContext();
    webapp.setContextPath(contextPath);
    if (location.toExternalForm().endsWith("redpen-server/target/classes/")) {
        // use redpen-server/target/redpen-server instead, because target/classes doesn't contain web resources.
        webapp.setWar(location.toExternalForm() + "../redpen-server/");
    } else {
        webapp.setWar(location.toExternalForm());
    }
    if (commandLine.hasOption("c")) {
        webapp.setInitParameter("redpen.conf.path", commandLine.getOptionValue("c"));
    }

    handlerList.addHandler(webapp);
    server.setHandler(handlerList);

    server.start();
    server.join();
}

From source file:com.cc.apptroy.baksmali.main.java

/**
 * Run!/*from   w  w w . j a va 2  s. c o m*/
 */
public static void main(String[] args) throws IOException {
    Locale locale = new Locale("en", "US");
    Locale.setDefault(locale);

    CommandLineParser parser = new PosixParser();
    CommandLine commandLine;

    try {
        commandLine = parser.parse(options, args);
    } catch (ParseException ex) {
        usage();
        return;
    }

    baksmaliOptions options = new baksmaliOptions();

    boolean disassemble = true;
    boolean doDump = false;
    String dumpFileName = null;
    boolean setBootClassPath = false;

    String[] remainingArgs = commandLine.getArgs();
    Option[] clOptions = commandLine.getOptions();

    for (int i = 0; i < clOptions.length; i++) {
        Option option = clOptions[i];
        String opt = option.getOpt();

        switch (opt.charAt(0)) {
        case 'v':
            version();
            return;
        case '?':
            while (++i < clOptions.length) {
                if (clOptions[i].getOpt().charAt(0) == '?') {
                    usage(true);
                    return;
                }
            }
            usage(false);
            return;
        case 'o':
            options.outputDirectory = commandLine.getOptionValue("o");
            break;
        case 'p':
            options.noParameterRegisters = true;
            break;
        case 'l':
            options.useLocalsDirective = true;
            break;
        case 's':
            options.useSequentialLabels = true;
            break;
        case 'b':
            options.outputDebugInfo = false;
            break;
        case 'd':
            options.bootClassPathDirs.add(option.getValue());
            break;
        case 'f':
            options.addCodeOffsets = true;
            break;
        case 'r':
            String[] values = commandLine.getOptionValues('r');
            int registerInfo = 0;

            if (values == null || values.length == 0) {
                registerInfo = baksmaliOptions.ARGS | baksmaliOptions.DEST;
            } else {
                for (String value : values) {
                    if (value.equalsIgnoreCase("ALL")) {
                        registerInfo |= baksmaliOptions.ALL;
                    } else if (value.equalsIgnoreCase("ALLPRE")) {
                        registerInfo |= baksmaliOptions.ALLPRE;
                    } else if (value.equalsIgnoreCase("ALLPOST")) {
                        registerInfo |= baksmaliOptions.ALLPOST;
                    } else if (value.equalsIgnoreCase("ARGS")) {
                        registerInfo |= baksmaliOptions.ARGS;
                    } else if (value.equalsIgnoreCase("DEST")) {
                        registerInfo |= baksmaliOptions.DEST;
                    } else if (value.equalsIgnoreCase("MERGE")) {
                        registerInfo |= baksmaliOptions.MERGE;
                    } else if (value.equalsIgnoreCase("FULLMERGE")) {
                        registerInfo |= baksmaliOptions.FULLMERGE;
                    } else {
                        usage();
                        return;
                    }
                }

                if ((registerInfo & baksmaliOptions.FULLMERGE) != 0) {
                    registerInfo &= ~baksmaliOptions.MERGE;
                }
            }
            options.registerInfo = registerInfo;
            break;
        case 'c':
            String bcp = commandLine.getOptionValue("c");
            if (bcp != null && bcp.charAt(0) == ':') {
                options.addExtraClassPath(bcp);
            } else {
                setBootClassPath = true;
                options.setBootClassPath(bcp);
            }
            break;
        case 'x':
            options.deodex = true;
            break;
        case 'X':
            options.experimental = true;
            break;
        case 'm':
            options.noAccessorComments = true;
            break;
        case 'a':
            options.apiLevel = Integer.parseInt(commandLine.getOptionValue("a"));
            break;
        case 'j':
            options.jobs = Integer.parseInt(commandLine.getOptionValue("j"));
            break;
        case 'i':
            String rif = commandLine.getOptionValue("i");
            options.setResourceIdFiles(rif);
            break;
        case 't':
            options.useImplicitReferences = true;
            break;
        case 'e':
            options.dexEntry = commandLine.getOptionValue("e");
            break;
        case 'k':
            options.checkPackagePrivateAccess = true;
            break;
        case 'N':
            disassemble = false;
            break;
        case 'D':
            doDump = true;
            dumpFileName = commandLine.getOptionValue("D");
            break;
        case 'I':
            options.ignoreErrors = true;
            break;
        case 'T':
            options.customInlineDefinitions = new File(commandLine.getOptionValue("T"));
            break;
        default:
            assert false;
        }
    }

    if (remainingArgs.length != 1) {
        usage();
        return;
    }

    if (options.jobs <= 0) {
        options.jobs = Runtime.getRuntime().availableProcessors();
        if (options.jobs > 6) {
            options.jobs = 6;
        }
    }

    String inputDexFileName = remainingArgs[0];

    File dexFileFile = new File(inputDexFileName);
    if (!dexFileFile.exists()) {
        System.err.println("Can't find the file " + inputDexFileName);
        System.exit(1);
    }

    //Read in and parse the dex file
    DexBackedDexFile dexFile = DexFileFactory.loadDexFile(dexFileFile, options.dexEntry, options.apiLevel,
            options.experimental);

    if (dexFile.isOdexFile()) {
        if (!options.deodex) {
            System.err.println("Warning: You are disassembling an odex file without deodexing it. You");
            System.err.println("won't be able to re-assemble the results unless you deodex it with the -x");
            System.err.println("option");
            options.allowOdex = true;
        }
    } else {
        options.deodex = false;
    }

    if (!setBootClassPath && (options.deodex || options.registerInfo != 0)) {
        if (dexFile instanceof DexBackedOdexFile) {
            options.bootClassPathEntries = ((DexBackedOdexFile) dexFile).getDependencies();
        } else {
            options.bootClassPathEntries = getDefaultBootClassPathForApi(options.apiLevel,
                    options.experimental);
        }
    }

    if (options.customInlineDefinitions == null && dexFile instanceof DexBackedOdexFile) {
        options.inlineResolver = InlineMethodResolver
                .createInlineMethodResolver(((DexBackedOdexFile) dexFile).getOdexVersion());
    }

    boolean errorOccurred = false;
    if (disassemble) {
        errorOccurred = !baksmali.disassembleDexFile(dexFile, options);
    }

    if (doDump) {
        if (dumpFileName == null) {
            dumpFileName = commandLine.getOptionValue(inputDexFileName + ".dump");
        }
        dump.dump(dexFile, dumpFileName, options.apiLevel, options.experimental);
    }

    if (errorOccurred) {
        System.exit(1);
    }
}

From source file:eu.mrbussy.pdfsplitter.Application.java

/**
 * Start the main program.//from  www .  j  av a 2  s.co  m
 * 
 * @param args
 *            - Arguments passed on to the program
 */
public static void main(String[] args) {

    // Read configurations
    try {
        String configDirname = FilenameUtils.concat(System.getProperty("user.home"),
                String.format(".%1$s%2$s", NAME, IOUtils.DIR_SEPARATOR));
        String filename = FilenameUtils.concat(configDirname, CONFIGURATION_FILE);

        // Check to see if the directory exists and the file can be created/opened
        File configDir = new File(configDirname);
        if (!configDir.exists())
            configDir.mkdir();

        // Check to see if the file exists. If not create it
        File file = new File(filename);
        if (!file.exists()) {
            file.createNewFile();
        }
        Configuration = new PropertiesConfiguration(file);
        // Automatically store the settings that change
        Configuration.setAutoSave(true);

    } catch (ConfigurationException | IOException ex) {
        // Unable to read the file. Probably because it does not exist --> create it.
        ex.printStackTrace();
    }

    // Set locale to a configured language
    Locale.setDefault(
            new Locale(Configuration.getString("language", "nl"), Configuration.getString("country", "NL")));

    // Start by parsing the command line
    ParseCommandline(args);

    // Display the help if required and leave the app
    if (arguments.hasOption("h")) {
        showHelp();
    }

    // Display the app version and leave the app.
    if (arguments.hasOption("v")) {
        showVersion();
    }

    // Not command line so start the app GUI
    if (!arguments.hasOption("c")) {
        try {
            // Change the look and feel
            UIManager.setLookAndFeel(
                    Configuration.getString("LookAndFeel", "com.sun.java.swing.plaf.gtk.GTKLookAndFeel"));
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    (new MainWindow()).setVisible(true);
                }
            });
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
                | UnsupportedLookAndFeelException e) {
            // Something terrible happened so show the  help
            showHelp();
        }

    }

}

From source file:SimpleMenu.java

/** A simple test program for the above code */
public static void main(String[] args) {
    // Get the locale: default, or specified on command-line
    Locale locale;/*w w w.j a  va 2s  .c om*/
    if (args.length == 2)
        locale = new Locale(args[0], args[1]);
    else
        locale = Locale.getDefault();

    // Get the resource bundle for that Locale. This will throw an
    // (unchecked) MissingResourceException if no bundle is found.
    ResourceBundle bundle = ResourceBundle.getBundle("com.davidflanagan.examples.i18n.Menus", locale);

    // Create a simple GUI window to display the menu with
    final JFrame f = new JFrame("SimpleMenu: " + // Window title
            locale.getDisplayName(Locale.getDefault()));
    JMenuBar menubar = new JMenuBar(); // Create a menubar.
    f.setJMenuBar(menubar); // Add menubar to window

    // Define an action listener for that our menu will use.
    ActionListener listener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String s = e.getActionCommand();
            Component c = f.getContentPane();
            if (s.equals("red"))
                c.setBackground(Color.red);
            else if (s.equals("green"))
                c.setBackground(Color.green);
            else if (s.equals("blue"))
                c.setBackground(Color.blue);
        }
    };

    // Now create a menu using our convenience routine with the resource
    // bundle and action listener we've created
    JMenu menu = SimpleMenu.create(bundle, "colors", new String[] { "red", "green", "blue" }, listener);

    // Finally add the menu to the GUI, and pop it up
    menubar.add(menu); // Add the menu to the menubar
    f.setSize(300, 150); // Set the window size.
    f.setVisible(true); // Pop the window up.
}