Example usage for java.text NumberFormat getIntegerInstance

List of usage examples for java.text NumberFormat getIntegerInstance

Introduction

In this page you can find the example usage for java.text NumberFormat getIntegerInstance.

Prototype

public static final NumberFormat getIntegerInstance() 

Source Link

Document

Returns an integer number format for the current default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:components.IntegerEditor.java

public IntegerEditor(int min, int max) {
    super(new JFormattedTextField());
    ftf = (JFormattedTextField) getComponent();
    minimum = new Integer(min);
    maximum = new Integer(max);

    //Set up the editor for the integer cells.
    integerFormat = NumberFormat.getIntegerInstance();
    NumberFormatter intFormatter = new NumberFormatter(integerFormat);
    intFormatter.setFormat(integerFormat);
    intFormatter.setMinimum(minimum);//from  w ww  . j a  va 2  s. c o  m
    intFormatter.setMaximum(maximum);

    ftf.setFormatterFactory(new DefaultFormatterFactory(intFormatter));
    ftf.setValue(minimum);
    ftf.setHorizontalAlignment(JTextField.TRAILING);
    ftf.setFocusLostBehavior(JFormattedTextField.PERSIST);

    //React when the user presses Enter while the editor is
    //active.  (Tab is handled as specified by
    //JFormattedTextField's focusLostBehavior property.)
    ftf.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "check");
    ftf.getActionMap().put("check", new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            if (!ftf.isEditValid()) { //The text is invalid.
                if (userSaysRevert()) { //reverted
                    ftf.postActionEvent(); //inform the editor
                }
            } else
                try { //The text is valid,
                    ftf.commitEdit(); //so use it.
                    ftf.postActionEvent(); //stop editing
                } catch (java.text.ParseException exc) {
                }
        }
    });
}

From source file:edu.psu.citeseerx.misc.charts.CiteChartBuilderJFree.java

protected JFreeChart buildChart(Document doc) throws SQLException {

    Long clusterid = doc.getClusterID();
    if (clusterid == null) {
        return null;
    }//w  ww .  j a  v a2 s . c  o m

    java.util.List<ThinDoc> citingDocs = citedao.getCitingDocuments(clusterid, 0, MAX_CITING);
    XYDataset dataset = collectData(citingDocs);
    if (dataset.getItemCount(0) <= 1) {
        return null;
    }

    XYBarDataset ivl_dataset = new XYBarDataset(dataset, 15.0);
    JFreeChart chart = ChartFactory.createXYBarChart(null, "Year", true, "Citation Count", ivl_dataset,
            PlotOrientation.VERTICAL, false, false, false);
    chart.setBackgroundPaint(Color.WHITE);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.WHITE);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    XYItemRenderer r = plot.getRenderer();

    NumberAxis axis = (NumberAxis) plot.getDomainAxis();
    axis.setNumberFormatOverride(NumberFormat.getIntegerInstance());
    //axis.setTickUnit(new DateTickUnit(DateTickUnit.YEAR, -1));
    //axis.setDateFormatOverride(new SimpleDateFormat("yyyy"));
    return chart;

}

From source file:org.jboss.test.selenium.ScreenshotInterceptor.java

public ScreenshotInterceptor() {
    numberFormat = NumberFormat.getIntegerInstance();
    numberFormat.setMinimumIntegerDigits(3);

    try {/*from  ww  w. j a  v  a2  s .c om*/
        messageDigest = MessageDigest.getInstance("SHA-1");
    } catch (NoSuchAlgorithmException e1) {
        System.out.println("***** Algorithm SHA-1 is not available.");
    }

    try {
        FileUtils.forceMkdir(screenshotsOutputDir);
        // FIXME it should clean directory only if it is the first test suite
        // FileUtils.cleanDirectory(failuresOutputDir);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:siddur.solidtrust.cost.CarCostService.java

private static String tranfer(String value) {
    //Marktplaats is based on 1250 kilometers per month. I want to recalculate this for 1083 kilometers
    float rate = 1083f / 1250f;
    String v = value.replace(",", ".");
    if (StringUtils.isNumeric(v)) {
        float rc = Float.parseFloat(value.replace(",", ".")) * rate;
        NumberFormat nf = NumberFormat.getIntegerInstance();
        nf.setMaximumFractionDigits(2);/*from  w  w w . j a  v a  2 s .  co m*/
        String _v = nf.format(rc);
        return _v.replace(".", ",");
    }
    return value;
}

From source file:nlp.mediawiki.parser.SinglestreamXmlDumpParser.java

@Override
public String toString() {
    NumberFormat nf = NumberFormat.getIntegerInstance();
    nf.setGroupingUsed(true);//from   w  w  w  . ja va  2s .co  m

    return String.format("Singlestreamed XML Dump parser { \n * Batch size: %s, \n * Input: %s \n}",
            nf.format(batchsize), pageInput == null ? "[Inputstream]" : pageInput.getAbsolutePath());
}

From source file:com.anrisoftware.globalpom.format.byteformat.ByteFormat.java

/**
 * @see ByteFormatFactory#create()
 */
@AssistedInject
ByteFormat() {
    this(NumberFormat.getIntegerInstance());
}

From source file:org.evosuite.ga.stoppingconditions.StoppingConditionImpl.java

/**
 * <p>getValueString</p>//from  w  w w  . j a va2 s  .  c  o  m
 *
 * @return a {@link java.lang.String} object.
 */
public String getValueString() {
    String value = NumberFormat.getIntegerInstance().format(getCurrentValue());
    value = StringUtils.leftPad(value, 12);
    String limit = NumberFormat.getIntegerInstance().format(getLimit());
    limit = StringUtils.rightPad(limit, 12);
    return value + " / " + limit;
}

From source file:ubic.gemma.web.taglib.common.auditAndSecurity.WhatsNewBoxTag.java

@Override
public int doStartTag() throws JspException {

    Collection<ExpressionExperiment> newExpressionExperiments = whatsNew.getNewExpressionExperiments();
    Collection<ArrayDesign> newArrayDesigns = whatsNew.getNewArrayDesigns();
    Collection<ExpressionExperiment> updatedExpressionExperiments = whatsNew.getUpdatedExpressionExperiments();
    Collection<ArrayDesign> updatedArrayDesigns = whatsNew.getUpdatedArrayDesigns();
    // don't show things that are "new" as "updated" too (if they were updated after being loaded)
    updatedExpressionExperiments.removeAll(newExpressionExperiments);
    updatedArrayDesigns.removeAll(newArrayDesigns);

    StringBuilder buf = new StringBuilder();

    if (newArrayDesigns.size() == 0 && newExpressionExperiments.size() == 0
            && updatedExpressionExperiments.size() == 0 && updatedArrayDesigns.size() == 0) {
        buf.append("<input type='hidden' name='nothing new' />");
    } else {/*  w ww.j  a va  2s.c om*/
        buf.append(" <strong>Changes in the");
        Date date = whatsNew.getDate();
        Date now = Calendar.getInstance().getTime();
        long millis = now.getTime() - date.getTime();
        double days = millis / (double) DateUtils.MILLIS_PER_DAY;
        if (days > 0.9 && days < 2.0) {
            buf.append(" last day");
        } else if (days < 8) {
            buf.append(" last week");
        } else {
            NumberFormat nf = NumberFormat.getIntegerInstance();
            buf.append(" last " + nf.format(days) + " days");
        }
        buf.append("</strong> ");
        buf.append("<p>");

        int numEEs = newExpressionExperiments.size();
        int numADs = newArrayDesigns.size();
        int updatedAds = updatedArrayDesigns.size();
        int updatedEEs = updatedExpressionExperiments.size();

        if (numEEs > 0) {
            int count = 0;
            boolean tooMany = false;
            List<Long> ids = new ArrayList<Long>();
            for (ExpressionExperiment ee : newExpressionExperiments) {
                ids.add(ee.getId());
                if (++count > MAX_NEW_ITEMS) {
                    tooMany = true;
                    break;
                }
            }
            buf.append("<a " + (tooMany ? "title='View the first " + MAX_NEW_ITEMS + "'" : "")
                    + " href=\"/Gemma/expressionExperiment/showAllExpressionExperiments.html?id=");
            buf.append(StringUtils.join(ids, ","));
            buf.append("\">" + numEEs + " new data set" + (numEEs > 1 ? "s" : "") + "</a>.<br />");
        }
        if (numADs > 0) {

            int count = 0;
            boolean tooMany = false;
            List<Long> ids = new ArrayList<Long>();
            for (ArrayDesign ad : newArrayDesigns) {
                // buf.append( ad.getId() + "," );
                ids.add(ad.getId());
                if (++count > MAX_NEW_ITEMS) {
                    tooMany = true;
                    break;
                }
            }
            buf.append("<a " + (tooMany ? "title='View the first " + MAX_NEW_ITEMS + "'" : "")
                    + " href=\"/Gemma/arrays/showAllArrayDesigns.html?id=");
            buf.append(StringUtils.join(ids, ","));
            buf.append("\">" + numADs + " new platform" + (numADs > 1 ? "s" : "") + "</a>.<br />");
        }

        if (updatedEEs > 0) {
            boolean tooMany = false;
            List<Long> ids = new ArrayList<Long>();
            int count = 0;
            for (ExpressionExperiment ee : updatedExpressionExperiments) {
                ids.add(ee.getId());

                if (++count > MAX_NEW_ITEMS) {
                    tooMany = true;
                    break;
                }
            }
            buf.append("<a " + (tooMany ? "title='View the first " + MAX_NEW_ITEMS + "'" : "")
                    + " href=\"/Gemma/expressionExperiment/showAllExpressionExperiments.html?id=");
            buf.append(StringUtils.join(ids, ","));
            buf.append("\">" + updatedEEs + " updated data set" + (updatedEEs > 1 ? "s" : "") + "</a>.<br />");

        }

        if (updatedAds > 0) {
            int count = 0;
            boolean tooMany = false;
            List<Long> ids = new ArrayList<Long>();
            for (ArrayDesign ad : updatedArrayDesigns) {
                ids.add(ad.getId());
                if (++count > MAX_NEW_ITEMS) {
                    tooMany = true;
                    break;
                }
            }
            buf.append("<a " + (tooMany ? "title='View the first " + MAX_NEW_ITEMS + "'" : "")
                    + " href=\"/Gemma/arrays/showAllArrayDesigns.html?id=");
            buf.append(StringUtils.join(ids, ","));
            buf.append("\">" + updatedAds + " updated platform" + (updatedAds > 1 ? "s" : "") + "</a>.<br />");

        }

        buf.append("</p>");
    }

    try {
        pageContext.getOut().print(buf.toString());
    } catch (Exception ex) {
        throw new JspException("ContactTag: " + ex.getMessage());
    }
    return SKIP_BODY;
}

From source file:org.sonar.plugins.scmstats.charts.StackedBarChart3D.java

private JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createStackedBarChart3D(null, "Authors", "Activity", categorydataset,
            PlotOrientation.HORIZONTAL, true, true, false);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();

    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setNumberFormatOverride(new DecimalFormat("0%"));

    StackedBarRenderer3D stackedbarrenderer3d = (StackedBarRenderer3D) categoryplot.getRenderer();
    stackedbarrenderer3d.setRenderAsPercentages(true);
    stackedbarrenderer3d.setDrawBarOutline(false);
    stackedbarrenderer3d.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{3}",
            NumberFormat.getIntegerInstance(), new DecimalFormat("0.0%")));
    stackedbarrenderer3d.setBaseItemLabelsVisible(true);
    stackedbarrenderer3d/*from  w  w w. ja v  a 2  s. com*/
            .setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    stackedbarrenderer3d
            .setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));

    stackedbarrenderer3d.setSeriesPaint(0, Color.decode("#66CD00"));
    stackedbarrenderer3d.setSeriesPaint(1, Color.decode("#4F94CD"));
    stackedbarrenderer3d.setSeriesPaint(2, Color.decode("#FF4040"));
    return jfreechart;
}

From source file:slash.navigation.converter.gui.elevationview.ElevationView.java

private XYPlot createPlot(JFreeChart chart) {
    XYPlot plot = chart.getXYPlot();//from   w w w .  j  a  va2s .  c o m
    plot.setForegroundAlpha(0.65F);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
    Font font = new JLabel().getFont();
    rangeAxis.setLabelFont(font);

    NumberAxis valueAxis = (NumberAxis) plot.getDomainAxis();
    valueAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
    valueAxis.setLowerMargin(0.0);
    valueAxis.setUpperMargin(0.0);
    valueAxis.setLabelFont(font);

    XYItemRenderer renderer = plot.getRenderer();
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{2}m @ {1} Km",
            NumberFormat.getIntegerInstance(), NumberFormat.getIntegerInstance()));
    return plot;
}