Gridarta Editor
ObjectChoiceDisplay.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2023 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.gui.panel.objectchoicedisplay;
21 
22 import java.awt.Color;
23 import java.awt.GridBagConstraints;
24 import java.awt.GridBagLayout;
25 import javax.swing.JLabel;
26 import javax.swing.JPanel;
30 import net.sf.japi.swing.action.ActionBuilder;
31 import net.sf.japi.swing.action.ActionBuilderFactory;
32 import org.jetbrains.annotations.NotNull;
33 import org.jetbrains.annotations.Nullable;
34 
41 public class ObjectChoiceDisplay extends JPanel {
42 
46  private static final long serialVersionUID = 1L;
47 
51  @NotNull
52  private static final ActionBuilder ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder("net.sf.gridarta");
53 
57  @NotNull
59 
63  @NotNull
64  private final JLabel gameObjectNameLabel = new JLabel();
65 
69  @NotNull
70  private final JLabel gameObjectArchetypeNameLabel = new JLabel();
71 
75  @NotNull
76  private final JLabel gameObjectTypeLabel = new JLabel();
77 
81  @NotNull
82  private final JLabel gameObjectExtentsLabel = new JLabel();
83 
89  this.archetypeTypeSet = archetypeTypeSet;
90  setLayout(new GridBagLayout());
91 
92  final GridBagConstraints gcl = new GridBagConstraints();
93  final GridBagConstraints gcr = new GridBagConstraints();
94  gcl.fill = GridBagConstraints.HORIZONTAL;
95  gcr.fill = GridBagConstraints.HORIZONTAL;
96  gcl.weightx = 0.0;
97  gcr.weightx = 1.0;
98  gcl.ipadx = 6;
99  gcr.ipadx = 0;
100  gcl.anchor = GridBagConstraints.WEST;
101  gcr.anchor = GridBagConstraints.WEST;
102  gcl.gridwidth = 1;
103  gcr.gridwidth = GridBagConstraints.REMAINDER;
104 
105  add(ActionBuilderUtils.newLabel(ACTION_BUILDER, "objectChooser.captionName"), gcl);
106  add(gameObjectNameLabel, gcr);
107 
108  add(ActionBuilderUtils.newLabel(ACTION_BUILDER, "objectChooser.captionArchetype"), gcl);
110 
111  add(ActionBuilderUtils.newLabel(ACTION_BUILDER, "objectChooser.captionType"), gcl);
112  add(gameObjectTypeLabel, gcr);
113 
114  add(ActionBuilderUtils.newLabel(ACTION_BUILDER, "objectChooser.captionTile"), gcl);
115  add(gameObjectExtentsLabel, gcr);
116  }
117 
125  public void showObjectChooserQuickObject(@Nullable final BaseObject<?, ?, ?, ?> gameObject, final boolean isPickmapActive) {
126  if (gameObject == null) {
127  if (isPickmapActive) {
128  gameObjectNameLabel.setText(ActionBuilderUtils.getString(ACTION_BUILDER, "objectChooser.randomPick"));
129  gameObjectNameLabel.setForeground(Color.BLUE);
130  } else {
131  gameObjectNameLabel.setText(null);
132  }
133  gameObjectArchetypeNameLabel.setText(null);
134  gameObjectTypeLabel.setText(null);
135  gameObjectExtentsLabel.setText(null);
136  } else {
137  final BaseObject<?, ?, ?, ?> headObject = gameObject.getHead();
138  final String objName = headObject.getBestName();
139  gameObjectNameLabel.setForeground(Color.BLACK);
140  gameObjectNameLabel.setText(objName);
141 
142  gameObjectArchetypeNameLabel.setText(headObject.getArchetype().getArchetypeName());
143 
145 
146  if (headObject.isMulti()) {
147  gameObjectExtentsLabel.setText(ACTION_BUILDER.format("objectChooser.tileSize", headObject.getMultiRefCount(), headObject.getSizeX(), headObject.getSizeY()));
148  } else {
149  gameObjectExtentsLabel.setText(ActionBuilderUtils.getString(ACTION_BUILDER, "objectChooser.tileSingle"));
150  }
151  }
152  }
153 
154 }
net.sf.gridarta.model.archetypetype
Defines types of GameObjects with corresponding attributes.
Definition: AbstractArchetypeAttributeInvSpell.java:20
net.sf.gridarta.model.baseobject.BaseObject.isMulti
boolean isMulti()
Returns whether this Archetype is a multi-part object.
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.model.archetypetype.ArchetypeTypeSet.getDisplayName
String getDisplayName(@NotNull final BaseObject<?, ?, ?, ?> baseObject)
Returns a description of this type.
Definition: ArchetypeTypeSet.java:258
net.sf.gridarta.gui.panel.objectchoicedisplay.ObjectChoiceDisplay.ACTION_BUILDER
static final ActionBuilder ACTION_BUILDER
The ActionBuilder.
Definition: ObjectChoiceDisplay.java:52
net.sf
net.sf.gridarta.model.baseobject.BaseObject.getSizeX
int getSizeX()
Determines the horizontal extent in squares.
net.sf.gridarta.model.baseobject.BaseObject.getBestName
String getBestName()
Returns the name which is best appropriate to describe this GameObject.
net.sf.gridarta.utils.ActionBuilderUtils.newLabel
static JLabel newLabel(@NotNull final ActionBuilder actionBuilder, @NotNull final String key)
Creates a new JLabel from a resource key.
Definition: ActionBuilderUtils.java:117
net.sf.gridarta.model.archetypetype.ArchetypeTypeSet
Manages ArchetypeType instances, list, and bitmask definitions.
Definition: ArchetypeTypeSet.java:40
net.sf.gridarta.model.baseobject.BaseObject.getArchetype
R getArchetype()
Returns the Archetype this GameObject is based on.
net
net.sf.gridarta.gui.panel.objectchoicedisplay.ObjectChoiceDisplay.gameObjectNameLabel
final JLabel gameObjectNameLabel
Displays the selected game object's name.
Definition: ObjectChoiceDisplay.java:64
net.sf.gridarta.utils.ActionBuilderUtils.getString
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
Definition: ActionBuilderUtils.java:71
net.sf.gridarta.gui.panel.objectchoicedisplay.ObjectChoiceDisplay.gameObjectArchetypeNameLabel
final JLabel gameObjectArchetypeNameLabel
Display the selected game object's archetype name.
Definition: ObjectChoiceDisplay.java:70
net.sf.gridarta.gui.panel.objectchoicedisplay.ObjectChoiceDisplay.archetypeTypeSet
final ArchetypeTypeSet archetypeTypeSet
The ArchetypeTypeSet for looking up game object types.
Definition: ObjectChoiceDisplay.java:58
net.sf.gridarta.model.baseobject.BaseObject
Definition: BaseObject.java:34
net.sf.gridarta.model.baseobject.BaseObject.getSizeY
int getSizeY()
Determines the vertical extent in squares.
net.sf.gridarta.gui.panel.objectchoicedisplay.ObjectChoiceDisplay.serialVersionUID
static final long serialVersionUID
The serial version UID.
Definition: ObjectChoiceDisplay.java:46
net.sf.gridarta.model.baseobject.BaseObject.getHead
T getHead()
Return the head part of a multi-part object.
net.sf.gridarta.gui.panel.objectchoicedisplay.ObjectChoiceDisplay.showObjectChooserQuickObject
void showObjectChooserQuickObject(@Nullable final BaseObject<?, ?, ?, ?> gameObject, final boolean isPickmapActive)
Displays information about the selected game object.
Definition: ObjectChoiceDisplay.java:125
net.sf.gridarta.model
net.sf.gridarta.model.baseobject
Definition: AbstractBaseObject.java:20
net.sf.gridarta.gui.panel.objectchoicedisplay.ObjectChoiceDisplay.gameObjectTypeLabel
final JLabel gameObjectTypeLabel
Display the selected game object's type information.
Definition: ObjectChoiceDisplay.java:76
net.sf.gridarta.utils.ActionBuilderUtils
Utility class for ActionBuilder related functions.
Definition: ActionBuilderUtils.java:31
net.sf.gridarta.gui.panel.objectchoicedisplay.ObjectChoiceDisplay
The object choice display shows information about the selected object in the object chooser.
Definition: ObjectChoiceDisplay.java:41
net.sf.gridarta.model.baseobject.BaseObject.getMultiRefCount
int getMultiRefCount()
Returns the number of parts for multi-part heads.
net.sf.gridarta.utils
Definition: ActionBuilderUtils.java:20
net.sf.gridarta.gui.panel.objectchoicedisplay.ObjectChoiceDisplay.ObjectChoiceDisplay
ObjectChoiceDisplay(@NotNull final ArchetypeTypeSet archetypeTypeSet)
Creates a new instance.
Definition: ObjectChoiceDisplay.java:88
net.sf.gridarta.gui.panel.objectchoicedisplay.ObjectChoiceDisplay.gameObjectExtentsLabel
final JLabel gameObjectExtentsLabel
Displays the selected game object's extents.
Definition: ObjectChoiceDisplay.java:82