List of usage examples for java.text DecimalFormat setMaximumFractionDigits
@Override public void setMaximumFractionDigits(int newValue)
From source file:ca.ualberta.cmput301w14t08.geochan.fragments.ThreadViewFragment.java
/** * When comment is selected, additional information is displayed in the form * of location coordinates and action buttons. * This method sets that location field TextView in * the view./*from w ww. jav a 2s . c om*/ * * @param view The View of the Comment that was selected. * @param comment The Comment itself that was selected by the user. */ public void setLocationField(View view, Comment comment) { TextView replyLocationText = (TextView) view.findViewById(R.id.thread_view_comment_location); GeoLocation repLocCom = comment.getLocation(); if (repLocCom != null) { if (repLocCom.getLocationDescription() != null) { replyLocationText.setText("near: " + repLocCom.getLocationDescription()); } else { DecimalFormat format = new DecimalFormat(); format.setRoundingMode(RoundingMode.HALF_EVEN); format.setMinimumFractionDigits(0); format.setMaximumFractionDigits(4); replyLocationText.setText("Latitude: " + format.format(repLocCom.getLatitude()) + " Longitude: " + format.format(repLocCom.getLongitude())); } } else { replyLocationText.setText("Error: No location found"); } }
From source file:ca.ualberta.cmput301w14t08.geochan.adapters.ThreadViewAdapter.java
/** * Sets the required fields of the orignal post of the thread. * Title, creator, comment, timestamp, location. * /* ww w.j av a2 s. c om*/ * @param convertView * View container of a listView item. */ private void setOPFields(View convertView) { // Thread title TextView title = (TextView) convertView.findViewById(R.id.thread_view_op_threadTitle); // Special case of Viewing a Favourite Comment in ThreadView if (thread.getTitle().equals("")) { title.setVisibility(View.GONE); LinearLayout buttons = (LinearLayout) convertView.findViewById(R.id.thread_view_op_buttons); buttons.setVisibility(View.GONE); } else { title.setText(thread.getTitle()); } // Thread creator TextView threadBy = (TextView) convertView.findViewById(R.id.thread_view_op_commentBy); threadBy.setText( "Posted by " + thread.getBodyComment().getUser() + "#" + thread.getBodyComment().getHash() + " "); if (HashHelper.getHash(thread.getBodyComment().getUser()).equals(thread.getBodyComment().getHash())) { threadBy.setBackgroundResource(R.drawable.username_background_thread_rect); threadBy.setTextColor(Color.WHITE); } // Thread body comment TextView body = (TextView) convertView.findViewById(R.id.thread_view_op_commentBody); body.setText(thread.getBodyComment().getTextPost()); // Thread timestamp TextView threadTime = (TextView) convertView.findViewById(R.id.thread_view_op_commentDate); threadTime.setText(thread.getBodyComment().getCommentDateString()); // Location text TextView origPostLocationText = (TextView) convertView.findViewById(R.id.thread_view_op_locationText); GeoLocation loc = thread.getBodyComment().getLocation(); String locDescriptor = loc.getLocationDescription(); if (loc != null) { if (locDescriptor != null) { origPostLocationText.setText("near: " + locDescriptor); } else { // The rounding of long and lat for max 4 decimal digits. DecimalFormat format = new DecimalFormat(); format.setRoundingMode(RoundingMode.HALF_EVEN); format.setMinimumFractionDigits(0); format.setMaximumFractionDigits(4); origPostLocationText.setText("Latitude: " + format.format(loc.getLatitude()) + " Longitude: " + format.format(loc.getLongitude())); } } // Set the thumbnail if there is an image if (thread.getBodyComment().hasImage()) { ImageButton thumbnail = (ImageButton) convertView.findViewById(R.id.thread_view_comment_thumbnail); thumbnail.setVisibility(View.VISIBLE); thumbnail.setFocusable(false); thumbnail.setImageBitmap(thread.getBodyComment().getImageThumb()); } }
From source file:gov.redhawk.statistics.ui.views.StatisticsView.java
private void updateStatsLabels(int i) { int showIndex = i; if (datalist.length == 1) { showIndex = 0;/*from ww w . j a va2 s . c om*/ } Stats s; if (showIndex < 0) { s = magnitudeStats; } else { s = stats[showIndex]; } for (int j = 0; j < STAT_PROPS.length; j++) { DecimalFormat form; double value = s.getStat(STAT_PROPS[j]).doubleValue(); if (STAT_PROPS[j].equals(Stats.NUM)) { form = new DecimalFormat(); } else if (value != 0 && (Math.abs(value) * 10 < 1 || Math.abs(value) / 10 > 99)) { form = new DecimalFormat("0.0#E0"); } else { form = new DecimalFormat(); form.setMaximumFractionDigits(3); form.setMaximumIntegerDigits(2); } labels[j].setText(form.format(value)); } section.setDescription(getCategoryName(showIndex)); }
From source file:org.glom.web.server.ReportGenerator.java
/** * @param x/*from w ww.j a v a 2 s . c om*/ * @param libglomLayoutItemField * @return */ private JRDesignTextField createFieldValueElement(final Position pos, final LayoutItemField libglomLayoutItemField) { final JRDesignTextField textField = new JRDesignTextField(); // Make sure this field starts at the right of the previous field, // because JasperReports uses absolute positioning. textField.setY(pos.y); textField.setX(pos.x); textField.setWidth(width); // No data will be shown without this. // This only stretches vertically, but that is better than // nothing. textField.setStretchWithOverflow(true); textField.setHeight(height); // We must specify _some_ height. final JRDesignExpression expression = createFieldExpression(libglomLayoutItemField); textField.setExpression(expression); if (libglomLayoutItemField.getGlomType() == GlomFieldType.TYPE_NUMERIC) { // Numeric formatting: final Formatting formatting = libglomLayoutItemField.getFormattingUsed(); final NumericFormat numericFormat = formatting.getNumericFormat(); final DecimalFormat format = new DecimalFormat(); format.setMaximumFractionDigits(numericFormat.getDecimalPlaces()); format.setGroupingUsed(numericFormat.getUseThousandsSeparator()); // TODO: Use numericFormat.get_currency_symbol(), possibly via format.setCurrency(). textField.setPattern(format.toPattern()); } else if (libglomLayoutItemField.getGlomType() == GlomFieldType.TYPE_DATE) { // Date formatting // TODO: Use a 4-digit-year short form, somehow. try // We use a try block because getDateInstance() is not guaranteed to return a SimpleDateFormat. { final SimpleDateFormat format = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, Locale.ROOT); textField.setPattern(format.toPattern()); } catch (final Exception ex) { Log.info("ReportGenerator: The cast of SimpleDateFormat failed."); } } else if (libglomLayoutItemField.getGlomType() == GlomFieldType.TYPE_TIME) { // Time formatting try // We use a try block because getDateInstance() is not guaranteed to return a SimpleDateFormat. { final SimpleDateFormat format = (SimpleDateFormat) DateFormat.getTimeInstance(DateFormat.SHORT, Locale.ROOT); textField.setPattern(format.toPattern()); } catch (final Exception ex) { Log.info("ReportGenerator: The cast of SimpleDateFormat failed."); } } return textField; }
From source file:dbseer.gui.panel.DBSeerMiddlewarePanel.java
private void initializeGUI() { this.setLayout(new MigLayout()); JLabel ipAddressLabel = new JLabel("IP Address:"); JLabel portLabel = new JLabel("Port:"); JLabel idLabel = new JLabel("ID:"); JLabel passwordLabel = new JLabel("Password:"); ipField = new JTextField(20); DecimalFormat portFormatter = new DecimalFormat(); portFormatter.setMaximumFractionDigits(0); portFormatter.setMaximumIntegerDigits(5); portFormatter.setMinimumIntegerDigits(1); portFormatter.setDecimalSeparatorAlwaysShown(false); portFormatter.setGroupingUsed(false); portField = new JFormattedTextField(portFormatter); portField.setColumns(6);/* w w w .j a v a 2s .c om*/ portField.setText("3555"); // default port. idField = new JTextField(20); passwordField = new JPasswordField(20); logInOutButton = new JButton("Login"); logInOutButton.addActionListener(this); startMonitoringButton = new JButton("Start Monitoring"); startMonitoringButton.addActionListener(this); stopMonitoringButton = new JButton("Stop Monitoring"); stopMonitoringButton.addActionListener(this); startMonitoringButton.setEnabled(true); stopMonitoringButton.setEnabled(false); ipField.setText(DBSeerGUI.userSettings.getLastMiddlewareIP()); portField.setText(String.valueOf(DBSeerGUI.userSettings.getLastMiddlewarePort())); idField.setText(DBSeerGUI.userSettings.getLastMiddlewareID()); NumberFormatter formatter = new NumberFormatter(NumberFormat.getIntegerInstance()); formatter.setMinimum(1); formatter.setMaximum(120); formatter.setAllowsInvalid(false); refreshRateLabel = new JLabel("Monitoring Refresh Rate:"); refreshRateField = new JFormattedTextField(formatter); JLabel refreshRateRangeLabel = new JLabel("(1~120 sec)"); refreshRateField.setText("1"); applyRefreshRateButton = new JButton("Apply"); applyRefreshRateButton.addActionListener(this); this.add(ipAddressLabel, "cell 0 0 2 1, split 4"); this.add(ipField); this.add(portLabel); this.add(portField); this.add(idLabel, "cell 0 2"); this.add(idField, "cell 1 2"); this.add(passwordLabel, "cell 0 3"); this.add(passwordField, "cell 1 3"); this.add(refreshRateLabel, "cell 0 4"); this.add(refreshRateField, "cell 1 4, growx, split 3"); this.add(refreshRateRangeLabel); this.add(applyRefreshRateButton, "growx, wrap"); // this.add(logInOutButton, "cell 0 2 2 1, growx, split 3"); this.add(startMonitoringButton); this.add(stopMonitoringButton); }
From source file:keel.GraphInterKeel.datacf.visualizeData.VisualizePanelAttribute.java
private void infoAttribute() { this.enabledTable(true); // Extended info about selected attribute if (((VisualizePanel) this.getParent().getParent()).getData() .getAttributeTypeIndex(this.tableInfojTable.getSelectedRow()).equals("nominal")) { this.valuesjScrollPane.setEnabled(true); this.valuesjScrollPane.setVisible(true); this.valuesjTextPane.setEnabled(true); this.valuesjTextPane.setVisible(true); Vector r = ((VisualizePanel) this.getParent().getParent()).getData() .getRangesVar(((VisualizePanel) this.getParent().getParent()).getData() .getAttributeIndex(this.tableInfojTable.getSelectedRow())); this.valuesjTextPane.setText(""); this.valueAveragejLabel.setText(""); this.valueVariancejLabel.setText(""); this.valueRankjLabelIzdo.setText(" "); this.valueRankjLabelDcho.setText(" "); String cadena = new String(); for (int i = 0; i < r.size(); i++) { if (i == 0) { cadena = r.elementAt(i).toString() + ""; this.valuesjTextPane.setText(cadena); } else { cadena = this.valuesjTextPane.getText() + "\n" + r.elementAt(i).toString(); }//from w w w. j av a2 s.c o m this.valuesjTextPane.setText(cadena); } boolean legend = false; // Draw bar chart DefaultCategoryDataset dataset = new DefaultCategoryDataset(); try { for (int i = 0; i < ((VisualizePanel) this.getParent().getParent()).getData().getNData(); i++) { String column = ((VisualizePanel) this.getParent().getParent()).getData().getDataIndex(i, this.tableInfojTable.getSelectedRow()); String row = ""; if (((VisualizePanel) this.getParent().getParent()).getOutAttribute() != -1 && this.tableInfojTable .getSelectedRow() != ((VisualizePanel) this.getParent().getParent()) .getOutAttribute()) { row = "Class " + ((VisualizePanel) this.getParent().getParent()).getData().getDataIndex(i, ((VisualizePanel) this.getParent().getParent()).getOutAttribute()); legend = true; } if (column != null) { if (dataset.getRowIndex(row) == -1 || ((dataset.getColumnIndex(column) == -1))) { dataset.addValue(1.0, row, column); } else { dataset.incrementValue(1.0, row, column); } } } } catch (ArrayIndexOutOfBoundsException exp) { JOptionPane.showMessageDialog(this, "The data set contains some errors. This attribute can not be visualized", "Error", 2); } this.chart = ChartFactory.createBarChart3D("", "", "", dataset, PlotOrientation.VERTICAL, legend, false, false); this.chart.setBackgroundPaint(new Color(0xFFFFFF)); //BufferedImage image = this.chart.createBufferedImage(210, 140); BufferedImage image = this.chart.createBufferedImage(400, 240); this.imagejLabel.setIcon(new ImageIcon(image)); this.clickToExpandjLabel.setVisible(true); } else { this.valuesjScrollPane.setEnabled(false); this.valuesjScrollPane.setVisible(false); this.valuesjTextPane.setEnabled(false); this.valuesjTextPane.setVisible(false); Vector r = ((VisualizePanel) this.getParent().getParent()).getData() .getRangesVar(((VisualizePanel) this.getParent().getParent()).getData() .getAttributeIndex(this.tableInfojTable.getSelectedRow())); this.valueRankjLabelIzdo.setText(r.elementAt(0).toString()); this.valueRankjLabelDcho.setText(r.elementAt(1).toString()); // Average double m = 0.0; for (int i = 0; i < ((VisualizePanel) this.getParent().getParent()).getData().getNData(); i++) { String valor = ((VisualizePanel) this.getParent().getParent()).getData().getDataIndex(i, this.tableInfojTable.getSelectedRow()); if (valor != null) { m += Double.valueOf(valor).doubleValue(); } } m = m / ((VisualizePanel) this.getParent().getParent()).getData().getNData(); DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(3); this.valueAveragejLabel.setText(df.format(m)); // Variance double v = 0.0; for (int i = 0; i < ((VisualizePanel) this.getParent().getParent()).getData().getNData(); i++) { String valor = ((VisualizePanel) this.getParent().getParent()).getData().getDataIndex(i, this.tableInfojTable.getSelectedRow()); if (valor != null) { v += Math.pow(Double.valueOf(valor).doubleValue() - m, 2); } } v = v / (((VisualizePanel) this.getParent().getParent()).getData().getNData() - 1); this.valueVariancejLabel.setText(df.format(v)); // Draw scatter plot XYSeriesCollection juegoDatos = new XYSeriesCollection(); boolean legend = false; if (((VisualizePanel) this.getParent().getParent()).getOutAttribute() != -1) { Vector outputRang = ((VisualizePanel) this.getParent().getParent()).getData() .getRange(((VisualizePanel) this.getParent().getParent()).getOutAttribute()); XYSeries series[] = new XYSeries[outputRang.size()]; for (int i = 0; i < outputRang.size(); i++) { series[i] = new XYSeries("Class " + outputRang.elementAt(i)); juegoDatos.addSeries(series[i]); } for (int i = 0; i < ((VisualizePanel) this.getParent().getParent()).getData().getNData(); i++) { int clase = outputRang.indexOf(((VisualizePanel) this.getParent().getParent()).getData() .getDataIndex(i, ((VisualizePanel) this.getParent().getParent()).getOutAttribute())); String valor = ((VisualizePanel) this.getParent().getParent()).getData().getDataIndex(i, this.tableInfojTable.getSelectedRow()); if (valor != null) { series[clase].add(Double.parseDouble(Integer.toString(i)), Double.valueOf(valor).doubleValue()); } } legend = true; } else { XYSeries series = new XYSeries("Regresin"); juegoDatos.addSeries(series); for (int i = 0; i < ((VisualizePanel) this.getParent().getParent()).getData().getNData(); i++) { String valor = ((VisualizePanel) this.getParent().getParent()).getData().getDataIndex(i, this.tableInfojTable.getSelectedRow()); if (valor != null) { series.add(Double.parseDouble(Integer.toString(i)), Double.valueOf(valor).doubleValue()); } } } chart = ChartFactory.createScatterPlot("", "", "", juegoDatos, PlotOrientation.VERTICAL, legend, false, false); chart.setBackgroundPaint(new Color(0xFFFFFF)); //BufferedImage image = chart.createBufferedImage(210, 140); BufferedImage image = chart.createBufferedImage(400, 240); this.imagejLabel.setIcon(new ImageIcon(image)); this.clickToExpandjLabel.setVisible(true); } }
From source file:org.totschnig.myexpenses.util.Utils.java
/** * @param currency/*from w ww . j a va2s .c om*/ * @param separator * @return a Decimalformat with the number of fraction digits appropriate for * currency, and with the given separator, but without the currency * symbol appropriate for CSV and QIF export */ public static DecimalFormat getDecimalFormat(Currency currency, char separator) { DecimalFormat nf = new DecimalFormat(); DecimalFormatSymbols symbols = new DecimalFormatSymbols(); symbols.setDecimalSeparator(separator); nf.setDecimalFormatSymbols(symbols); int fractionDigits = currency.getDefaultFractionDigits(); if (fractionDigits != -1) { nf.setMinimumFractionDigits(fractionDigits); nf.setMaximumFractionDigits(fractionDigits); } else { nf.setMaximumFractionDigits(Money.DEFAULTFRACTIONDIGITS); } nf.setGroupingUsed(false); return nf; }
From source file:org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FSAppAttempt.java
private boolean reservationExceedsThreshold(FSSchedulerNode node, NodeType type) { // Only if not node-local if (type != NodeType.NODE_LOCAL) { int existingReservations = getNumReservations(node.getRackName(), type == NodeType.OFF_SWITCH); int totalAvailNodes = (type == NodeType.OFF_SWITCH) ? scheduler.getNumClusterNodes() : scheduler.getNumNodesInRack(node.getRackName()); int numAllowedReservations = (int) Math.ceil(totalAvailNodes * scheduler.getReservableNodesRatio()); if (existingReservations >= numAllowedReservations) { DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(2); if (LOG.isDebugEnabled()) { LOG.debug("Reservation Exceeds Allowed number of nodes:" + " app_id=" + getApplicationId() + " existingReservations=" + existingReservations + " totalAvailableNodes=" + totalAvailNodes + " reservableNodesRatio=" + df.format(scheduler.getReservableNodesRatio()) + " numAllowedReservations=" + numAllowedReservations); }/*from w ww . ja va 2s . co m*/ return true; } } return false; }
From source file:streamme.visuals.Main.java
@Override public void onDownloadPart(int part) { DecimalFormat df = new DecimalFormat("0.00"); df.setMaximumFractionDigits(2); float mb = part * Options.FRAGMENT_SIZE / 1048576.f; if (totalParts < 0) { this.download_progress.setText(df.format(mb) + " MB"); } else {//from w w w. java 2 s . co m float tmb = totalParts * Options.FRAGMENT_SIZE / 1048576.f; this.download_progress .setText(df.format(mb) + " MB/" + df.format(tmb) + " MB (" + part * 100 / totalParts + "%)"); } }
From source file:streamme.visuals.Main.java
@Override public void onDownloadStart(int initPart, int totalParts) { DecimalFormat df = new DecimalFormat("0.00"); df.setMaximumFractionDigits(2); this.totalParts = totalParts; float mb = initPart * Options.FRAGMENT_SIZE / 1048576.f; if (totalParts < 0) { this.download_progress.setText(df.format(mb) + " MB"); } else {/*from w ww. j ava 2 s. c om*/ float tmb = totalParts * Options.FRAGMENT_SIZE / 1048576.f; this.download_progress.setText( df.format(mb) + " MB/" + df.format(tmb) + " MB (" + initPart * 100 / totalParts + "%)"); } this.message.setText("Downloading..."); }