File: TerrainDefinitionPanel.java

package info (click to toggle)
gpsprune 17-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,984 kB
  • ctags: 5,218
  • sloc: java: 39,403; sh: 25; makefile: 17; python: 15
file content (86 lines) | stat: -rw-r--r-- 2,329 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package tim.prune.gui;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

import tim.prune.I18nManager;
import tim.prune.config.Config;
import tim.prune.threedee.TerrainDefinition;

/**
 * Gui component for defining the 3d terrain,
 * including whether to use one or not, and if so
 * what resolution to use for the grid
 */
public class TerrainDefinitionPanel extends JPanel
{
	/** Checkbox to use a terrain or not */
	private JCheckBox _useCheckbox = null;
	/** Field for entering the grid size */
	private WholeNumberField _gridSizeField = null;


	/**
	 * Constructor
	 */
	public TerrainDefinitionPanel()
	{
		setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
		// Components
		_useCheckbox = new JCheckBox(I18nManager.getText("dialog.3d.useterrain"));
		_useCheckbox.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				activateGridField();
			}
		});
		add(_useCheckbox);
		add(Box.createHorizontalGlue());
		JLabel label = new JLabel(I18nManager.getText("dialog.3d.terraingridsize") + ": ");
		add(label);
		_gridSizeField = new WholeNumberField(4);
		_gridSizeField.setValue(Config.getConfigInt(Config.KEY_TERRAIN_GRID_SIZE)); // default grid size
		_gridSizeField.setMaximumSize(new Dimension(100, 50));
		_gridSizeField.setEnabled(false);
		add(_gridSizeField);
	}

	/**
	 * @param inDefinition terrain parameters to set
	 */
	public void initTerrainParameters(TerrainDefinition inDefinition)
	{
		_useCheckbox.setSelected(inDefinition != null && inDefinition.getUseTerrain());
		if (inDefinition != null && inDefinition.getGridSize() > 0) {
			_gridSizeField.setValue(inDefinition.getGridSize());
		}
		activateGridField();
	}

	/**
	 * @return true if the terrain is selected
	 */
	public boolean getUseTerrain() {
		return _useCheckbox.isSelected() && getGridSize() > 2;
	}

	/**
	 * @return number of nodes along each side of the grid
	 */
	public int getGridSize() {
		return _gridSizeField.getValue();
	}

	/**
	 * Set the grid field to be enabled or not based on the checkbox
	 */
	private void activateGridField() {
		_gridSizeField.setEnabled(_useCheckbox.isSelected());
	}
}