diff options
author | Audrius Meskauskas <audriusa@Bioinformatics.org> | 2006-04-27 08:23:45 +0000 |
---|---|---|
committer | Audrius Meskauskas <audriusa@Bioinformatics.org> | 2006-04-27 08:23:45 +0000 |
commit | f5a496a2c313d1c3a29bfeb98f57057ed97e2b8b (patch) | |
tree | 34089abc90adcb83c0188adb6f89681dc5c0415a /examples | |
parent | c90aa78a0388d575d5923b76be2addb42fbdcade (diff) | |
download | classpath-f5a496a2c313d1c3a29bfeb98f57057ed97e2b8b.tar.gz |
2006-04-27 Audrius Meskauskas <AudriusA@Bioinformatics.org>
* examples/gnu/classpath/examples/swing/TreeDemo.java
(createContent): Added root visibility and selection listener demos.
* javax/swing/JTree.java (setRootVisible): If false, unselect
the root node, if it is selected.
* javax/swing/plaf/basic/BasicTreeUI.java
(TreeTraverseAction.actionPerformed): Do not select the root if it
is not visible.
* javax/swing/tree/DefaultTreeSelectionModel.java (removeSelectionPath,
removeSelectionPaths): Reset lead to null if the current lead path is
removed from selection.
* javax/swing/tree/TreePath.java (getParentPath): Cache the parent path.
* javax/swing/tree/FixedHeightLayoutCache.java (NodeRecord.getPath):
Return the same path regardless is root visible or not. (update):
Reduce the identation if the root is not visible.
* javax/swing/tree/VariableHeightLayoutCache.java (NodeRecord.getPath):
Return the same path regardless is root visible or not. (update):
Reduce the identation if the root is not visible.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/gnu/classpath/examples/swing/TreeDemo.java | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/examples/gnu/classpath/examples/swing/TreeDemo.java b/examples/gnu/classpath/examples/swing/TreeDemo.java index a54585940..32f765f73 100644 --- a/examples/gnu/classpath/examples/swing/TreeDemo.java +++ b/examples/gnu/classpath/examples/swing/TreeDemo.java @@ -48,10 +48,13 @@ import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComponent; import javax.swing.JFrame; +import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTree; import javax.swing.SwingUtilities; +import javax.swing.event.TreeSelectionEvent; +import javax.swing.event.TreeSelectionListener; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.DefaultTreeSelectionModel; @@ -169,6 +172,7 @@ public class TreeDemo } }); + // Demonstration of the various selection modes final JCheckBox cbSingle = new JCheckBox("single selection"); cbSingle.addActionListener(new ActionListener() { @@ -182,18 +186,49 @@ public class TreeDemo DefaultTreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); } }); - + + // Demonstration of the root visibility changes + final JCheckBox cbRoot = new JCheckBox("root"); + cbRoot.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + tree.setRootVisible(cbRoot.isSelected()); + } + }); + cbRoot.setSelected(true); + + // Demonstration of the tree selection listener. + final JLabel choice = new JLabel("Make a choice"); + tree.getSelectionModel().addTreeSelectionListener( + new TreeSelectionListener() + { + public void valueChanged(TreeSelectionEvent event) + { + TreePath was = event.getOldLeadSelectionPath(); + TreePath now = event.getNewLeadSelectionPath(); + String swas = + was == null ? "none":was.getLastPathComponent().toString(); + String snow = + now == null ? "none":now.getLastPathComponent().toString(); + choice.setText("From "+swas+" to "+snow); + } + } + ); + setLayout(new BorderLayout()); JPanel p2 = new JPanel(); p2.add(add); p2.add(cbSingle); + p2.add(cbRoot); tree.getSelectionModel(). setSelectionMode(DefaultTreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); add(p2, BorderLayout.NORTH); add(new JScrollPane(tree), BorderLayout.CENTER); + add(choice, BorderLayout.SOUTH); } public void actionPerformed(ActionEvent e) |