Example #1
0
  @Override
  public void actionPerformed(ActionEvent event) {
    if (event.getActionCommand().equals("random")) {
      // create some random data and populate the scatter plot panel
      Random rand = new Random();

      float xValues[] = new float[2000 + rand.nextInt(1000)];
      float yValues[] = new float[xValues.length];
      float zValues[] = new float[2000 + rand.nextInt(1000)];
      for (int i = 0; i < xValues.length; i++) {
        xValues[i] = rand.nextFloat() * 400.f;
        yValues[i] = rand.nextFloat() * 600.f;
      }

      visPanel.setData(
          xValues, yValues, zValues, columnNames.get(y_index), columnNames.get(x_index), maxminXY);
    } else if (event.getActionCommand().equals("exit")) {
      System.exit(0);
    } else {
      // Additionally´╝î add the selecting function to the menu bar
      // When choose the column for the menu bar, update the JCombox
      String cmd = event.getActionCommand();
      String[] cmdParam = cmd.split(",");
      //			for (String str : cmdParam) {
      //				System.out.println(str);
      //			}
      if (cmdParam[0].equals("SetX")) {
        x_index = columnNames.indexOf(cmdParam[1]);
        // Update the JCombox
        jbX.setSelectedItem(cmdParam[1]);
      } else {
        y_index = columnNames.indexOf(cmdParam[1]);
        // Update the JCombox
        jbY.setSelectedItem(cmdParam[1]);
      }

      maxminXY = new Double[] {max[x_index], min[x_index], max[y_index], min[y_index]};

      float xValues[] = new float[rows.size()];
      float yValues[] = new float[rows.size()];
      float zValues[] = new float[rows.size()];

      for (int irow = 0; irow < rows.size(); irow++) {
        ArrayList<Double> row = rows.get(irow);
        xValues[irow] = row.get(x_index).floatValue();
        yValues[irow] = row.get(y_index).floatValue();

        if (z_index >= 0) {
          zValues[irow] =
              (float) ((row.get(z_index) - min[z_index]) / (max[z_index] - min[z_index]));
        } else zValues[irow] = 1;

        //				xValues[irow] = (float) ((row.get(x_index) - min[x_index]) / (max[x_index] -
        // min[x_index]));
        // System.out.println(xValues[irow]);
        //				yValues[irow] = (float) ((row.get(y_index) - min[y_index]) / (max[y_index] -
        // min[y_index]));
        // System.out.println(yValues[irow]);
      }
      //			visPanel.setData(xValues, yValues, columnNames.get(x_index), columnNames.get(y_index));
      visPanel.setData(
          xValues, yValues, zValues, columnNames.get(y_index), columnNames.get(x_index), maxminXY);
    }
  }
Example #2
0
  private void initializePanel() {
    visPanel = new VisPanel();
    visPanel.setBackground(Color.white);
    visPanel.setForeground(Color.darkGray);

    JPanel mainPanel = (JPanel) appFrame.getContentPane();
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add(visPanel, BorderLayout.CENTER);

    // Add two JComboBoxs for x and y axis and set up the action listeners
    jbX = new JComboBox<String>(columnNamestring);
    jbX.setEnabled(true);
    jbX.setBorder(BorderFactory.createTitledBorder("Choose X-axis"));

    ActionListener xListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent actionEvent) {
            x_index = columnNames.indexOf(jbX.getSelectedItem());
            maxminXY = new Double[] {max[x_index], min[x_index], max[y_index], min[y_index]};

            float xValues[] = new float[rows.size()];
            float yValues[] = new float[rows.size()];
            float zValues[] = new float[rows.size()];

            for (int irow = 0; irow < rows.size(); irow++) {
              ArrayList<Double> row = rows.get(irow);
              xValues[irow] = row.get(x_index).floatValue();
              yValues[irow] = row.get(y_index).floatValue();
              if (z_index >= 0) {
                zValues[irow] =
                    (float) ((row.get(z_index) - min[z_index]) / (max[z_index] - min[z_index]));
              } else zValues[irow] = 1;

              //					xValues[irow] = (float) ((row.get(x_index) - min[x_index]) / (max[x_index] -
              // min[x_index]));
              //					yValues[irow] = (float) ((row.get(y_index) - min[y_index]) / (max[y_index] -
              // min[y_index]));
            }
            //				visPanel.setData(xValues, yValues, columnNames.get(x_index),
            // columnNames.get(y_index));
            visPanel.setData(
                xValues,
                yValues,
                zValues,
                columnNames.get(y_index),
                columnNames.get(x_index),
                maxminXY);
            Double[] meanDev = new Double[4];
            meanDev[0] = mean.get(x_index).doubleValue();
            meanDev[1] = mean.get(y_index).doubleValue();
            meanDev[2] = deviation.get(x_index).doubleValue();
            meanDev[3] = deviation.get(y_index).doubleValue();
            visPanel.setStaticdata(meanDev, binCounter.get(x_index), binCounter.get(y_index));
          }
        };
    jbX.addActionListener(xListener);
    mainPanel.add(jbX, BorderLayout.PAGE_START);

    jbY = new JComboBox<String>(columnNamestring);
    jbY.setEnabled(true);
    jbY.setBorder(BorderFactory.createTitledBorder("Choose Y-axis"));
    ActionListener yListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent actionEvent) {
            y_index = columnNames.indexOf(jbY.getSelectedItem());
            maxminXY = new Double[] {max[x_index], min[x_index], max[y_index], min[y_index]};

            float xValues[] = new float[rows.size()];
            float yValues[] = new float[rows.size()];
            float zValues[] = new float[rows.size()];
            for (int irow = 0; irow < rows.size(); irow++) {
              ArrayList<Double> row = rows.get(irow);
              xValues[irow] = row.get(x_index).floatValue();
              yValues[irow] = row.get(y_index).floatValue();
              if (z_index >= 0) {
                zValues[irow] =
                    (float) ((row.get(z_index) - min[z_index]) / (max[z_index] - min[z_index]));
              } else zValues[irow] = 1;
            }
            visPanel.setData(
                xValues,
                yValues,
                zValues,
                columnNames.get(y_index),
                columnNames.get(x_index),
                maxminXY);
            Double[] meanDev = new Double[4];
            meanDev[0] = mean.get(x_index).doubleValue();
            meanDev[1] = mean.get(y_index).doubleValue();
            meanDev[2] = deviation.get(x_index).doubleValue();
            meanDev[3] = deviation.get(y_index).doubleValue();
            visPanel.setStaticdata(meanDev, binCounter.get(x_index), binCounter.get(y_index));
          }
        };
    jbY.addActionListener(yListener);
    mainPanel.add(jbY, BorderLayout.PAGE_END);

    jbZ = new JComboBox<String>(columnNamestringZ);
    jbZ.setEnabled(true);
    jbZ.setBorder(BorderFactory.createTitledBorder("Choose Circle Radius"));

    ActionListener zListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent actionEvent) {
            z_index = columnNames.indexOf(jbZ.getSelectedItem());
            maxminXY = new Double[] {max[x_index], min[x_index], max[y_index], min[y_index]};

            float xValues[] = new float[rows.size()];
            float yValues[] = new float[rows.size()];
            float zValues[] = new float[rows.size()];
            for (int irow = 0; irow < rows.size(); irow++) {
              ArrayList<Double> row = rows.get(irow);
              xValues[irow] = row.get(x_index).floatValue();
              yValues[irow] = row.get(y_index).floatValue();
              if (z_index >= 0) {
                zValues[irow] =
                    (float) ((row.get(z_index) - min[z_index]) / (max[z_index] - min[z_index]));
              } else zValues[irow] = 1;
            }
            visPanel.setData(
                xValues,
                yValues,
                zValues,
                columnNames.get(y_index),
                columnNames.get(x_index),
                maxminXY);
            Double[] meanDev = new Double[4];
            meanDev[0] = mean.get(x_index).doubleValue();
            meanDev[1] = mean.get(y_index).doubleValue();
            meanDev[2] = deviation.get(x_index).doubleValue();
            meanDev[3] = deviation.get(y_index).doubleValue();
            visPanel.setStaticdata(meanDev, binCounter.get(x_index), binCounter.get(y_index));
          }
        };
    jbZ.addActionListener(zListener);
    mainPanel.add(jbZ, BorderLayout.WEST);
  }