20 package net.sf.gridarta.gui.panel.gameobjectattributes;
22 import java.awt.Component;
23 import java.awt.Container;
24 import java.awt.GridBagConstraints;
25 import java.awt.GridBagLayout;
26 import javax.swing.AbstractButton;
27 import javax.swing.ImageIcon;
28 import javax.swing.JCheckBox;
29 import javax.swing.JComponent;
30 import javax.swing.JPanel;
31 import javax.swing.JTextField;
32 import javax.swing.border.TitledBorder;
33 import javax.swing.text.JTextComponent;
49 import net.
sf.japi.swing.action.ActionBuilder;
50 import net.
sf.japi.swing.action.ActionBuilderFactory;
51 import org.jetbrains.annotations.NotNull;
52 import org.jetbrains.annotations.Nullable;
65 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
107 private final JPanel
panel =
new JPanel();
119 private static final long serialVersionUID = 1L;
122 protected void direction(@Nullable
final Integer direction) {
123 final int dir = direction == null ? 0 : direction;
125 if (gameObject != null) {
127 if (mapSquare != null) {
174 super(gameObjectAttributesModel);
177 faceComponent =
new FaceComponent(
"", faceObjects, faceObjectProviders, noFaceSquareIcon, unknownSquareIcon,
"");
178 animationComponent =
new AnimationComponent(
"", animationObjects, faceObjectProviders, noFaceSquareIcon, unknownSquareIcon);
180 final GridBagLayout gridBagLayout =
new GridBagLayout();
181 final GridBagConstraints gbc =
new GridBagConstraints();
183 panel.setLayout(gridBagLayout);
184 gbc.fill = GridBagConstraints.BOTH;
187 gbc.anchor = GridBagConstraints.NORTHWEST;
194 gridBagLayout.setConstraints(facePanel, gbc);
195 panel.add(facePanel);
202 gridBagLayout.setConstraints(animationPanel, gbc);
203 panel.add(animationPanel);
211 gridBagLayout.setConstraints(directionPanel, gbc);
212 panel.add(directionPanel);
219 refresh(gameObjectAttributesModel.getSelectedGameObject());
223 protected final void refresh(@Nullable
final G gameObject) {
226 final String faceName;
227 if (gameObject == null) {
230 final String tmpFaceName = gameObject.getFaceName();
231 if (tmpFaceName != null) {
238 faceName =
normalizeFace(gameObject.getArchetype().getFaceName());
240 if (!faceName.equals(
"NONE") && !faceObjects.
containsKey(faceName)) {
245 final String animName;
246 if (gameObject == null) {
249 final String tmpAnimName = gameObject.getAnimName();
250 if (tmpAnimName != null) {
256 animName =
normalizeFace(gameObject.getArchetype().getAnimName());
258 if (!animName.equals(
"NONE") && !animationObjects.
containsKey(animName)) {
263 final boolean animated;
264 if (gameObject == null) {
274 final String animSpeed;
275 if (gameObject == null) {
285 if (gameObject == null || !gameObject.getArchetype().usesDirection()) {
288 direction = gameObject.getDirection();
289 if (severity ==
Severity.
DEFAULT && direction != gameObject.getArchetype().getDirection()) {
297 defaultFaceComponentValue = faceName;
298 animationComponent.
setEnabled(gameObject != null);
300 defaultAnimComponentValue = animName;
301 animatedCheckBox.setEnabled(gameObject != null);
302 animatedCheckBox.setSelected(animated);
303 defaultAnimatedCheckBoxValue = animated;
304 animSpeedTextField.setEnabled(gameObject != null);
305 animSpeedTextField.setText(animSpeed);
306 defaultAnimSpeedTextFieldValue = animSpeed;
307 directionComponent.
setEnabled(gameObject != null);
313 return !faceComponent.
getFaceName().equals(defaultFaceComponentValue) || !animationComponent.
getAnimName().equals(defaultAnimComponentValue) || animatedCheckBox.isSelected() != defaultAnimatedCheckBoxValue || !animSpeedTextField.getText().equals(defaultAnimSpeedTextFieldValue);
318 faceComponent.requestFocusInWindow();
322 protected void apply(@NotNull
final G gameObject) {
324 final String faceName2;
325 if (faceName.equals(
"NONE")) {
326 final String archFaceName = gameObject.getArchetype().getFaceName();
327 faceName2 = archFaceName == null || archFaceName.isEmpty() ?
"" :
"NONE";
329 faceName2 = faceName;
334 final String animName2;
335 if (animName.equals(
"NONE")) {
336 final String archAnimName = gameObject.getArchetype().getAnimName();
337 animName2 = archAnimName == null || archAnimName.isEmpty() ?
"" :
"NONE";
339 animName2 = animName;
343 final boolean isAnimated = animatedCheckBox.isSelected();
350 final String animSpeed = animSpeedTextField.getText().trim();
351 final String animSpeedAttribute = gameObject.getArchetype().getAttributeString(
BaseObject.
ANIM_SPEED);
352 if (animSpeed.isEmpty() || (animSpeed.equals(
"0") ?
"" : animSpeed).equals(animSpeedAttribute)) {
371 final GridBagLayout gridBagLayout =
new GridBagLayout();
373 final JComponent facePanel =
new JPanel();
374 facePanel.setLayout(gridBagLayout);
377 final GridBagConstraints gbc =
new GridBagConstraints();
379 gbc.fill = GridBagConstraints.HORIZONTAL;
381 gbc.anchor = GridBagConstraints.NORTHWEST;
384 gridBagLayout.setConstraints(faceComponent, gbc);
385 facePanel.add(faceComponent);
387 addFiller(gridBagLayout, facePanel, 1, 1);
397 final GridBagLayout gridBagLayout =
new GridBagLayout();
398 final JComponent animationPanel =
new JPanel();
399 animationPanel.setLayout(gridBagLayout);
402 final GridBagConstraints gbc =
new GridBagConstraints();
404 gbc.fill = GridBagConstraints.HORIZONTAL;
406 gbc.anchor = GridBagConstraints.NORTHWEST;
410 gridBagLayout.setConstraints(animationComponent, gbc);
411 animationPanel.add(animationComponent);
414 gridBagLayout.setConstraints(animatedCheckBox, gbc);
415 animationPanel.add(animatedCheckBox);
417 gbc.fill = GridBagConstraints.NONE;
423 gridBagLayout.setConstraints(speedLabel, gbc);
424 animationPanel.add(speedLabel);
426 gbc.fill = GridBagConstraints.HORIZONTAL;
429 gridBagLayout.setConstraints(animSpeedTextField, gbc);
430 animationPanel.add(animSpeedTextField);
432 addFiller(gridBagLayout, animationPanel, 2, 3);
433 return animationPanel;
442 final GridBagLayout gridBagLayout =
new GridBagLayout();
444 final JComponent directionPanel =
new JPanel();
445 directionPanel.setLayout(gridBagLayout);
448 final GridBagConstraints gbc =
new GridBagConstraints();
450 gbc.fill = GridBagConstraints.NONE;
454 gridBagLayout.setConstraints(directionComponent, gbc);
455 directionPanel.add(directionComponent);
457 addFiller(gridBagLayout, directionPanel, 1, 1);
458 return directionPanel;
468 private static void addFiller(@NotNull
final GridBagLayout gridBagLayout, @NotNull
final Container container,
final int gridWidth,
final int gridY) {
469 final GridBagConstraints gbc =
new GridBagConstraints();
470 gbc.fill = GridBagConstraints.BOTH;
472 gbc.gridwidth = gridWidth;
474 final Component filler =
new JPanel();
475 gridBagLayout.setConstraints(filler, gbc);
476 container.add(filler);
487 return value == null || value.isEmpty() ?
"NONE" : value;
void addAutoApply( @NotNull final Component component)
Registers a component that auto-applies when the focus is lost.
void setAnimName(@NotNull final String animName)
Sets the current animation name.
Component getInputComponent()
Returns the input field component.
The data package contains classes for handling data that is organized in a tree.
final void updateDirection(@Nullable final Integer direction)
Sets the selected direction.
void setEnabled(final boolean enabled)
A MapModel reflects the data of a map.
Graphical User Interface of Gridarta.
A JPanel that allows the user to select an animation name.
MapModel< G, A, R > getMapModel()
Returns the MapModel this map square is part of.
This class manages NamedObjects, managing their tree as well as providing a method for showing a dial...
String ANIM_SPEED
The name of the "anim_speed" attribute.
void endTransaction()
End a transaction.
Gridarta can handle frame information of animations and allow the selection of an animation using a t...
String ANIMATION
The attribute name of the object's animation.
String FACE
The attribute name of the object's face.
String getAnimName()
Returns the current animation name.
final NamedObjects<?> animationObjects
The AnimationObjects for looking up animations.
A JPanel that allows the user to select a face name.
String defaultFaceComponentValue
The default value of faceComponent.
boolean defaultAnimatedCheckBoxValue
The default value of animatedCheckBox.
final JTextComponent animSpeedTextField
The JTextField for selecting the animation speed.
final DirectionComponent directionComponent
The DirectionComponent for selecting the game object's direction.
FaceTab(@NotNull final GameObjectAttributesModel< G, A, R > gameObjectAttributesModel, @NotNull final FaceObjects faceObjects, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final AnimationObjects animationObjects, @NotNull final ImageIcon noFaceSquareIcon, @NotNull final ImageIcon unknownSquareIcon)
Creates a new instance.
MODIFIED
The tab contents are modified from defaults.
The "Face" tab in the archetype chooser.
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
GameObject< G, A, R > getSelectedGameObject()
Returns the currently selected GameObject.
void setEnabled(final boolean enabled)
static void addFiller(@NotNull final GridBagLayout gridBagLayout, @NotNull final Container container, final int gridWidth, final int gridY)
Adds a filler component that fills the remaining space.
String DIRECTION
The attribute name of the object's direction.
final FaceComponent faceComponent
The FaceComponent for selecting the game object's face.
A GUI component for selecting a direction.
AnimationObjects is a container for AnimationObjects.
GameObjects are the objects based on Archetypes found on maps.
void setTabSeverity( @NotNull final Severity tabSeverity)
Sets the tab severity.
Component getInputComponent()
Returns the input field component.
FaceObjects is a container for FaceObjects.
Component createDirectionPanel()
Creates the "Direction" panel.
String getFaceName()
Returns the current face name.
ERROR
The tab contents are invalid.
String defaultAnimComponentValue
The default value of animationComponent.
void apply(@NotNull final G gameObject)
Component createFacePanel()
Creates the "Face" panel.
Severity levels for colors of tabs.
Utility class for ActionBuilder related functions.
void setEnabled(final boolean enabled)
final AnimationComponent animationComponent
The FaceComponent for selecting the game object's animation.
Provider for faces of GameObjects and Archetypes.
The face is the appearance of an object.
String IS_ANIMATED
The attribute name of the "is_animated" flag.
final void refresh(@Nullable final G gameObject)
final AbstractButton animatedCheckBox
The JCheckBox for selecting whether the game object is animated.
static final ActionBuilder ACTION_BUILDER
The action builder.
boolean containsKey(@NotNull String name)
Check whether an object is defined.
void setFaceName(@NotNull final String faceName)
Sets the current face name.
DEFAULT
The tab contents are unchanged from defaults.
static String normalizeFace(@Nullable final String value)
Normalizes a face or animation name.
final NamedObjects<?> faceObjects
The FaceObjects for looking up faces.
static JLabel newLabel(@NotNull final ActionBuilder actionBuilder, @NotNull final String key)
Creates a new JLabel from a resource key.
void beginTransaction(@NotNull String name)
Starts a new transaction.
Interface for MapArchObjects.
Base class for GameObjectAttributesTab implementations.
Component createAnimationPanel()
Creates the "Animation" panel.
final JPanel panel
The content panel.
String defaultAnimSpeedTextFieldValue
The default value of animSpeedTextField.