use of java.util.Formatter in project OpenNotebook by jaltekruse.
the class GenericAdjustmentPanel method addPanelContent.
@Override
public void addPanelContent() {
setLayout(new GridBagLayout());
GridBagConstraints con = new GridBagConstraints();
con.fill = GridBagConstraints.HORIZONTAL;
con.weightx = .1;
con.gridx = 0;
con.gridy = 0;
con.insets = new Insets(0, 5, 0, 5);
add(new JLabel(mAtt.getName()), con);
field = new JTextField();
con.weightx = 1;
con.gridx = 1;
con.insets = new Insets(0, 0, 0, 0);
add(field, con);
if (mAtt.getValue() instanceof Double) {
int len = mAtt.getValue().toString().length();
if (len > 5) {
formatter = new Formatter();
field.setText(String.format("%.5G", mAtt.getValue()));
}
} else {
if (mAtt.getValue() == null) {
field.setText("");
} else
field.setText(mAtt.getValue().toString());
}
field.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent arg0) {
}
@Override
public void focusLost(FocusEvent arg0) {
try {
if (mAtt.getParentObject() != null) {
mAtt.getParentObject().setAttributeValueWithString(mAtt.getName(), field.getText());
} else {
mAtt.setValueWithString(field.getText());
}
if (notebookPanel != null) {
notebookPanel.getCurrentDocViewer().repaintDoc();
notebookPanel.getCurrentDocViewer().updateObjectToolFrame();
}
} catch (AttributeException e) {
if (!showingDialog) {
JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
showingDialog = false;
}
}
}
});
field.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
applyPanelValueToObject();
}
});
}
use of java.util.Formatter in project databus by linkedin.
the class DtailPrinter method printStats.
public void printStats() {
if (0 == _winNum)
_winNum = 1;
long elapsedMs = _endTs - _startTs;
Formatter fmt = new Formatter();
fmt.format(GLOBAL_STATS_FORMAT, elapsedMs, _eventsNum, (1000.0 * _eventsNum / elapsedMs), _winNum, (1000.0 * _winNum / elapsedMs), _payloadBytes, (1000.0 * _payloadBytes / elapsedMs), _payloadBytes / _eventsNum, _eventBytes, (1000.0 * _eventBytes / elapsedMs), 1.0 * _eventLagNs / (1000000L * _eventsNum));
fmt.flush();
fmt.close();
String statsStr = fmt.toString();
try {
_out.write(statsStr.getBytes(Charset.defaultCharset()));
_out.flush();
} catch (IOException e) {
LOG.error("unable to write stats", e);
}
}
use of java.util.Formatter in project pinpoint by naver.
the class FormatTest method format2.
@Test
public void format2() {
StringBuilder buffer = new StringBuilder();
Formatter formatter = new Formatter(buffer);
formatter.format("(%s, %s, %s)", 1, 2, 3);
Assert.assertEquals(buffer.toString(), "(1, 2, 3)");
}
use of java.util.Formatter in project pinpoint by naver.
the class FormatTest method format.
@Test
public void format() {
StringBuilder buffer = new StringBuilder();
Formatter formatter = new Formatter(buffer);
formatter.format("%1s", "ab");
formatter.format("%3s", "a");
Assert.assertEquals(buffer.toString(), "ab a");
}
use of java.util.Formatter in project neo4j by neo4j.
the class DefaultUdcInformationCollector method determineMacAddress.
private String determineMacAddress() {
String formattedMac = "0";
try {
InetAddress address = InetAddress.getLocalHost();
NetworkInterface ni = NetworkInterface.getByInetAddress(address);
if (ni != null) {
byte[] mac = ni.getHardwareAddress();
if (mac != null) {
StringBuilder sb = new StringBuilder(mac.length * 2);
Formatter formatter = new Formatter(sb);
for (byte b : mac) {
formatter.format("%02x", b);
}
formattedMac = sb.toString();
}
}
} catch (Throwable t) {
//
}
return formattedMac;
}
Aggregations