List of usage examples for java.text DecimalFormat setMinimumIntegerDigits
@Override public void setMinimumIntegerDigits(int newValue)
From source file:org.clueminer.chameleon.GraphPropertyStore.java
public void printFancy(int w, int d) { DecimalFormat format = new DecimalFormat(); format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); format.setMinimumIntegerDigits(1); format.setMaximumFractionDigits(d);/*from w w w . j a va 2s . com*/ format.setMinimumFractionDigits(d); format.setGroupingUsed(false); printFancy(new PrintWriter(System.out, true), format, w + 2); }
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);/*from ww w . j ava 2 s . co m*/ 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:Matrix.java
/** * Print the matrix to the output stream. Line the elements up in columns * with a Fortran-like 'Fw.d' style format. * /*from w w w . ja v a2 s . c o m*/ * @param output * Output stream. * @param w * Column width. * @param d * Number of digits after the decimal. */ public void print(PrintWriter output, int w, int d) { DecimalFormat format = new DecimalFormat(); format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); format.setMinimumIntegerDigits(1); format.setMaximumFractionDigits(d); format.setMinimumFractionDigits(d); format.setGroupingUsed(false); print(output, format, w + 2); }
From source file:com.eveningoutpost.dexdrip.Home.java
private void handleWordPair() { boolean preserve = false; if ((thisnumber == -1) || (thisword == "")) return;/*from w w w. ja va 2s .co m*/ Log.d(TAG, "GOT WORD PAIR: " + thisnumber + " = " + thisword); switch (thisword) { case "rapid": if ((insulinset == false) && (thisnumber > 0)) { thisinsulinnumber = thisnumber; textInsulinDose.setText(Double.toString(thisnumber) + " units"); Log.d(TAG, "Rapid dose: " + Double.toString(thisnumber)); insulinset = true; btnInsulinDose.setVisibility(View.VISIBLE); textInsulinDose.setVisibility(View.VISIBLE); } else { Log.d(TAG, "Rapid dose already set"); preserve = true; } break; case "carbs": if ((carbsset == false) && (thisnumber > 0)) { thiscarbsnumber = thisnumber; textCarbohydrates.setText(Integer.toString((int) thisnumber) + " carbs"); carbsset = true; Log.d(TAG, "Carbs eaten: " + Double.toString(thisnumber)); btnCarbohydrates.setVisibility(View.VISIBLE); textCarbohydrates.setVisibility(View.VISIBLE); } else { Log.d(TAG, "Carbs already set"); preserve = true; } break; case "blood": if ((glucoseset == false) && (thisnumber > 0)) { thisglucosenumber = thisnumber; if (prefs.getString("units", "mgdl").equals("mgdl")) { if (textBloodGlucose != null) textBloodGlucose.setText(Double.toString(thisnumber) + " mg/dl"); } else { if (textBloodGlucose != null) textBloodGlucose.setText(Double.toString(thisnumber) + " mmol/l"); } Log.d(TAG, "Blood test: " + Double.toString(thisnumber)); glucoseset = true; if (textBloodGlucose != null) { btnBloodGlucose.setVisibility(View.VISIBLE); textBloodGlucose.setVisibility(View.VISIBLE); } } else { Log.d(TAG, "Blood glucose already set"); preserve = true; } break; case "time": Log.d(TAG, "processing time keyword"); if ((timeset == false) && (thisnumber >= 0)) { final NumberFormat nf = NumberFormat.getNumberInstance(Locale.US); final DecimalFormat df = (DecimalFormat) nf; //DecimalFormat df = new DecimalFormat("#"); df.setMinimumIntegerDigits(2); df.setMinimumFractionDigits(2); df.setMaximumFractionDigits(2); df.setMaximumIntegerDigits(2); final Calendar c = Calendar.getInstance(); final SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("dd/M/yyyy ", Locale.US); final SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("dd/M/yyyy HH.mm", Locale.US); // TODO double check 24 hour 12.00 etc final String datenew = simpleDateFormat1.format(c.getTime()) + df.format(thisnumber); Log.d(TAG, "Time Timing data datenew: " + datenew); final Date datethen; final Date datenow = new Date(); try { datethen = simpleDateFormat2.parse(datenew); double difference = datenow.getTime() - datethen.getTime(); // is it more than 1 hour in the future? If so it must be yesterday if (difference < -(1000 * 60 * 60)) { difference = difference + (86400 * 1000); } else { // - midnight feast pre-bolus nom nom if (difference > (60 * 60 * 23 * 1000)) difference = difference - (86400 * 1000); } Log.d(TAG, "Time Timing data: " + df.format(thisnumber) + " = difference ms: " + JoH.qs(difference)); textTime.setText(df.format(thisnumber)); timeset = true; thistimeoffset = difference; btnTime.setVisibility(View.VISIBLE); textTime.setVisibility(View.VISIBLE); } catch (ParseException e) { // toast to explain? Log.d(TAG, "Got exception parsing date time"); } } else { Log.d(TAG, "Time data already set"); preserve = true; } break; } // end switch if (preserve == false) { Log.d(TAG, "Clearing speech values"); thisnumber = -1; thisword = ""; } else { Log.d(TAG, "Preserving speech values"); } // don't show approve/cancel if we only have time if (insulinset || glucoseset || carbsset) { btnApprove.setVisibility(View.VISIBLE); btnCancel.setVisibility(View.VISIBLE); if (small_screen) { final float button_scale_factor = 0.60f; ((ViewGroup.MarginLayoutParams) btnApprove.getLayoutParams()).leftMargin = 0; ((ViewGroup.MarginLayoutParams) btnBloodGlucose.getLayoutParams()).leftMargin = 0; ((ViewGroup.MarginLayoutParams) btnBloodGlucose.getLayoutParams()).setMarginStart(0); ((ViewGroup.MarginLayoutParams) btnCancel.getLayoutParams()).setMarginStart(0); ((ViewGroup.MarginLayoutParams) btnApprove.getLayoutParams()).rightMargin = 0; ((ViewGroup.MarginLayoutParams) btnCancel.getLayoutParams()).rightMargin = 0; btnApprove.setScaleX(button_scale_factor); btnApprove.setScaleY(button_scale_factor); btnCancel.setScaleX(button_scale_factor); btnCancel.setScaleY(button_scale_factor); btnInsulinDose.setScaleX(button_scale_factor); btnCarbohydrates.setScaleX(button_scale_factor); btnCarbohydrates.setScaleY(button_scale_factor); btnBloodGlucose.setScaleX(button_scale_factor); btnBloodGlucose.setScaleY(button_scale_factor); btnInsulinDose.setScaleY(button_scale_factor); btnTime.setScaleX(button_scale_factor); btnTime.setScaleY(button_scale_factor); final int small_text_size = 12; textCarbohydrates.setTextSize(small_text_size); textInsulinDose.setTextSize(small_text_size); textBloodGlucose.setTextSize(small_text_size); textTime.setTextSize(small_text_size); } } if (insulinset || glucoseset || carbsset || timeset) { if (chart != null) { chart.setAlpha((float) 0.10); } WatchUpdaterService.sendTreatment(thiscarbsnumber, thisinsulinnumber, thisglucosenumber, thistimeoffset, textTime.getText().toString()); } }