20 package net.sf.gridarta.gui.dialog.plugin.parameter;
22 import java.awt.Component;
23 import java.awt.event.ActionEvent;
24 import java.awt.event.ActionListener;
25 import javax.swing.AbstractButton;
26 import javax.swing.JButton;
27 import javax.swing.JComponent;
28 import javax.swing.JOptionPane;
29 import javax.swing.JSpinner;
30 import javax.swing.SpinnerNumberModel;
31 import javax.swing.event.ChangeEvent;
32 import javax.swing.event.ChangeListener;
37 import org.jetbrains.annotations.NotNull;
60 private final AbstractButton
config =
new JButton(
"...");
69 final SpinnerNumberModel model =
new SpinnerNumberModel((
int) parameter.getValue(), parameter.getMin(), parameter.getMax(), 1);
70 model.setMinimum(parameter.getMin());
71 model.setMaximum(parameter.getMax());
72 model.
setValue(parameter.getValue());
73 value =
new JSpinner(model);
74 value.addChangeListener(
new ChangeListener() {
77 public void stateChanged(@NotNull
final ChangeEvent e) {
78 parameter.setValue((Integer) model.getNumber());
81 config.setBorderPainted(
false);
82 config.addActionListener(
new ActionListener() {
85 public void actionPerformed(@NotNull
final ActionEvent e) {
86 final String min = JOptionPane.showInputDialog(parent,
"Minimum value:", parameter.getMin());
92 min1 = Integer.parseInt(min);
93 }
catch (
final NumberFormatException ignored) {
94 JOptionPane.showMessageDialog(parent,
"Invalid minimum value: " + min);
97 parameter.setMin(min1);
98 model.setMinimum(min1);
101 final String max = JOptionPane.showInputDialog(parent,
"Maximum value:", parameter.getMax());
107 max1 = Integer.parseInt(max);
108 }
catch (
final NumberFormatException ignored) {
109 JOptionPane.showMessageDialog(parent,
"Invalid maximum value: " + max);
112 parameter.setMax(max1);
113 model.setMaximum(max1);
138 final String toolTip =
"[" + Integer.toString(parameter.
getMin()) +
"," + Integer.toString(parameter.
getMax()) +
"]";
139 config.setToolTipText(toolTip);
140 value.setToolTipText(toolTip);
IntegerParameterView(@NotNull final Component parent, @NotNull final IntegerParameter< G, A, R > parameter)
Creates a new instance.
int getMin()
Returns the minimal allowed value.
final JSpinner value
The component for editing the parameter's value.
final IntegerParameter< G, A, R > parameter
The IntegerParameter that is shown.
A PluginParameter that holds an integer value and a range of valid values.
final AbstractButton config
The component for editing the parameter's configuration.
Interface for views that display plugin parameters.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
void updateTooltip()
Updates the tooltip text of config and value to reflect the current parameters.
GameObjects are the objects based on Archetypes found on maps.
A PluginParameterView for an IntegerParameter.
JComponent getConfigComponent()
Returns a JComponent for editing the parameter configuration.
int getMax()
Returns the maximal allowed value.
JComponent getValueComponent()
Returns a JComponent for editing the parameter value.
void setValue(@NotNull final Integer value)
Interface for MapArchObjects.