List of usage examples for java.text MessageFormat MessageFormat
public MessageFormat(String pattern)
From source file:org.apereo.portal.portlets.dynamicskin.FileSystemDynamicSkinService.java
public void setSkinIncludeFile(String skinIncludeFile) { this.skinIncludeFile = new MessageFormat(skinIncludeFile); }
From source file:net.solarnetwork.node.runtime.JobSettingSpecifierProvider.java
/** * Construct with settings UID./*from w w w .j ava2 s . c o m*/ * * @param settingUID * the setting UID * @param source * a message source */ public JobSettingSpecifierProvider(String settingUID, MessageSource source) { super(); this.settingUID = settingUID; this.messageSource = source; if (source == null || !hasMessage(source, "title")) { messages.put("title", new MessageFormat(titleValue(settingUID))); } AbstractMessageSource msgSource = new AbstractMessageSource() { @Override protected MessageFormat resolveCode(String code, Locale locale) { return messages.get(code); } }; msgSource.setParentMessageSource(source); this.messageSource = msgSource; }
From source file:net.fenyo.gnetwatch.Config.java
/** * Returns an i18n message./* w w w. java 2 s. c o m*/ * @param key i18n key. * @param params array of arguments to scatter in the i18n locale dependant message. * @return String locale dependant message. */ public String getPattern(final String key, final Object[] params) { final MessageFormat formatter = new MessageFormat(""); formatter.setLocale(locale); formatter.applyPattern(getString(key)); return formatter.format(params); }
From source file:org.eclipse.swt.examples.accessibility.Shape.java
void addListeners() { addPaintListener(e -> {//from ww w . j a v a 2s . c o m GC gc = e.gc; Display display = getDisplay(); Color c = display.getSystemColor(color); gc.setBackground(c); Rectangle rect = getClientArea(); int length = Math.min(rect.width, rect.height); if (shape == CIRCLE) { gc.fillOval(0, 0, length, length); } else { gc.fillRectangle(0, 0, length, length); } if (isFocusControl()) gc.drawFocus(rect.x, rect.y, rect.width, rect.height); }); addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { redraw(); } @Override public void focusLost(FocusEvent e) { redraw(); } }); addMouseListener(MouseListener.mouseDownAdapter(e -> { if (getClientArea().contains(e.x, e.y)) { setFocus(); } })); addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { // key listener enables traversal out } }); addTraverseListener(e -> { switch (e.detail) { case SWT.TRAVERSE_TAB_NEXT: case SWT.TRAVERSE_TAB_PREVIOUS: e.doit = true; break; } }); getAccessible().addAccessibleListener(new AccessibleAdapter() { @Override public void getName(AccessibleEvent e) { MessageFormat formatter = new MessageFormat(""); formatter.applyPattern(bundle.getString("name")); //$NON_NLS$ String colorName = bundle.getString("color" + color); //$NON_NLS$ String shapeName = bundle.getString("shape" + shape); //$NON_NLS$ e.result = formatter.format(new String[] { colorName, shapeName }); //$NON_NLS$ } }); getAccessible().addAccessibleControlListener(new AccessibleControlAdapter() { @Override public void getRole(AccessibleControlEvent e) { e.detail = ACC.ROLE_GRAPHIC; } @Override public void getState(AccessibleControlEvent e) { e.detail = ACC.STATE_FOCUSABLE; if (isFocusControl()) e.detail |= ACC.STATE_FOCUSED; } }); }
From source file:it.cnr.icar.eric.client.ui.swing.metal.MetalThemeMenu.java
/** * Constucts a JMenu named 'name' with a a RadioButton for each * object in 'themeArray'.//from w w w . java 2 s .c om * * @param name the visible name for the Menu. * @param themeArray the array of themes to put in the menu. */ public MetalThemeMenu(String name, MetalTheme[] themeArray) { super(name); themeNames = ResourceBundle.getBundle(BASE_NAME, Locale.getDefault()); themes = themeArray; ButtonGroup group = new ButtonGroup(); JRadioButtonMenuItem defaultItem = null; for (int i = 0; i < themes.length; i++) { String themeName; try { themeName = themeNames.getString(themes[i].getName().replaceAll("\\s", "")); } catch (MissingResourceException mre) { themeName = themes[i].getName(); Object[] noResourceArgs = { themes[i].getName(), getLocale() }; MessageFormat form = new MessageFormat(themeNames.getString("message.error.noResource")); log.error(form.format(noResourceArgs)); } JRadioButtonMenuItem item = new JRadioButtonMenuItem(themeName); group.add(item); add(item); item.setActionCommand(i + ""); item.addActionListener(this); // Theme name without spaces is the key for looking up localized item text. item.setName(themes[i].getName().replaceAll(" ", "")); if (i == 0) { item.setSelected(true); defaultItem = item; } } //add listener for 'locale' bound property RegistryBrowser.getInstance().addPropertyChangeListener(RegistryBrowser.PROPERTY_LOCALE, this); defaultItem.doClick(); }
From source file:org.jamwiki.parser.jflex.WikiSignatureTag.java
/** * *///w w w. j a va2 s. c o m private String retrieveUserSignature(ParserInput parserInput) { WikiUser user = parserInput.getWikiUser(); if (user != null && !StringUtils.isBlank(user.getSignature())) { return user.getSignature(); } String login = parserInput.getUserDisplay(); String email = parserInput.getUserDisplay(); String displayName = parserInput.getUserDisplay(); String userId = "-1"; if (user != null && !StringUtils.isBlank(user.getUsername())) { login = user.getUsername(); displayName = (!StringUtils.isBlank(user.getDisplayName())) ? user.getDisplayName() : login; email = user.getEmail(); userId = Long.toString(user.getUserId()); } if (login == null || displayName == null) { logger.info("Signature tagged parsed without user information available, returning empty"); return ""; } MessageFormat formatter = new MessageFormat( Environment.getValue(Environment.PROP_PARSER_SIGNATURE_USER_PATTERN)); Object params[] = new Object[7]; params[0] = NamespaceHandler.NAMESPACE_USER + NamespaceHandler.NAMESPACE_SEPARATOR + login; // FIXME - hard coding params[1] = NamespaceHandler.NAMESPACE_SPECIAL + NamespaceHandler.NAMESPACE_SEPARATOR + "Contributions?contributor=" + login; params[2] = NamespaceHandler.NAMESPACE_USER_COMMENTS + NamespaceHandler.NAMESPACE_SEPARATOR + login; params[3] = login; params[4] = displayName; params[5] = email != null ? email : ""; params[6] = userId; return formatter.format(params); }
From source file:playmidi.task.MidiPlayTask.java
/** * midi???//from w ww. j av a2 s.co m */ private synchronized void play(int count) throws InterruptedException { sequencer.setLoopCount(count); MessageFormat msg1 = new MessageFormat("?File={0},LoopCount={1},Length(MicroSecond)={2}"); Object[] parameters1 = { midiFile.getAbsolutePath(), count, sequencer.getMicrosecondLength() }; LOG.info(msg1.format(parameters1)); sequencer.start(); }
From source file:net.mlw.vlh.web.util.JspUtils.java
public static String format(Object value, String format, Locale loc) { if (value == null) { return ""; } else {//w w w . java 2 s. co m if (value instanceof Number) { if (format == null || format.length() == 0) { return value.toString(); } MessageFormat mf = new MessageFormat("{0,number," + format + "}"); if (loc != null) { mf.setLocale(loc); mf.applyPattern(mf.toPattern()); } return mf.format(new Object[] { value }); } else if (value instanceof java.util.Date) { if (format == null || format.length() == 0) { //TODO: get the default date format in here somehow. format = // SystemProperties.getProperty("default.dateFormat", "EEE, MMM // d, ''yy"); format = "EEE, MMM d, ''yy"; } MessageFormat mf = new MessageFormat("{0,date," + format + "}"); if (loc != null) { mf.setLocale(loc); mf.applyPattern(mf.toPattern()); } return mf.format(new Object[] { value }); } else if (value instanceof Calendar) { Calendar calendar = (Calendar) value; if (format == null || format.length() == 0) { //TODO: get the default date format in here somehow. format = // SystemProperties.getProperty("default.dateFormat", "EEE, MMM // d, ''yy"); format = "EEE, MMM d, ''yy"; } MessageFormat mf = new MessageFormat("{0,date," + format + "}"); if (loc != null) { mf.setLocale(loc); mf.applyPattern(mf.toPattern()); } return mf.format(new Object[] { value }); } else { return value.toString(); } } }
From source file:com.qpark.eip.core.failure.BaseFailureHandler.java
private static String format(final FailureMessagePhraseableType m, final Object... data) { StringBuffer sb = new StringBuffer(1024); if (m != null) { if (m.getText() != null && m.getText().trim().length() > 0) { if (data != null && data.length > 0) { MessageFormat mf = new MessageFormat(checkUnnumberedBrackets(m.getText())); sb.append(mf.format(data)); } else { sb.append(m.getText());/* ww w . j a va 2s . c o m*/ } } if (m.getPhraseKey() != null) { for (String key : m.getPhraseKey()) { if (phrases.get(key) != null && phrases.get(key).length() > 0) { if (sb.length() > 0) { sb.append(" "); } } sb.append(phrases.get(key)); } } } return sb.toString(); }
From source file:nl.toolforge.karma.core.ErrorCode.java
/** * <p>Gets a localized error message for the <code>ErrorCode</code> instance. Error messages are defined in a * <code>error-messages-<locale>.properties</code> (e.g. <code>error-messages-NL.properties</code>). A message * text is identified by a key <code>message.</code> concatenated with {@link #getErrorCodeString}. * <p/>//from w w w . j a va 2s . com * </p>When no resource bundle can be found for <code>locale</code>, the default locale <code>Locale.ENGLISH</code> is * used. * * @param locale A locale object (e.g. representing the current locale of the user environment). * @return A localized error message or {@link #getErrorCodeString} when no message was found for this errorcode or the * resourcebundle could not be found for <code>locale</code>. */ public String getErrorMessage(Locale locale) { if (locale == null) { locale = currentLocale; } String message = ""; if (messageBundle == null) { try { locale = Locale.ENGLISH; messageBundle = ResourceBundle.getBundle("error-messages", locale); } catch (MissingResourceException m) { logger.error("No default resource bundle available for locale " + locale); return getErrorCodeString(); } } try { message = messageBundle.getString("message." + getErrorCodeString()); if (getMessageArguments().length != 0) { MessageFormat messageFormat = new MessageFormat(message); message = messageFormat.format(getMessageArguments()); } } catch (RuntimeException r) { logger.error("No message found for errorcode : " + getErrorCodeString()); message = getErrorCodeString(); } if (message.startsWith(getErrorCodeString())) { return message; } return getErrorCodeString() + " : " + message; }