20 package net.sf.gridarta.gui.dialog.bookmarks;
22 import java.awt.Component;
23 import java.awt.Dimension;
24 import java.awt.GridBagConstraints;
25 import java.awt.GridBagLayout;
26 import java.awt.dnd.DnDConstants;
27 import javax.swing.Action;
28 import javax.swing.Icon;
29 import javax.swing.JButton;
30 import javax.swing.JDialog;
31 import javax.swing.JLabel;
32 import javax.swing.JOptionPane;
33 import javax.swing.JPanel;
34 import javax.swing.JScrollPane;
35 import javax.swing.JTree;
36 import javax.swing.JViewport;
37 import javax.swing.ScrollPaneConstants;
38 import javax.swing.SwingConstants;
39 import javax.swing.WindowConstants;
40 import javax.swing.event.TreeSelectionEvent;
41 import javax.swing.event.TreeSelectionListener;
42 import javax.swing.tree.DefaultMutableTreeNode;
43 import javax.swing.tree.TreePath;
44 import javax.swing.tree.TreeSelectionModel;
59 import net.
sf.japi.swing.action.ActionBuilder;
60 import net.
sf.japi.swing.action.ActionBuilderFactory;
61 import net.
sf.japi.swing.action.ActionMethod;
62 import org.jetbrains.annotations.NotNull;
63 import org.jetbrains.annotations.Nullable;
80 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
126 private final Action
editAction = ACTION_BUILDER.createAction(
false,
"manageBookmarksEdit",
this);
133 private final Action
removeAction = ACTION_BUILDER.createAction(
false,
"manageBookmarksRemove",
this);
140 private final Action
unDeleteAction = ACTION_BUILDER.createAction(
false,
"manageBookmarksUnDelete",
this);
147 private final Action
newDirectoryAction = ACTION_BUILDER.createAction(
false,
"manageBookmarksNewDirectory",
this);
154 private final JButton
closeButton =
new JButton(ACTION_BUILDER.createAction(
false,
"manageBookmarksClose",
this));
173 bookmarksTree = mapMenu.newTree();
175 new TreeDragSource(bookmarksTree, DnDConstants.ACTION_COPY_OR_MOVE);
178 final JButton editButton =
new JButton(editAction);
179 final JButton removeButton =
new JButton(removeAction);
180 final JButton unDeleteButton =
new JButton(unDeleteAction);
181 final JButton newDirectoryButton =
new JButton(newDirectoryAction);
182 setOptions(
new Object[] { editButton, removeButton, unDeleteButton, newDirectoryButton, closeButton });
187 dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
188 dialog.setModal(
false);
189 dialog.setResizable(
true);
197 public void showDialog(@NotNull
final Component parentComponent) {
198 setInitialValue(bookmarksTree);
199 bookmarksTree.setRootVisible(
false);
200 bookmarksTree.setSelectionRow(0);
201 dialog.setLocationRelativeTo(parentComponent);
202 dialog.setMinimumSize(
new Dimension(600, 300));
203 dialog.setPreferredSize(
new Dimension(800, 600));
204 dialog.setVisible(
true);
214 preview.setHorizontalAlignment(SwingConstants.CENTER);
215 preview.setPreferredSize(
new Dimension(200, 200));
217 final JPanel mainPanel =
new JPanel(
new GridBagLayout());
221 final JScrollPane bookmarksScrollPane =
new JScrollPane();
222 bookmarksScrollPane.setViewportView(bookmarksTree);
223 bookmarksScrollPane.setBackground(bookmarksTree.getBackground());
224 bookmarksScrollPane.getViewport().add(bookmarksTree);
225 bookmarksScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
226 bookmarksScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
227 bookmarksScrollPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
229 final GridBagConstraints gbc =
new GridBagConstraints();
230 gbc.fill = GridBagConstraints.BOTH;
235 mainPanel.add(bookmarksScrollPane, gbc);
239 mainPanel.add(preview, gbc);
241 bookmarksTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
244 final TreeSelectionListener treeSelectionListener =
new TreeSelectionListener() {
247 public void valueChanged(
final TreeSelectionEvent e) {
252 bookmarksTree.addTreeSelectionListener(treeSelectionListener);
262 selectedTreePath = bookmarksTree.getSelectionPath();
307 public void setValue(@Nullable
final Object newValue) {
308 super.setValue(newValue);
309 if (newValue != UNINITIALIZED_VALUE) {
321 if (tmpSelectedTreePath == null) {
325 final DefaultMutableTreeNode selectedTreeNode = (DefaultMutableTreeNode) tmpSelectedTreePath.getLastPathComponent();
326 if (selectedTreeNode == mapMenu.
getRoot()) {
331 final DefaultMutableTreeNode tmpSelectedTreeNode = (DefaultMutableTreeNode) tmpSelectedTreePath.getLastPathComponent();
338 mapMenuEntry.setTitle(bookmarkDirectoryDialog.
getDirectory());
339 bookmarksTree.getModel().valueForPathChanged(tmpSelectedTreePath, mapMenuEntry);
348 bookmarksTree.getModel().valueForPathChanged(tmpSelectedTreePath, mapMenuEntry);
353 ((
MapMenuEntry) tmpSelectedTreeNode.getUserObject()).visit(mapMenuEntryVisitor);
366 if (tmpSelectedTreePath == null) {
370 final DefaultMutableTreeNode selectedTreeNode = (DefaultMutableTreeNode) tmpSelectedTreePath.getLastPathComponent();
371 if (selectedTreeNode == mapMenu.
getRoot()) {
376 final int[] selectionRows = bookmarksTree.getSelectionRows();
378 final int index = selectionRows == null ? 0 : selectionRows[0];
380 bookmarksTree.setSelectionRow(index - 1);
394 if (deletedNode == null) {
399 final TreePath treePath = mapMenu.
addMapMenuEntry(deletedNode.getDirectory(), deletedNode.getTreeNode());
400 bookmarksTree.setSelectionPath(treePath);
413 if (tmpSelectedTreePath == null) {
418 final DefaultMutableTreeNode selectedTreeNode = (DefaultMutableTreeNode) tmpSelectedTreePath.getLastPathComponent();
421 final String directory = bookmarkDirectoryDialog.
getDirectory();
423 final DefaultMutableTreeNode parent;
425 if (selectedTreeNode == mapMenu.
getRoot()) {
426 parent = selectedTreeNode;
429 parent = (DefaultMutableTreeNode) selectedTreeNode.getParent();
430 assert parent != null;
431 index = parent.getIndex(selectedTreeNode) + 1;
434 final TreePath treePath = mapMenu.
insertNodeInto(mapEntry, parent, index);
435 bookmarksTree.setSelectionPath(treePath);
451 @Nullable
final Icon previewIcon;
452 if (selectedTreePath == null) {
455 final DefaultMutableTreeNode tmpSelectedTreeNode = (DefaultMutableTreeNode) selectedTreePath.getLastPathComponent();
457 previewIcon = mapMenuEntryIcons.
getIcon(mapMenuEntry);
459 preview.setIcon(previewIcon);
void manageBookmarksClose()
Action method for "close bookmarks dialog".
String getDescription()
Returns the description.
static final long serialVersionUID
The serial Version UID.
Graphical User Interface of Gridarta.
final JTree bookmarksTree
The JTree of all bookmarks.
static final ActionBuilder ACTION_BUILDER
The ActionBuilder.
boolean doUnDeleteBookmark(final boolean performAction)
Restores the last deleted bookmark.
void setValue(@Nullable final Object newValue)
void manageBookmarksUnDelete()
Action method for "undo deletion".
final MapImageCache< G, A, R > mapImageCache
The MapImageCache for creating map previews.
void manageBookmarksRemove()
Action method for "remove bookmark".
A dialog that displays existing bookmarks and allows to edit or remove them.
final MapMenuEntryIcons mapMenuEntryIcons
The MapMenuEntryIcons for looking up icons.
void manageBookmarksEdit()
Action method for "edit bookmark".
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
boolean doRemoveBookmark(final boolean performAction)
Removes the selected bookmark.
boolean doNewDirectory(final boolean performAction)
Create a new directory.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
void updateActions()
Updates the actions' states to reflect the current selection.
TreePath selectedTreePath
The currently selected entry.
final JButton closeButton
The JButton for cancel.
boolean showDialog()
Opens the dialog.
final Action editAction
The Action for "edit bookmark".
A dialog that displays one bookmark and allows to edit the values.
final Action unDeleteAction
The Action for "remove bookmark".
GameObjects are the objects based on Archetypes found on maps.
final MapMenu mapMenu
The MapMenu being edited.
Caches icon and preview images for map files.
final Action removeAction
The Action for "remove bookmark".
void showDialog(@NotNull final Component parentComponent)
Opens the dialog.
boolean showDialog()
Opens the dialog.
Utility class for ActionBuilder related functions.
void updateSelectedBookmark()
Updates selectedTreePath from bookmarksTree.
final Action newDirectoryAction
The Action for "new directory".
A dialog that queries a bookmark directory name.
ManageBookmarksDialog(@NotNull final Component parentComponent, @NotNull final MapImageCache< G, A, R > mapImageCache, @NotNull final MapMenu mapMenu)
Creates a new instance.
JPanel createPanel()
Creates the GUI.
boolean doEditBookmark(final boolean performAction)
Edits the selected bookmark.
Border DIALOG_BORDER
The Border object to be used when creating dialogs.
final JDialog dialog
The dialog.
void manageBookmarksNewDirectory()
Action method for "new directory".
final JLabel preview
The map preview image.
String getDirectory()
Returns the directory name.
Interface for MapArchObjects.
Defines common UI constants used in different dialogs.