/** Used to find the global attributes that another inspector has set so I can share it. */
  ChartGenerator chartToUse(final String sName, Frame parent, final GUIState simulation) {
    Bag charts = new Bag();
    if (simulation.guiObjects != null)
      for (int i = 0; i < simulation.guiObjects.numObjs; i++)
        if (simulation.guiObjects.objs[i] instanceof ChartGenerator
            && validChartGenerator((ChartGenerator) (simulation.guiObjects.objs[i])))
          charts.add(simulation.guiObjects.objs[i]);
    if (charts.numObjs == 0) return createNewChart(simulation);

    // init the dialog panel
    JPanel p = new JPanel();
    p.setLayout(new BorderLayout());

    String[] chartNames = new String[charts.numObjs + 1];

    chartNames[0] = "[Create a New Chart]";
    for (int i = 0; i < charts.numObjs; i++)
      chartNames[i + 1] = ((ChartGenerator) (charts.objs[i])).getTitle();

    // add widgets
    JPanel panel2 = new JPanel();
    panel2.setLayout(new BorderLayout());
    panel2.setBorder(new javax.swing.border.TitledBorder("Plot on Chart..."));
    JComboBox encoding = new JComboBox(chartNames);
    panel2.add(encoding, BorderLayout.CENTER);
    p.add(panel2, BorderLayout.SOUTH);

    // ask
    if (JOptionPane.showConfirmDialog(
            parent, p, "Create a New Chart...", JOptionPane.OK_CANCEL_OPTION)
        != JOptionPane.OK_OPTION) return null;

    if (encoding.getSelectedIndex() == 0) return createNewChart(simulation);
    else return (ChartGenerator) (charts.objs[encoding.getSelectedIndex() - 1]);
  }
    public GlobalAttributes() {
      setLayout(new BorderLayout());
      LabelledList list =
          new LabelledList(includeAggregationMethodAttributes() ? "Add Data..." : "Redraw");
      add(list, BorderLayout.CENTER);

      if (includeAggregationMethodAttributes()) {
        NumberTextField stepsField =
            new NumberTextField(1, true) {
              public double newValue(double value) {
                value = (long) value;
                if (value <= 0) return currentValue;
                else {
                  interval = (long) value;
                  return value;
                }
              }
            };

        list.addLabelled("Every", stepsField);
        list.addLabelled("", new JLabel("...Timesteps"));

        String[] optionsLabel = {"Current", "Maximum", "Minimum", "Mean"};
        final JComboBox optionsBox = new JComboBox(optionsLabel);
        optionsBox.setSelectedIndex(aggregationMethod);
        optionsBox.addActionListener(
            new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                aggregationMethod = optionsBox.getSelectedIndex();
              }
            });
        list.addLabelled("Using", optionsBox);
      }

      String[] optionsLabel2 =
          new String[] {
            "When Adding Data",
            "Every 0.1 Seconds",
            "Every 0.5 Seconds",
            "Every Second",
            "Every 2 Seconds",
            "Every 5 Seconds",
            "Every 10 Seconds",
            "Never"
          };
      final JComboBox optionsBox2 = new JComboBox(optionsLabel2);
      optionsBox2.setSelectedIndex(redraw);
      optionsBox2.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              redraw = optionsBox2.getSelectedIndex();
              generator.update(); // keep up-to-date
            }
          });
      if (includeAggregationMethodAttributes()) list.addLabelled("Redraw", optionsBox2);
      else list.add(optionsBox2);
    }