20 package net.sf.gridarta.gui.panel.gameobjectattributes;
22 import java.awt.Color;
23 import java.awt.Component;
24 import java.awt.Container;
25 import java.awt.GridBagConstraints;
26 import java.awt.GridBagLayout;
27 import java.awt.Insets;
28 import javax.swing.ButtonGroup;
29 import javax.swing.JLabel;
30 import javax.swing.JPanel;
31 import javax.swing.JTextField;
32 import javax.swing.JToggleButton;
33 import javax.swing.text.JTextComponent;
43 import net.
sf.japi.swing.action.ActionBuilder;
44 import net.
sf.japi.swing.action.ActionBuilderFactory;
45 import net.
sf.japi.swing.action.ActionMethod;
46 import org.jetbrains.annotations.NotNull;
47 import org.jetbrains.annotations.Nullable;
61 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
117 private final JPanel
panel =
new JPanel();
131 super(gameObjectAttributesModel);
135 final GridBagLayout gridBagLayout =
new GridBagLayout();
136 final GridBagConstraints gbc =
new GridBagConstraints();
138 panel.setLayout(gridBagLayout);
139 gbc.fill = GridBagConstraints.BOTH;
142 gbc.anchor = GridBagConstraints.NORTHWEST;
143 gbc.insets =
new Insets(4, 4, 0, 0);
150 gridBagLayout.setConstraints(archNameField, gbc);
151 panel.add(archNameField);
153 archFaceText.setText(
"");
158 gridBagLayout.setConstraints(archFaceText, gbc);
159 panel.add(archFaceText);
161 archTypeText.setText(
"");
166 gridBagLayout.setConstraints(archTypeText, gbc);
167 panel.add(archTypeText);
169 archMapPos.setText(
"");
174 gridBagLayout.setConstraints(archMapPos, gbc);
175 panel.add(archMapPos);
183 panel.add(dirPanel, gbc);
186 refresh(gameObjectAttributesModel.getSelectedGameObject());
201 final Container dirPanel =
new JPanel(
new GridBagLayout());
202 final GridBagConstraints gbc =
new GridBagConstraints();
203 gbc.fill = GridBagConstraints.BOTH;
204 gbc.anchor = GridBagConstraints.CENTER;
205 gbc.insets =
new Insets(2, 2, 2, 2);
228 private void createButton(
final int direction, @NotNull
final Container panel, @NotNull
final GridBagConstraints gbc,
final int x,
final int y) {
229 final JToggleButton button =
new JToggleButton(ACTION_BUILDER.createAction(
false,
"direction" + direction,
this));
230 directionButtonGroup.add(button);
231 button.setFocusable(
false);
232 button.setEnabled(
false);
235 panel.add(button, gbc);
241 return !archNameField.getText().equals(defaultArchNameFieldValue);
246 archNameField.requestFocusInWindow();
250 protected void apply(@NotNull
final G gameObject) {
251 gameObject.setAttributeString(
BaseObject.
NAME, archNameField.getText());
255 protected final void refresh(@Nullable
final G gameObject) {
260 if (gameObject == null) {
263 final String objName = gameObject.getAttributeString(
BaseObject.
NAME,
false);
264 if (objName.isEmpty()) {
265 final String archObjName = gameObject.getArchetype().getObjName();
266 setArchNameField(archObjName.isEmpty() ? gameObject.getArchetype().getArchetypeName() : archObjName, Color.black);
273 if (gameObject == null) {
274 archFaceText.setText(
"Image:");
276 final StringBuilder faceText =
new StringBuilder(
"Image: ");
278 archFaceText.setText(faceText.toString());
282 if (gameObject == null) {
283 archTypeText.setText(
"Type:");
285 final StringBuilder typeText =
new StringBuilder(
"Type: ");
287 typeText.append(
" [").append(gameObject.getArchetype().getArchetypeName()).append(
']');
288 if (gameObject.isMulti()) {
289 typeText.append(
" [").append(gameObject.getSizeX()).append(
'x').append(gameObject.getSizeY()).append(
']');
291 typeText.append(
" [single]");
293 archTypeText.setText(typeText.toString());
297 if (gameObject == null) {
298 archMapPos.setText(
"Status: ");
300 final StringBuilder specialText =
new StringBuilder(
"Status:");
301 if (!gameObject.isInContainer()) {
302 specialText.append(
" (map: ").append(gameObject.getMapX()).append(
", ").append(gameObject.getMapY()).append(
')');
304 if (gameObject.isScripted()) {
305 specialText.append(
" (script)");
307 if (gameObject.getMsgText() != null || gameObject.getArchetype().getMsgText() != null) {
308 specialText.append(
" (msg)");
310 final int invObjects = gameObject.countInvObjects();
311 if (invObjects > 0) {
312 specialText.append(
" (inv: ").append(invObjects).append(
')');
316 specialText.append(
" (env: ").append(cont.
getArchetype().getArchetypeName()).append(
')');
318 archMapPos.setText(specialText.toString());
322 for (
final Component button : directionButtons) {
323 button.setBackground(null);
325 final boolean enableDirButtons = gameObject != null && gameObject.
usesDirection();
326 for (
final Component button : directionButtons) {
327 button.setEnabled(enableDirButtons);
329 final int direction = enableDirButtons ? gameObject.getDirection() : 0;
330 directionButtons[direction < directionButtons.length ?
direction : 0].setSelected(
true);
340 final String faceName = gameObject.getFaceObjName();
341 if (faceName != null) {
342 final FaceSource faceSource = gameObject.getFaceObjSource();
343 sb.append(faceName).append(
" (");
344 switch (faceSource) {
346 sb.append(
"face not found");
354 sb.append(
"archetype face");
362 sb.append(
"archetype anim");
367 sb.append(
">no face<");
449 if (selectedGameObject == null) {
454 if (mapSquare == null) {
473 archNameField.setForeground(color);
474 archNameField.setText(objName);
475 defaultArchNameFieldValue = objName;
void apply(@NotNull final G gameObject)
void addAutoApply( @NotNull final Component component)
Registers a component that auto-applies when the focus is lost.
void direction2()
Action method for direction.
void setArchNameField(@NotNull final String objName, @NotNull final Color color)
Updates the value of the archNameField.
Component createDirPanel()
Creates the panel consisting of the direction buttons.
void direction3()
Action method for direction.
A MapModel reflects the data of a map.
void direction1()
Action method for direction.
final ButtonGroup directionButtonGroup
The ButtonGroup for the direction buttons.
Graphical User Interface of Gridarta.
MapModel< G, A, R > getMapModel()
Returns the MapModel this map square is part of.
Manages ArchetypeType instances, list, and bitmask definitions.
void endTransaction()
End a transaction.
Enumeration describing the state of the face.
final ArchetypeTypeSet archetypeTypeSet
The archetype type set.
void createButton(final int direction, @NotNull final Container panel, @NotNull final GridBagConstraints gbc, final int x, final int y)
Creates a direction button.
void setAttributeInt(@NotNull String attributeName, int value)
Sets an int value attribute.
MODIFIED
The tab contents are modified from defaults.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
static final ActionBuilder ACTION_BUILDER
The action builder.
final JLabel archMapPos
The label containing the location of the game object on the map.
String DIRECTION
The attribute name of the object's direction.
final void refresh(@Nullable final G gameObject)
String defaultArchNameFieldValue
The initial value of the archNameField.
void direction5()
Action method for direction.
void direction4()
Action method for direction.
void direction6()
Action method for direction.
GameObjects are the objects based on Archetypes found on maps.
final JTextComponent archNameField
The input field containing the game object's name.
boolean usesDirection()
Return whether this base object uses the "direction" attribute.
void direction8()
Action method for direction.
void setTabSeverity( @NotNull final Severity tabSeverity)
Sets the tab severity.
final GameObjectAttributesModel< G, A, R > gameObjectAttributesModel
The model to track.
G getSelectedGameObject()
Returns the selected game object.
R getArchetype()
Returns the Archetype this GameObject is based on.
ArchTab(@NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final GameObjectAttributesModel< G, A, R > gameObjectAttributesModel)
Creates a new instance.
static void appendFaceSource(@NotNull final StringBuilder sb, @NotNull final BaseObject<?, ?, ?, ?> gameObject)
Appends a description of a game object's face to a StringBuilder.
Severity levels for colors of tabs.
final JPanel panel
The content panel.
String NAME
The attribute name of the object's name.
void direction7()
Action method for direction.
DEFAULT
The tab contents are unchanged from defaults.
void direction0()
Action method for direction.
String getDisplayName(@NotNull final BaseObject<?, ?, ?, ?> baseObject)
Returns a description of this type.
void beginTransaction(@NotNull String name)
Starts a new transaction.
void direction(final int direction)
Action proxy for direction.
final JLabel archTypeText
The label containing information about the game object's type.
Defines types of GameObjects with corresponding attributes.
G selectedGameObject
The currently selected game object.
final JToggleButton [] directionButtons
The buttons for the direction panel.
final JLabel archFaceText
The label containing the game object's face name.
Interface for MapArchObjects.
Base class for GameObjectAttributesTab implementations.
MapSquare< G, A, R > getMapSquare()
Get the MapSquare of this GameObjectContainer.
The "Arch" tab in the archetype chooser.