01: /*
02: *
03: * (c) Copyright 2004 - 2007 osbl development team.
04: *
05: * This file is part of the osbl (http://osbl.wilken.de).
06: *
07: * the osbl is free software; you can redistribute it and/or modify
08: * it under the terms of the GNU General Public License
09: * as published by the Free Software Foundation; either version 2.1
10: * of the License, or (at your option) any later version.
11: *
12: * Please see COPYING for the complete licence.
13: */
14: package org.osbl.client.wings.navigation;
15:
16: import javax.swing.tree.*;
17:
18: import org.wings.*;
19: import org.wings.plaf.css.TreeCG;
20: import org.wings.util.PropertyAccessor;
21: import org.wings.tree.STreeSelectionModel;
22: import org.osbl.client.wings.XTitleLabel;
23:
24: /**
25: * @author hengels
26: * @version $Revision: 1.3 $
27: */
28: public class Navigation extends SPanel {
29: public static final SIcon LEAF = new SResourceIcon(
30: "org/wings/icons/transdot.gif");
31: public static final SIcon ARROW_DOWN = new SResourceIcon(
32: "org/wings/icons/ArrowDown.gif");
33: public static final SIcon ARROW_RIGHT = new SResourceIcon(
34: "org/wings/icons/ArrowRight.gif");
35:
36: private STree tree = new STree();
37:
38: public Navigation() {
39: super .setLayout(new SBorderLayout(8, 8));
40:
41: TreeCG treeCG = new TreeCG();
42: tree.setCG(treeCG);
43: PropertyAccessor.setProperty(treeCG, "leafControlIcon", LEAF);
44: PropertyAccessor.setProperty(treeCG, "collapseControlIcon",
45: ARROW_DOWN);
46: PropertyAccessor.setProperty(treeCG, "expandControlIcon",
47: ARROW_RIGHT);
48:
49: tree.setStyle("Navigation");
50: tree.setCellRenderer(new NavigationTreeCellRenderer());
51: tree.getSelectionModel().setSelectionMode(
52: STreeSelectionModel.SINGLE_TREE_SELECTION);
53: tree.addMouseListener(new NavigationListener());
54: tree.setNodeIndentDepth(12);
55: tree.setRootVisible(false);
56:
57: add(new XTitleLabel("Navigation"), SBorderLayout.NORTH);
58: add(tree, SBorderLayout.CENTER);
59: }
60:
61: public void setModel(TreeNode root) {
62: tree.setModel(new DefaultTreeModel(root));
63: for (int i = 0; i < tree.getRowCount(); i++) {
64: TreePath path = tree.getPathForRow(i);
65: if (path.getPathCount() == 2)
66: tree.expandRow(i);
67: }
68: }
69: }
|