20 package net.sf.gridarta.gui.misc;
22 import java.awt.Dimension;
23 import java.awt.GridBagConstraints;
24 import java.awt.GridBagLayout;
25 import java.awt.Point;
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
28 import java.awt.event.MouseEvent;
29 import java.awt.event.MouseMotionListener;
30 import java.text.NumberFormat;
31 import javax.swing.JLabel;
32 import javax.swing.JPanel;
33 import javax.swing.Timer;
34 import javax.swing.border.BevelBorder;
53 import net.
sf.japi.swing.action.ActionBuilder;
54 import net.
sf.japi.swing.action.ActionBuilderFactory;
55 import org.jetbrains.annotations.NotNull;
56 import org.jetbrains.annotations.Nullable;
79 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
143 public void mapCursorChangedPos(@NotNull
final Point location) {
148 public void mapCursorChangedMode() {
153 public void mapCursorChangedGameObject(@Nullable
final MapSquare<G, A, R> mapSquare, @Nullable
final G gameObject) {
158 public void mapCursorChangedSize() {
176 public void mapCreated(@NotNull
final MapControl<G, A, R> mapControl,
final boolean interactive) {
177 setStatusText(
"Creating new map " + mapControl.getMapModel().getMapArchObject().getMapName() +
".");
200 public void activeMapViewChanged(@Nullable
final MapView<G, A, R> mapView) {
224 final String mapType = mapControl.isPickmap() ?
"map" :
"pickmap";
225 setStatusText(
"Saved " + mapType +
" '" + mapControl.getMapModel().getMapArchObject().getMapName() +
"'.");
238 public void mouseDragged(@NotNull
final MouseEvent e) {
243 public void mouseMoved(@NotNull
final MouseEvent e) {
257 public void actionPerformed(@NotNull
final ActionEvent e) {
260 final int faceObjectsCount = faceObjects.
size();
262 final Runtime runtime = Runtime.getRuntime();
263 final long freeMem = runtime.freeMemory();
264 final long totMem = runtime.totalMemory();
265 final long usedMem = totMem - freeMem;
283 setLayout(
new GridBagLayout());
284 setBorder(
new BevelBorder(BevelBorder.LOWERED));
286 final GridBagConstraints gbc =
new GridBagConstraints();
287 gbc.fill = GridBagConstraints.HORIZONTAL;
288 gbc.anchor = GridBagConstraints.WEST;
292 mouse =
new JLabel(
" ");
293 mouse.setBorder(
new BevelBorder(BevelBorder.LOWERED));
296 cursor =
new JLabel(
" ");
297 cursor.setBorder(
new BevelBorder(BevelBorder.LOWERED));
301 status =
new JLabel(
" ");
302 status.setBorder(
new BevelBorder(BevelBorder.LOWERED));
306 memory =
new JLabel(
" ");
307 memory.setBorder(
new BevelBorder(BevelBorder.LOWERED));
310 mapManager.addMapManagerListener(mapManagerListener);
311 mapViewManager.addMapViewManagerListener(mapViewManagerListener);
313 new Timer(5000, statusBarUpdate).start();
321 status.setText(text);
329 private static final NumberFormat
FORMAT = NumberFormat.getInstance();
332 FORMAT.setMinimumFractionDigits(1);
333 FORMAT.setMaximumFractionDigits(1);
340 private static final String[]
UNITS = {
"Bytes",
"KB",
"MB",
"GB" };
350 for (
int i = UNITS.length - 1; i >= 0; i--) {
351 final long m = 1L << (long) (i * 10);
353 return FORMAT.format((
double) mem / (
double) m) + UNITS[i];
366 final String formatCursor;
367 if (mapCursor == null) {
370 final Point pos = mapCursor.getLocation();
371 final int cursorX = pos.x;
372 final int cursorY = pos.y;
373 if (mapCursor.isDragging()) {
374 final Dimension offset = mapCursor.getDragOffset();
375 assert offset != null;
376 final int offsetX = Math.abs(offset.width) + 1;
377 final int offsetY = Math.abs(offset.height) + 1;
378 formatCursor = ACTION_BUILDER.format(
"statusCursorDragging", cursorX, cursorY, offsetX, offsetY);
380 formatCursor = ACTION_BUILDER.format(
"statusCursorActive", cursorX, cursorY);
383 cursor.setText(formatCursor);
393 final int mouseMapX = mouseMapTmp.x;
394 final int mouseMapY = mouseMapTmp.y;
395 mouse.setText(ACTION_BUILDER.format(
"statusMouseOn", mouseMapX, mouseMapY));
397 mouse.setText(ACTION_BUILDER.format(
"statusMouseOff"));
402 if (this.mapView != null) {
403 this.mapView.getMapCursor().removeMapCursorListener(mapCursorListener);
404 this.mapView.getRenderer().removeMouseMotionListener(mouseMotionListener);
409 if (this.mapView != null) {
411 this.mapView.getRenderer().addMouseMotionListener(mouseMotionListener);
final MouseMotionListener mouseMotionListener
The MouseMotionListener for tracking the mouse position in map windows.
Implements the main status bar of the application.
The data package contains classes for handling data that is organized in a tree.
A MapManager manages all opened maps.
Graphical User Interface of Gridarta.
StatusBar(@NotNull final MapManager< G, A, R > mapManager, @NotNull final MapViewManager< G, A, R > mapViewManager, @NotNull final ArchetypeSet< G, A, R > archetypeSet, @NotNull final NamedObjects< FaceObject > faceObjects)
Constructs a status bar that has the given main controller object set as its controller.
This class manages NamedObjects, managing their tree as well as providing a method for showing a dial...
static final String [] UNITS
The units used by getMemoryString(long).
void setCurrentMapView(@Nullable final MapView< G, A, R > mapView)
Common interface for FaceObject.
final ActionListener statusBarUpdate
The action listener which is registered to periodically update the status bar.
int size()
Get the number of objects.
final MapCursorListener< G, A, R > mapCursorListener
The map cursor listener to detect map cursor changes.
final JLabel memory
The label that shows the memory status.
MapCursor provides methods to move and drag on map.
static String getMemoryString(final long mem)
Returns the given memory amount as a string scales the value to be bytes, kilobytes or megabytes...
Base package of all Gridarta classes.
void addMapCursorListener(@NotNull final MapCursorListener< G, A, R > listener)
Register a MapCursorListener.
Reflects a game object (object on a map).
int getArchetypeCount()
Returns the number of Archetypes available.
static final NumberFormat FORMAT
The DecimalFormat to use for formatting the numbers in getMemoryString(long).
Interface for listeners listening to MapManager changes.
Interface for listeners listening on changes in MapControl instances.
final Point mouseMapTmp
Temporary used to get map coordinates.
GameObjects are the objects based on Archetypes found on maps.
Interface for listeners interested in events related to MapViewManager instances. ...
final MapManagerListener< G, A, R > mapManagerListener
The map manager listener to detect current map changes.
final MapControlListener< G, A, R > mapControlListener
The MapControlListener used to detect saved maps.
final MapViewManagerListener< G, A, R > mapViewManagerListener
The map view manager listener to detect current map changes.
void setStatusText(final String text)
Sets the level status text, which usually displays arch numbers.
void mousePosChanged(@NotNull final MouseEvent e)
Set new mouse and map coordinates to mouse label.
Base classes for rendering maps.
final ArchetypeSet< G, A, R > archetypeSet
The ArchetypeSet.
static final long serialVersionUID
The serial Version UID.
final JLabel mouse
The label that shows the mouse.
MapView< G, A, R > mapView
The map view for which mapCursorListener is registered, or.
boolean getSquareLocationAt(@NotNull Point point, @NotNull Point retPoint)
Returns the map location at the given point.
The face is the appearance of an 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.
static final ActionBuilder ACTION_BUILDER
Action Builder.
final JLabel cursor
The label that shows the cursor.
Common interface for renderers of map control instances.
Interface that captures similarities between different ArchetypeSet implementations.
Interface for listeners listening to MapCursor related events.
void mapCursorChanged(@Nullable final MapCursor< G, A, R > mapCursor)
Sets the coordinates of the MapCursor to cursor label and the offset when in drag mode...
final NamedObjects< FaceObject > faceObjects
The NamedObjects instance to use.
Interface for MapArchObjects.
final JLabel status
The label that shows the one line text message.