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.TreeSelectionListener;
41 import javax.swing.tree.DefaultMutableTreeNode;
42 import javax.swing.tree.TreePath;
43 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");
178 final JButton editButton =
new JButton(
editAction);
182 setOptions(
new Object[] { editButton, removeButton, unDeleteButton, newDirectoryButton,
closeButton });
187 dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
189 dialog.setResizable(
true);
197 public void showDialog(@NotNull
final Component parentComponent) {
201 dialog.setLocationRelativeTo(parentComponent);
202 dialog.setMinimumSize(
new Dimension(600, 300));
203 dialog.setPreferredSize(
new Dimension(800, 600));
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();
223 bookmarksScrollPane.setBackground(
bookmarksTree.getBackground());
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);
241 bookmarksTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
245 bookmarksTree.addTreeSelectionListener(treeSelectionListener);
300 public void setValue(@Nullable
final Object newValue) {
301 super.setValue(newValue);
302 if (newValue != UNINITIALIZED_VALUE) {
314 if (tmpSelectedTreePath ==
null) {
318 final DefaultMutableTreeNode selectedTreeNode = (DefaultMutableTreeNode) tmpSelectedTreePath.getLastPathComponent();
324 final DefaultMutableTreeNode tmpSelectedTreeNode = (DefaultMutableTreeNode) tmpSelectedTreePath.getLastPathComponent();
331 mapMenuEntry.setTitle(bookmarkDirectoryDialog.
getDirectory());
332 bookmarksTree.getModel().valueForPathChanged(tmpSelectedTreePath, mapMenuEntry);
341 bookmarksTree.getModel().valueForPathChanged(tmpSelectedTreePath, mapMenuEntry);
346 ((
MapMenuEntry) tmpSelectedTreeNode.getUserObject()).visit(mapMenuEntryVisitor);
359 if (tmpSelectedTreePath ==
null) {
363 final DefaultMutableTreeNode selectedTreeNode = (DefaultMutableTreeNode) tmpSelectedTreePath.getLastPathComponent();
369 final int[] selectionRows =
bookmarksTree.getSelectionRows();
371 final int index = selectionRows ==
null ? 0 : selectionRows[0];
387 if (deletedNode ==
null) {
406 if (tmpSelectedTreePath ==
null) {
411 final DefaultMutableTreeNode selectedTreeNode = (DefaultMutableTreeNode) tmpSelectedTreePath.getLastPathComponent();
416 final DefaultMutableTreeNode parent;
419 parent = selectedTreeNode;
422 parent = (DefaultMutableTreeNode) selectedTreeNode.getParent();
423 assert parent !=
null;
424 index = parent.getIndex(selectedTreeNode) + 1;
444 @Nullable
final Icon previewIcon;
448 final DefaultMutableTreeNode tmpSelectedTreeNode = (DefaultMutableTreeNode)
selectedTreePath.getLastPathComponent();