List of usage examples for java.text MessageFormat MessageFormat
public MessageFormat(String pattern)
From source file:com.opensymphony.xwork2.util.LocalizedTextUtil.java
private static MessageFormat buildMessageFormat(String pattern, Locale locale) { MessageFormatKey key = new MessageFormatKey(pattern, locale); MessageFormat format = messageFormats.get(key); if (format == null) { format = new MessageFormat(pattern); format.setLocale(locale);/*from w w w . j a va 2s . c o m*/ format.applyPattern(pattern); messageFormats.put(key, format); } return format; }
From source file:com.okta.tools.awscli.java
private static void UpdateCredentialsFile(String profileName, String awsAccessKey, String awsSecretKey, String awsSessionToken) throws IOException { ProfilesConfigFile profilesConfigFile = null; Object[] args = { new String(profileName) }; MessageFormat profileNameFormatWithBrackets = new MessageFormat("[{0}]"); String profileNameWithBrackets = profileNameFormatWithBrackets.format(args); try {/*from w w w. java 2 s . com*/ profilesConfigFile = new ProfilesConfigFile(); } catch (AmazonClientException ace) { PopulateCredentialsFile(profileNameWithBrackets, awsAccessKey, awsSecretKey, awsSessionToken); } try { if (profilesConfigFile != null && profilesConfigFile.getCredentials(profileName) != null) { //if we end up here, it means we were able to find a matching profile PopulateCredentialsFile(profileNameWithBrackets, awsAccessKey, awsSecretKey, awsSessionToken); } } catch (AmazonClientException ace) { //this could happen if the default profile doesn't have a valid AWS Access Key ID //in this case, error would be "Unable to load credentials into profile [default]: AWS Access Key ID is not specified." PopulateCredentialsFile(profileNameWithBrackets, awsAccessKey, awsSecretKey, awsSessionToken); } catch (IllegalArgumentException iae) { //if we end up here, it means we were not able to find a matching profile so we need to append one PopulateCredentialsFile(profileNameWithBrackets, awsAccessKey, awsSecretKey, awsSessionToken); //FileWriter fileWriter = new FileWriter(System.getProperty("user.home") + "/.aws/credentials", true); //TODO: need to be updated to work with Windows //PrintWriter writer = new PrintWriter(fileWriter); //WriteNewProfile(writer, profileNameWithBrackets, awsAccessKey, awsSecretKey, awsSessionToken); //fileWriter.close(); } }
From source file:net.sf.fspdfs.chartthemes.spring.AegeanChartTheme.java
/** * */// ww w. j av a2s.c om protected JFreeChart createDialChart() throws JRException { JRMeterPlot jrPlot = (JRMeterPlot) getPlot(); // get data for diagrams DialPlot dialPlot = new DialPlot(); if (getDataset() != null) { dialPlot.setDataset((ValueDataset) getDataset()); } StandardDialFrame dialFrame = new StandardDialFrame(); dialFrame.setForegroundPaint(Color.BLACK); dialFrame.setBackgroundPaint(Color.BLACK); dialFrame.setStroke(new BasicStroke(1f)); dialPlot.setDialFrame(dialFrame); DialBackground db = new DialBackground(ChartThemesConstants.TRANSPARENT_PAINT); dialPlot.setBackground(db); ScaledDialScale scale = null; int dialUnitScale = 1; Range range = convertRange(jrPlot.getDataRange()); if (range != null) { double bound = Math.max(Math.abs(range.getUpperBound()), Math.abs(range.getLowerBound())); dialUnitScale = ChartThemesUtilities.getScale(bound); double lowerBound = ChartThemesUtilities.getTruncatedValue(range.getLowerBound(), dialUnitScale); double upperBound = ChartThemesUtilities.getTruncatedValue(range.getUpperBound(), dialUnitScale); scale = new ScaledDialScale(lowerBound, upperBound, 210, -240, (upperBound - lowerBound) / 6, 1); if ((lowerBound == (int) lowerBound && upperBound == (int) upperBound && scale.getMajorTickIncrement() == (int) scale.getMajorTickIncrement()) || dialUnitScale > 1) { scale.setTickLabelFormatter(new DecimalFormat("#,##0")); } else if (dialUnitScale == 1) { scale.setTickLabelFormatter(new DecimalFormat("#,##0.0")); } else if (dialUnitScale <= 0) { scale.setTickLabelFormatter(new DecimalFormat("#,##0.00")); } } else { scale = new ScaledDialScale(); } scale.setTickRadius(0.9); scale.setTickLabelOffset(0.16); JRFont tickLabelFont = jrPlot.getTickLabelFont(); Integer defaultBaseFontSize = (Integer) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.BASEFONT_SIZE); Font themeTickLabelFont = getFont( (JRFont) getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_TICK_LABEL_FONT), tickLabelFont, defaultBaseFontSize); scale.setTickLabelFont(themeTickLabelFont); scale.setMajorTickStroke(new BasicStroke(1f)); scale.setMinorTickStroke(new BasicStroke(0.7f)); scale.setMajorTickPaint(Color.BLACK); scale.setMinorTickPaint(Color.BLACK); scale.setTickLabelsVisible(true); scale.setFirstTickLabelVisible(true); dialPlot.addScale(0, scale); List intervals = jrPlot.getIntervals(); if (intervals != null && intervals.size() > 0) { int size = Math.min(3, intervals.size()); int colorStep = 0; if (size > 3) colorStep = 255 / (size - 3); for (int i = 0; i < size; i++) { JRMeterInterval interval = (JRMeterInterval) intervals.get(i); Range intervalRange = convertRange(interval.getDataRange()); double intervalLowerBound = ChartThemesUtilities.getTruncatedValue(intervalRange.getLowerBound(), dialUnitScale); double intervalUpperBound = ChartThemesUtilities.getTruncatedValue(intervalRange.getUpperBound(), dialUnitScale); Color color = i < 3 ? (Color) ChartThemesConstants.AEGEAN_INTERVAL_COLORS.get(i) : new Color(255 - colorStep * (i - 3), 0 + colorStep * (i - 3), 0); ScaledDialRange dialRange = new ScaledDialRange(intervalLowerBound, intervalUpperBound, interval.getBackgroundColor() == null ? color : interval.getBackgroundColor(), 15f); dialRange.setInnerRadius(0.5); dialRange.setOuterRadius(0.5); dialPlot.addLayer(dialRange); } } JRValueDisplay display = jrPlot.getValueDisplay(); String displayVisibility = display != null && getChart().hasProperties() ? getChart().getPropertiesMap().getProperty(DefaultChartTheme.PROPERTY_DIAL_VALUE_DISPLAY_VISIBLE) : "false"; if (Boolean.valueOf(displayVisibility).booleanValue()) { ScaledDialValueIndicator dvi = new ScaledDialValueIndicator(0, dialUnitScale); dvi.setBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT); // dvi.setFont(JRFontUtil.getAwtFont(jrFont).deriveFont(10f).deriveFont(Font.BOLD)); dvi.setOutlinePaint(ChartThemesConstants.TRANSPARENT_PAINT); dvi.setPaint(Color.WHITE); String pattern = display.getMask() != null ? display.getMask() : "#,##0.####"; if (pattern != null) dvi.setNumberFormat(new DecimalFormat(pattern)); dvi.setRadius(0.15); dvi.setValueAnchor(RectangleAnchor.CENTER); dvi.setTextAnchor(TextAnchor.CENTER); //dvi.setTemplateValue(Double.valueOf(getDialTickValue(dialPlot.getValue(0),dialUnitScale))); dialPlot.addLayer(dvi); } String label = getChart().hasProperties() ? getChart().getPropertiesMap().getProperty(DefaultChartTheme.PROPERTY_DIAL_LABEL) : null; if (label != null) { if (dialUnitScale < 0) label = new MessageFormat(label) .format(new Object[] { String.valueOf(Math.pow(10, dialUnitScale)) }); else if (dialUnitScale < 3) label = new MessageFormat(label).format(new Object[] { "1" }); else label = new MessageFormat(label) .format(new Object[] { String.valueOf((int) Math.pow(10, dialUnitScale - 2)) }); JRFont displayFont = jrPlot.getValueDisplay().getFont(); Font themeDisplayFont = getFont( (JRFont) getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_DISPLAY_FONT), displayFont, defaultBaseFontSize); String[] textLines = label.split("\\n"); for (int i = 0; i < textLines.length; i++) { DialTextAnnotation dialAnnotation = new DialTextAnnotation(textLines[i]); dialAnnotation.setFont(themeDisplayFont); dialAnnotation.setPaint(Color.BLACK); dialAnnotation.setRadius(Math.sin(Math.PI / 6.0) + i / 10.0); dialAnnotation.setAnchor(TextAnchor.CENTER); dialPlot.addLayer(dialAnnotation); } } DialPointer needle = new ScaledDialPointer(dialUnitScale, 0.047); needle.setVisible(true); needle.setRadius(0.7); dialPlot.addLayer(needle); DialCap cap = new DialCap(); cap.setRadius(0.05); cap.setFillPaint(Color.BLACK); cap.setOutlinePaint(ChartThemesConstants.TRANSPARENT_PAINT); dialPlot.setCap(cap); JFreeChart jfreeChart = new JFreeChart((String) evaluateExpression(getChart().getTitleExpression()), null, dialPlot, getChart().getShowLegend() == null ? false : getChart().getShowLegend().booleanValue()); // Set all the generic options configureChart(jfreeChart, getPlot()); jfreeChart.setBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT); jfreeChart.setBorderVisible(false); return jfreeChart; }
From source file:freemind.controller.Controller.java
/** * Set the Frame title with mode and file if exist *///from ww w. j av a 2 s. co m public void setTitle() { Object[] messageArguments = { getMode().toLocalizedString() }; MessageFormat formatter = new MessageFormat(getResourceString("mode_title")); String title = formatter.format(messageArguments); String rawTitle = ""; MindMap model = null; MapModule mapModule = getMapModule(); if (mapModule != null) { model = mapModule.getModel(); rawTitle = mapModule.toString(); title = rawTitle + (model.isSaved() ? "" : "*") + " - " + title + (model.isReadOnly() ? " (" + getResourceString("read_only") + ")" : ""); File file = model.getFile(); if (file != null) { title += " " + file.getAbsolutePath(); } } getFrame().setTitle(title); for (Iterator iterator = mMapTitleChangeListenerSet.iterator(); iterator.hasNext();) { MapModuleManager.MapTitleChangeListener listener = (MapModuleManager.MapTitleChangeListener) iterator .next(); listener.setMapTitle(rawTitle, mapModule, model); } }
From source file:net.sf.jasperreports.chartthemes.spring.AegeanChartTheme.java
@Override protected JFreeChart createDialChart() throws JRException { JRMeterPlot jrPlot = (JRMeterPlot) getPlot(); // get data for diagrams DialPlot dialPlot = new DialPlot(); if (getDataset() != null) { dialPlot.setDataset((ValueDataset) getDataset()); }/*from w w w . j a va2s.c o m*/ StandardDialFrame dialFrame = new StandardDialFrame(); dialFrame.setForegroundPaint(Color.BLACK); dialFrame.setBackgroundPaint(Color.BLACK); dialFrame.setStroke(new BasicStroke(1f)); dialPlot.setDialFrame(dialFrame); DialBackground db = new DialBackground(ChartThemesConstants.TRANSPARENT_PAINT); dialPlot.setBackground(db); ScaledDialScale scale = null; int dialUnitScale = 1; Range range = convertRange(jrPlot.getDataRange()); if (range != null) { double bound = Math.max(Math.abs(range.getUpperBound()), Math.abs(range.getLowerBound())); dialUnitScale = ChartThemesUtilities.getScale(bound); double lowerBound = ChartThemesUtilities.getTruncatedValue(range.getLowerBound(), dialUnitScale); double upperBound = ChartThemesUtilities.getTruncatedValue(range.getUpperBound(), dialUnitScale); int tickCount = jrPlot.getTickCount() != null && jrPlot.getTickCount() > 1 ? jrPlot.getTickCount() : 7; scale = new ScaledDialScale(lowerBound, upperBound, 210, -240, (upperBound - lowerBound) / (tickCount - 1), 1); if ((lowerBound == (int) lowerBound && upperBound == (int) upperBound && scale.getMajorTickIncrement() == (int) scale.getMajorTickIncrement()) || dialUnitScale > 1) { scale.setTickLabelFormatter( new DecimalFormat("#,##0", DecimalFormatSymbols.getInstance(getLocale()))); } else if (dialUnitScale == 1) { scale.setTickLabelFormatter( new DecimalFormat("#,##0.0", DecimalFormatSymbols.getInstance(getLocale()))); } else if (dialUnitScale <= 0) { scale.setTickLabelFormatter( new DecimalFormat("#,##0.00", DecimalFormatSymbols.getInstance(getLocale()))); } else { // localizing the default tick label formatter scale.setTickLabelFormatter( new DecimalFormat("0.0", DecimalFormatSymbols.getInstance(getLocale()))); } } else { scale = new ScaledDialScale(); // localizing the default tick label formatter scale.setTickLabelFormatter(new DecimalFormat("0.0", DecimalFormatSymbols.getInstance(getLocale()))); } scale.setTickRadius(0.9); scale.setTickLabelOffset(0.16); JRFont tickLabelFont = jrPlot.getTickLabelFont(); Integer defaultBaseFontSize = (Integer) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.BASEFONT_SIZE); Font themeTickLabelFont = getFont( (JRFont) getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_TICK_LABEL_FONT), tickLabelFont, defaultBaseFontSize); scale.setTickLabelFont(themeTickLabelFont); scale.setMajorTickStroke(new BasicStroke(1f)); scale.setMinorTickStroke(new BasicStroke(0.7f)); scale.setMajorTickPaint(Color.BLACK); scale.setMinorTickPaint(Color.BLACK); scale.setTickLabelsVisible(true); scale.setFirstTickLabelVisible(true); dialPlot.addScale(0, scale); List<JRMeterInterval> intervals = jrPlot.getIntervals(); if (intervals != null && intervals.size() > 0) { int size = Math.min(3, intervals.size()); int colorStep = 0; if (size > 3) colorStep = 255 / (size - 3); for (int i = 0; i < size; i++) { JRMeterInterval interval = intervals.get(i); Range intervalRange = convertRange(interval.getDataRange()); double intervalLowerBound = ChartThemesUtilities.getTruncatedValue(intervalRange.getLowerBound(), dialUnitScale); double intervalUpperBound = ChartThemesUtilities.getTruncatedValue(intervalRange.getUpperBound(), dialUnitScale); Color color = i < 3 ? (Color) ChartThemesConstants.AEGEAN_INTERVAL_COLORS.get(i) : new Color(255 - colorStep * (i - 3), 0 + colorStep * (i - 3), 0); ScaledDialRange dialRange = new ScaledDialRange(intervalLowerBound, intervalUpperBound, interval.getBackgroundColor() == null ? color : interval.getBackgroundColor(), 15f); dialRange.setInnerRadius(0.5); dialRange.setOuterRadius(0.5); dialPlot.addLayer(dialRange); } } JRValueDisplay display = jrPlot.getValueDisplay(); String displayVisibility = display != null && getChart().hasProperties() ? getChart().getPropertiesMap().getProperty(DefaultChartTheme.PROPERTY_DIAL_VALUE_DISPLAY_VISIBLE) : "false"; if (Boolean.valueOf(displayVisibility)) { ScaledDialValueIndicator dvi = new ScaledDialValueIndicator(0, dialUnitScale); dvi.setBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT); // dvi.setFont(JRFontUtil.getAwtFont(jrFont).deriveFont(10f).deriveFont(Font.BOLD)); dvi.setOutlinePaint(ChartThemesConstants.TRANSPARENT_PAINT); dvi.setPaint(Color.WHITE); String pattern = display.getMask() != null ? display.getMask() : "#,##0.####"; if (pattern != null) dvi.setNumberFormat(new DecimalFormat(pattern, DecimalFormatSymbols.getInstance(getLocale()))); dvi.setRadius(0.15); dvi.setValueAnchor(RectangleAnchor.CENTER); dvi.setTextAnchor(TextAnchor.CENTER); //dvi.setTemplateValue(Double.valueOf(getDialTickValue(dialPlot.getValue(0),dialUnitScale))); dialPlot.addLayer(dvi); } String label = getChart().hasProperties() ? getChart().getPropertiesMap().getProperty(DefaultChartTheme.PROPERTY_DIAL_LABEL) : null; if (label != null) { if (dialUnitScale < 0) label = new MessageFormat(label) .format(new Object[] { String.valueOf(Math.pow(10, dialUnitScale)) }); else if (dialUnitScale < 3) label = new MessageFormat(label).format(new Object[] { "1" }); else label = new MessageFormat(label) .format(new Object[] { String.valueOf((int) Math.pow(10, dialUnitScale - 2)) }); JRFont displayFont = jrPlot.getValueDisplay().getFont(); Font themeDisplayFont = getFont( (JRFont) getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_DISPLAY_FONT), displayFont, defaultBaseFontSize); String[] textLines = label.split("\\n"); for (int i = 0; i < textLines.length; i++) { DialTextAnnotation dialAnnotation = new DialTextAnnotation(textLines[i]); dialAnnotation.setFont(themeDisplayFont); dialAnnotation.setPaint(Color.BLACK); dialAnnotation.setRadius(Math.sin(Math.PI / 6.0) + i / 10.0); dialAnnotation.setAnchor(TextAnchor.CENTER); dialPlot.addLayer(dialAnnotation); } } DialPointer needle = new ScaledDialPointer(dialUnitScale, 0.047); needle.setVisible(true); needle.setRadius(0.7); dialPlot.addLayer(needle); DialCap cap = new DialCap(); cap.setRadius(0.05); cap.setFillPaint(Color.BLACK); cap.setOutlinePaint(ChartThemesConstants.TRANSPARENT_PAINT); dialPlot.setCap(cap); JFreeChart jfreeChart = new JFreeChart(evaluateTextExpression(getChart().getTitleExpression()), null, dialPlot, getChart().getShowLegend() == null ? false : getChart().getShowLegend()); // Set all the generic options configureChart(jfreeChart, getPlot()); jfreeChart.setBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT); jfreeChart.setBorderVisible(false); return jfreeChart; }
From source file:com.opensymphony.xwork2.util.DefaultLocalizedTextProvider.java
private MessageFormat buildMessageFormat(String pattern, Locale locale) { MessageFormatKey key = new MessageFormatKey(pattern, locale); MessageFormat format = messageFormats.get(key); if (format == null) { format = new MessageFormat(pattern); format.setLocale(locale);/*ww w . ja va 2 s. c om*/ format.applyPattern(pattern); messageFormats.put(key, format); } return format; }
From source file:com.hurence.logisland.processor.mailer.MailerProcessor.java
/** * This parses the HTML template to//from w w w . ja v a 2 s .c o m * - get the list of needed parameters (${xxx} parameters in the template, so get the foo, bar etc variables) * - create a usable template using the MessageFormat system (have strings with ${0}, ${1} instead of ${foo}, ${bar}) * @param htmlTemplate */ private void prepareTemplateAndParameters(String htmlTemplate) { Pattern pattern = Pattern.compile("\\$\\{(.+?)}"); // Detect ${...} sequences Matcher matcher = pattern.matcher(htmlTemplate); // To construct a new template with ${0}, ${1} fields .. StringBuilder buffer = new StringBuilder(); int previousStart = 0; int currentParameterIndex = 0; // Loop through the parameters in the template while (matcher.find()) { String parameter = matcher.group(1); String stringBeforeCurrentParam = htmlTemplate.substring(previousStart, matcher.start()); // Add string before parameter buffer.append(stringBeforeCurrentParam); // Replace parameter with parameter index buffer.append("{" + currentParameterIndex + "}"); // Save current parameter name in the list parameterNames.add(parameter); previousStart = matcher.end(); currentParameterIndex++; } // Add string after the last parameter String stringAfterLastParam = htmlTemplate.substring(previousStart); buffer.append(stringAfterLastParam); // Create the HTML form htmlForm = new MessageFormat(buffer.toString()); }
From source file:uk.ac.lkl.cram.ui.ModuleFrame.java
private void addTLALineItem() { //Disable the menu item addTLALineItemMI.setEnabled(false);//from ww w . ja v a2 s . c om TLACreatorWizardIterator iterator = new TLACreatorWizardIterator(module); WizardDescriptor wizardDescriptor = new WizardDescriptor(iterator); iterator.initialize(wizardDescriptor); // {0} will be replaced by WizardDescriptor.Panel.getComponent().getName() // {1} will be replaced by WizardDescriptor.Iterator.name() wizardDescriptor.setTitleFormat(new MessageFormat("{0} ({1})")); wizardDescriptor.setTitle("TLA Creator Wizard for " + module.getModuleName() + " module"); Dialog dialog = DialogDisplayer.getDefault().createDialog(wizardDescriptor); //Modeless within the document dialog.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL); dialog.setVisible(true); dialog.toFront(); boolean cancelled = wizardDescriptor.getValue() != WizardDescriptor.FINISH_OPTION; //LOGGER.info("Cancelled: " + cancelled); if (!cancelled) { //Get the newly created line item TLALineItem lineItem = iterator.getLineItem(); //If the user created a new TLA, add it to their preferences if (iterator.isVanilla()) { UserTLALibrary.getDefaultLibrary().addActivity(lineItem.getActivity()); } module.addTLALineItem(lineItem); //No undo support here--assume user will just remove the line item } //Enable the menu item addTLALineItemMI.setEnabled(true); }
From source file:com.agloco.util.StringUtil.java
private static String format(String s, String format) { if (s == null) return ""; MessageFormat f = new MessageFormat(format); return f.format(s); }