View Javadoc

1   /*
2    * Copyright (C) 2010 Unreal Visualizer Authors
3    *
4    * This program is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU General Public License as published by
6    * the Free Software Foundation, either version 3 of the License, or
7    * (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16   */
17  package nl.tudelft.goal.ut2004.visualizer.gui.dialogs;
18  
19  import java.awt.FlowLayout;
20  import java.awt.Frame;
21  import javax.swing.JButton;
22  import javax.swing.JDialog;
23  import javax.swing.JLabel;
24  import javax.swing.JSpinner;
25  import javax.swing.SpinnerNumberModel;
26  
27  import nl.tudelft.goal.ut2004.visualizer.gui.action.PauseResumeAction;
28  import nl.tudelft.goal.ut2004.visualizer.gui.action.SetSpeedAction;
29  import nl.tudelft.goal.ut2004.visualizer.util.WindowPersistenceHelper;
30  
31  /**
32   * Dialog for changing speed of the game.
33   * 
34   * @author M.P. Korstanje
35   * 
36   */
37  public class ChangeGameSpeedDialog extends JDialog {
38  
39  	private JSpinner speedSelection;
40  	private JLabel setSpeed;
41  	private JButton pauseResume;
42  	/**
43  	 * Helper class to persist this window.
44  	 */
45  	private WindowPersistenceHelper persistenceHelper;
46  	
47  	public ChangeGameSpeedDialog(Frame parent) {
48  		super(parent, false);
49  		setTitle("Change Game Speed");
50  
51  		this.pauseResume = new JButton(new PauseResumeAction());
52  
53  		this.speedSelection = new JSpinner(
54  		// 1 = default speed, 0.1 minimum, 10.0 max. 0.1 step size.
55  				new SpinnerNumberModel(1, 0.1, 10.0, 0.1));
56  		this.speedSelection
57  				.setEditor(new JSpinner.NumberEditor(speedSelection));
58  		this.setSpeed = new JLabel("Game Speed");
59  
60  		this.speedSelection
61  				.addChangeListener(new SetSpeedAction(speedSelection));
62  
63  		setLayout(new FlowLayout());
64  		add(pauseResume);
65  		add(setSpeed);
66  		add(speedSelection);
67  
68  		this.setSize(400, 75);
69  		// Setup persistence
70  		persistenceHelper = new WindowPersistenceHelper(this);
71  		persistenceHelper.load();
72  
73  	}
74  }