Gridarta Editor
net.sf.gridarta.gui.mapmenu.MapMenu Class Reference

Manages the contents of a recent or bookmark menu. More...

+ Collaboration diagram for net.sf.gridarta.gui.mapmenu.MapMenu:

Classes

class  DeletedNode
 Result value consisting of a TreeNode and its location (directory). More...
 

Public Member Functions

TreePath addMapMenuEntry (@NotNull final String directory, @NotNull final DefaultMutableTreeNode treeNode)
 Adds a DefaultMutableTreeNode to this menu. More...
 
void addMapMenuEntry (@NotNull final String directory, @NotNull final MapMenuEntry mapMenuEntry)
 Adds a MapMenuEntry to this menu. More...
 
DeletedNode getDeletedNode (final boolean delete)
 Returns the last deleted node. More...
 
DefaultMutableTreeNode getOrCreateDirectory (@NotNull final MutableTreeNode this2, @NotNull final String path)
 Returns the MapMenuEntryDir for a given path. More...
 
DefaultMutableTreeNode getRoot ()
 Returns the root node. More...
 
TreePath insertNodeInto (@NotNull final MapMenuEntry mapEntry, @NotNull final DefaultMutableTreeNode parent, final int index)
 Inserts a new node into the tree. More...
 
void load ()
 Loads the contents from preferences. More...
 
 MapMenu (@NotNull final String key, @NotNull final PathManager pathManager)
 Creates a new instance. More...
 
JTree newTree ()
 Creates a new JTree for this map menu. More...
 
void removeNode (@NotNull final DefaultMutableTreeNode treeNode)
 Removes a node from the tree. More...
 
void save ()
 Saves the contents to preferences if modified since last save. More...
 
void saveAlways ()
 Saves the contents to preferences. More...
 
int size ()
 Returns the number of entries in this menu. More...
 

Private Member Functions

String getDirectory (@NotNull final TreeNode treeNode)
 Returns the directory of a TreeNode. More...
 
int saveEntries (@NotNull final DefaultMutableTreeNode treeNode, final int startIndex, @NotNull final String directory)
 Saves a TreeNode instance's contents to preferences. More...
 
int size (@NotNull final TreeNode root)
 Returns the number of entries in a sub-tree. More...
 

Private Attributes

final Deque< DeletedNodedeletedNodes = new ArrayDeque<>()
 Recently deleted nodes. More...
 
final MapMenuLoader mapMenuLoader
 The MapMenuLoader for loading/storing the menu contents. More...
 
final DefaultMutableTreeNode root = new DefaultMutableTreeNode(new MapMenuEntryDir("Bookmarks"), true)
 The root node of treeModel. More...
 
final DefaultTreeModel treeModel = new DefaultTreeModel(root)
 The DefaultTreeModel that contains all menu entries. More...
 
final TreeModelListener treeModelListener
 The TreeModelListener attached to treeModel for detecting modifications. More...
 
boolean treeModelModified
 Whether treeModel has been modified since last save. More...
 

Static Private Attributes

static final Category LOG = Logger.getLogger(MapMenu.class)
 The Logger for printing log messages. More...
 

Detailed Description

Manages the contents of a recent or bookmark menu.

Author
Andreas Kirschbaum

Definition at line 46 of file MapMenu.java.

Constructor & Destructor Documentation

◆ MapMenu()

net.sf.gridarta.gui.mapmenu.MapMenu.MapMenu ( @NotNull final String  key,
@NotNull final PathManager  pathManager 
)

Creates a new instance.

Parameters
keythe preferences key prefix
pathManagerthe path manager instance

Definition at line 117 of file MapMenu.java.

References net.sf.gridarta.gui.mapmenu.MapMenu.LOG, net.sf.gridarta.gui.mapmenu.MapMenu.mapMenuLoader, net.sf.gridarta.gui.mapmenu.MapMenu.treeModel, and net.sf.gridarta.gui.mapmenu.MapMenu.treeModelListener.

Member Function Documentation

◆ addMapMenuEntry() [1/2]

TreePath net.sf.gridarta.gui.mapmenu.MapMenu.addMapMenuEntry ( @NotNull final String  directory,
@NotNull final DefaultMutableTreeNode  treeNode 
)

Adds a DefaultMutableTreeNode to this menu.

Parameters
directorythe directory to add to
treeNodethe tree node
Returns
the tree path for the inserted node

Definition at line 222 of file MapMenu.java.

References directory, net.sf.gridarta.gui.mapmenu.MapMenu.getOrCreateDirectory(), net.sf.gridarta.gui.mapmenu.MapMenu.LOG, net.sf.gridarta.utils.StringUtils.PATTERN_SLASH, net.sf.gridarta.gui.mapmenu.MapMenu.root, and net.sf.gridarta.gui.mapmenu.MapMenu.treeModel.

+ Here is the call graph for this function:

◆ addMapMenuEntry() [2/2]

void net.sf.gridarta.gui.mapmenu.MapMenu.addMapMenuEntry ( @NotNull final String  directory,
@NotNull final MapMenuEntry  mapMenuEntry 
)

Adds a MapMenuEntry to this menu.

Parameters
directorythe directory to add to
mapMenuEntrythe map menu entry

Definition at line 210 of file MapMenu.java.

References directory.

Referenced by net.sf.gridarta.gui.dialog.bookmarks.ManageBookmarksDialog< G, A, R >.doUnDeleteBookmark(), net.sf.gridarta.gui.mapmenu.MapMenu.load(), and net.sf.gridarta.gui.mapmenu.MapMenuPreferencesTest.test3().

+ Here is the caller graph for this function:

◆ getDeletedNode()

DeletedNode net.sf.gridarta.gui.mapmenu.MapMenu.getDeletedNode ( final boolean  delete)

Returns the last deleted node.

Parameters
deletewhether to delete the returned node
Returns
the deleted node or
null

Definition at line 342 of file MapMenu.java.

References net.sf.gridarta.gui.mapmenu.MapMenu.deletedNodes.

Referenced by net.sf.gridarta.gui.dialog.bookmarks.ManageBookmarksDialog< G, A, R >.doUnDeleteBookmark().

+ Here is the caller graph for this function:

◆ getDirectory()

String net.sf.gridarta.gui.mapmenu.MapMenu.getDirectory ( @NotNull final TreeNode  treeNode)
private

Returns the directory of a TreeNode.

Parameters
treeNodethe tree node
Returns
the directory

Definition at line 319 of file MapMenu.java.

References net.sf.gridarta.gui.mapmenu.MapMenuEntry.getTitle(), net.sf.gridarta.gui.mapmenu.MapMenuEntry.toString(), and net.sf.gridarta.gui.mapmenu.MapMenu.treeModel.

Referenced by net.sf.gridarta.gui.mapmenu.MapMenu.removeNode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getOrCreateDirectory()

DefaultMutableTreeNode net.sf.gridarta.gui.mapmenu.MapMenu.getOrCreateDirectory ( @NotNull final MutableTreeNode  this2,
@NotNull final String  path 
)

Returns the MapMenuEntryDir for a given path.

If more than one matching path exists the last one is returned.

Parameters
this2the tree node to insert into
paththe path; must not contain '/'
Returns
the entry

Definition at line 245 of file MapMenu.java.

References net.sf.gridarta.gui.mapmenu.MapMenuEntry.allowsChildren(), net.sf.gridarta.gui.mapmenu.MapMenuEntry.getTitle(), net.sf.gridarta.gui.mapmenu.MapMenuEntryDir.isValidDirectory(), net.sf.gridarta.gui.mapmenu.MapMenu.LOG, and net.sf.gridarta.gui.mapmenu.MapMenu.treeModel.

Referenced by net.sf.gridarta.gui.mapmenu.MapMenu.addMapMenuEntry(), net.sf.gridarta.gui.mapmenu.MapMenuTest.testSubDir1(), and net.sf.gridarta.gui.mapmenu.MapMenuTest.testSubDir2().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRoot()

◆ insertNodeInto()

TreePath net.sf.gridarta.gui.mapmenu.MapMenu.insertNodeInto ( @NotNull final MapMenuEntry  mapEntry,
@NotNull final DefaultMutableTreeNode  parent,
final int  index 
)

Inserts a new node into the tree.

Parameters
mapEntrythe map entry to add
parentthe parent node to add to
indexthe index to add at
Returns
the tree path for the inserted node

Definition at line 280 of file MapMenu.java.

References net.sf.gridarta.gui.mapmenu.MapMenu.LOG, net.sf.gridarta.gui.mapmenu.MapMenu.save(), and net.sf.gridarta.gui.mapmenu.MapMenu.treeModel.

Referenced by net.sf.gridarta.gui.mapmenu.TestMapMenuPreferences.addEntry(), net.sf.gridarta.gui.mapmenu.BookmarksMapMenuPreferences.addEntry(), net.sf.gridarta.gui.mapmenu.RecentMapMenuPreferences.addEntry(), and net.sf.gridarta.gui.dialog.bookmarks.ManageBookmarksDialog< G, A, R >.doNewDirectory().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ load()

◆ newTree()

JTree net.sf.gridarta.gui.mapmenu.MapMenu.newTree ( )

Creates a new JTree for this map menu.

Returns
the tree

Definition at line 380 of file MapMenu.java.

References net.sf.gridarta.gui.mapmenu.MapMenu.treeModel.

Referenced by net.sf.gridarta.gui.dialog.bookmarks.ManageBookmarksDialog< G, A, R >.ManageBookmarksDialog().

+ Here is the caller graph for this function:

◆ removeNode()

void net.sf.gridarta.gui.mapmenu.MapMenu.removeNode ( @NotNull final DefaultMutableTreeNode  treeNode)

◆ save()

void net.sf.gridarta.gui.mapmenu.MapMenu.save ( )

Saves the contents to preferences if modified since last save.

Definition at line 151 of file MapMenu.java.

References net.sf.gridarta.gui.mapmenu.MapMenu.saveAlways(), and net.sf.gridarta.gui.mapmenu.MapMenu.treeModelModified.

Referenced by net.sf.gridarta.gui.mapmenu.MapMenu.insertNodeInto(), net.sf.gridarta.gui.mapmenu.MapMenu.removeNode(), and net.sf.gridarta.gui.dialog.bookmarks.ManageBookmarksDialog< G, A, R >.setValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveAlways()

◆ saveEntries()

int net.sf.gridarta.gui.mapmenu.MapMenu.saveEntries ( @NotNull final DefaultMutableTreeNode  treeNode,
final int  startIndex,
@NotNull final String  directory 
)
private

Saves a TreeNode instance's contents to preferences.

Parameters
treeNodethe tree node instance
startIndexthe preference index for saving the first entry
directorythe directory of the tree node
Returns
the preference index for saving the next entry

Definition at line 179 of file MapMenu.java.

References net.sf.gridarta.gui.mapmenu.MapMenuLoader.Type.DIR, directory, net.sf.gridarta.model.mapmodel.MapFile.getFile(), net.sf.gridarta.gui.mapmenu.MapMenuEntryMap.getMapFile(), net.sf.gridarta.gui.mapmenu.MapMenuEntry.getTitle(), net.sf.gridarta.gui.mapmenu.MapMenuLoader.Type.MAP, net.sf.gridarta.gui.mapmenu.MapMenu.mapMenuLoader, net.sf.gridarta.gui.mapmenu.MapMenuLoader.saveEntry(), net.sf.gridarta.gui.mapmenu.MapMenu.treeModel, and net.sf.gridarta.gui.mapmenu.MapMenuEntry.visit().

Referenced by net.sf.gridarta.gui.mapmenu.MapMenu.saveAlways().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ size() [1/2]

int net.sf.gridarta.gui.mapmenu.MapMenu.size ( )

Returns the number of entries in this menu.

Returns
the number of entries

Definition at line 350 of file MapMenu.java.

References net.sf.gridarta.gui.mapmenu.MapMenu.root.

Referenced by net.sf.gridarta.gui.mapmenu.MapMenu.size(), net.sf.gridarta.gui.mapmenu.MapMenuPreferencesTest.test2(), and net.sf.gridarta.gui.mapmenu.MapMenuManagerTest.testSaveBookmarks().

+ Here is the caller graph for this function:

◆ size() [2/2]

int net.sf.gridarta.gui.mapmenu.MapMenu.size ( @NotNull final TreeNode  root)
private

Returns the number of entries in a sub-tree.

Parameters
rootthe root of the sub-tree
Returns
the number of entries

Definition at line 359 of file MapMenu.java.

References net.sf.gridarta.gui.mapmenu.MapMenuEntry.allowsChildren(), net.sf.gridarta.gui.mapmenu.MapMenu.LOG, net.sf.gridarta.gui.mapmenu.MapMenu.root, net.sf.gridarta.gui.mapmenu.MapMenu.size(), and net.sf.gridarta.gui.mapmenu.MapMenu.treeModel.

+ Here is the call graph for this function:

Member Data Documentation

◆ deletedNodes

final Deque<DeletedNode> net.sf.gridarta.gui.mapmenu.MapMenu.deletedNodes = new ArrayDeque<>()
private

Recently deleted nodes.

The first node is the last deleted node.

Definition at line 76 of file MapMenu.java.

Referenced by net.sf.gridarta.gui.mapmenu.MapMenu.getDeletedNode(), and net.sf.gridarta.gui.mapmenu.MapMenu.removeNode().

◆ LOG

◆ mapMenuLoader

final MapMenuLoader net.sf.gridarta.gui.mapmenu.MapMenu.mapMenuLoader
private

◆ root

final DefaultMutableTreeNode net.sf.gridarta.gui.mapmenu.MapMenu.root = new DefaultMutableTreeNode(new MapMenuEntryDir("Bookmarks"), true)
private

◆ treeModel

◆ treeModelListener

final TreeModelListener net.sf.gridarta.gui.mapmenu.MapMenu.treeModelListener
private
Initial value:
= new TreeModelListener() {
@Override
public void treeNodesChanged(final TreeModelEvent e) {
}
@Override
public void treeNodesInserted(final TreeModelEvent e) {
}
@Override
public void treeNodesRemoved(final TreeModelEvent e) {
}
@Override
public void treeStructureChanged(final TreeModelEvent e) {
}
}

The TreeModelListener attached to treeModel for detecting modifications.

Definition at line 88 of file MapMenu.java.

Referenced by net.sf.gridarta.gui.mapmenu.MapMenu.MapMenu().

◆ treeModelModified

boolean net.sf.gridarta.gui.mapmenu.MapMenu.treeModelModified
private

Whether treeModel has been modified since last save.

Definition at line 81 of file MapMenu.java.

Referenced by net.sf.gridarta.gui.mapmenu.MapMenu.load(), and net.sf.gridarta.gui.mapmenu.MapMenu.save().


The documentation for this class was generated from the following file:
net.sf.gridarta.gui.mapmenu.MapMenu.treeModelModified
boolean treeModelModified
Whether treeModel has been modified since last save.
Definition: MapMenu.java:81