Gridarta Editor
MapMenuEntryTreeCellRenderer.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.mapmenu;
21 
22 import java.awt.Component;
23 import java.awt.Image;
24 import javax.swing.ImageIcon;
25 import javax.swing.JTree;
26 import javax.swing.tree.DefaultMutableTreeNode;
27 import javax.swing.tree.DefaultTreeCellRenderer;
30 import org.jetbrains.annotations.NotNull;
31 
37 public class MapMenuEntryTreeCellRenderer extends DefaultTreeCellRenderer implements MapMenuEntryVisitor {
38 
42  private static final long serialVersionUID = 1L;
43 
47  @NotNull
49 
54  private boolean expanded;
55 
61  this.mapImageCache = mapImageCache;
62  }
63 
64  @Override
65  public Component getTreeCellRendererComponent(final JTree tree, final Object value, final boolean sel, final boolean expanded, final boolean leaf, final int row, final boolean hasFocus) {
66  super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
67  final DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) value;
68  final MapMenuEntry mapMenuEntry = (MapMenuEntry) treeNode.getUserObject();
69  setText(mapMenuEntry.getTitle());
70  this.expanded = expanded;
71  mapMenuEntry.visit(this);
72  return this;
73  }
74 
75  @Override
76  public void visit(@NotNull final MapMenuEntryDir mapMenuEntry) {
77  setIcon(expanded ? getOpenIcon() : getClosedIcon());
78  }
79 
80  @Override
81  public void visit(@NotNull final MapMenuEntryMap mapMenuEntry) {
82  final MapFile mapFile = mapMenuEntry.getMapFile();
83  setToolTipText(mapFile.getMapPath().toString());
84  final Image icon = mapImageCache.getOrCreateIcon(mapFile.getFile());
85  if (icon != null) {
86  setIcon(new ImageIcon(icon));
87  }
88  }
89 
90 }
net.sf.gridarta.gui.mapimagecache
Definition: ImageType.java:20
net.sf.gridarta.gui.mapmenu.MapMenuEntryTreeCellRenderer.getTreeCellRendererComponent
Component getTreeCellRendererComponent(final JTree tree, final Object value, final boolean sel, final boolean expanded, final boolean leaf, final int row, final boolean hasFocus)
Definition: MapMenuEntryTreeCellRenderer.java:65
net.sf.gridarta.gui.mapmenu.MapMenuEntry
Abstract base class for recent and bookmark menu entries.
Definition: MapMenuEntry.java:29
net.sf.gridarta
Base package of all Gridarta classes.
net.sf
net.sf.gridarta.model.mapmodel
Definition: AboveFloorInsertionMode.java:20
net.sf.gridarta.gui.mapmenu.MapMenuEntryTreeCellRenderer.mapImageCache
final MapImageCache<?, ?, ?> mapImageCache
The MapImageCache queried for icons.
Definition: MapMenuEntryTreeCellRenderer.java:48
net.sf.gridarta.gui.mapmenu.MapMenuEntryTreeCellRenderer.expanded
boolean expanded
Parameter for passing the expanded state into the {} function.
Definition: MapMenuEntryTreeCellRenderer.java:54
net.sf.gridarta.gui.mapmenu.MapMenuEntryTreeCellRenderer
A DefaultTreeCellRenderer for rendering MapMenuEntry instances.
Definition: MapMenuEntryTreeCellRenderer.java:37
net.sf.gridarta.model.mapmodel.MapFile.getMapPath
AbsoluteMapPath getMapPath()
Returns the map path within getMapsDir().
Definition: MapFile.java:93
net.sf.gridarta.gui
Graphical User Interface of Gridarta.
net.sf.gridarta.gui.mapmenu.MapMenuEntryTreeCellRenderer.MapMenuEntryTreeCellRenderer
MapMenuEntryTreeCellRenderer(@NotNull final MapImageCache<?, ?, ?> mapImageCache)
Creates a new instance.
Definition: MapMenuEntryTreeCellRenderer.java:60
net.sf.gridarta.gui.mapimagecache.MapImageCache
Caches icon and preview images for map files.
Definition: MapImageCache.java:53
net
net.sf.gridarta.gui.mapimagecache.MapImageCache.getOrCreateIcon
Image getOrCreateIcon(@NotNull final File mapFile)
Returns an icon Image for a given map file.
Definition: MapImageCache.java:192
net.sf.gridarta.gui.mapmenu.MapMenuEntry.getTitle
String getTitle()
Returns the entry's title.
Definition: MapMenuEntry.java:55
net.sf.gridarta.gui.mapmenu.MapMenuEntryTreeCellRenderer.serialVersionUID
static final long serialVersionUID
The serial version UID.
Definition: MapMenuEntryTreeCellRenderer.java:42
net.sf.gridarta.gui.mapmenu.MapMenuEntryTreeCellRenderer.visit
void visit(@NotNull final MapMenuEntryDir mapMenuEntry)
Called for MapMenuEntryDir instances.
Definition: MapMenuEntryTreeCellRenderer.java:76
net.sf.gridarta.model.mapmodel.MapFile.getFile
File getFile()
Returns a File for this map file.
Definition: MapFile.java:102
net.sf.gridarta.model.mapmodel.AbsoluteMapPath.toString
String toString()
Definition: AbsoluteMapPath.java:117
net.sf.gridarta.model.mapmodel.MapFile
The location of a map file with a map directory.
Definition: MapFile.java:31
net.sf.gridarta.gui.mapmenu.MapMenuEntry.visit
abstract void visit(@NotNull MapMenuEntryVisitor visitor)
Calls the.
net.sf.gridarta.gui.mapmenu.MapMenuEntryTreeCellRenderer.visit
void visit(@NotNull final MapMenuEntryMap mapMenuEntry)
Called for MapMenuEntryMap instances.
Definition: MapMenuEntryTreeCellRenderer.java:81
net.sf.gridarta.model
net.sf.gridarta.gui.mapmenu.MapMenuEntryVisitor
Interface for classes operating on MapMenuEntry instances.
Definition: MapMenuEntryVisitor.java:28
net.sf.gridarta.gui.mapmenu.MapMenuEntryMap
A MapMenuEntry that represents a map.
Definition: MapMenuEntryMap.java:29
net.sf.gridarta.gui.mapmenu.MapMenuEntryDir
A MapMenuEntry that represents a directory.
Definition: MapMenuEntryDir.java:28