20 package net.sf.gridarta.gui.utils;
22 import java.awt.Component;
23 import java.awt.GridBagConstraints;
24 import java.awt.GridBagLayout;
25 import java.awt.Insets;
26 import java.util.ArrayList;
27 import java.util.Collection;
28 import java.util.HashMap;
30 import javax.swing.AbstractButton;
31 import javax.swing.ButtonGroup;
32 import javax.swing.JPanel;
33 import javax.swing.JToggleButton;
34 import net.
sf.japi.swing.action.ActionBuilder;
35 import net.
sf.japi.swing.action.ActionBuilderFactory;
36 import net.
sf.japi.swing.action.ActionMethod;
37 import org.jetbrains.annotations.NotNull;
38 import org.jetbrains.annotations.Nullable;
59 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
83 private final Map<Integer, JToggleButton>
directions =
new HashMap<>(9);
95 super(
new GridBagLayout());
96 final GridBagConstraints gbc =
new GridBagConstraints();
97 gbc.fill = GridBagConstraints.BOTH;
98 gbc.anchor = GridBagConstraints.CENTER;
99 gbc.insets =
new Insets(1, 1, 1, 1);
109 if (includeDefault) {
131 final AbstractButton selectedButton = directions.get(direction);
132 if (selectedButton != null) {
133 selectedButton.setSelected(
true);
144 private void createButton(@Nullable
final Integer
direction, @NotNull
final GridBagConstraints gbc,
final int x,
final int y) {
145 final JToggleButton button =
new JToggleButton(ACTION_BUILDER.createAction(
false,
"direction" + direction,
this));
146 directionButtonGroup.add(button);
147 button.setFocusable(
false);
149 button.setMargin(EMPTY_INSETS);
153 directionButtons.add(button);
154 button.setSelected(
true);
155 directions.put(direction, button);
246 super.setEnabled(enabled);
254 final boolean enabled = enableButtons && isEnabled();
255 for (
final Component button : directionButtons) {
256 button.setEnabled(enabled);
static final Insets EMPTY_INSETS
Empty Insets.
final void updateDirection(@Nullable final Integer direction)
Sets the selected direction.
DirectionComponent(final boolean includeDefault)
Creates a new instance.
void setEnabled(final boolean enabled)
static final ActionBuilder ACTION_BUILDER
The ActionBuilder instance.
void createButton(@Nullable final Integer direction, @NotNull final GridBagConstraints gbc, final int x, final int y)
Creates a direction button.
void direction3()
Action method for direction.
final Map< Integer, JToggleButton > directions
Maps direction to button.
static final long serialVersionUID
The serial version UID.
void direction7()
Action method for direction.
void direction2()
Action method for direction.
boolean enableButtons
Whether the buttons are currently enabled.
void direction1()
Action method for direction.
A GUI component for selecting a direction.
void directionnull()
Action method for default direction.
final void updateEnabled(final boolean enableButtons)
Enables/disables the direction buttons for a given archetype.
void direction6()
Action method for direction.
abstract void direction(@Nullable Integer direction)
Called whenever a direction button has been selected.
void direction8()
Action method for direction.
void updateEnabled()
Enables/disables the buttons.
final Collection< JToggleButton > directionButtons
The buttons in directionButtonGroup.
void direction4()
Action method for direction.
void direction0()
Action method for direction.
final ButtonGroup directionButtonGroup
The ButtonGroup for the direction buttons.
void direction5()
Action method for direction.