20 package net.sf.gridarta.gui.dialog.gameobjectattributes;
22 import java.awt.Container;
23 import java.awt.GridLayout;
24 import java.awt.event.ActionEvent;
25 import javax.swing.AbstractAction;
26 import javax.swing.JCheckBox;
27 import javax.swing.JOptionPane;
28 import javax.swing.JPanel;
29 import javax.swing.event.ChangeEvent;
30 import javax.swing.event.ChangeListener;
38 import org.jetbrains.annotations.NotNull;
39 import org.jetbrains.annotations.Nullable;
83 public void stateChanged(
final ChangeEvent e) {
95 public void stateChanged(
final ChangeEvent e) {
122 gridPanel =
new JPanel(
new GridLayout(0, 2, 3, 3));
123 final AttributeBitmask attributeBitmask = dialogAttributeBitmask.getBitmask();
124 final int number = attributeBitmask.
getNumber();
125 final int value = dialogAttributeBitmask.getValue();
126 checkbox =
new JCheckBox[number];
127 for (
int i = 0; i < number; i++) {
128 final String name = attributeBitmask.
getBitName(i);
130 checkbox[i] =
new JCheckBox(name);
131 checkbox[i].addChangeListener(singleChangeListener);
132 checkbox[i].setSelected(
isActive(i + 1, value));
133 gridPanel.add(checkbox[i]);
136 if (gridPanel.getComponentCount() % 2 != 0) {
137 gridPanel.add(
new JPanel());
140 allCheckbox.addChangeListener(allChangeListener);
141 gridPanel.add(allCheckbox);
147 if (newValue != null) {
148 dialogAttributeBitmask.
setValue(newValue);
156 return super.clone();
157 }
catch (
final CloneNotSupportedException ex) {
158 throw new AssertionError(ex);
170 final String attributeName = dialogAttributeBitmask.getRef().getAttributeName();
171 final String title =
"Choose " + attributeName.substring(0, 1).toUpperCase() + attributeName.substring(1);
172 if (JOptionPane.showConfirmDialog(dialogAttributeBitmask.
getInput(),
gridPanel, title, JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE) == JOptionPane.OK_OPTION) {
184 final int number = attributeBitmask.
getNumber();
186 for (
int i = 0; i < number; i++) {
187 if (checkbox[i] != null && checkbox[i].isSelected()) {
198 final int value = dialogAttributeBitmask.
getValue();
200 for (
int i = 0; i < number; i++) {
201 if (checkbox[i] != null) {
202 checkbox[i].setSelected(
isActive(i + 1, value));
213 final int number = attributeBitmask.
getNumber();
214 for (
int i = 0; i < number; i++) {
215 if (checkbox[i] != null) {
216 checkbox[i].setSelected(state);
229 final int number = attributeBitmask.
getNumber();
231 for (i = 0; i < number; i++) {
232 if (checkbox[i] != null) {
239 final boolean state = checkbox[i++].isSelected();
241 if (checkbox[i] != null && checkbox[i].isSelected() != state) {
256 private static boolean isActive(
final int index,
final int mask) {
257 final int bit = 1 << (index - 1);
258 return (mask & bit) == bit;
final JCheckBox [] checkbox
The single-bit check boxes.
final DialogAttributeBitmask< G, A, R > dialogAttributeBitmask
The DialogAttributeBitmask where this change button belongs to.
A TristateCheckBox that skips the indeterminate state when activated.
int getValue()
Get the active bitmask value.
void setAllBits(final boolean state)
Sets all bit-value check boxes to the given state.
MaskChangeAL(@NotNull final String label, @NotNull final DialogAttributeBitmask< G, A, R > dialogAttributeBitmask)
Constructor.
Graphical User Interface of Gridarta.
String getBitName(final int index)
Returns the name of a bitmask value.
Implements TristateCheckBox, a JCheckBox variant that supports three states: deselected, indeterminate, selected.
TristateButtonModel getTristateModel()
Returns the model as a TristateButtonModel.
static boolean isActive(final int index, final int mask)
Check whether the given bit-index is an active bit in the bitmask.
final Container gridPanel
The top-level container of the dialog.
static final long serialVersionUID
The serial version UID.
int getValue()
Returns the currently selected values.
A JCheckBox that supports three states: deselected, indeterminate, selected.
Base package of all Gridarta classes.
final ChangeListener singleChangeListener
The ChangeListener attached to all single-bit check boxes.
Reflects a game object (object on a map).
AttributeBitmask getBitmask()
int getNumber()
Returns the number of bitmask entries (not counting zero).
Possible states for TristateButtonModels.
GameObjects are the objects based on Archetypes found on maps.
This class manages bitmask values which appear in Gridarta archetype attributes.
void setValue()
Sets the currently selected values to the default values.
Component getInput()
Returns the input ui component for editing the value.
final TristateCheckBox allCheckbox
The all-bits check box.
final ChangeListener allChangeListener
The ChangeListener attached to the "All" check box.
TristateState getBitState()
Returns the TristateState that reflects the current state of all bit-value check boxes.
Integer showBitmaskDialog()
Open a popup frame to select bitmask-entries via choose boxes.
ActionListener for the change buttons of bitmasks.
static TristateState getTristateState(final boolean state)
Returns the tristate state for a boolean state.
void actionPerformed(@NotNull final ActionEvent e)
void setValue(final int value)
Set the active bitmask value.
Defines types of GameObjects with corresponding attributes.
Interface for MapArchObjects.