20 package net.sf.gridarta.gui.panel.objectchooser;
22 import java.awt.BorderLayout;
23 import java.awt.Point;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.Collections;
27 import java.util.List;
28 import javax.swing.JPanel;
29 import javax.swing.JTabbedPane;
30 import javax.swing.SwingConstants;
31 import javax.swing.event.ChangeEvent;
32 import javax.swing.event.ChangeListener;
53 import org.jetbrains.annotations.NotNull;
54 import org.jetbrains.annotations.Nullable;
90 private final JTabbedPane
tabbedPane =
new JTabbedPane(SwingConstants.TOP);
96 private final List<ObjectChooserTab<G, A, R>>
tabs =
new ArrayList<>();
102 private final Collection<ObjectChooserListener<G, A, R>>
listeners =
new ArrayList<>();
140 public void mapCursorChangedPos(@NotNull
final Point location) {
145 public void mapCursorChangedMode() {
150 public void mapCursorChangedGameObject(@Nullable
final MapSquare<G, A, R> mapSquare, @Nullable
final G gameObject) {
155 public void mapCursorChangedSize() {
169 public DefaultObjectChooser(@NotNull
final ObjectChooserTab<G, A, R> archetypeChooserControl, @NotNull
final ObjectChooserTab<G, A, R> pickmapChooserControl, @NotNull
final ArchetypeChooserModel<G, A, R> archetypeChooserModel, @NotNull
final PickmapChooserModel<G, A, R> pickmapChooserModel, @NotNull
final ArchetypeTypeSet archetypeTypeSet) {
170 super(
new BorderLayout());
177 addTab(archetypeChooserControl);
178 addTab(pickmapChooserControl);
180 final ChangeListener changeListener =
new ChangeListener() {
183 public void stateChanged(
final ChangeEvent e) {
188 tabbedPane.addChangeListener(changeListener);
191 add(tabbedPane, BorderLayout.CENTER);
192 add(objectChoiceDisplay, BorderLayout.SOUTH);
207 public void selectedArchetypeChanged(@Nullable
final R selectedArchetype) {
214 public void directionChanged(@Nullable
final Integer direction) {
224 archetypeChooserModel.addArchetypeChooserModelListener(archetypeChooserModelListener);
230 if (activePickmapState != pickmapState) {
237 if (activePickmapState == pickmapState) {
243 public void pickmapModifiedChanged(
final int index, @NotNull
final PickmapState<G, A, R> pickmapState) {
248 pickmapChooserModel.addPickmapChooserListener(pickmapChooserModelListener);
259 tabbedPane.addTab(tab.getTitle(), tab.getComponent());
269 tab = tabs.get(index);
270 }
catch (
final IndexOutOfBoundsException ignored) {
273 if (activeTab == tab) {
277 if (activeTab != null) {
281 if (activeTab != null) {
307 return activeTab != null && activeTab.
isMatching(gameObject);
312 listeners.add(listener);
317 listeners.remove(listener);
322 tabbedPane.setSelectedIndex(0);
327 tabbedPane.setSelectedIndex(1);
339 return activeTab == null ? null : activeTab.
getSelection();
345 return activeTab == null ? Collections.<G>emptyList() : activeTab.
getSelections();
352 final int index = tabbedPane.getSelectedIndex();
353 if (index != selectedIndex) {
354 selectedIndex = index;
364 if (activePickmapView != null) {
367 activePickmapState = pickmapState;
369 if (activePickmapView != null) {
378 activePickmapView = activePickmapState != null ? activePickmapState.
getMapView() : null;
389 if (mapCursor == null) {
392 final Point location = mapCursor.getLocation();
393 if (activePickmapState == null) {
397 if (pickmap == null) {
414 if (cursorSelection == gameObject) {
417 cursorSelection = gameObject;
420 listener.selectionChanged(gameObject);
final ObjectChoiceDisplay objectChoiceDisplay
The ObjectChoiceDisplay that display information about the currently selected object.
final MapCursorListener< G, A, R > mapCursorListener
The map cursor listener attached to activePickmapView.
R getSelectedArchetype()
Returns the selected Archetype.
A MapModel reflects the data of a map.
Graphical User Interface of Gridarta.
int selectedIndex
The current state of selection.
Interface for listeners for pickmap related events.
A named panel within the ArchetypeChooserModel.
Manages ArchetypeType instances, list, and bitmask definitions.
Maintains the state of a pickmap file.
A named folder within the ArchetypeChooserModel.
void removeObjectChooserListener(@NotNull final ObjectChooserListener< G, A, R > listener)
MapCursor provides methods to move and drag on map.
BaseObject< G, A, R, ?> cursorSelection
The last reported selection.
List<? extends BaseObject< G, A, R, ?> > getSelections()
final JTabbedPane tabbedPane
Panel holding both archetype chooser and pickmap chooser.
MapModel< G, A, R > getMapModel()
Returns the map model.
void updatePickmapInfo(@Nullable final MapCursor< G, A, R > mapCursor)
Updates the display information for the active pickmap.
Base package of all Gridarta classes.
BaseObject< G, A, R, ?> getCursorSelection()
void addMapCursorListener(@NotNull final MapCursorListener< G, A, R > listener)
Register a MapCursorListener.
ArchetypeChooserPanel< G, A, R > getSelectedPanel()
Returns the selected ArchetypeChooserPanel.
Reflects a game object (object on a map).
void addTab(@NotNull final ObjectChooserTab< G, A, R > tab)
Adds a tab.
final List< ObjectChooserTab< G, A, R > > tabs
The tabs in the same order as tabbedPane.
MapControl< G, A, R > getPickmap()
Returns the MapControl representing this pickmap.
PickmapState< G, A, R > activePickmapState
The last known active PickmapState.
MapSquare< G, A, R > getMapSquare(@NotNull Point pos)
Get the square at a specified location.
GameObjects are the objects based on Archetypes found on maps.
final Collection< ObjectChooserListener< G, A, R > > listeners
The registered listeners.
void fireSelectionChanged(@Nullable final BaseObject< G, A, R, ?> gameObject)
Notifies all listeners that the selection may have changed.
G getFirst(@NotNull final GameObjectMatcher gameObjectMatcher)
Returns the first occurrence of a matching game object.
void setActiveTab(final int index)
Records whether the archetype chooser or the pickmap chooser is active.
final ObjectChooserTab< G, A, R > pickmapChooserControl
The pickmap chooser control.
Maintains loaded PickmapState instances.
Base classes for rendering maps.
MapView< G, A, R > getMapView()
Returns the MapView instance for this pickmap.
void moveArchetypeChooserToFront()
BaseObject< G, A, R, ?> getSelection()
Returns the selected game object.
Classes implementing the pickmap chooser.
DefaultObjectChooser(@NotNull final ObjectChooserTab< G, A, R > archetypeChooserControl, @NotNull final ObjectChooserTab< G, A, R > pickmapChooserControl, @NotNull final ArchetypeChooserModel< G, A, R > archetypeChooserModel, @NotNull final PickmapChooserModel< G, A, R > pickmapChooserModel, @NotNull final ArchetypeTypeSet archetypeTypeSet)
Creates a new instance.
Interface for listeners interested in ArchetypeChooserModel related events.
final boolean isPickmapActive()
Abstract base class for classes implementing display modes of the archetype chooser.
MapView< G, A, R > activePickmapView
The MapView of activePickmapState.
void updateActivePickmap(@Nullable final PickmapState< G, A, R > pickmapState)
Records an active pickmap.
final ArchetypeChooserModel< G, A, R > archetypeChooserModel
The ArchetypeChooserModel.
The view of the archetype chooser.
void showObjectChooserQuickObject(@Nullable final BaseObject<?, ?, ?, ?> gameObject, final boolean isPickmapActive)
Displays information about the selected game object.
MapCursor< G, A, R > getMapCursor()
Returns the MapCursor of this view.
Currently nothing more than a marker interface for unification.
A map view consists of a map grid and a map cursor, and is attached to a map control.
void setActive(boolean active)
Called whenever this tab becomes active or inactive.
ArchetypeChooserFolder< G, A, R > getSelectedFolder()
Returns the selected ArchetypeChooserFolder.
boolean isMatching(@NotNull G gameObject)
Returns whether the current selection matches the given game object.
void movePickmapChooserToFront()
void addObjectChooserListener(@NotNull final ObjectChooserListener< G, A, R > listener)
Common base interface for ObjectChoosers.
static final long serialVersionUID
The serial version UID.
Interface for listeners listening to MapCursor related events.
The object choice display shows information about the selected object in the object chooser...
Defines types of GameObjects with corresponding attributes.
boolean isMatching(@NotNull final G gameObject)
Returns whether a given game object matches the selection.
void updateActivePickmap()
Updates the display state after activePickmapState has changed.
List<? extends BaseObject< G, A, R, ?> > getSelections()
Returns the selected game objects.
final BaseObject< G, A, R, ?> getSelection()
void removeMapCursorListener(@NotNull final MapCursorListener< G, A, R > listener)
Remove a MapCursorListener.
The object Chooser implementation.
Interface for MapArchObjects.
ObjectChooserTab< G, A, R > activeTab
The active tab or.
void updateSelectedIndex()
Updates selectedIndex.