Skip to content

Commit

Permalink
Card Pane Association (#549)
Browse files Browse the repository at this point in the history
* Allow specifying tree node hash code as string name of card in settings/preferences card panes.
* If card with the tree node name does not exist, then showing it is a noop, and hash code name takes precedence.
* Use hash code for all built in settings/preferences panels in the card panes.
  • Loading branch information
RobertBColton committed Feb 20, 2021
1 parent 1d9c522 commit c18c187
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
2 changes: 1 addition & 1 deletion org/lateralgm/main/LGM.java
Expand Up @@ -131,7 +131,7 @@

public final class LGM
{
public static final String version = "1.8.222"; //$NON-NLS-1$
public static final String version = "1.8.223"; //$NON-NLS-1$

// TODO: This list holds the class loader for any loaded plugins which should be
// cleaned up and closed when the application closes.
Expand Down
28 changes: 16 additions & 12 deletions org/lateralgm/main/PreferencesFrame.java
Expand Up @@ -120,7 +120,7 @@ public PreferencesFrame()
{
DefaultMutableTreeNode node = new DefaultMutableTreeNode(group.name);
root.add(node);
cardPane.add(group.makePanel(), group.name);
cardPane.add(group.makePanel(), Integer.toString(node.hashCode()));
}

//TODO: Fix UI bugs in JoshEdit repo and then use the serialize feature to save them.
Expand Down Expand Up @@ -161,20 +161,24 @@ public PreferencesFrame()

tree.addTreeSelectionListener(new TreeSelectionListener()
{
public void valueChanged(TreeSelectionEvent e)
{
DefaultMutableTreeNode node =
(DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
public void valueChanged(TreeSelectionEvent e)
{
// retrieve the node that was selected
DefaultMutableTreeNode node =
(DefaultMutableTreeNode) tree.getLastSelectedPathComponent();

/* if nothing is selected */
if (node == null) return;
// short-circuit if nothing is selected
if (node == null) return;

/* retrieve the node that was selected */
String nodeInfo = node.getUserObject().toString();
CardLayout cl = (CardLayout) (cardPane.getLayout());

CardLayout cl = (CardLayout) (cardPane.getLayout());
cl.show(cardPane,nodeInfo);
}
// show panel with same name as the node
String nodeInfo = node.getUserObject().toString();
cl.show(cardPane,nodeInfo);
// show card with node hash if name was not unique
nodeInfo = Integer.toString(node.hashCode());
cl.show(cardPane,nodeInfo);
}
});

JScrollPane scroll = new JScrollPane(tree);
Expand Down
28 changes: 17 additions & 11 deletions org/lateralgm/subframes/GameSettingFrame.java
Expand Up @@ -844,21 +844,27 @@ public GameSettingFrame(GameSettings res, ResNode node)
// reload after adding all root children to make sure its children are visible
((DefaultTreeModel)tree.getModel()).reload();

tree.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
tree.addTreeSelectionListener(new TreeSelectionListener()
{
public void valueChanged(TreeSelectionEvent e)
{
// retrieve the node that was selected
DefaultMutableTreeNode node = (DefaultMutableTreeNode)
tree.getLastSelectedPathComponent();

// if nothing is selected
// short-circuit if nothing is selected
if (node == null) return;

CardLayout cl = (CardLayout) (cardPane.getLayout());

// retrieve the node that was selected
// show panel with same name as the node
String nodeInfo = node.getUserObject().toString();

CardLayout cl = (CardLayout)(cardPane.getLayout());
cl.show(cardPane, nodeInfo);
}
});
cl.show(cardPane,nodeInfo);
// show card with node hash if name was not unique
nodeInfo = Integer.toString(node.hashCode());
cl.show(cardPane,nodeInfo);
}
});

JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,
new JScrollPane(tree),cardPane);
Expand Down Expand Up @@ -892,7 +898,7 @@ private DefaultMutableTreeNode buildTab(DefaultMutableTreeNode root, String key,
root.add(node);
if (pane != null) {
pane.setName(key);
cardPane.add(Messages.getString(key),pane);
cardPane.add(pane,Integer.toString(node.hashCode()));
}
return node;
}
Expand Down

0 comments on commit c18c187

Please sign in to comment.