Exemplo n.º 1
0
  public int showDialog(JChart chart) {

    JOptionPane optionPane =
        new JOptionPane(
            optionPanel,
            JOptionPane.QUESTION_MESSAGE,
            JOptionPane.OK_CANCEL_OPTION,
            null,
            null,
            null);
    optionPane.setBorder(new EmptyBorder(12, 12, 12, 12));

    Axis xAxis = chart.getXAxis();
    Axis yAxis = chart.getYAxis();

    if (canLogXAxis) {
      logXAxis.setSelected(xAxis instanceof LogAxis);
    }

    if (canLogYAxis) {
      logYAxis.setSelected(yAxis instanceof LogAxis);
    }

    if (!manualXAxis.isSelected()) {
      minXValue.setValue(xAxis.getMinAxis());
      maxXValue.setValue(xAxis.getMaxAxis());
    }

    if (!manualYAxis.isSelected()) {
      minYValue.setValue(yAxis.getMinAxis());
      maxYValue.setValue(yAxis.getMaxAxis());
    }

    final JDialog dialog = optionPane.createDialog(frame, "Setup Chart");
    dialog.pack();

    dialog.setVisible(true);

    final Integer value = (Integer) optionPane.getValue();
    final int result = (value != null && value != -1) ? value : JOptionPane.CANCEL_OPTION;

    if (result == JOptionPane.OK_OPTION) {
      applySettings(chart);
    }

    return result;
  }
Exemplo n.º 2
0
  public void applySettings(JChart chart) {
    Axis xAxis = chart.getXAxis();
    Axis yAxis = chart.getYAxis();

    if (canLogXAxis) {
      if (logXAxis.isSelected()) {
        xAxis = new LogAxis();
      } else {
        xAxis = new LinearAxis();
      }
      chart.setXAxis(xAxis);
    }

    if (manualXAxis.isSelected()) {
      xAxis.setManualRange(minXValue.getValue(), maxXValue.getValue());
      xAxis.setAxisFlags(Axis.AT_VALUE, Axis.AT_VALUE);
    } else {
      xAxis.setAxisFlags(defaultMinXAxisFlag, defaultMaxXAxisFlag);
    }

    if (canLogYAxis) {
      if (logYAxis.isSelected()) {
        yAxis = new LogAxis();
      } else {
        yAxis = new LinearAxis();
      }
      chart.setYAxis(yAxis);
    }

    if (manualYAxis.isSelected()) {
      yAxis.setManualRange(minYValue.getValue(), maxYValue.getValue());
      yAxis.setAxisFlags(Axis.AT_VALUE, Axis.AT_VALUE);
    } else {
      yAxis.setAxisFlags(defaultMinYAxisFlag, defaultMaxYAxisFlag);
    }
  }