コード例 #1
0
  /** Performs the action of loading a session from a file. */
  public void actionPerformed(ActionEvent e) {
    DataModel dataModel = getDataEditor().getSelectedDataModel();

    if (!(dataModel instanceof DataSet)) {
      JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "Must be a tabular data set.");
      return;
    }

    this.dataSet = (DataSet) dataModel;

    SpinnerNumberModel spinnerNumberModel = new SpinnerNumberModel(getNumLags(), 0, 20, 1);
    JSpinner jSpinner = new JSpinner(spinnerNumberModel);
    jSpinner.setPreferredSize(jSpinner.getPreferredSize());

    spinnerNumberModel.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            SpinnerNumberModel model = (SpinnerNumberModel) e.getSource();
            setNumLags(model.getNumber().intValue());
          }
        });

    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());

    Box b = Box.createVerticalBox();
    Box b1 = Box.createHorizontalBox();
    b1.add(new JLabel("Number of time lags: "));
    b1.add(Box.createHorizontalGlue());
    b1.add(Box.createHorizontalStrut(15));
    b1.add(jSpinner);
    b1.setBorder(new EmptyBorder(10, 10, 10, 10));
    b.add(b1);

    panel.add(b, BorderLayout.CENTER);

    EditorWindow editorWindow = new EditorWindow(panel, "Create time series data", "Save", true);
    DesktopController.getInstance().addEditorWindow(editorWindow);
    editorWindow.setVisible(true);

    editorWindow.addInternalFrameListener(
        new InternalFrameAdapter() {
          public void internalFrameClosed(InternalFrameEvent e) {
            EditorWindow window = (EditorWindow) e.getSource();

            if (!window.isCanceled()) {
              if (dataSet.isContinuous()) {
                createContinuousTimeSeriesData();
              } else if (dataSet.isDiscrete()) {
                createDiscreteTimeSeriesData();
              } else {
                JOptionPane.showMessageDialog(
                    JOptionUtils.centeringComp(),
                    "Data set must be either continuous or discrete.");
              }
            }
          }
        });
  }
コード例 #2
0
ファイル: MyDateChooseBtn.java プロジェクト: singleD/se2
    private void createYearAndMonthPanal() {
      Calendar c = getNowCalendar();
      int currentYear = c.get(Calendar.YEAR);
      int currentMonth = c.get(Calendar.MONTH) + 1;
      int currentHour = c.get(Calendar.HOUR_OF_DAY);
      yearSpin =
          new JSpinner(new javax.swing.SpinnerNumberModel(currentYear, startYear, lastYear, 1));
      monthSpin = new JSpinner(new javax.swing.SpinnerNumberModel(currentMonth, 1, 12, 1));
      hourSpin = new JSpinner(new javax.swing.SpinnerNumberModel(currentHour, 0, 23, 1));

      yearPanel.setLayout(new java.awt.FlowLayout());
      yearPanel.setBackground(controlLineColor);

      yearSpin.setPreferredSize(new Dimension(48, 20));
      yearSpin.setName("Year");
      yearSpin.setEditor(new JSpinner.NumberEditor(yearSpin, "####"));
      yearSpin.addChangeListener(this);
      yearPanel.add(yearSpin);

      JLabel yearLabel = new JLabel("年");
      yearLabel.setForeground(controlTextColor);
      yearPanel.add(yearLabel);

      monthSpin.setPreferredSize(new Dimension(35, 20));
      monthSpin.setName("Month");
      monthSpin.addChangeListener(this);
      yearPanel.add(monthSpin);

      JLabel monthLabel = new JLabel("月");
      monthLabel.setForeground(controlTextColor);
      yearPanel.add(monthLabel);

      hourSpin.setPreferredSize(new Dimension(35, 20));
      hourSpin.setName("Hour");
      hourSpin.addChangeListener(this);
      yearPanel.add(hourSpin);

      JLabel hourLabel = new JLabel("日");
      hourLabel.setForeground(controlTextColor);
      yearPanel.add(hourLabel);
    }
コード例 #3
0
 private void configureSpinnerFloat(JSpinner spinner) {
   JSpinner.NumberEditor editor = (JSpinner.NumberEditor) spinner.getEditor();
   DecimalFormat format = editor.getFormat();
   format.setMinimumFractionDigits(3);
   format.setMinimumIntegerDigits(1);
   editor.getTextField().setHorizontalAlignment(SwingConstants.CENTER);
   Dimension d = spinner.getPreferredSize();
   d.width = 60;
   spinner.setPreferredSize(d);
   spinner.addChangeListener(this);
   spinner.setMaximumSize(d);
 }
コード例 #4
0
ファイル: NewGameDialog.java プロジェクト: NevilleVH/scrabble
  public NewGameDialog(GUI parent) {
    this.parent = parent;
    this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    this.setTitle("New game");
    this.setSize(250, 150);
    this.setResizable(false);
    this.setLocationRelativeTo(null);
    JPanel contentPane = new JPanel();
    this.add(contentPane);
    contentPane.setLayout(new FlowLayout()); // BoxLayout(contentPane, BoxLayout.PAGE_AXIS));

    SpinnerNumberModel model = new SpinnerNumberModel(1, 1, 3, 1);
    JLabel numAIlabel = new JLabel("Number of opponents:");
    numAIlabel.setMaximumSize(numAIlabel.getPreferredSize());
    contentPane.add(numAIlabel);

    numAI = new JSpinner(model); /*{
            @Override
            public Dimension getMaximumSize() {
                Dimension dim = super.getMaximumSize();
                dim.height = getPreferredSize().height;
                return dim;
            }
        };*/
    numAI.setEditor(new JSpinner.DefaultEditor(numAI));
    numAI.setPreferredSize(new Dimension(100, 30));

    // numAI.setMaximumSize(numAI.getPreferredSize());

    contentPane.add(numAI);
    chooseDifficulty = new ButtonGroup();
    JRadioButton easy = new JRadioButton("Easy");
    JRadioButton intermediate = new JRadioButton("Intermediate");
    JRadioButton hard = new JRadioButton("Hard");
    easy.setActionCommand("EASY");
    intermediate.setActionCommand("INTERMEDIATE");
    hard.setActionCommand("HARD");
    chooseDifficulty.add(easy);
    chooseDifficulty.add(intermediate);
    chooseDifficulty.add(hard);
    contentPane.add(easy);
    contentPane.add(intermediate);
    contentPane.add(hard);
    easy.doClick();
    JButton confirm = new JButton("Confirm");
    contentPane.add(confirm);
    confirm.addActionListener(this);

    this.setVisible(true);
  }
コード例 #5
0
  /** Builds the panel. */
  public void setup() {
    SpinnerNumberModel model =
        new SpinnerNumberModel(this.params.getInt("numTimeLags", 1), 0, Integer.MAX_VALUE, 1);
    JSpinner jSpinner = new JSpinner(model);
    jSpinner.setPreferredSize(jSpinner.getPreferredSize());

    model.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            SpinnerNumberModel model = (SpinnerNumberModel) e.getSource();
            params.set("numTimeLags", model.getNumber().intValue());
          }
        });

    Box b1 = Box.createHorizontalBox();
    b1.add(new JLabel("Number of lags: "));
    b1.add(Box.createHorizontalGlue());
    b1.add(Box.createHorizontalStrut(15));
    b1.add(jSpinner);
    b1.setBorder(new EmptyBorder(10, 10, 10, 10));
    add(b1, BorderLayout.CENTER);
  }
コード例 #6
0
ファイル: LingDisplay.java プロジェクト: lizziesilver/tetrad
  public LingDisplay(final Ling.StoredGraphs storedGraphs) {
    this.storedGraphs = storedGraphs;

    if (storedGraphs.getNumGraphs() == 0) {
      workbench = new GraphWorkbench();
    } else {
      workbench = new GraphWorkbench(storedGraphs.getGraph(0));
    }

    subsetIndices = getStableIndices(storedGraphs);

    final SpinnerNumberModel model =
        new SpinnerNumberModel(subsetIndices.size() == 0 ? 0 : 1, 0, subsetIndices.size(), 1);
    model.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            int index = model.getNumber().intValue();
            workbench.setGraph(storedGraphs.getGraph(subsetIndices.get(index - 1)));
          }
        });

    spinner = new JSpinner();
    subsetCombo = new JComboBox(new String[] {"Show Stable", "Show Unstable", "Show All"});
    subsetCombo.setSelectedItem("Show Stable");
    spinner.setModel(model);
    totalLabel = new JLabel(" of " + subsetIndices.size());

    subsetCombo.setMaximumSize(subsetCombo.getPreferredSize());
    subsetCombo.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            resetDisplay();
          }
        });

    spinner.setPreferredSize(new Dimension(50, 20));
    spinner.setMaximumSize(spinner.getPreferredSize());
    Box b = Box.createVerticalBox();
    Box b1 = Box.createHorizontalBox();
    //        b1.add(Box.createHorizontalGlue());
    //        b1.add(Box.createHorizontalStrut(10));
    b1.add(subsetCombo);
    b1.add(Box.createHorizontalGlue());
    b1.add(new JLabel("DAG "));
    b1.add(spinner);
    b1.add(totalLabel);

    b.add(b1);

    Box b2 = Box.createHorizontalBox();
    JPanel graphPanel = new JPanel();
    graphPanel.setLayout(new BorderLayout());
    JScrollPane jScrollPane = new JScrollPane(workbench);
    //        jScrollPane.setPreferredSize(new Dimension(400, 400));
    graphPanel.add(jScrollPane);
    //        graphPanel.setBorder(new TitledBorder("DAG"));
    b2.add(graphPanel);
    b.add(b2);

    setLayout(new BorderLayout());
    //        add(menuBar(), BorderLayout.NORTH);
    add(b, BorderLayout.CENTER);
  }
コード例 #7
0
  private void initializeComponents() {
    this.setTitle("Configuration");
    this.setResizable(false);

    setLayout(new BorderLayout(20, 20));

    JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.X_AXIS));
    mainPanel.setBorder(new LineBorder(mainPanel.getBackground(), 10));
    add(mainPanel, BorderLayout.CENTER);

    GridBagConstraints labelConstraints = new GridBagConstraints();
    labelConstraints.gridx = 0;
    labelConstraints.anchor = GridBagConstraints.WEST;
    labelConstraints.insets = new Insets(5, 5, 5, 5);

    GridBagConstraints inputConstraints = new GridBagConstraints();
    inputConstraints.gridx = 1;
    inputConstraints.anchor = GridBagConstraints.EAST;
    inputConstraints.weightx = 1;
    inputConstraints.insets = new Insets(5, 5, 5, 5);

    JPanel evolutionOptionsPanel = new JPanel();
    evolutionOptionsPanel.setBorder(new TitledBorder("Evolution"));
    evolutionOptionsPanel.setLayout(new BoxLayout(evolutionOptionsPanel, BoxLayout.Y_AXIS));
    mainPanel.add(evolutionOptionsPanel);

    // world size
    JPanel worldSizePanel = new JPanel(new GridBagLayout());
    evolutionOptionsPanel.add(worldSizePanel);
    JLabel worldSizeLabel = new JLabel("World Size");
    worldSizeLabel.setToolTipText("Size of the world in pixels. Width x Height.");
    worldSizePanel.add(worldSizeLabel, labelConstraints);
    JPanel worldSizeInputPanel = new JPanel();
    worldSizeInputPanel.setLayout(new GridBagLayout());
    final AutoSelectOnFocusSpinner worldSizeWidthSpinner =
        new AutoSelectOnFocusSpinner(
            new SpinnerNumberModel(config.getDimension().width, 1, Integer.MAX_VALUE, 1));
    final AutoSelectOnFocusSpinner worldSizeHeightSpinner =
        new AutoSelectOnFocusSpinner(
            new SpinnerNumberModel(config.getDimension().height, 1, Integer.MAX_VALUE, 1));
    worldSizeInputPanel.add(worldSizeWidthSpinner);
    JLabel separatorLabel = new JLabel("x");
    GridBagConstraints c = new GridBagConstraints();
    c.insets = new Insets(0, 5, 0, 5);
    worldSizeInputPanel.add(separatorLabel, c);
    worldSizeInputPanel.add(worldSizeHeightSpinner);
    worldSizePanel.add(worldSizeInputPanel, inputConstraints);

    // starting energy
    JPanel startingEnergyPanel = new JPanel(new GridBagLayout());
    evolutionOptionsPanel.add(startingEnergyPanel);
    JLabel startingEnergyLabel = new JLabel("Starting Energy");
    startingEnergyLabel.setToolTipText(
        "<html>The amount of energy all newly painted pixels start out with.<br />Note that changing this will not affect already painted pixels.</html>");
    startingEnergyPanel.add(startingEnergyLabel, labelConstraints);
    final AutoSelectOnFocusSpinner startingEnergySpinner =
        new AutoSelectOnFocusSpinner(
            new SpinnerNumberModel(config.startingEnergy, 1, Integer.MAX_VALUE, 1));
    startingEnergyPanel.add(startingEnergySpinner, inputConstraints);

    // mutation rate
    JPanel mutationRatePanel = new JPanel(new GridBagLayout());
    evolutionOptionsPanel.add(mutationRatePanel);
    JLabel mutationRateLabel = new JLabel("Mutation Rate");
    mutationRateLabel.setToolTipText(
        "<html>Chance for a mutation to occur during copy or mixing operations.<br />A value of 0.01 means a 1% chance, a value of 0 disables mutation.</html>");
    mutationRatePanel.add(mutationRateLabel, labelConstraints);
    final JSpinner mutationRateSpinner =
        new JSpinner(new SpinnerNumberModel(config.mutationRate, 0.0, 1.0, 0.01));
    mutationRateSpinner.setEditor(
        new JSpinner.NumberEditor(mutationRateSpinner, "#.##############"));
    mutationRateSpinner.setPreferredSize(
        new Dimension(180, mutationRateSpinner.getPreferredSize().height));
    final JFormattedTextField mutationRateSpinnerText =
        ((JSpinner.NumberEditor) mutationRateSpinner.getEditor()).getTextField();
    mutationRateSpinnerText.addFocusListener(
        new FocusListener() {
          public void focusGained(FocusEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  public void run() {
                    mutationRateSpinnerText.selectAll();
                  }
                });
          }

          public void focusLost(FocusEvent e) {}
        });
    mutationRatePanel.add(mutationRateSpinner, inputConstraints);

    JPanel guiOptionsPanel = new JPanel();
    guiOptionsPanel.setBorder(new TitledBorder("GUI"));
    guiOptionsPanel.setLayout(new BoxLayout(guiOptionsPanel, BoxLayout.Y_AXIS));
    mainPanel.add(guiOptionsPanel);

    // background color
    JPanel backgroundColorPanel = new JPanel(new GridBagLayout());
    guiOptionsPanel.add(backgroundColorPanel, labelConstraints);
    JLabel backgroundColorLabel = new JLabel("Background Color");
    backgroundColorLabel.setToolTipText(
        "<html>Pick the background color.<br />If you have a lot of dark pixels, you might want to set this to a light color.</html>");
    backgroundColorPanel.add(backgroundColorLabel, labelConstraints);
    backgroundColor = new PixelColor(config.backgroundColor);
    JPanel backgroundColorAlignmentPanel = new JPanel();
    backgroundColorAlignmentPanel.setLayout(new GridBagLayout());
    backgroundColorAlignmentPanel.setPreferredSize(mutationRateSpinner.getPreferredSize());
    final ColorChooserLabel backgroundColorChooserLabel = new ColorChooserLabel(backgroundColor);
    backgroundColorAlignmentPanel.add(backgroundColorChooserLabel);
    backgroundColorPanel.add(backgroundColorAlignmentPanel, inputConstraints);

    // FPS
    JPanel fpsPanel = new JPanel(new GridBagLayout());
    guiOptionsPanel.add(fpsPanel);
    JLabel fpsLabel = new JLabel("FPS");
    fpsLabel.setToolTipText(
        "<html>The repaint interval in frames per second (FPS).<br />Set this to a lower value to save a few CPU cycles.</html>");
    fpsPanel.add(fpsLabel, labelConstraints);
    final AutoSelectOnFocusSpinner fpsSpinner =
        new AutoSelectOnFocusSpinner(new SpinnerNumberModel(config.fps, 1, Integer.MAX_VALUE, 1));
    fpsPanel.add(fpsSpinner, inputConstraints);

    // paint history size
    JPanel paintHistorySizePanel = new JPanel(new GridBagLayout());
    guiOptionsPanel.add(paintHistorySizePanel);
    JLabel paintHistorySizeLabel = new JLabel("Paint-History Size");
    paintHistorySizeLabel.setToolTipText(
        "<html>Sets the number of entries in the paint history.<br />In case you have not found it yet: the paint history is the little menu that appears when you right-click on the image.</html>");
    paintHistorySizePanel.add(paintHistorySizeLabel, labelConstraints);
    final AutoSelectOnFocusSpinner paintHistorySizeSpinner =
        new AutoSelectOnFocusSpinner(
            new SpinnerNumberModel(config.paintHistorySize, 1, Integer.MAX_VALUE, 1));
    paintHistorySizePanel.add(paintHistorySizeSpinner, inputConstraints);

    JPanel videoOptionsPanel = new JPanel();
    videoOptionsPanel.setBorder(new TitledBorder("Video Recording"));
    videoOptionsPanel.setLayout(new BoxLayout(videoOptionsPanel, BoxLayout.Y_AXIS));
    mainPanel.add(videoOptionsPanel);

    // FPS video
    JPanel fpsVideoPanel = new JPanel(new GridBagLayout());
    videoOptionsPanel.add(fpsVideoPanel);
    JLabel fpsVideoLabel = new JLabel("FPS of videos");
    fpsVideoLabel.setToolTipText("The number of frames per second (FPS) in recorded videos.");
    fpsVideoPanel.add(fpsVideoLabel, labelConstraints);
    final AutoSelectOnFocusSpinner fpsVideoSpinner =
        new AutoSelectOnFocusSpinner(
            new SpinnerNumberModel(config.fpsVideo, 1, Integer.MAX_VALUE, 1));
    fpsVideoPanel.add(fpsVideoSpinner, inputConstraints);

    // video encoder command
    JPanel videoEncoderPanel = new JPanel(new GridBagLayout());
    videoOptionsPanel.add(videoEncoderPanel);
    JLabel videoEncoderLabel = new JLabel("Video Encoder");
    videoEncoderLabel.setToolTipText(
        "<html>The command to invoke your video encoder.<br />Use the tokens INPUT_FILE and OUTPUT_FILE to denote input and output files of your encoder.</html>");
    videoEncoderPanel.add(videoEncoderLabel, labelConstraints);
    final JTextArea videoEncoderTextArea = new JTextArea(Configuration.ENCODER_COMMAND);
    videoEncoderTextArea.setLineWrap(true);
    videoEncoderTextArea.setWrapStyleWord(true);
    JScrollPane videoEncoderScrollPane =
        new JScrollPane(
            videoEncoderTextArea,
            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    videoEncoderScrollPane.setViewportBorder(null);
    videoEncoderScrollPane.setPreferredSize(
        new Dimension(worldSizeInputPanel.getPreferredSize().width, 100));
    videoEncoderPanel.add(videoEncoderScrollPane, inputConstraints);

    JPanel controlPanel = new JPanel();
    add(controlPanel, BorderLayout.SOUTH);

    JButton okButton = new JButton("OK");
    okButton.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {

            new Thread() {

              @Override
              public void run() {
                config.world.addChangeListener(
                    new IChangeListener() {

                      public void changed() {
                        int i, j;
                        double d;
                        String s;

                        // evolution

                        i = (Integer) worldSizeWidthSpinner.getValue();
                        j = (Integer) worldSizeHeightSpinner.getValue();
                        if (config.getDimension().width != i || config.getDimension().height != i) {
                          config.setDimension(new Dimension(i, j));
                        }

                        i = (Integer) startingEnergySpinner.getValue();
                        if (config.startingEnergy != i) {
                          config.startingEnergy = i;
                        }

                        d = (Double) mutationRateSpinner.getValue();
                        if (config.mutationRate != d) {
                          config.mutationRate = d;
                        }

                        // gui

                        i = backgroundColor.getInteger();
                        if (config.backgroundColor != i) {
                          config.backgroundColor = i;
                        }

                        i = (Integer) fpsSpinner.getValue();
                        if (config.fps != i) {
                          config.fps = i;
                        }

                        i = (Integer) paintHistorySizeSpinner.getValue();
                        if (config.paintHistorySize != i) {
                          config.paintHistorySize = i;
                        }

                        // video recording

                        i = (Integer) fpsVideoSpinner.getValue();
                        if (config.fpsVideo != i) {
                          config.fpsVideo = i;
                        }

                        s = videoEncoderTextArea.getText();
                        if (false == Configuration.ENCODER_COMMAND.equals(s)) {
                          Configuration.ENCODER_COMMAND = s;
                        }

                        dispose();
                      }
                    });
              }
            }.start();
          }
        });
    controlPanel.add(okButton);
    JButton cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            dispose();
          }
        });
    controlPanel.add(cancelButton);

    pack();
  }