Search in sources :

Example 11 with Formatter

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();
        }
    });
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) Formatter(java.util.Formatter) ActionEvent(java.awt.event.ActionEvent) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) FocusEvent(java.awt.event.FocusEvent) AttributeException(doc.attributes.AttributeException) ActionListener(java.awt.event.ActionListener) FocusListener(java.awt.event.FocusListener)

Example 12 with Formatter

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);
    }
}
Also used : Formatter(java.util.Formatter) IOException(java.io.IOException)

Example 13 with Formatter

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)");
}
Also used : Formatter(java.util.Formatter) Test(org.junit.Test)

Example 14 with Formatter

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");
}
Also used : Formatter(java.util.Formatter) Test(org.junit.Test)

Example 15 with Formatter

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;
}
Also used : Formatter(java.util.Formatter) NetworkInterface(java.net.NetworkInterface) InetAddress(java.net.InetAddress)

Aggregations

Formatter (java.util.Formatter)313 File (java.io.File)18 AlertDialog (android.app.AlertDialog)14 DialogInterface (android.content.DialogInterface)14 Justif (aQute.lib.justif.Justif)12 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)10 Map (java.util.Map)10 Test (org.junit.Test)10 BigInteger (java.math.BigInteger)9 Locale (java.util.Locale)9 IOException (java.io.IOException)8 UnknownFormatConversionException (java.util.UnknownFormatConversionException)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 BigDecimal (java.math.BigDecimal)7 IllegalFormatException (java.util.IllegalFormatException)7 IllegalFormatFlagsException (java.util.IllegalFormatFlagsException)7 Resources (android.content.res.Resources)6 LayoutBuilder (android.text.StaticLayoutTest.LayoutBuilder)6 FormatFlagsConversionMismatchException (java.util.FormatFlagsConversionMismatchException)6