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;
60 import net.
sf.japi.swing.action.ActionBuilder;
61 import net.
sf.japi.swing.action.ActionBuilderFactory;
62 import net.
sf.japi.swing.action.ActionMethod;
63 import org.jetbrains.annotations.NotNull;
64 import org.jetbrains.annotations.Nullable;
81 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
179 final JButton editButton =
new JButton(
editAction);
183 setOptions(
new Object[] { editButton, removeButton, unDeleteButton, newDirectoryButton,
closeButton });
188 dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
190 dialog.setResizable(
true);
198 public void showDialog(@NotNull
final Component parentComponent) {
202 dialog.setLocationRelativeTo(parentComponent);
203 dialog.setMinimumSize(
new Dimension(600, 300));
204 dialog.setPreferredSize(
new Dimension(800, 600));
215 preview.setHorizontalAlignment(SwingConstants.CENTER);
216 preview.setPreferredSize(
new Dimension(200, 200));
218 final JPanel mainPanel =
new JPanel(
new GridBagLayout());
222 final JScrollPane bookmarksScrollPane =
new JScrollPane();
224 bookmarksScrollPane.setBackground(
bookmarksTree.getBackground());
226 bookmarksScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
227 bookmarksScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
228 bookmarksScrollPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
230 final GridBagConstraints gbc =
new GridBagConstraints();
231 gbc.fill = GridBagConstraints.BOTH;
236 mainPanel.add(bookmarksScrollPane, gbc);
242 bookmarksTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
245 final TreeSelectionListener treeSelectionListener =
new TreeSelectionListener() {
248 public void valueChanged(
final TreeSelectionEvent e) {
253 bookmarksTree.addTreeSelectionListener(treeSelectionListener);
308 public void setValue(@Nullable
final Object newValue) {
309 super.setValue(newValue);
310 if (newValue != UNINITIALIZED_VALUE) {
322 if (tmpSelectedTreePath ==
null) {
326 final DefaultMutableTreeNode selectedTreeNode = (DefaultMutableTreeNode) tmpSelectedTreePath.getLastPathComponent();
332 final DefaultMutableTreeNode tmpSelectedTreeNode = (DefaultMutableTreeNode) tmpSelectedTreePath.getLastPathComponent();
339 mapMenuEntry.setTitle(bookmarkDirectoryDialog.
getDirectory());
340 bookmarksTree.getModel().valueForPathChanged(tmpSelectedTreePath, mapMenuEntry);
349 bookmarksTree.getModel().valueForPathChanged(tmpSelectedTreePath, mapMenuEntry);
354 ((
MapMenuEntry) tmpSelectedTreeNode.getUserObject()).visit(mapMenuEntryVisitor);
367 if (tmpSelectedTreePath ==
null) {
371 final DefaultMutableTreeNode selectedTreeNode = (DefaultMutableTreeNode) tmpSelectedTreePath.getLastPathComponent();
377 final int[] selectionRows =
bookmarksTree.getSelectionRows();
379 final int index = selectionRows ==
null ? 0 : selectionRows[0];
395 if (deletedNode ==
null) {
414 if (tmpSelectedTreePath ==
null) {
419 final DefaultMutableTreeNode selectedTreeNode = (DefaultMutableTreeNode) tmpSelectedTreePath.getLastPathComponent();
422 final String directory = bookmarkDirectoryDialog.
getDirectory();
424 final DefaultMutableTreeNode parent;
427 parent = selectedTreeNode;
430 parent = (DefaultMutableTreeNode) selectedTreeNode.getParent();
431 assert parent !=
null;
432 index = parent.getIndex(selectedTreeNode) + 1;
452 @Nullable
final Icon previewIcon;
456 final DefaultMutableTreeNode tmpSelectedTreeNode = (DefaultMutableTreeNode)
selectedTreePath.getLastPathComponent();