List of usage examples for java.util Locale getDefault
public static Locale getDefault()
From source file:EventObject.java
public static void main(String[] args) { JFrame f = new JFrame(); JButton ok = new JButton("Ok"); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(event.getWhen()); Locale locale = Locale.getDefault(); String s = DateFormat.getTimeInstance(DateFormat.SHORT, locale).format(new Date()); if (event.getID() == ActionEvent.ACTION_PERFORMED) System.out.println(" Event Id: ACTION_PERFORMED"); System.out.println(" Time: " + s); String source = event.getSource().getClass().getName(); System.out.println(" Source: " + source); int mod = event.getModifiers(); if ((mod & ActionEvent.ALT_MASK) > 0) System.out.println("Alt "); if ((mod & ActionEvent.SHIFT_MASK) > 0) System.out.println("Shift "); if ((mod & ActionEvent.META_MASK) > 0) System.out.println("Meta "); if ((mod & ActionEvent.CTRL_MASK) > 0) System.out.println("Ctrl "); }/*from w w w . j a va2 s . c om*/ }); f.add(ok); f.setSize(420, 250); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { LocalDate date = LocalDate.of(2014, 2, 15); // 2014-02-15 // ISO-8601 standard // the day-of-week to represent, from 1 (Monday) to 7 (Sunday) DayOfWeek dayOfWeek = date.getDayOfWeek(); System.out.println(dayOfWeek); // SATURDAY System.out.println(DayOfWeek.of(3)); // WEDNESDAY System.out.println(dayOfWeek.getValue()); // 6 System.out.println(dayOfWeek.name()); // SATURDAY System.out.println(date.getDayOfMonth()); // 15 System.out.println(date.atStartOfDay()); // 2014-02-15 00:00 System.out.println("DayOfWeek"); dayOfWeek = DayOfWeek.FRIDAY; Locale locale = Locale.getDefault(); System.out.println(dayOfWeek.getDisplayName(TextStyle.FULL, locale)); // Friday System.out.println(dayOfWeek.getDisplayName(TextStyle.NARROW, locale)); // F System.out.println(dayOfWeek.getDisplayName(TextStyle.SHORT, locale)); // Fri }
From source file:com.spring.tutorial.messages.App.java
public static void main(String[] args) { ApplicationContext ctx = new ClassPathXmlApplicationContext( "com/spring/tutorial/messages/applicationContext.xml"); MessageSource ms = ctx.getBean(MessageSource.class); //Message resolution String success = ms.getMessage("msg.success", null, Locale.getDefault()); String successEN = ms.getMessage("msg.success", null, Locale.ENGLISH); String successFR = ms.getMessage("msg.success", null, Locale.FRENCH); String successDE = ms.getMessage("msg.success", null, Locale.GERMAN); //Message resolution and i18n String label = ms.getMessage("lbl.result", null, Locale.getDefault()); //Not necessary to pass the locale String error = ms.getMessage("err.failure", null, null); //Non-existent message (if the call does not specify, the default message argument, //and the message code does not exist, an exception will be thrown) String nonExistent = ms.getMessage("my.message", null, "Not found, defaults to this message", null); LOGGER.info("Success message (es - the default): " + success); LOGGER.info("Success message (en): " + successEN); LOGGER.info("Success message (fr): " + successFR); LOGGER.info("Success message (de) defaults to local language: " + successDE); LOGGER.info("Label text: " + label); LOGGER.info("Error message: " + error); LOGGER.info("Non-existent message (defaults to message specified as argument): " + nonExistent); ((ClassPathXmlApplicationContext) ctx).close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Locale locale = Locale.getDefault(); ResourceBundle rb = ResourceBundle.getBundle("JFileChooser", locale); UIManager.put("FileChooser.lookInLabelText", rb.getString("lookInLabelText")); UIManager.put("FileChooser.filesOfTypeLabelText", rb.getString("filesOfTypeLabelText")); UIManager.put("FileChooser.upFolderToolTipText", rb.getString("upFolderToolTipText")); }
From source file:Main.java
public static void main(String[] args) throws Exception { URL url = new URL("http://www.java2s.com/style/download.png"); BufferedImage bi = ImageIO.read(url); for (float q = 0.2f; q < .9f; q += .2f) { OutputStream outStream = new FileOutputStream(new File("c:/Java_Dev/Image-" + q + ".jpg")); ImageWriter imgWriter = ImageIO.getImageWritersByFormatName("jpg").next(); ImageOutputStream ioStream = ImageIO.createImageOutputStream(outStream); imgWriter.setOutput(ioStream);/* w w w. j a v a 2s . c o m*/ JPEGImageWriteParam jpegParams = new JPEGImageWriteParam(Locale.getDefault()); jpegParams.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); jpegParams.setCompressionQuality(q); imgWriter.write(null, new IIOImage(bi, null, null), jpegParams); ioStream.flush(); ioStream.close(); imgWriter.dispose(); } }
From source file:org.eclipse.swt.snippets.Snippet2.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 2"); shell.setLayout(new FillLayout()); final Table table = new Table(shell, SWT.BORDER); table.setHeaderVisible(true);/*from w w w.ja v a 2 s. c o m*/ final TableColumn column1 = new TableColumn(table, SWT.NONE); column1.setText("Column 1"); final TableColumn column2 = new TableColumn(table, SWT.NONE); column2.setText("Column 2"); TableItem item = new TableItem(table, SWT.NONE); item.setText(new String[] { "a", "3" }); item = new TableItem(table, SWT.NONE); item.setText(new String[] { "b", "2" }); item = new TableItem(table, SWT.NONE); item.setText(new String[] { "c", "1" }); column1.setWidth(100); column2.setWidth(100); Listener sortListener = e -> { TableItem[] items = table.getItems(); Collator collator = Collator.getInstance(Locale.getDefault()); TableColumn column = (TableColumn) e.widget; int index = column == column1 ? 0 : 1; for (int i = 1; i < items.length; i++) { String value1 = items[i].getText(index); for (int j = 0; j < i; j++) { String value2 = items[j].getText(index); if (collator.compare(value1, value2) < 0) { String[] values = { items[i].getText(0), items[i].getText(1) }; items[i].dispose(); TableItem item1 = new TableItem(table, SWT.NONE, j); item1.setText(values); items = table.getItems(); break; } } } table.setSortColumn(column); }; column1.addListener(SWT.Selection, sortListener); column2.addListener(SWT.Selection, sortListener); table.setSortColumn(column1); table.setSortDirection(SWT.UP); shell.setSize(shell.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:com.hp.mqm.atrf.Main.java
public static void main(String[] args) { long start = System.currentTimeMillis(); setUncaughtExceptionHandler();//from w w w . ja v a 2s . com CliParser cliParser = new CliParser(); cliParser.handleHelpAndVersionOptions(args); configureLog4J(); logger.info(System.lineSeparator() + System.lineSeparator()); logger.info("************************************************************************************"); DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.getDefault()); DateFormat timeFormatter = DateFormat.getTimeInstance(DateFormat.DEFAULT, Locale.getDefault()); logger.info((String.format("Starting HPE ALM Test Result Collection Tool %s %s", dateFormatter.format(new Date()), timeFormatter.format(new Date())))); logger.info("************************************************************************************"); FetchConfiguration configuration = cliParser.parse(args); ConfigurationUtilities.setConfiguration(configuration); App app = new App(configuration); app.start(); long end = System.currentTimeMillis(); logger.info(String.format("Finished creating tests and test results on ALM Octane in %s seconds", (end - start) / 1000)); logger.info(System.lineSeparator()); }
From source file:Main.java
public static void main(String[] av) { Locale l = Locale.getDefault(); System.out.println("Today's Locale is " + l); }
From source file:TableSortByColumn.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final Table table = new Table(shell, SWT.BORDER); table.setHeaderVisible(true);//ww w. j av a 2 s. c o m final TableColumn column1 = new TableColumn(table, SWT.NONE); column1.setText("Column 1"); final TableColumn column2 = new TableColumn(table, SWT.NONE); column2.setText("Column 2"); TableItem item = new TableItem(table, SWT.NONE); item.setText(new String[] { "a", "3" }); item = new TableItem(table, SWT.NONE); item.setText(new String[] { "b", "2" }); item = new TableItem(table, SWT.NONE); item.setText(new String[] { "c", "1" }); column1.setWidth(100); column2.setWidth(100); Listener sortListener = new Listener() { public void handleEvent(Event e) { TableItem[] items = table.getItems(); Collator collator = Collator.getInstance(Locale.getDefault()); TableColumn column = (TableColumn) e.widget; int index = column == column1 ? 0 : 1; for (int i = 1; i < items.length; i++) { String value1 = items[i].getText(index); for (int j = 0; j < i; j++) { String value2 = items[j].getText(index); if (collator.compare(value1, value2) < 0) { String[] values = { items[i].getText(0), items[i].getText(1) }; items[i].dispose(); TableItem item = new TableItem(table, SWT.NONE, j); item.setText(values); items = table.getItems(); break; } } } table.setSortColumn(column); } }; column1.addListener(SWT.Selection, sortListener); column2.addListener(SWT.Selection, sortListener); table.setSortColumn(column1); table.setSortDirection(SWT.UP); shell.setSize(shell.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:generators.ElementMetaValidator.java
public static void main(String[] args) { ClassicEngineBoot.getInstance().start(); int invalidExpressionsCounter = 0; int deprecatedExpressionsCounter = 0; final HashNMap expressionsByGroup = new HashNMap(); ElementTypeRegistry registry = ElementTypeRegistry.getInstance(); final ElementMetaData[] elementMetaDatas = registry.getAllElementTypes(); for (int i = 0; i < elementMetaDatas.length; i++) { final ElementMetaData metaData = elementMetaDatas[i]; if (metaData == null) { logger.warn("Null Expression encountered"); continue; }//from ww w. j a v a 2 s . com missingProperties.clear(); try { final Object type = metaData.create(); } catch (InstantiationException e) { logger.warn("Expression class is null"); } final String typeName = metaData.getName(); logger.debug("Processing " + typeName); final Locale locale = Locale.getDefault(); final String displayName = metaData.getDisplayName(locale); if (isValid(displayName, metaData.getName()) == false) { logger.warn("ElementType '" + typeName + ": No valid display name"); } if (metaData.isDeprecated()) { deprecatedExpressionsCounter += 1; final String deprecateMessage = metaData.getDeprecationMessage(locale); if (isValid(deprecateMessage, "Use a Formula instead") == false) { logger.warn("ElementType '" + typeName + ": No valid deprecate message"); } } final String grouping = metaData.getGrouping(locale); if (isValid(grouping, "Group") == false) { logger.warn("ElementType '" + typeName + ": No valid grouping message"); } expressionsByGroup.add(grouping, metaData); final StyleMetaData[] styleMetaDatas = metaData.getStyleDescriptions(); for (int j = 0; j < styleMetaDatas.length; j++) { final StyleMetaData propertyMetaData = styleMetaDatas[j]; final String propertyDisplayName = propertyMetaData.getDisplayName(locale); if (isValid(propertyDisplayName, propertyMetaData.getName()) == false) { logger.warn("ElementType '" + typeName + ": Style " + propertyMetaData.getName() + ": No DisplayName"); } final String propertyGrouping = propertyMetaData.getGrouping(locale); if (isValid(propertyGrouping, "Group") == false) { logger.warn("ElementType '" + typeName + ": Style " + propertyMetaData.getName() + ": Grouping is not valid"); } if (propertyMetaData.isDeprecated()) { final String deprecateMessage = propertyMetaData.getDeprecationMessage(locale); if (isValid(deprecateMessage, "Deprecated") == false) { logger.warn("ElementType '" + typeName + ": Style " + propertyMetaData.getName() + ": No valid deprecate message"); } } } final AttributeMetaData[] attributeMetaDatas = metaData.getAttributeDescriptions(); for (int j = 0; j < attributeMetaDatas.length; j++) { final AttributeMetaData propertyMetaData = attributeMetaDatas[j]; final String propertyDisplayName = propertyMetaData.getDisplayName(locale); if (isValid(propertyDisplayName, propertyMetaData.getName()) == false) { logger.warn("ElementType '" + typeName + ": Attr " + propertyMetaData.getName() + ": No DisplayName"); } final String propertyGrouping = propertyMetaData.getGrouping(locale); if (isValid(propertyGrouping, "Group") == false) { logger.warn("ElementType '" + typeName + ": Attr " + propertyMetaData.getName() + ": Grouping is not valid"); } if (propertyMetaData.isDeprecated()) { final String deprecateMessage = propertyMetaData.getDeprecationMessage(locale); if (isValid(deprecateMessage, "Deprecated") == false) { logger.warn("ElementType '" + typeName + ": Attr " + propertyMetaData.getName() + ": No valid deprecate message"); } } } System.err.flush(); try { Thread.sleep(25); } catch (InterruptedException e) { } for (int x = 0; x < missingProperties.size(); x++) { final String property = (String) missingProperties.get(x); System.out.println(property); } if (missingProperties.isEmpty() == false) { invalidExpressionsCounter += 1; missingProperties.clear(); } System.out.flush(); try { Thread.sleep(25); } catch (InterruptedException e) { } } logger.info("Validated " + elementMetaDatas.length + " expressions. Invalid: " + invalidExpressionsCounter + " Deprecated: " + deprecatedExpressionsCounter); final Object[] keys = expressionsByGroup.keySet().toArray(); Arrays.sort(keys); for (int i = 0; i < keys.length; i++) { final Object key = keys[i]; logger.info("Group: '" + key + "' Size: " + expressionsByGroup.getValueCount(key)); final Object[] objects = expressionsByGroup.toArray(key); for (int j = 0; j < objects.length; j++) { ElementMetaData metaData = (ElementMetaData) objects[j]; logger.info(" " + metaData.getName()); } } }