3 import java.awt.Dimension;
4 import java.awt.event.ActionEvent;
5 import java.awt.event.ActionListener;
7 import javax.swing.Box;
8 import javax.swing.BoxLayout;
9 import javax.swing.JCheckBox;
10 import javax.swing.JLabel;
11 import javax.swing.JPanel;
13 import tim.prune.I18nManager;
14 import tim.prune.config.Config;
15 import tim.prune.threedee.TerrainDefinition;
18 * Gui component for defining the 3d terrain,
19 * including whether to use one or not, and if so
20 * what resolution to use for the grid
22 public class TerrainDefinitionPanel extends JPanel
24 /** Checkbox to use a terrain or not */
25 private JCheckBox _useCheckbox = null;
26 /** Field for entering the grid size */
27 private WholeNumberField _gridSizeField = null;
33 public TerrainDefinitionPanel()
35 setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
37 _useCheckbox = new JCheckBox(I18nManager.getText("dialog.3d.useterrain"));
38 _useCheckbox.addActionListener(new ActionListener() {
39 public void actionPerformed(ActionEvent arg0) {
44 add(Box.createHorizontalGlue());
45 JLabel label = new JLabel(I18nManager.getText("dialog.3d.terraingridsize") + ": ");
47 _gridSizeField = new WholeNumberField(4);
48 _gridSizeField.setValue(Config.getConfigInt(Config.KEY_TERRAIN_GRID_SIZE)); // default grid size
49 _gridSizeField.setMaximumSize(new Dimension(100, 50));
50 _gridSizeField.setEnabled(false);
55 * @param inDefinition terrain parameters to set
57 public void initTerrainParameters(TerrainDefinition inDefinition)
59 _useCheckbox.setSelected(inDefinition != null && inDefinition.getUseTerrain());
60 if (inDefinition != null && inDefinition.getGridSize() > 0) {
61 _gridSizeField.setValue(inDefinition.getGridSize());
67 * @return true if the terrain is selected
69 public boolean getUseTerrain() {
70 return _useCheckbox.isSelected() && getGridSize() > 2;
74 * @return number of nodes along each side of the grid
76 public int getGridSize() {
77 return _gridSizeField.getValue();
81 * Set the grid field to be enabled or not based on the checkbox
83 private void activateGridField() {
84 _gridSizeField.setEnabled(_useCheckbox.isSelected());