List of usage examples for java.text NumberFormat getNumberInstance
public static final NumberFormat getNumberInstance()
From source file:op.care.med.inventory.DlgTX.java
private void initDialog() { initComponents();/*from w ww .j a v a 2 s . co m*/ lblText.setText(SYSTools.xx("opde.medication.tx.text")); lblValue.setText(SYSTools.xx("misc.msg.amount")); lblWeightControl.setText(SYSTools.xx("opde.medication.tx.controlWeight")); lblUnit2.setText("g"); bestandsumme = MedStockTools.getSum(tx.getStock()); weight = null; txtWeightControlled.setVisible(tx.getStock().getTradeForm().isWeightControlled()); lblWeightControl.setVisible(tx.getStock().getTradeForm().isWeightControlled()); lblUnit.setText(TradeFormTools.getPackUnit(tx.getStock().getTradeForm())); if (tx.getStock().hasPackage()) { packgroesse = tx.getStock().getPackage().getContent(); } else { packgroesse = BigDecimal.valueOf(Double.MAX_VALUE); } txtValue.setText(NumberFormat.getNumberInstance().format(tx.getAmount())); if (txtWeightControlled.isVisible()) { txtWeightControlled.setToolTipText(SYSTools.xx("opde.medication.controlWeight.only.after.change")); txtWeightControlled.setText(NumberFormat.getNumberInstance() .format(tx.getWeight() != null ? tx.getWeight() : BigDecimal.ZERO)); } setVisible(true); }
From source file:RelativeDateFormat.java
/** * Creates a new instance./*from w w w. java 2 s .co m*/ * * @param baseMillis the time zone (<code>null</code> not permitted). */ public RelativeDateFormat(long baseMillis) { super(); this.baseMillis = baseMillis; this.showZeroDays = false; this.showZeroHours = true; this.positivePrefix = ""; this.dayFormatter = NumberFormat.getNumberInstance(); this.daySuffix = "d"; this.hourFormatter = NumberFormat.getNumberInstance(); this.hourSuffix = "h"; this.minuteFormatter = NumberFormat.getNumberInstance(); this.minuteSuffix = "m"; this.secondFormatter = NumberFormat.getNumberInstance(); this.secondFormatter.setMaximumFractionDigits(3); this.secondFormatter.setMinimumFractionDigits(3); this.secondSuffix = "s"; // we don't use the calendar or numberFormat fields, but equals(Object) // is failing without them being non-null this.calendar = new GregorianCalendar(); this.numberFormat = new DecimalFormat("0"); }
From source file:com.manydesigns.portofino.chart.Chart1DGenerator.java
public JFreeChart generate(ChartDefinition chartDefinition, Persistence persistence, Locale locale) { DefaultPieDataset dataset = new DefaultPieDataset(); java.util.List<Object[]> result; String query = chartDefinition.getQuery(); logger.info(query);//from www.java2 s. com Session session = persistence.getSession(chartDefinition.getDatabase()); result = QueryUtils.runSql(session, query); for (Object[] current : result) { ComparableWrapper key = new ComparableWrapper((Comparable) current[0]); dataset.setValue(key, (Number) current[1]); if (current.length > 2) { key.setLabel(current[2].toString()); } } JFreeChart chart = createChart(chartDefinition, dataset); chart.setAntiAlias(isAntiAlias()); // impostiamo il bordo invisibile // eventualmente e' il css a fornirne uno // eventualmente e' il css a fornirne uno chart.setBorderVisible(isBorderVisible()); // impostiamo il titolo TextTitle title = chart.getTitle(); title.setFont(titleFont); title.setMargin(10.0, 0.0, 0.0, 0.0); // ottieni il Plot PiePlot plot = (PiePlot) chart.getPlot(); String urlExpression = chartDefinition.getUrlExpression(); if (!StringUtils.isBlank(urlExpression)) { PieURLGenerator urlGenerator = new ChartPieUrlGenerator(urlExpression); plot.setURLGenerator(urlGenerator); } else { plot.setURLGenerator(null); } // il plot ha sfondo e bordo trasparente // (quindi si vede il colore del chart) plot.setBackgroundPaint(transparentColor); plot.setOutlinePaint(transparentColor); // Modifico il toolTip // hongliangpan add // :?{0} {1} {2} ? ,??? plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})", NumberFormat.getNumberInstance(), new DecimalFormat("0.00%"))); // {0}={1}({2}) plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}")); // ?(0.0-1.0) // plot.setForegroundAlpha(1.0f); // imposta la distanza delle etichette dal plot plot.setLabelGap(0.03); // plot.setLabelGenerator(new MyPieSectionLabelGenerator()); // imposta il messaggio se non ci sono dati plot.setNoDataMessage(ElementsThreadLocals.getText("no.data.available")); plot.setCircular(true); plot.setBaseSectionOutlinePaint(Color.BLACK); DrawingSupplier supplier = new DesaturatedDrawingSupplier(plot.getDrawingSupplier()); plot.setDrawingSupplier(supplier); // ? plot.setForegroundAlpha(1.0f); // impostiamo il titolo della legenda String legendString = chartDefinition.getLegend(); Title subtitle = new TextTitle(legendString, legendFont, Color.BLACK, RectangleEdge.BOTTOM, HorizontalAlignment.CENTER, VerticalAlignment.CENTER, new RectangleInsets(0, 0, 0, 0)); subtitle.setMargin(0, 0, 5, 0); chart.addSubtitle(subtitle); // impostiamo la legenda LegendTitle legend = chart.getLegend(); legend.setBorder(0, 0, 0, 0); legend.setItemFont(legendItemFont); int legendMargin = 10; legend.setMargin(0.0, legendMargin, legendMargin, legendMargin); legend.setBackgroundPaint(transparentColor); // impostiamo un gradiente orizzontale Paint chartBgPaint = new GradientPaint(0, 0, new Color(255, 253, 240), 0, getHeight(), Color.WHITE); chart.setBackgroundPaint(chartBgPaint); return chart; }
From source file:org.jfree.chart.demo.MultiplePieChartDemo2.java
/** * Creates a sample chart with the given dataset. * /* w w w . j ava 2s .c o m*/ * @param dataset the dataset. * * @return A sample chart. */ private JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createMultiplePieChart("Multiple Pie Chart", // chart title dataset, // dataset TableOrder.BY_COLUMN, true, // include legend true, false); final MultiplePiePlot plot = (MultiplePiePlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setOutlineStroke(new BasicStroke(1.0f)); final JFreeChart subchart = plot.getPieChart(); final PiePlot p = (PiePlot) subchart.getPlot(); p.setBackgroundPaint(null); p.setOutlineStroke(null); p.setLabelGenerator(new StandardPieItemLabelGenerator("{0} ({2})", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance())); p.setMaximumLabelWidth(0.35); p.setLabelFont(new Font("SansSerif", Font.PLAIN, 9)); p.setInteriorGap(0.30); return chart; }
From source file:com.attribyte.essem.model.index.IndexStats.java
private String asCount(final long val) { NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMinimumFractionDigits(0);//from w w w. j a v a 2 s.co m nf.setMaximumFractionDigits(0); nf.setMinimumIntegerDigits(1); return nf.format(val); }
From source file:io.pcp.parfait.benchmark.StandardMetricThroughPutBenchmark.java
private void report(boolean startPcp, List<MonitoredCounter> counters, long timeTaken, List<CounterIncrementer> counterIncrementers) { long totalBlockedCount = computeTotalBlockedCount( transformToListOfBlockedMetricCollectors(counterIncrementers)); long totalBlockedTime = computeTotalBlockedTime( transformToListOfBlockedMetricCollectors(counterIncrementers)); double counterIncrements = computeTotalCounterIncrements(counters); double incrementRate = counterIncrements / ((double) timeTaken / 1000); NumberFormat numberFormat = NumberFormat.getNumberInstance(); numberFormat.setGroupingUsed(true);/*from w w w .j ava 2s. c om*/ numberFormat.setMaximumFractionDigits(2); numberFormat.setMinimumFractionDigits(2); String incrementRateString = StringUtils.leftPad(numberFormat.format(incrementRate), 15); System.out.printf( "pcpStarted: %s\tperMetricLock: %s\tincrementRate(/sec): %s\t blockedCount: %d\t blockedTime: %d\n", startPcp, usePerMetricLock, incrementRateString, totalBlockedCount, totalBlockedTime); }
From source file:org.angnysa.yaba.swing.BudgetFrame.java
private void buildTransactionTable() { transactionModel = new TransactionTableModel(service); transactionTable = new JTable(transactionModel); transactionTable.setRowHeight((int) (transactionTable.getRowHeight() * 1.2)); transactionTable.getColumnModel().getColumn(TransactionTableModel.COL_END) .setCellEditor(new CustomCellEditor( new JFormattedTextField(new OptionalValueFormatter(new JodaLocalDateFormat())))); transactionTable.setDefaultEditor(LocalDate.class, new CustomCellEditor(new JFormattedTextField(new JodaLocalDateFormat()))); transactionTable.setDefaultEditor(ReadablePeriod.class, new CustomCellEditor(new JFormattedTextField(new OptionalValueFormatter(new JodaPeriodFormat())))); transactionTable.setDefaultEditor(Double.class, new CustomCellEditor(new JFormattedTextField(NumberFormat.getNumberInstance()))); transactionTable.setDefaultRenderer(LocalDate.class, new FormattedTableCellRenderer(new JodaLocalDateFormat())); transactionTable.setDefaultRenderer(ReadablePeriod.class, new FormattedTableCellRenderer(new JodaPeriodFormat())); transactionTable.setDefaultRenderer(Double.class, new FormattedTableCellRenderer(TransactionAmountFormatFactory.getFormat())); transactionTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); transactionTable.setAutoCreateRowSorter(true); transactionTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "delete"); //$NON-NLS-1$ transactionTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), "delete"); //$NON-NLS-1$ transactionTable.getActionMap().put("delete", new AbstractAction() { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override/*from www . j a va2 s . c o m*/ public void actionPerformed(ActionEvent e) { int row = transactionTable.getSelectedRow(); if (row >= 0) { row = transactionTable.getRowSorter().convertRowIndexToModel(row); transactionModel.deleteRow(row); } } }); }
From source file:ubic.gemma.web.controller.BaseFormController.java
/** * Set up a custom property editor for converting form inputs to real objects. Override this to add additional * custom editors (call super.initBinder() in your implementation) *///w ww.j a va2s. c o m @InitBinder protected void initBinder(WebDataBinder binder) { NumberFormat nf = NumberFormat.getNumberInstance(); binder.registerCustomEditor(Integer.class, null, new CustomNumberEditor(Integer.class, nf, true)); binder.registerCustomEditor(Long.class, null, new CustomNumberEditor(Long.class, nf, true)); binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor()); }
From source file:com.attribyte.essem.model.index.IndexStats.java
private String asPercent(final double val) { NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMinimumFractionDigits(2);// w w w .j ava 2 s . co m nf.setMaximumFractionDigits(2); nf.setMinimumIntegerDigits(1); return nf.format(val * 100.0); }
From source file:com.hm.his.module.user.controller.UserController.java
/** * <p>Description:<p>/* w ww . ja v a 2 s . c o m*/ * @author ZhouPengyu * @date 2016-3-2 ?11:39:16 */ @RequestMapping(value = { "/hospitalRegister" }, produces = "application/json;charset=UTF-8", method = RequestMethod.POST) @ResponseBody public String register(@RequestBody Map<String, String> requestParams, HttpServletRequest request, HttpServletResponse response) { String userName = requestParams.get("userName"); String password = requestParams.get("password"); String realName = requestParams.get("realName"); String phone = requestParams.get("phone"); String mail = requestParams.get("mail"); String registerInvitation = requestParams.get("registerInvitation"); String hospitalName = requestParams.get("hospitalName"); String address = requestParams.get("address"); String hospitalLicense = requestParams.get("hospitalLicense"); String invitationCode = requestParams.get("invitationCode"); String smsCaptcha = requestParams.get("smsCaptcha"); HisResponse hisResponse = new HisResponse(); try { String sessionId = SessionUtils.getSession().getId(); String smsCaptchaCache = JedisHelper.get(String.class, sessionId).split("-")[0]; String cachePhoneNo = JedisHelper.get(String.class, sessionId).split("-")[1]; log.error(sessionId + "----??" + smsCaptcha + "--??" + smsCaptchaCache); Map<String, Object> map = new HashMap<String, Object>(); if ((smsCaptchaCache == null || !smsCaptchaCache.equals(smsCaptcha) || !cachePhoneNo.equals(phone)) && !"hmluckycharm!".equals(smsCaptcha)) { map.put("status", 5); hisResponse.setBody(map); return hisResponse.toString(); } Doctor doctor = new Doctor(); if (StringUtils.isNotEmpty(registerInvitation)) { if (registerInvitation.equals("huimeitimes")) { doctor.setStatus(1l); } else { hisResponse.setErrorCode(401); return hisResponse.toString(); } } else doctor.setStatus(1l); Hospital hospital = new Hospital(); hospital.setHospitalName(hospitalName); hospital.setAddress(address); hospital.setOrganizationLicense(hospitalLicense); hospital.setInvitationCode(invitationCode); hospitalService.saveHospital(hospital); Long number = hospital.getHospitalId(); NumberFormat formatter = NumberFormat.getNumberInstance(); formatter.setMinimumIntegerDigits(8); formatter.setGroupingUsed(false); String s = formatter.format(number); hospital.setHospitalNumber( "HM" + RC4Utils.encry_RC4_string(s, UUID.randomUUID().toString()).toUpperCase()); hospitalService.saveHospital(hospital); doctor.setDoctorName(userName); //? ---? doctor.setPassword(MD5Utils.encrypt(password)); //?? doctor.setHighPasswd(MD5Utils.passwordSaltHash(doctor.getDoctorName(), doctor.getPassword())); doctor.setRealName(realName); doctor.setMail(mail); doctor.setPhone(phone); doctor.setFlag(1L); doctor.setIsAdmin(1l); doctor.setHospitalId(hospital.getHospitalId()); doctorService.saveDoctor(doctor); if (doctor.getDoctorId() != null && doctor.getDoctorId() != 0l) { // hospitalExamService.insertDefaultExam(hospital.getHospitalId(), doctor.getDoctorId()); // drugService.addDefaultDrugForNewHospital(hospital.getHospitalId(), doctor.getDoctorId()); map.put("status", doctor.getStatus()); map.put("doctorId", doctor.getDoctorId()); if (hospital.getInvitationCode() != null && hospital.getInvitationCode().equals("18684989279")) map.put("changeImg", 1); else map.put("changeImg", 0); if (doctor.getStatus() != 1l) { smsService.getHospitalSmsConfig(hospital.getHospitalId()); HmMailUtil.sendMail(doctor, hospital); //?? } hisResponse.setBody(map); } else { hisResponse.setErrorCode(401); } } catch (Exception e) { e.printStackTrace(); } return hisResponse.toString(); }