20 package net.sf.gridarta.gui.data;
22 import java.awt.Component;
23 import java.awt.Window;
24 import java.awt.event.MouseAdapter;
25 import java.awt.event.MouseEvent;
26 import javax.swing.JOptionPane;
27 import javax.swing.JScrollPane;
28 import javax.swing.JTree;
29 import javax.swing.tree.TreeNode;
30 import javax.swing.tree.TreePath;
35 import net.
sf.japi.swing.action.ActionBuilder;
36 import net.
sf.japi.swing.action.ActionBuilderFactory;
37 import org.jetbrains.annotations.NotNull;
38 import org.jetbrains.annotations.Nullable;
52 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
72 final NamedObject initialObject = namedObjects.get(initial);
73 final String initialPath = initialObject != null ? initialObject.
getPath() : initial;
74 final JTree tree =
new JTree(namedObjects.getTreeRoot());
76 final JScrollPane scrollPane =
new JScrollPane(tree);
77 tree.setExpandsSelectedPaths(
true);
78 final TreePath path = namedObjects.getTreeRoot().getPathFor(initialPath);
79 tree.makeVisible(path);
80 tree.setSelectionPath(path);
81 tree.scrollPathToVisible(path);
82 final JOptionPane pane =
new JOptionPane(scrollPane, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, null, null);
83 final Window dialog = pane.createDialog(parentComponent, ACTION_BUILDER.format(
"chooseNamedObject.title", namedObjects.getName()));
84 pane.selectInitialValue();
86 tree.addMouseListener(
new MouseAdapter() {
89 public void mousePressed(
final MouseEvent e) {
90 if (e.getClickCount() == 2) {
91 final TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
92 if (selPath != null) {
93 final TreeNode node = (TreeNode) selPath.getLastPathComponent();
102 dialog.setVisible(
true);
105 if (pane.getValue() == null || !pane.getValue().equals(0)) {
109 final TreePath selectionPath = tree.getSelectionPath();
110 if (selectionPath == null) {
TreeCellRenderer for NamedTreeNodes in trees.
The data package contains classes for handling data that is organized in a tree.
This class manages NamedObjects, managing their tree as well as providing a method for showing a dial...
NamedObjectsUtils()
Private constructor to prevent instantiation.
Utility class for NamedObjects related functions.
Base package of all Gridarta classes.
static< E extends NamedObject > String showNodeChooserDialog(@NotNull final Component parentComponent, @NotNull final String initial, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final NamedObjects< E > namedObjects)
Show a dialog for choosing from the object tree.
String getPath()
Get the path of this AbstractNamedObject.
Provider for faces of GameObjects and Archetypes.
The face is the appearance of an object.
static final ActionBuilder ACTION_BUILDER
The ActionBuilder.
TreeNode implementation for Named Objects (like arches, faces, animations, artifacts etc...