20 package net.sf.gridarta.gui.treasurelist;
22 import java.awt.BorderLayout;
23 import java.awt.Component;
24 import java.awt.Container;
25 import java.awt.Frame;
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
28 import javax.swing.AbstractButton;
29 import javax.swing.BorderFactory;
30 import javax.swing.JButton;
31 import javax.swing.JDialog;
32 import javax.swing.JPanel;
33 import javax.swing.JScrollPane;
34 import javax.swing.JSplitPane;
35 import javax.swing.JTree;
36 import javax.swing.JViewport;
37 import javax.swing.ScrollPaneConstants;
38 import javax.swing.WindowConstants;
39 import javax.swing.text.JTextComponent;
40 import javax.swing.tree.DefaultMutableTreeNode;
41 import javax.swing.tree.TreeNode;
42 import javax.swing.tree.TreePath;
51 import net.
sf.japi.swing.action.ActionBuilder;
52 import net.
sf.japi.swing.action.ActionBuilderFactory;
53 import org.jetbrains.annotations.NotNull;
54 import org.jetbrains.annotations.Nullable;
69 public static final String
NONE_SYM =
"<none>";
75 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
107 private final AbstractButton
okButton =
new JButton(
"Select");
114 private final AbstractButton
noneButton =
new JButton(
"None");
133 super(treasureTree.getRoot());
138 faceObjectProviders.addFaceObjectProvidersListener(faceObjectProvidersListener);
140 putClientProperty(
"JTree.lineStyle",
"Angled");
141 setCellRenderer(
new TreasureCellRenderer(archetypeSet, treasureTree.getRoot(), faceObjectProviders, resourceIcons));
153 public synchronized void showDialog(@Nullable
final JTextComponent input, @NotNull
final Component parent) {
156 final boolean hasBeenDisplayed = frame != null;
158 if (frame.isShowing()) {
159 assert frame != null;
160 frame.setVisible(
false);
164 expandPath(
new TreePath(treasureTree.
getRoot()));
165 for (
int i = getRowCount() - 1; i > 0; i--) {
170 frame =
new JDialog(this.parent,
"Treasurelists",
false);
171 frame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
173 setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 5));
174 final JScrollPane scrollPane =
new JScrollPane(
this);
175 scrollPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
176 scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
177 scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
180 final JSplitPane splitPane =
new JSplitPane(JSplitPane.VERTICAL_SPLIT, scrollPane, buttonPanel);
181 splitPane.setOneTouchExpandable(
false);
182 assert frame != null;
183 splitPane.setDividerLocation(frame.getHeight() - buttonPanel.getMinimumSize().height - 4);
185 splitPane.setDividerSize(4);
186 splitPane.setResizeWeight(1.0);
188 assert frame != null;
189 frame.getContentPane().add(splitPane);
191 expandPath(
new TreePath(treasureTree.
getRoot()));
194 okButton.setVisible(input != null);
195 noneButton.setVisible(input != null);
197 assert frame != null;
198 frame.setSize(470, 550);
199 assert frame != null;
200 frame.setLocationRelativeTo(parent);
203 final String listName = input.getText().trim();
204 final DefaultMutableTreeNode treasureNode = treasureTree.
get(listName);
205 if (treasureNode != null) {
206 final DefaultMutableTreeNode[] node =
new DefaultMutableTreeNode[2];
207 node[0] = treasureTree.
getRoot();
208 node[1] = treasureNode;
209 final TreePath treePath =
new TreePath(node);
210 expandPath(treePath);
211 setSelectionPath(treePath);
213 if (!hasBeenDisplayed) {
216 assert frame != null;
218 assert frame != null;
219 frame.setSize(470, 550);
220 setSelectionPath(treePath);
223 scrollRowToVisible(getRowCount() - 1);
224 scrollPathToVisible(treePath);
226 scrollRowToVisible(0);
227 setSelectionPath(null);
230 scrollRowToVisible(0);
231 setSelectionPath(null);
233 assert frame != null;
234 frame.setVisible(
true);
243 final JPanel buttonPanel =
new JPanel(
new BorderLayout());
245 final Container leftSide =
new JPanel();
246 final Container rightSide =
new JPanel();
248 okButton.addActionListener(
new ActionListener() {
251 public void actionPerformed(@NotNull
final ActionEvent e) {
253 if (result != null) {
259 rightSide.add(okButton);
261 noneButton.addActionListener(
new ActionListener() {
264 public void actionPerformed(@NotNull
final ActionEvent e) {
270 rightSide.add(noneButton);
272 final AbstractButton cancelButton =
new JButton(
"Cancel");
273 cancelButton.addActionListener(
new ActionListener() {
276 public void actionPerformed(@NotNull
final ActionEvent e) {
277 assert frame != null;
278 frame.setVisible(
false);
282 rightSide.add(cancelButton);
284 final AbstractButton helpButton =
new JButton(
"Help");
285 helpButton.addActionListener(
new ActionListener() {
288 public void actionPerformed(@NotNull
final ActionEvent e) {
289 new Help(parent,
"treasurelists.html").setVisible(
true);
293 leftSide.add(helpButton);
294 final Component testButton =
new JButton(
"Test");
295 leftSide.add(testButton);
296 testButton.setEnabled(
false);
298 buttonPanel.add(leftSide, BorderLayout.WEST);
299 buttonPanel.add(rightSide, BorderLayout.EAST);
309 input.setText(
" " + result);
311 assert frame != null;
312 frame.setVisible(
false);
323 if (isSelectionEmpty()) {
327 TreeNode node = (TreeNode) getSelectionPath().getLastPathComponent();
329 if (node == treasureTree.
getRoot()) {
334 final TreeNode parentNode = node.getParent();
335 if (parentNode == treasureTree.
getRoot()) {
346 ACTION_BUILDER.showMessageDialog(frame,
"treasurelistForbidden", treasureTreeNode.
getTreasureObj().
getName());
static final long serialVersionUID
The serial version UID.
final Frame parent
The main view.
String getName()
Returns the name of this treasure object.
void selectValue(@NotNull final String result)
Selects a value and closes the dialog.
TreasureTreeNode get(@NotNull final String name)
Returns a treasure list by name.
Graphical User Interface of Gridarta.
TreasureObj getTreasureObj()
This packages implements the online help system for the Gridarta editor.
JPanel buildButtonPanel()
Builds the button panel (bottom-line of the dialog window).
CFTreasureListTree(@NotNull final TreasureTree treasureTree, @NotNull final Frame parent, @NotNull final ArchetypeSet<?, ?, ?> archetypeSet, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final ResourceIcons resourceIcons)
Creates a new instance.
Base package of all Gridarta classes.
String getSelectedTreasureList()
Returns the name of the currently selected treasurelist.
JDialog frame
JDialog containing the tree.
final AbstractButton noneButton
The button for none.
final TreasureTree treasureTree
All defined treasure lists.
The CFTreasureListTree class fully manages treasurelists.
A TreasureObj representing a folder.
Implements the Help Window is a separate frame with html content.
JTextComponent input
The text input field.
static final String NONE_SYM
The string displayed in attribute dialog for "none".
Stores all defined treasure lists.
Interface for listeners interested in FaceObjectProviders related events.
Provider for faces of GameObjects and Archetypes.
static final ActionBuilder ACTION_BUILDER
The ActionBuilder.
The face is the appearance of an object.
DefaultMutableTreeNode getRoot()
Returns the root node for normal treasure lists.
Creates ImageIcon instances from resources.
This cell renderer is responsible for drawing the treasure-object cells in the JTree.
Subclass: Nodes in the CFTreasureListTree.
final AbstractButton okButton
The button for ok.
synchronized void showDialog(@Nullable final JTextComponent input, @NotNull final Component parent)
Shows the dialog window containing this tree.
Interface that captures similarities between different ArchetypeSet implementations.