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");
138 faceObjectProviders.addFaceObjectProvidersListener(faceObjectProvidersListener);
140 putClientProperty(
"JTree.lineStyle",
"Angled");
156 final boolean hasBeenDisplayed =
frame !=
null;
159 frame =
new JDialog(this.parent,
"Treasurelists",
false);
160 frame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
162 setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 5));
163 final JScrollPane scrollPane =
new JScrollPane(
this);
164 scrollPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
165 scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
166 scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
169 final JSplitPane splitPane =
new JSplitPane(JSplitPane.VERTICAL_SPLIT, scrollPane, buttonPanel);
170 splitPane.setOneTouchExpandable(
false);
171 assert
frame !=
null;
172 splitPane.setDividerLocation(
frame.getHeight() - buttonPanel.getMinimumSize().height - 4);
174 splitPane.setDividerSize(4);
175 splitPane.setResizeWeight(1.0);
177 assert
frame !=
null;
178 frame.getContentPane().add(splitPane);
182 if (
frame.isShowing()) {
183 assert
frame !=
null;
184 frame.setVisible(
false);
189 for (
int i = getRowCount() - 1; i > 0; i--) {
197 assert
frame !=
null;
198 frame.setSize(470, 550);
199 assert
frame !=
null;
203 scrollRowToVisible(0);
204 setSelectionPath(
null);
206 final String listName =
input.getText().trim();
207 final DefaultMutableTreeNode treasureNode =
treasureTree.
get(listName);
208 if (treasureNode ==
null) {
209 scrollRowToVisible(0);
210 setSelectionPath(
null);
212 final DefaultMutableTreeNode[] node =
new DefaultMutableTreeNode[2];
214 node[1] = treasureNode;
215 final TreePath treePath =
new TreePath(node);
216 expandPath(treePath);
217 setSelectionPath(treePath);
219 if (!hasBeenDisplayed) {
222 assert
frame !=
null;
224 assert
frame !=
null;
225 frame.setSize(470, 550);
226 setSelectionPath(treePath);
229 scrollRowToVisible(getRowCount() - 1);
230 scrollPathToVisible(treePath);
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) {
261 noneButton.addActionListener(
new ActionListener() {
264 public void actionPerformed(@NotNull
final ActionEvent e) {
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();
334 final TreeNode parentNode = node.getParent();