use of java.text.Format in project mzmine2 by mzmine.
the class ExactMzDataPoint method getName.
public String getName() {
Format mzFormat = MZmineCore.getConfiguration().getMZFormat();
Format intensityFormat = MZmineCore.getConfiguration().getIntensityFormat();
String str = "m/z: " + mzFormat.format(mz) + ", intensity: " + intensityFormat.format(intensity);
return str;
}
use of java.text.Format in project mzmine2 by mzmine.
the class ScanUtils method scanToString.
/**
* Common utility method to be used as Scan.toString() method in various Scan implementations
*
* @param scan Scan to be converted to String
* @return String representation of the scan
*/
@Nonnull
public static String scanToString(@Nonnull Scan scan, @Nonnull Boolean includeFileName) {
StringBuffer buf = new StringBuffer();
Format rtFormat = MZmineCore.getConfiguration().getRTFormat();
Format mzFormat = MZmineCore.getConfiguration().getMZFormat();
if (includeFileName)
buf.append(scan.getDataFile().getName());
buf.append("#");
buf.append(scan.getScanNumber());
buf.append(" @");
buf.append(rtFormat.format(scan.getRetentionTime()));
buf.append(" MS");
buf.append(scan.getMSLevel());
if (scan.getMSLevel() > 1)
buf.append(" (" + mzFormat.format(scan.getPrecursorMZ()) + ")");
switch(scan.getSpectrumType()) {
case CENTROIDED:
buf.append(" c");
break;
case PROFILE:
buf.append(" p");
break;
case THRESHOLDED:
buf.append(" t");
break;
}
buf.append(" ");
buf.append(scan.getPolarity().asSingleChar());
return buf.toString();
}
use of java.text.Format in project Spark by igniterealtime.
the class BroadcastHistoryFrame method initComponents.
private void initComponents() {
SearchButton = new javax.swing.JToggleButton();
DateField = new javax.swing.JFormattedTextField();
SearchDate = new javax.swing.JLabel();
Date date = new Date();
Format formatter = new SimpleDateFormat("yyy-MM");
String myDate = formatter.format(date);
DateField.setValue(myDate);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
JScrollPane panelPane = new JScrollPane(BroadcastHistoryArea);
SearchDate.setText(Res.getString("label.broadcast.history.search.date"));
setTitle(Res.getString("title.broadcast.history"));
try {
readFromFile(myDate);
} catch (IOException ex) {
Log.error("Couldn't read from file" + ex.getMessage() + Arrays.toString(ex.getStackTrace()));
}
SearchButton.setText((Res.getString("button.search")));
SearchButton.addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mouseClicked(java.awt.event.MouseEvent evt) {
SearchButtonMouseClicked(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(panelPane, javax.swing.GroupLayout.DEFAULT_SIZE, 533, javax.swing.GroupLayout.DEFAULT_SIZE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(SearchDate).addComponent(SearchButton).addComponent(DateField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addGap(22, 22, 22)));
layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGap(15, 15, 15).addComponent(panelPane, javax.swing.GroupLayout.DEFAULT_SIZE, 350, javax.swing.GroupLayout.DEFAULT_SIZE)).addGroup(layout.createSequentialGroup().addGap(15, 15, 15).addComponent(SearchDate).addGap(10, 10, 10).addComponent(DateField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addGap(10, 10, 10).addComponent(SearchButton))).addContainerGap(15, Short.MAX_VALUE)));
pack();
final Rectangle bounds = LayoutSettingsManager.getLayoutSettings().getBroadcastHistoryBounds();
if (bounds == null || bounds.width <= 0 || bounds.height <= 0) {
// Use default settings.
setLocationRelativeTo(null);
} else {
setBounds(bounds);
}
addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
LayoutSettingsManager.getLayoutSettings().setBroadcastHistoryBounds(getBounds());
}
@Override
public void componentMoved(ComponentEvent e) {
LayoutSettingsManager.getLayoutSettings().setBroadcastHistoryBounds(getBounds());
}
});
}
use of java.text.Format in project hadoop by apache.
the class HumanReadableHistoryViewerPrinter method printJobCounters.
private void printJobCounters(StringBuilder buff, Counters totalCounters, Counters mapCounters, Counters reduceCounters) {
// Killed jobs might not have counters
if (totalCounters != null) {
buff.append("\nCounters: \n\n");
buff.append(String.format("|%1$-30s|%2$-30s|%3$-10s|%4$-10s|%5$-10s|", "Group Name", "Counter name", "Map Value", "Reduce Value", "Total Value"));
buff.append("\n------------------------------------------" + "---------------------------------------------");
for (String groupName : totalCounters.getGroupNames()) {
CounterGroup totalGroup = totalCounters.getGroup(groupName);
CounterGroup mapGroup = mapCounters.getGroup(groupName);
CounterGroup reduceGroup = reduceCounters.getGroup(groupName);
Format decimal = new DecimalFormat();
Iterator<Counter> ctrItr = totalGroup.iterator();
while (ctrItr.hasNext()) {
org.apache.hadoop.mapreduce.Counter counter = ctrItr.next();
String name = counter.getName();
String mapValue = decimal.format(mapGroup.findCounter(name).getValue());
String reduceValue = decimal.format(reduceGroup.findCounter(name).getValue());
String totalValue = decimal.format(counter.getValue());
buff.append(String.format("%n|%1$-30s|%2$-30s|%3$-10s|%4$-10s|%5$-10s", totalGroup.getDisplayName(), counter.getDisplayName(), mapValue, reduceValue, totalValue));
}
}
}
}
use of java.text.Format in project sonarqube by SonarSource.
the class WriteTag method formatValue.
/**
* Format value according to specified format string (as tag attribute or
* as string from message resources) or to current user locale.
*
* When a format string is retrieved from the message resources,
* <code>applyLocalizedPattern</code> is used. For more about localized
* patterns, see
* <http://www.dei.unipd.it/corsi/fi2ae-docs/source/jdk1.1.7/src/java/text/resources/>.
* (To obtain the correct value for some characters, you may need to view
* the file in a hex editor and then use the Unicode escape form in the
* property resources file.)
*
* @param valueToFormat value to process and convert to String
* @throws JspException if a JSP exception has occurred
*/
protected String formatValue(Object valueToFormat) throws JspException {
Format format = null;
Object value = valueToFormat;
Locale locale = TagUtils.getInstance().getUserLocale(pageContext, this.localeKey);
boolean formatStrFromResources = false;
String formatString = formatStr;
// Return String object as is.
if (value instanceof java.lang.String) {
return (String) value;
} else {
// formatKey.
if ((formatString == null) && (formatKey != null)) {
formatString = retrieveFormatString(this.formatKey);
if (formatString != null) {
formatStrFromResources = true;
}
}
// Prepare format object for numeric values.
if (value instanceof Number) {
if (formatString == null) {
if ((value instanceof Byte) || (value instanceof Short) || (value instanceof Integer) || (value instanceof Long) || (value instanceof BigInteger)) {
formatString = retrieveFormatString(INT_FORMAT_KEY);
} else if ((value instanceof Float) || (value instanceof Double) || (value instanceof BigDecimal)) {
formatString = retrieveFormatString(FLOAT_FORMAT_KEY);
}
if (formatString != null) {
formatStrFromResources = true;
}
}
if (formatString != null) {
try {
format = NumberFormat.getNumberInstance(locale);
if (formatStrFromResources) {
((DecimalFormat) format).applyLocalizedPattern(formatString);
} else {
((DecimalFormat) format).applyPattern(formatString);
}
} catch (IllegalArgumentException e) {
JspException ex = new JspException(messages.getMessage("write.format", formatString));
TagUtils.getInstance().saveException(pageContext, ex);
throw ex;
}
}
} else if (value instanceof java.util.Date) {
if (formatString == null) {
if (value instanceof java.sql.Timestamp) {
formatString = retrieveFormatString(SQL_TIMESTAMP_FORMAT_KEY);
} else if (value instanceof java.sql.Date) {
formatString = retrieveFormatString(SQL_DATE_FORMAT_KEY);
} else if (value instanceof java.sql.Time) {
formatString = retrieveFormatString(SQL_TIME_FORMAT_KEY);
} else if (value instanceof java.util.Date) {
formatString = retrieveFormatString(DATE_FORMAT_KEY);
}
}
if (formatString != null) {
format = new SimpleDateFormat(formatString, locale);
}
}
}
if (format != null) {
return format.format(value);
} else {
return value.toString();
}
}
Aggregations