 |
Gridarta Editor
|
Go to the documentation of this file.
20 package net.sf.gridarta.gui.panel.gameobjectattributes;
22 import java.awt.BorderLayout;
23 import java.awt.Component;
24 import java.awt.Container;
25 import java.awt.GridLayout;
26 import java.util.Collection;
27 import java.util.HashSet;
28 import java.util.IdentityHashMap;
30 import java.util.Map.Entry;
32 import java.util.concurrent.CopyOnWriteArrayList;
33 import javax.swing.Action;
34 import javax.swing.JButton;
35 import javax.swing.JLabel;
36 import javax.swing.JPanel;
37 import javax.swing.JTabbedPane;
38 import javax.swing.SwingConstants;
62 import net.
sf.japi.swing.action.ActionBuilder;
63 import net.
sf.japi.swing.action.ActionBuilderFactory;
64 import net.
sf.japi.swing.action.ActionMethod;
65 import org.jetbrains.annotations.NotNull;
66 import org.jetbrains.annotations.Nullable;
84 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
121 private final JTabbedPane
panelDesktop =
new JTabbedPane(SwingConstants.TOP);
134 private final Collection<GameObjectAttributesControlListener>
listeners =
new CopyOnWriteArrayList<>();
175 private final Collection<GameObjectAttributesTab<G, A, R>>
tabs =
new HashSet<>();
181 private final Map<GameObjectAttributesTab<G, A, R>, Integer>
tabIndex =
new IdentityHashMap<>();
187 private final Map<Component, GameObjectAttributesTab<G, A, R>>
componentTabs =
new IdentityHashMap<>();
223 public void mapCreated(@NotNull
final MapControl<G, A, R> mapControl,
final boolean interactive) {
246 public void mapSizeChanged(@NotNull
final Size2D newSize) {
257 for (
final Iterable<G> mapSquare : mapSquares) {
258 for (
final G gameObject : mapSquare) {
259 if (gameObject == topGameObject) {
267 public void mapObjectsChanged(@NotNull
final Set<G> gameObjects, @NotNull
final Set<G> transientGameObjects) {
281 public void mapFileChanged(@Nullable
final MapFile oldMapFile) {
286 public void modifiedChanged() {
301 public void preBeginTransaction() {
307 public void beginTransaction(@NotNull
final String
name) {
317 public void postEndTransaction() {
330 public void selectionChanged(@Nullable
final MapSquare<G, A, R> mapSquare, @Nullable
final G gameObject) {
350 public void refreshSelectedGameObject() {
368 public void apply() {
386 public GameObjectAttributesControl(@NotNull
final GameObjectAttributesModel<G, A, R> gameObjectAttributesModel, @NotNull
final GameObjectAttributesDialogFactory<G, A, R> gameObjectAttributesDialogFactory, @NotNull
final ObjectChooser<G, A, R> objectChooser, @NotNull
final MapManager<G, A, R> mapManager, @NotNull
final SelectedSquareModel<G, A, R> selectedSquareModel, @NotNull
final GameObjectFactory<G, A, R> gameObjectFactory, @NotNull
final MapViewSettings mapViewSettings) {
387 super(
new BorderLayout());
395 final Container mapArchPanel =
new JPanel();
396 mapArchPanel.setLayout(
new BorderLayout());
397 add(mapArchPanel, BorderLayout.CENTER);
400 buttonPanel.setLayout(
new GridLayout(0, 1));
401 mapArchPanel.add(buttonPanel, BorderLayout.WEST);
460 if (!
tabs.contains(tab)) {
461 throw new IllegalArgumentException(
"undefined tab: " + tab);
473 final Component component =
panelDesktop.getSelectedComponent();
485 final Integer index =
tabIndex.get(tab);
491 final JLabel title =
new JLabel(
panelDesktop.getTitleAt(index));
492 title.setForeground(tabSeverity.getColor());
495 Severity mainSeverity = tabSeverity;
497 final Severity tmpSeverity = pair2.getKey().getTabSeverity();
499 mainSeverity = tmpSeverity;
507 listener.severityChanged(mainSeverity);
553 if (gameObject ==
null) {
578 if (baseObject ==
null) {
583 if (prevGameObject ==
null) {
592 if (insertedGameObject !=
null) {
594 insertedGameObject.addLast(prevGameObject);
625 if (gameObject ==
null) {
630 if (mapSquare ==
null) {
636 boolean canApply =
false;
638 if (tab.canApply()) {
651 if (tab.canApply()) {
666 final Container buttonPanel =
new JPanel();
G insertArchToMap(@NotNull BaseObject< G, A, R, ?> templateBaseObject, @Nullable G nextGameObject, @NotNull Point pos, boolean join)
Insert a game object to the map at a specified position.
void applyArchPanelChanges()
When the "apply"-button on the ArchPanel (at the bottom of the window) is pressed,...
A MapModel reflects the data of a map.
Container createButtonPanel()
Creates the button panel containing the actions.
GameObjectAttributesControl(@NotNull final GameObjectAttributesModel< G, A, R > gameObjectAttributesModel, @NotNull final GameObjectAttributesDialogFactory< G, A, R > gameObjectAttributesDialogFactory, @NotNull final ObjectChooser< G, A, R > objectChooser, @NotNull final MapManager< G, A, R > mapManager, @NotNull final SelectedSquareModel< G, A, R > selectedSquareModel, @NotNull final GameObjectFactory< G, A, R > gameObjectFactory, @NotNull final MapViewSettings mapViewSettings)
Creates a new instance.
Abstract factory for creating GameObject instances.
A MapManager manages all opened maps.
static final long serialVersionUID
The serial version UID.
Point getMapLocation()
Returns the coordinate on the map.
Common base class for the panel that allows users to edit a GameObject's attributes.
final MapViewSettings mapViewSettings
The MapViewSettings instance.
Base package of all Gridarta classes.
void endTransaction()
End a transaction.
void showAttributeDialog(@NotNull final G gameObject)
Shows the game object attributes dialog for a given GameObject instance.
final GameObjectAttributesModelListener< G, A, R > gameObjectAttributesModelListener
The listener attached to gameObjectAttributesModel.
void addGameObjectAttributesTabListener(@NotNull GameObjectAttributesTabListener< G, A, R > listener)
Adds a listener.
Interface for listeners listening on map transactions of MapModels.
void beginTransaction(@NotNull String name)
Starts a new transaction.
boolean isAutojoin()
Returns whether "autojoin" is enabled.
Interface for listeners listening to MapManager changes.
Severity getSeverity()
Returns the overall Severity.
final MapModelListener< G, A, R > mapModelListener
The map model listener which is attached to currentMapControl.
void setSelectedGameObject(@Nullable final G selectedGameObject)
If a game object is selected, the MapArchPanels (bottom right windows) get updated.
final Collection< GameObjectAttributesControlListener > listeners
The registered GameObjectAttributesControlListeners to notify.
Reflects a game object (object on a map).
Container for settings that affect the rendering of maps.
void addTab(@NotNull final GameObjectAttributesTab< G, A, R > tab)
Adds a tab.
void addMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Register a map listener.
Severity severity
The overall Severity.
boolean isInMapTransaction
Records whether a map transaction is active.
final Collection< GameObjectAttributesTab< G, A, R > > tabs
All active tabs.
void fireRefreshSelectedGameObject()
Notifies all listeners that the selected game object has changed.
final Map< Component, GameObjectAttributesTab< G, A, R > > componentTabs
Maps tab's component to tab.
Graphical User Interface of Gridarta.
final GameObjectAttributesDialogFactory< G, A, R > gameObjectAttributesDialogFactory
The MainControl to use, e.g.
Records a set of changed map squares.
G selectedGameObject
The currently selected game object.
Interface for listeners interested in GameObjectAttributesControl related events.
Severity levels for colors of tabs.
final Action aMapArchAddInv
Action for "add to inventory".
final MapManagerListener< G, A, R > mapManagerListener
The map manager listener.
GameObjects are the objects based on Archetypes found on maps.
final MapTransactionListener< G, A, R > mapTransactionListener
The map transaction listener which is attached to {}.
void mapArchAttrib()
Action method for displaying the attributes of the currently selected object.
Interface for listeners interested in events of SelectedSquareModel instances.
void addTabInt(final GameObjectAttributesTab< G, A, R > tab)
Adds a tab which is not shown in the tab panel.
void removeMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Unregister a map listener.
Interface for MapArchObjects.
void autoApplyArchPanelChanges()
Same as applyArchPanelChanges() but does protect against recursive calls.
void removeGameObject(@NotNull G gameObject, boolean join)
Delete an existing GameObject from the map.
void mapArchAddEnv()
Action method for adding the currently selected object to the inventory of a new object.
The model component of the selected square control.
final Action aMapArchAttribute
Action for "edit attributes".
void removeMapTransactionListener(@NotNull MapTransactionListener< G, A, R > listener)
Unregisters a map transaction listener.
final ObjectChooser< G, A, R > objectChooser
The object chooser instance.
An interface for classes that collect errors.
final SelectedSquareModelListener< G, A, R > selectedSquareModelListener
The listener to detect changes of the selected game object.
BaseObject< G, A, R, ?> getSelection()
Returns the active arch in the left-side panel.
This package contains the framework for validating maps.
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
final Action aMapArchAddEnv
Action for "add to environment".
void setSelectedGameObject(@Nullable final G gameObject)
Sets the currently selected GameObject.
The location of a map file with a map directory.
void removeGameObjectAttributesControlListener(@NotNull final GameObjectAttributesControlListener listener)
Removes a GameObjectAttributesControlListener to notify.
Common base interface for ObjectChoosers.
void addMapTransactionListener(@NotNull MapTransactionListener< G, A, R > listener)
Registers a map transaction listener.
MapModel< G, A, R > getMapModel()
Returns the MapModel this map square is part of.
GameObjectAttributesTab< G, A, R > getSelectedTab()
Returns the selected tab.
A factory that creates dialogs for editing game object attributes.
Interface for listeners listening on MapModel events.
void addSelectedSquareListener(@NotNull final SelectedSquareModelListener< G, A, R > listener)
Adds a SelectedSquareModelListener to be notified.
MapSquare< G, A, R > getMapSquareOptional()
Returns the MapSquare this game object is part of.
void addGameObjectAttributesModelListener(@NotNull final GameObjectAttributesModelListener< G, A, R > listener)
Adds a listener to be notified.
void addLast(@NotNull G gameObject)
Add the given GameObject at the end of this Container.
int getLevel()
Returns the severity level.
final GameObjectAttributesTabListener< G, A, R > gameObjectAttributesTabListener
The listener attached to all tabs.
final SelectedSquareModel< G, A, R > selectedSquareModel
The SelectedSquareModel to update.
void refreshDisplay()
Update the displayed information for the selected game object.
final GameObjectAttributesModel< G, A, R > gameObjectAttributesModel
The model used by this controller.
final JTabbedPane panelDesktop
The main panel.
Currently nothing more than a marker interface for unification.
MapSquare< G, A, R > getMapSquare()
Returns the MapSquare this game object is part of.
Utility class for ActionBuilder related functions.
MapModel< G, A, R > getMapModel()
Returns the map model.
static final ActionBuilder ACTION_BUILDER
Action Builder.
void addGameObjectAttributesControlListener(@NotNull final GameObjectAttributesControlListener listener)
Adds a GameObjectAttributesControlListener to notify.
void selectTab(@NotNull final GameObjectAttributesTab< G, A, R > tab)
Selects a tab.
JPanel getPanel()
Creates the contents panel.
void mapArchAddInv()
Action method for adding an object to the inventory of the currently selected object.
G getSelectedGameObject()
Returns the selected game object.
Displays the contents of the currently selected map square.
void setTabSeverity(@NotNull final GameObjectAttributesTab< G, A, R > tab, @NotNull final Severity tabSeverity)
Sets the tab color of a tab.
DEFAULT
The tab contents are unchanged from defaults.
The class Size2D represents a 2d rectangular area.
MapSquare< G, A, R > getMapSquare()
Returns the MapSquare this game object is part of.
MapControl< G, A, R > currentMapControl
Last known active map.
final Map< GameObjectAttributesTab< G, A, R >, Integer > tabIndex
Maps tab to tab index.
boolean isInAutoApplyArchPanelChanges
Whether autoApplyArchPanelChanges() is currently running.
void createInventory(@NotNull GameObject< G, A, R > gameObject, @NotNull Iterable< G > archetype)
Copies inventory objects from an archetype into a game object.
final GameObjectFactory< G, A, R > gameObjectFactory
The GameObjectFactory for creating new GameObjects.