1 14 package wingset; 15 16 import org.wings.*; 17 import org.wings.util.PropertyAccessor; 18 19 import javax.swing.tree.DefaultTreeModel ; 20 import java.awt.event.ActionEvent ; 21 import java.awt.event.ActionListener ; 22 import java.awt.event.ItemEvent ; 23 import java.awt.event.ItemListener ; 24 25 29 public class TreeExample 30 extends WingSetPane { 31 private STree tree; 32 private static SIcon ARROW_DOWN = new SResourceIcon("org/wings/icons/ArrowDown.gif"); 33 private static SIcon ARROW_RIGHT = new SResourceIcon("org/wings/icons/ArrowRight.gif"); 34 35 private static SIcon PLUS = new SResourceIcon("org/wings/icons/plus.gif"); 36 private static SIcon MINUS = new SResourceIcon("org/wings/icons/minus.gif"); 37 private TreeControls controls; 38 39 public SComponent createExample() { 40 controls = new TreeControls(); 41 42 tree = new STree(new DefaultTreeModel (HugeTreeModel.ROOT_NODE)); 43 tree.setName("tree"); 44 tree.setShowAsFormComponent(false); 45 controls.addSizable(tree); 46 47 SForm panel = new SForm(new SBorderLayout()); 48 panel.add(controls, SBorderLayout.NORTH); 49 panel.add(tree, SBorderLayout.CENTER); 50 return panel; 51 } 52 53 class TreeControls extends ComponentControls { 54 private final String [] SELECTION_MODES = new String []{"no", "single", "multiple"}; 55 private final Integer [] WIDTHS = new Integer []{new Integer (12), new Integer (24), new Integer (36), new Integer (48)}; 56 57 public TreeControls() { 58 final SCheckBox showAsFormComponent = new SCheckBox("<html>Show as Form Component "); 59 showAsFormComponent.addActionListener(new ActionListener () { 60 public void actionPerformed(ActionEvent e) { 61 tree.setShowAsFormComponent(showAsFormComponent.isSelected()); 62 } 63 }); 64 65 final SComboBox selectionMode = new SComboBox(SELECTION_MODES); 66 selectionMode.addItemListener(new ItemListener () { 67 public void itemStateChanged(ItemEvent e) { 68 if ("no".equals(selectionMode.getSelectedItem())) 69 tree.getSelectionModel().setSelectionMode(STree.NO_SELECTION); 70 else if ("single".equals(selectionMode.getSelectedItem())) 71 tree.getSelectionModel().setSelectionMode(STree.SINGLE_SELECTION); 72 else if ("multiple".equals(selectionMode.getSelectedItem())) 73 tree.getSelectionModel().setSelectionMode(STree.MULTIPLE_SELECTION); 74 } 75 }); 76 77 final SComboBox indentationWidth = new SComboBox(WIDTHS); 78 indentationWidth.addItemListener(new ItemListener () { 79 public void itemStateChanged(ItemEvent e) { 80 tree.setNodeIndentDepth(((Integer ) indentationWidth.getSelectedItem()).intValue()); 81 } 82 }); 83 84 final SRadioButton plusButton = new SRadioButton("plus/minus"); 85 plusButton.setToolTipText("use [+] and [-] as expansion controls"); 86 87 final SRadioButton arrowButton = new SRadioButton("arrows"); 88 arrowButton.setToolTipText("use right-arrow and down-arrow as expansion controls"); 89 90 SButtonGroup group = new SButtonGroup(); 91 group.add(plusButton); 92 group.add(arrowButton); 93 plusButton.setSelected(true); 94 95 group.addActionListener(new ActionListener () { 96 public void actionPerformed(ActionEvent e) { 97 if (plusButton.isSelected()) { 98 PropertyAccessor.setProperty(tree.getCG(), "collapseControlIcon", MINUS); 99 PropertyAccessor.setProperty(tree.getCG(), "expandControlIcon", PLUS); 100 } else { 101 PropertyAccessor.setProperty(tree.getCG(), "collapseControlIcon", ARROW_DOWN); 102 PropertyAccessor.setProperty(tree.getCG(), "expandControlIcon", ARROW_RIGHT); 103 } 104 } 105 }); 106 107 add(showAsFormComponent); 108 add(new SLabel(" selection mode ")); 109 add(selectionMode); 110 add(new SLabel(" indentation width ")); 111 add(indentationWidth); 112 add(new SLabel(" folding icons ")); 113 add(plusButton); 114 add(arrowButton); 115 } 116 } 117 } 118 | Popular Tags |