コード例 #1
0
  private void refresh() {
    guiCount.setText(String.valueOf(analyze.getCount()));
    guiSum.setText(FORMAT.format(analyze.getSum()));
    guiMinimum.setText(FORMAT.format(analyze.getMinimum()));
    guiMaximum.setText(FORMAT.format(analyze.getMaximum()));
    guiMean.setText(FORMAT.format(analyze.getMean()));
    guiMedian.setText(FORMAT.format(analyze.getMedian()));

    guiChart.removeAll();
    guiChart.add(new ChartPanel(getChart((Integer) guiDivision.getModel().getValue())));

    double[] values = analyze.getValues();
    Double[][] vals = new Double[values.length][1];

    for (int i = 0; i < values.length; i++) {
      vals[i][0] = values[i];
    }

    guiTable.setTableHeader(null);
    guiTable.setModel(
        new DefaultTableModel(vals, new String[] {""}) {

          @Override
          public Class<?> getColumnClass(int columnIndex) {
            return Double.class;
          }
        });
    guiTable.setShowGrid(false, false);
    guiTable.setHighlighters(
        new Highlighter[] {
          HighlighterFactory.createAlternateStriping(Color.white, HighlighterFactory.QUICKSILVER, 1)
        });
    guiTable.revalidate();
    guiTable.repaint();

    guiTable.setEditable(analyze.getMethod() == METHOD.MANUAL);

    guiTable
        .getModel()
        .addTableModelListener(
            new TableModelListener() {

              @Override
              public void tableChanged(TableModelEvent e) {
                double[] values = new double[guiTable.getModel().getRowCount()];
                for (int i = 0; i < values.length; i++) {
                  values[i] = Double.valueOf(guiTable.getModel().getValueAt(i, 0).toString());
                }

                analyze.setValues(values);
              }
            });

    guiMethod.setSelectedItem(analyze.getMethod());
  }
コード例 #2
0
  public JFreeChart getChart(final int nbDivision) {
    XYSeries series = new XYSeries("Data");

    double before = analyze.getMinimum();
    for (float i = 1; i <= nbDivision; i++) {
      final double localmin = before;
      final double localmax =
          analyze.getMinimum() + (i / nbDivision) * (analyze.getMaximum() - analyze.getMinimum());
      before = localmax;
      long localsum = 0;

      for (Double d : analyze.getAllValues()) {
        if (i == 100) {
          // last element
          if (d >= localmin && d <= localmax) {
            localsum++;
          }
        } else {
          if (d >= localmin && d < localmax) {
            localsum++;
          }
        }
      }
      series.add(analyze.getMinimum() + (localmin + localmax) / 2, localsum);
    }

    XYSeriesCollection dataset = new XYSeriesCollection(series);

    JFreeChart chart =
        ChartFactory.createXYBarChart(
            "", "", false, "", dataset, PlotOrientation.VERTICAL, false, false, false);

    XYPlot plot = chart.getXYPlot();
    ((XYBarRenderer) plot.getRenderer()).setShadowVisible(false);
    ((XYBarRenderer) plot.getRenderer()).setUseYInterval(false);
    ((XYBarRenderer) plot.getRenderer()).setMargin(0);

    chart.getPlot().setBackgroundAlpha(0);
    chart.setBackgroundPaint(new Color(0f, 0f, 0f, 0f));

    return chart;
  }