Example usage for java.text MessageFormat applyPattern

List of usage examples for java.text MessageFormat applyPattern

Introduction

In this page you can find the example usage for java.text MessageFormat applyPattern.

Prototype

@SuppressWarnings("fallthrough") 
public void applyPattern(String pattern) 

Source Link

Document

Sets the pattern used by this message format.

Usage

From source file:org.jmesa.core.message.ResourceBundleMessages.java

@Override
public String getMessage(String code, Object[] args) {

    String result = findResource(customResourceBundle, code);

    if (result == null) {
        result = findResource(defaultResourceBundle, code);
    }/*from w w w .j ava 2s.  c o  m*/

    if (result != null && args != null) {
        MessageFormat formatter = new MessageFormat("");
        formatter.setLocale(locale);
        formatter.applyPattern(result);
        result = formatter.format(args);
    }

    return result;
}

From source file:org.extremecomponents.table.resource.TableResourceBundle.java

/**
 * Get the resource property.//from   www  .j a v a 2  s  . com
 */
public String getMessage(String code, Object[] args) {
    String result = findResource(customResourceBundle, code);

    if (result == null) {
        result = findResource(defaultResourceBundle, code);
    }

    if (result != null && args != null) {
        MessageFormat formatter = new MessageFormat("");
        formatter.setLocale(locale);
        formatter.applyPattern(result);
        result = formatter.format(args);
    }

    return result;
}

From source file:com.ultrapower.eoms.common.plugin.ecside.resource.TableResourceBundle.java

 /**
 * Get the resource property.// w w w  .  jav  a 2  s . com
 */
 public String getMessage(String code, Object[] args) {
   String result = null;
   ResourceBundle customResourceBundle;
   for (int i = 0; i < customResourceBundleList.size(); i++) {
      customResourceBundle = (ResourceBundle) customResourceBundleList
            .get(i);
      result = findResource(customResourceBundle, code);
      if (result != null) {
         break;
      }
   }

   if (result == null) {
      result = findResource(defaultResourceBundle, code);
   }

   if (result != null && args != null) {
      MessageFormat formatter = new MessageFormat("");
      formatter.setLocale(locale);
      formatter.applyPattern(result);
      result = formatter.format(args);
   }

   return result;
}

From source file:com.googlecode.jtiger.modules.ecside.resource.TableResourceBundle.java

/**
* Get the resource property./*  w  w w.ja v a 2  s .c  om*/
*/
public String getMessage(String code, Object[] args) {
    String result = null;
    ResourceBundle customResourceBundle;
    for (int i = 0; i < customResourceBundleList.size(); i++) {
        customResourceBundle = (ResourceBundle) customResourceBundleList.get(i);
        result = findResource(customResourceBundle, code);
        if (result != null) {
            break;
        }
    }

    if (result == null) {
        result = findResource(defaultResourceBundle, code);
    }

    if (result != null && args != null) {
        MessageFormat formatter = new MessageFormat("");
        formatter.setLocale(locale);
        formatter.applyPattern(result);
        result = formatter.format(args);
    }

    return result;
}

From source file:org.eclipse.swt.examples.accessibility.Shape.java

void addListeners() {
    addPaintListener(e -> {//from w  w  w  .jav a  2  s .  c  om
        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:net.fenyo.gnetwatch.Config.java

/**
 * Returns an i18n message.//from w w w  . jav  a  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:es.urjc.mctwp.service.Command.java

/**
 * This method get the appropriate message template and applies arguments to
 * generate a valid localized message.//  w  w w .j  a  v  a 2  s.c  o  m
 * 
 * @param arguments
 * @param template
 */
protected void createLogComment(String template, Object... arguments) {
    MessageFormat formatter = new MessageFormat("");
    formatter.applyPattern(messages.getString(template));
    logComment = formatter.format(arguments);
}

From source file:es.urjc.mctwp.service.Command.java

/**
 * This method get the appropriate message template and applies arguments to
 * generate a valid localized message.// w w  w .  j a  va 2  s . co  m
 * 
 * @param arguments
 * @param template
 */
protected void createUserComment(String template, Object... arguments) {
    MessageFormat formatter = new MessageFormat("");
    formatter.applyPattern(messages.getString(template));
    userComment = formatter.format(arguments);
}

From source file:org.panbox.desktop.common.gui.PairNewDeviceDialog.java

private void startNewRefreshTimer() {
    logger.debug("PairNewDeviceDialog : startNewRefreshTimer : Starting new refresh timeout timer.");
    timeout = PAKCorePairingHandler.PAIRING_TIMEOUT / 1000;
    refreshTimeout = new TimerTask() {

        @Override/* w  w w  .ja va2s .c  o  m*/
        public void run() {
            logger.debug("Timeout timer started... Left: " + timeout + " seconds.");
            MessageFormat formatter = new MessageFormat("", Settings.getInstance().getLocale());
            formatter.applyPattern(bundle.getString("client.deviceList.devicepairing.timeoutstatusbar"));
            statusInfoLabel.setText(formatter.format(new Object[] { timeout }));
            statusInfoLabel.invalidate();
            timeout--;
        }
    };
    timer = new Timer();
    timer.schedule(refreshTimeout, new Date(), 1000);
}

From source file:org.web4thejob.print.CsvPrinter.java

@Override
public File print(String title, List<RenderScheme> renderSchemes, Query query, List<Entity> entities) {
    Assert.notNull(renderSchemes);//from   www.ja v a 2 s  . c  o  m

    int i = 0;
    File file;
    try {
        String crlf = System.getProperty("line.separator");
        file = createTempFile();
        BufferedWriter writer = createFileStream(file);
        writer.write(title + crlf);
        writer.newLine();

        CSVWriter csv = new CSVWriter(writer);

        for (Entity entity : entities) {

            if (entity == null) {
                Assert.notNull(query);
                entity = ContextUtil.getDRS().findUniqueByQuery(query);
            }

            if (query != null && query.hasMasterCriterion()) {
                writer.write(describeMasterCriteria(query));
                writer.newLine();
            }

            if (query != null) {
                writer.write(describeCriteria(query));
                writer.newLine();
            }

            writeLine(csv, ContextUtil.getBean(ConversionService.class), entity, renderSchemes.get(i));
            writer.newLine();
            writer.newLine();
            i++;
        }

        //timestamp
        List<String> line = new ArrayList<String>();
        line.add(L10nMessages.L10N_LABEL_TIMESTAMP.toString());
        MessageFormat df = new MessageFormat("");
        df.setLocale(CoreUtil.getUserLocale());
        df.applyPattern("{0,date,yyyy-MM-dd hh:mm:ss}");
        line.add(df.format(new Object[] { new Date() }));
        csv.writeNext(line.toArray(new String[line.size()]));

        writer.newLine();

        writer.write("powered by web4thejob.org");
        writer.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    return file;

}