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;
31 import javax.swing.Action;
32 import javax.swing.JButton;
33 import javax.swing.JLabel;
34 import javax.swing.JPanel;
35 import javax.swing.JTabbedPane;
36 import javax.swing.SwingConstants;
61 import net.
sf.japi.swing.action.ActionBuilder;
62 import net.
sf.japi.swing.action.ActionBuilderFactory;
63 import net.
sf.japi.swing.action.ActionMethod;
64 import org.jetbrains.annotations.NotNull;
65 import org.jetbrains.annotations.Nullable;
83 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
120 private final JTabbedPane
panelDesktop =
new JTabbedPane(SwingConstants.TOP);
156 private final Action
aMapArchAddInv = ACTION_BUILDER.createAction(
false,
"mapArchAddInv",
this);
162 private final Action
aMapArchAddEnv = ACTION_BUILDER.createAction(
false,
"mapArchAddEnv",
this);
168 private final Action
aMapArchAttribute = ACTION_BUILDER.createAction(
false,
"mapArchAttrib",
this);
174 private final Collection<GameObjectAttributesTab<G, A, R>>
tabs =
new HashSet<>();
180 private final Map<GameObjectAttributesTab<G, A, R>, Integer>
tabIndex =
new IdentityHashMap<>();
186 private final Map<Component, GameObjectAttributesTab<G, A, R>>
componentTabs =
new IdentityHashMap<>();
208 if (currentMapControl != null) {
213 currentMapControl = mapControl;
214 if (currentMapControl != null) {
222 public void mapCreated(@NotNull
final MapControl<G, A, R> mapControl,
final boolean interactive) {
245 public void mapSizeChanged(@NotNull
final Size2D newSize) {
251 if (selectedGameObject == null) {
255 final G topGameObject = selectedGameObject.getTopContainer();
256 for (
final Iterable<G> mapSquare : mapSquares) {
257 for (
final G gameObject : mapSquare) {
258 if (gameObject == topGameObject) {
266 public void mapObjectsChanged(@NotNull
final Set<G> gameObjects, @NotNull
final Set<G> transientGameObjects) {
268 if (selectedGameObject == gameObject.getHead()) {
280 public void mapFileChanged(@Nullable
final MapFile oldMapFile) {
285 public void modifiedChanged() {
300 public void preBeginTransaction() {
302 isInMapTransaction =
true;
306 public void beginTransaction(@NotNull
final String name) {
316 public void postEndTransaction() {
317 isInMapTransaction =
false;
329 public void selectionChanged(@Nullable
final MapSquare<G, A, R> mapSquare, @Nullable
final G gameObject) {
342 public void selectedGameObjectChanged(@Nullable
final G selectedGameObject) {
349 public void refreshSelectedGameObject() {
367 public void apply() {
385 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) {
386 super(
new BorderLayout());
394 final Container mapArchPanel =
new JPanel();
395 mapArchPanel.setLayout(
new BorderLayout());
396 add(mapArchPanel, BorderLayout.CENTER);
399 buttonPanel.setLayout(
new GridLayout(0, 1));
400 mapArchPanel.add(buttonPanel, BorderLayout.WEST);
401 mapArchPanel.add(panelDesktop, BorderLayout.CENTER);
403 selectedSquareModel.addSelectedSquareListener(selectedSquareModelListener);
404 gameObjectAttributesModel.addGameObjectAttributesModelListener(gameObjectAttributesModelListener);
406 selectedGameObject = gameObjectAttributesModel.getSelectedGameObject();
408 currentMapControl = mapManager.getCurrentMap();
409 if (currentMapControl != null) {
414 mapManager.addMapManagerListener(mapManagerListener);
422 listeners.
add(listener);
430 listeners.
remove(listener);
438 tabIndex.put(tab, panelDesktop.getTabCount());
440 panelDesktop.add(tab.getPanel(),
ActionBuilderUtils.
getString(ACTION_BUILDER,
"mapArchTab" + tab.getClass().getSimpleName() +
".text"));
450 componentTabs.put(tab.
getPanel(), tab);
459 if (!tabs.contains(tab)) {
460 throw new IllegalArgumentException();
463 panelDesktop.setSelectedComponent(tab.getPanel());
472 final Component component = panelDesktop.getSelectedComponent();
484 final Integer index = tabIndex.get(tab);
490 final JLabel title =
new JLabel(panelDesktop.getTitleAt(index));
491 title.setForeground(tabSeverity.getColor());
492 panelDesktop.setTabComponentAt(index, title);
494 Severity mainSeverity = tabSeverity;
496 final Severity tmpSeverity = pair2.getKey().getTabSeverity();
498 mainSeverity = tmpSeverity;
501 if (severity == mainSeverity) {
504 severity = mainSeverity;
506 listener.severityChanged(mainSeverity);
523 aMapArchAddInv.setEnabled(selectedGameObject != null);
524 aMapArchAddEnv.setEnabled(selectedGameObject != null);
525 aMapArchAttribute.setEnabled(selectedGameObject != null);
535 if (selectedGameObject != null) {
552 if (gameObject == null) {
556 final G invNew = arch.
newInstance(gameObjectFactory);
559 assert mapSquare != null;
579 if (baseObject == null) {
584 if (prevGameObject == null) {
589 assert mapSquare != null;
594 if (insertedGameObject != null) {
596 insertedGameObject.addLast(prevGameObject);
609 if (selectedGameObject == null || isInAutoApplyArchPanelChanges || isInMapTransaction) {
613 isInAutoApplyArchPanelChanges =
true;
617 isInAutoApplyArchPanelChanges =
false;
627 if (gameObject == null) {
632 if (mapSquare == null) {
638 boolean canApply =
false;
640 if (tab.canApply()) {
653 if (tab.canApply()) {
668 final Container buttonPanel =
new JPanel();
669 buttonPanel.add(
new JButton(aMapArchAddInv));
670 buttonPanel.add(
new JButton(aMapArchAddEnv));
671 buttonPanel.add(
new JButton(aMapArchAttribute));
void removeGameObjectAttributesControlListener(@NotNull final GameObjectAttributesControlListener listener)
Removes a GameObjectAttributesControlListener to notify.
final MapTransactionListener< G, A, R > mapTransactionListener
The map transaction listener which is attached to currentMapControl.
void removeMapTransactionListener(@NotNull MapTransactionListener< G, A, R > listener)
Unregisters a map transaction listener.
static final long serialVersionUID
The serial version UID.
MapSquare< G, A, R > getMapSquare()
A MapModel reflects the data of a map.
A MapManager manages all opened maps.
void autoApplyArchPanelChanges()
Same as applyArchPanelChanges() but does protect against recursive calls.
boolean isAutojoin()
Returns whether "autojoin" is enabled.
Graphical User Interface of Gridarta.
T [] getListeners()
Returns an array of all the listeners.
G selectedGameObject
The currently selected game object.
final MapViewSettings mapViewSettings
The MapViewSettings instance.
MapModel< G, A, R > getMapModel()
Returns the MapModel this map square is part of.
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)
Create the GameObjectAttributesPanel.
This package contains the framework for validating maps.
void refreshDisplay()
Update the displayed information for the selected game object.
void endTransaction()
End a transaction.
final Collection< GameObjectAttributesTab< G, A, R > > tabs
All active tabs.
void removeGameObject(@NotNull G gameObject, boolean join)
Delete an existing GameObject from the map.
final MapModelListener< G, A, R > mapModelListener
The map model listener which is attached to currentMapControl.
Interface for listeners listening on MapModel events.
A factory that creates dialogs for editing game object attributes.
BaseObject< G, A, R, ?> getSelection()
Returns the active arch in the left-side panel.
Interface for listeners interested in events of SelectedSquareModel instances.
void createInventory(@NotNull GameObject< G, A, R > gameObject, @NotNull Iterable< G > archetype)
Copies inventory objects from an archetype into a game object.
void addMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Register a map listener.
final GameObjectAttributesDialogFactory< G, A, R > gameObjectAttributesDialogFactory
The MainControl to use, e.g.
MapModel< G, A, R > getMapModel()
Returns the map model.
Severity severity
The overall Severity.
boolean isInAutoApplyArchPanelChanges
Whether autoApplyArchPanelChanges() is currently running.
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
Severity getSeverity()
Returns the overall Severity.
Base package of all Gridarta classes.
final GameObjectAttributesTabListener< G, A, R > gameObjectAttributesTabListener
The listener attached to all tabs.
Interface for listeners listening on map transactions of MapModels.
Container createButtonPanel()
Creates the button panel containing the actions.
final GameObjectAttributesModel< G, A, R > gameObjectAttributesModel
The model used by this controller.
final JTabbedPane panelDesktop
The main panel.
Reflects a game object (object on a map).
void addTab(@NotNull final GameObjectAttributesTab< G, A, R > tab)
Adds a tab.
void mapArchAttrib()
Action method for displaying the attributes of the currently selected object.
void addMapTransactionListener(@NotNull MapTransactionListener< G, A, R > listener)
Registers a map transaction listener.
Abstract factory for creating GameObject instances.
void addGameObjectAttributesTabListener(@NotNull GameObjectAttributesTabListener< G, A, R > listener)
Adds a listener.
final Action aMapArchAttribute
Action for "edit attributes".
void fireRefreshSelectedGameObject()
Notifies all listeners that the selected game object has changed.
Interface for listeners listening to MapManager changes.
Interface for listeners interested in GameObjectAttributesControl related events. ...
void remove(@NotNull final T listener)
Removes a listener.
final Map< Component, GameObjectAttributesTab< G, A, R > > componentTabs
Maps tab's component to tab.
Container for settings that affect the rendering of maps.
void setTabSeverity(@NotNull final GameObjectAttributesTab< G, A, R > tab, @NotNull final Severity tabSeverity)
Sets the tab color of a tab.
GameObjects are the objects based on Archetypes found on maps.
void add(@NotNull final T listener)
Adds a listener.
final MapManagerListener< G, A, R > mapManagerListener
The map manager listener.
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.
Point getMapLocation()
Returns the coordinate on the map.
final SelectedSquareModelListener< G, A, R > selectedSquareModelListener
The listener to detect changes of the selected game object.
MapControl< G, A, R > currentMapControl
Last known active map.
final GameObjectAttributesModelListener< G, A, R > gameObjectAttributesModelListener
The listener attached to gameObjectAttributesModel.
Displays the contents of the currently selected map square.
JPanel getPanel()
Creates the contents panel.
int getLevel()
Returns the severity level.
GameObjectAttributesTab< G, A, R > getSelectedTab()
Returns the selected tab.
G newInstance(@NotNull GameObjectFactory< G, A, R > gameObjectFactory)
Creates a new GameObject instance: an Archetype is instantiated, a GameObject is cloned.
void applyArchPanelChanges()
When the "apply"-button on the ArchPanel (at the bottom of the window) is pressed, this function updates the active arch object.
void removeMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Unregister a map listener.
final ObjectChooser< G, A, R > objectChooser
The object chooser instance.
Severity levels for colors of tabs.
Utility class for ActionBuilder related functions.
Common base class for the panel that allows users to edit a GameObject's attributes.
Type-safe version of EventListenerList.
static final ActionBuilder ACTION_BUILDER
Action Builder.
void mapArchAddInv()
Action method for adding an object to the inventory of the currently selected object.
Currently nothing more than a marker interface for unification.
Records a set of changed map squares.
An interface for classes that collect errors.
DEFAULT
The tab contents are unchanged from defaults.
void mapArchAddEnv()
Action method for adding the currently selected object to the inventory of a new object.
void addGameObjectAttributesControlListener(@NotNull final GameObjectAttributesControlListener listener)
Adds a GameObjectAttributesControlListener to notify.
void setSelectedGameObject(@Nullable final G gameObject)
Sets the currently selected GameObject.
void setSelectedGameObject(@Nullable final G selectedGameObject)
If a game object is selected, the MapArchPanels (bottom right windows) get updated.
Common base interface for ObjectChoosers.
void beginTransaction(@NotNull String name)
Starts a new transaction.
The model component of the selected square control.
final Action aMapArchAddEnv
Action for "add to environment".
final EventListenerList2< GameObjectAttributesControlListener > listeners
The registered GameObjectAttributesControlListeners to notify.
final SelectedSquareModel< G, A, R > selectedSquareModel
The SelectedSquareModel to update.
void addLast(@NotNull G gameObject)
Add the given GameObject at the end of this Container.
void showAttributeDialog(@NotNull final G gameObject)
Shows the game object attributes dialog for a given GameObject instance.
boolean isInMapTransaction
Records whether a map transaction is active.
final Action aMapArchAddInv
Action for "add to inventory".
The location of a map file with a map directory.
Interface for MapArchObjects.
void selectTab(@NotNull final GameObjectAttributesTab< G, A, R > tab)
Selects a tab.
final Map< GameObjectAttributesTab< G, A, R >, Integer > tabIndex
Maps tab to tab index.
final GameObjectFactory< G, A, R > gameObjectFactory
The GameObjectFactory for creating new GameObjects.
void addTabInt(final GameObjectAttributesTab< G, A, R > tab)
Adds a tab which is not shown in the tab panel.
The class Size2D represents a 2d rectangular area.
MapSquare< G, A, R > getMapSquare()
Get the MapSquare of this GameObjectContainer.