protected void out(double[] y) { String s, blanks, blanksp, blanksm; blanksp = " "; blanksm = " "; int ny = y.length; int nlines = ny / 5; int nrest = ny % 5; for (int i = 0; i < nlines; i++) { s = ""; for (int j = 0; j < 5; j++) { int k = i * 5 + j; if (y[k] >= 0.) blanks = blanksp; else blanks = blanksm; s = s + blanks + numForm.format(y[k]); } df.writeLine(s); } if (nrest > 0) { s = ""; for (int j = 0; j < nrest; j++) { int k = nlines * 5 + j; if (y[k] >= 0.) blanks = blanksp; else blanks = blanksm; s = s + blanks + numForm.format(y[k]); } df.writeLine(s); } }
protected void plotScatterDiagram() { // plot sample as one dimensional scatter plot and Gaussian double xmax = 5.; double xmin = -5.; DatanGraphics.openWorkstation(getClass().getName(), "E3Min_1.ps"); DatanGraphics.setFormat(0., 0.); DatanGraphics.setWindowInComputingCoordinates(xmin, xmax, 0., .5); DatanGraphics.setViewportInWorldCoordinates(-.15, .9, .16, .86); DatanGraphics.setWindowInWorldCoordinates(-.414, 1., 0., 1.); DatanGraphics.setBigClippingWindow(); DatanGraphics.chooseColor(2); DatanGraphics.drawFrame(); DatanGraphics.drawScaleX("y"); DatanGraphics.drawScaleY("f(y)"); DatanGraphics.drawBoundary(); double xpl[] = new double[2]; double ypl[] = new double[2]; // plot scatter diagram DatanGraphics.chooseColor(1); for (int i = 0; i < y.length; i++) { xpl[0] = y[i]; xpl[1] = y[i]; ypl[0] = 0.; ypl[0] = .1; DatanGraphics.drawPolyline(xpl, ypl); } // draw Gaussian corresponding to solution int npl = 100; xpl = new double[npl]; ypl = new double[npl]; double fact = 1. / (Math.sqrt(2. * Math.PI) * x.getElement(1)); double dpl = (xmax - xmin) / (double) (npl - 1); for (int i = 0; i < npl; i++) { xpl[i] = xmin + (double) i * dpl; ypl[i] = fact * Math.exp(-.5 * Math.pow((xpl[i] - x.getElement(0)) / x.getElement(1), 2.)); } DatanGraphics.chooseColor(5); DatanGraphics.drawPolyline(xpl, ypl); // draw caption String sn = "N = " + nny; numForm.setMaximumFractionDigits(3); numForm.setMinimumFractionDigits(3); String sx1 = ", x_1# = " + numForm.format(x.getElement(0)); String sx2 = ", x_2# = " + numForm.format(x.getElement(1)); String sdx1 = ", &D@x_1# = " + numForm.format(Math.sqrt(cx.getElement(0, 0))); String sdx2 = ", &D@x_2# = " + numForm.format(Math.sqrt(cx.getElement(1, 1))); caption = sn + sx1 + sx2 + sdx1 + sdx2; DatanGraphics.setBigClippingWindow(); DatanGraphics.chooseColor(2); DatanGraphics.drawCaption(1., caption); DatanGraphics.closeWorkstation(); }
/** A class to render numbers in scientific format. */ class ScientificRenderer extends JLabel implements TableCellRenderer { NumberFormat format = NumberFormat.getInstance(); public ScientificRenderer(int sigfigs) { sigfigs = Math.min(sigfigs, 6); if (format instanceof DecimalFormat) { String pattern = "0.0"; // $NON-NLS-1$ for (int i = 0; i < sigfigs - 1; i++) { pattern += "0"; // $NON-NLS-1$ } pattern += "E0"; // $NON-NLS-1$ ((DecimalFormat) format).applyPattern(pattern); } } public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { setFont( getDefaultRenderer(String.class) .getTableCellRendererComponent(DatasetStatisticsTable.this, "a", false, false, 0, 0) .getFont()); //$NON-NLS-1$ setText(format.format(value)); setHorizontalAlignment(SwingConstants.TRAILING); return this; } }
public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { setFont( getDefaultRenderer(String.class) .getTableCellRendererComponent(DatasetStatisticsTable.this, "a", false, false, 0, 0) .getFont()); //$NON-NLS-1$ setText(format.format(value)); setHorizontalAlignment(SwingConstants.TRAILING); return this; }
public E3Min() { numForm = NumberFormat.getNumberInstance(Locale.US); numForm.setMaximumFractionDigits(12); numForm.setMinimumFractionDigits(12); String s = "Example demonstrating the use of class MinAsy by fitting a Gaussian to small sample" + " and determining the asymmetric errors of parameters by MinAsy"; df = new DatanFrame(getClass().getName(), s); AuxJInputGroup ig = new AuxJInputGroup("Enter number N of events (>= 2, <= 10000)", ""); JLabel errorLabel = new JLabel(); ni[0] = new AuxJNumberInput("N", "number of events", errorLabel); ig.add(ni[0]); ni[0].setProperties("N", true); ni[0].setMinimum(2); ni[0].setMaximum(10000); ni[0].setNumberInTextField(10); df.add(ig); df.add(errorLabel); JButton goButton = new JButton("Go"); GoButtonListener gl = new GoButtonListener(); goButton.addActionListener(gl); df.add(goButton); df.repaint(); }
private static Object formatBigDecimal(Object number, Locale locale) { NumberFormat nf = NumberFormat.getNumberInstance(locale); nf.setMinimumFractionDigits(2); return nf.format(number); }
public MainCitiesCriteriaPanel() { super(new BorderLayout()); CountryController countryc = Application.getCountryController(); CitiesController citiesc = Application.getCitiesController(); countryName = Application.getCountryName(); label = new JLabel(); labelPanel = new JPanel(); labelPanel.add(label); label.setText("Criteria to select main cities for " + countryName.replaceAll("_", " ")); listModel = new DefaultListModel(); Iterator<HashMap<String, String>> iter = citiesc.getToponymTypesIterator(); while (iter.hasNext()) { String topTypeName = iter.next().get("code"); listModel.addElement(topTypeName); } list = new JList(listModel); list.addListSelectionListener(this); listPanel = new JScrollPane(list); NumberFormat nCitiesFormat = NumberFormat.getInstance(); nCitiesFormat.setMaximumFractionDigits(0); nCitiesFormat.setMaximumIntegerDigits(4); NumberFormat distFormat = NumberFormat.getInstance(); distFormat.setMaximumFractionDigits(0); distFormat.setMaximumIntegerDigits(3); nCitiesField = new JFormattedTextField(nCitiesFormat); distField = new JFormattedTextField(distFormat); nCitiesField.setMaximumSize(new Dimension(50, 1)); distField.setMaximumSize(new Dimension(50, 1)); rb1 = new JRadioButton("Filter by type", true); rb2 = new JRadioButton("Filter by number", false); rb3 = new JRadioButton("Filter by distance to the borders (km)", false); ButtonGroup bgroup = new ButtonGroup(); bgroup.add(rb1); bgroup.add(rb2); bgroup.add(rb3); JPanel radioPanel = new JPanel(); radioPanel.setLayout(new BoxLayout(radioPanel, BoxLayout.Y_AXIS)); radioPanel.add(rb1); radioPanel.add(listPanel); radioPanel.add(rb2); radioPanel.add(nCitiesField); radioPanel.add(rb3); radioPanel.add(distField); submit = new JButton(); back = new JButton(); submit.setText("OK"); back.setText("GO BACK"); submit.addActionListener(this); back.addActionListener(this); buttonPanel = new JPanel(); buttonPanel.add(back); buttonPanel.add(submit); add(labelPanel, BorderLayout.NORTH); add(radioPanel, BorderLayout.CENTER); add(buttonPanel, BorderLayout.SOUTH); }