Gridarta Editor
MapCursorTracker.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.map.mapview;
21 
22 import java.awt.Point;
23 import javax.swing.JScrollPane;
24 import javax.swing.JViewport;
25 import javax.swing.ScrollPaneConstants;
34 import org.jetbrains.annotations.NotNull;
35 import org.jetbrains.annotations.Nullable;
36 
43 public class MapCursorTracker<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> {
44 
48  @NotNull
50 
54  @NotNull
56 
60  @NotNull
61  private final JScrollPane scrollPane;
62 
66  @NotNull
68 
69  @Override
70  public void mapCursorChangedPos(@NotNull final Point location) {
72  }
73 
74  @Override
75  public void mapCursorChangedMode() {
76  // Ignore mode change events
77  }
78 
79  @Override
80  public void mapCursorChangedGameObject(@Nullable final MapSquare<G, A, R> mapSquare, @Nullable final G gameObject) {
81  // ignore
82  }
83 
84  @Override
85  public void mapCursorChangedSize() {
86  // ignore
87  }
88 
89  };
90 
99  public MapCursorTracker(final boolean isPickmap, final int xScrollDistance, final int yScrollDistance, @NotNull final MapCursor<G, A, R> mapCursor, @NotNull final AbstractMapRenderer<G, A, R> renderer) {
100  this.mapCursor = mapCursor;
101  this.renderer = renderer;
102  this.mapCursor.addMapCursorListener(mapCursorListener);
103  scrollPane = new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
104  if (isPickmap) {
105  scrollPane.setBackground(CommonConstants.BG_COLOR);
106  }
107 
108  // set the pixel increment scrolling for clicking once on a scroll bar arrow
109  scrollPane.getVerticalScrollBar().setUnitIncrement(yScrollDistance);
110  scrollPane.getHorizontalScrollBar().setUnitIncrement(xScrollDistance);
111  scrollPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
112  scrollPane.setViewportView(renderer);
113  scrollPane.setFocusable(true);
115  }
116 
121  public void setViewPosition(@NotNull final Point viewPosition) {
122  scrollPane.getViewport().setViewPosition(viewPosition);
123  }
124 
129  public void closeNotify() {
130  scrollPane.setViewportView(null);
132  }
133 
137  private void ensureVisibleMapCursor() {
138  final Point cursorLocation = mapCursor.getLocation();
139  renderer.scrollRectToVisible(renderer.getSquareBounds(cursorLocation));
140  }
141 
146  @NotNull
147  public JScrollPane getScrollPane() {
148  return scrollPane;
149  }
150 
151 }
net.sf.gridarta.gui.map.mapview.MapCursorTracker.ensureVisibleMapCursor
void ensureVisibleMapCursor()
Makes sure the mapCursor is visible.
Definition: MapCursorTracker.java:137
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.model.mapmodel.MapSquare
A single Map Square.
Definition: MapSquare.java:45
net.sf
net.sf.gridarta.gui.map.mapview.MapCursorTracker.mapCursorListener
final MapCursorListener< G, A, R > mapCursorListener
The MapCursorListener attached to mapCursor.
Definition: MapCursorTracker.java:67
net.sf.gridarta.model.mapmodel
Definition: AboveFloorInsertionMode.java:20
net.sf.gridarta.utils.CommonConstants
Class with constants used in Gridarta and derivates.
Definition: CommonConstants.java:28
net.sf.gridarta.gui.map.renderer
Definition: AbstractIsoMapRenderer.java:20
net.sf.gridarta.gui.map.mapview.MapCursorTracker.MapCursorTracker
MapCursorTracker(final boolean isPickmap, final int xScrollDistance, final int yScrollDistance, @NotNull final MapCursor< G, A, R > mapCursor, @NotNull final AbstractMapRenderer< G, A, R > renderer)
Creates a new instance.
Definition: MapCursorTracker.java:99
net.sf.gridarta.model.archetype
Definition: AbstractArchetype.java:20
net.sf.gridarta.model.gameobject.GameObject
Reflects a game object (object on a map).
Definition: GameObject.java:36
net.sf.gridarta.model.mapcursor.MapCursorListener
Interface for listeners listening to MapCursor related events.
Definition: MapCursorListener.java:36
net.sf.gridarta.gui
Graphical User Interface of Gridarta.
net.sf.gridarta.gui.map.renderer.AbstractMapRenderer
Abstract base class for classes implementing MapRenderer.
Definition: AbstractMapRenderer.java:45
net.sf.gridarta.model.gameobject
GameObjects are the objects based on Archetypes found on maps.
Definition: AbstractGameObject.java:20
net
net.sf.gridarta.utils.CommonConstants.BG_COLOR
static final Color BG_COLOR
Background Color (for the Panels).
Definition: CommonConstants.java:38
net.sf.gridarta.model.maparchobject.MapArchObject
Interface for MapArchObjects.
Definition: MapArchObject.java:40
net.sf.gridarta.gui.map.mapview.MapCursorTracker.closeNotify
void closeNotify()
Must be called when this instance is not used anymore.
Definition: MapCursorTracker.java:129
net.sf.gridarta.model.mapcursor.MapCursor.getLocation
Point getLocation()
Get position of cursor.
Definition: MapCursor.java:227
net.sf.gridarta.model.mapcursor.MapCursor.removeMapCursorListener
void removeMapCursorListener(@NotNull final MapCursorListener< G, A, R > listener)
Remove a MapCursorListener.
Definition: MapCursor.java:427
net.sf.gridarta.model.mapcursor.MapCursor
MapCursor provides methods to move and drag on map.
Definition: MapCursor.java:58
net.sf.gridarta.gui.map.mapview.MapCursorTracker.getScrollPane
JScrollPane getScrollPane()
Returns the JScrollPane of the renderer.
Definition: MapCursorTracker.java:147
net.sf.gridarta.model
net.sf.gridarta.model.archetype.Archetype
Reflects an Archetype.
Definition: Archetype.java:41
net.sf.gridarta.gui.map
Base classes for rendering maps.
Definition: AbstractPerMapDialogManager.java:20
net.sf.gridarta.gui.map.mapview.MapCursorTracker.scrollPane
final JScrollPane scrollPane
The JScrollPane for this instance.
Definition: MapCursorTracker.java:61
net.sf.gridarta.gui.map.mapview.MapCursorTracker.renderer
final AbstractMapRenderer< G, A, R > renderer
The AbstractMapRenderer to update.
Definition: MapCursorTracker.java:55
net.sf.gridarta.gui.map.mapview.MapCursorTracker
Tracks the MapCursor of map and scrolls the {} so that the map cursor remains visible.
Definition: MapCursorTracker.java:43
net.sf.gridarta.model.maparchobject
Definition: AbstractMapArchObject.java:20
net.sf.gridarta.gui.map.mapview.MapCursorTracker.mapCursor
final MapCursor< G, A, R > mapCursor
The MapCursor to track.
Definition: MapCursorTracker.java:49
net.sf.gridarta.model.mapcursor
Definition: MapCursor.java:20
net.sf.gridarta.gui.map.mapview.MapCursorTracker.setViewPosition
void setViewPosition(@NotNull final Point viewPosition)
Sets the view position.
Definition: MapCursorTracker.java:121
net.sf.gridarta.utils
Definition: ActionBuilderUtils.java:20