001 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
002 *
003 * Copyright 2000-2013, Michael Meyling <mime@qedeq.org>.
004 *
005 * "Hilbert II" is free software; you can redistribute
006 * it and/or modify it under the terms of the GNU General Public
007 * License as published by the Free Software Foundation; either
008 * version 2 of the License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU General Public License for more details.
014 */
015
016 package org.qedeq.gui.se.tree;
017
018 import java.awt.Dimension;
019 import java.awt.GridLayout;
020 import java.awt.event.MouseListener;
021
022 import javax.swing.JPanel;
023 import javax.swing.JTree;
024 import javax.swing.ToolTipManager;
025 import javax.swing.event.TreeSelectionListener;
026 import javax.swing.tree.TreeModel;
027 import javax.swing.tree.TreePath;
028 import javax.swing.tree.TreeSelectionModel;
029
030
031 /**
032 * View for certain JTree.
033 *
034 * A View, which is a collection of classes representing the elements in the user interface
035 * (all of the things the user can see and respond to on the screen, such as buttons, display
036 * boxes, and so forth).
037 *
038 * @version $Revision: 1.4 $
039 * @author Michael Meyling
040 */
041 public final class QedeqTreeView extends JPanel {
042
043 /** Reference to JTree. */
044 private final JTree theTree;
045
046 /**
047 * Constructor.
048 *
049 * @param treeModel model for this tree
050 */
051 public QedeqTreeView(final TreeModel treeModel) {
052 super(new GridLayout(1, 1));
053 // don't change these values without looking at the paint method of the TreeCellRenderer
054 theTree = new JTree(treeModel);
055 theTree.setEditable(false);
056 theTree.setRootVisible(false);
057 theTree.setExpandsSelectedPaths(true);
058 theTree.setScrollsOnExpand(true);
059 theTree.setShowsRootHandles(true);
060 theTree.getSelectionModel().setSelectionMode(
061 TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
062 // enable tool tips for the tree
063 ToolTipManager.sharedInstance().registerComponent(theTree);
064
065 theTree.setCellRenderer(new QedeqTreeCellRenderer());
066 /* Make tree ask for the height of each row. */
067 theTree.setRowHeight(-1);
068
069 this.add(theTree);
070 this.setMinimumSize(new Dimension(150, 100));
071 }
072
073 /* @see JTree#expandPath
074 */
075 public final void expandPath(final TreePath path) {
076 theTree.expandPath(path);
077 }
078
079 /* @see JTree#addTreeSelectionListener
080 */
081 public final void addTreeSelectionListener(final TreeSelectionListener listener) {
082 theTree.addTreeSelectionListener(listener);
083 }
084
085
086 /* @see JTree#setSelectionRow
087 */
088 public void setSelectionRow(final int row) {
089 theTree.setSelectionRow(row);
090 }
091
092 /* @see JTree#setSelectionPath
093 */
094 public void setSelectionPath(final TreePath path) {
095 theTree.setSelectionPath(path);
096 }
097
098 /* @see JTree#getSelectionPath
099 */
100 public TreePath getSelectionPath() {
101 return theTree.getSelectionPath();
102 }
103
104 /* @see JTree#getSelectionPaths
105 */
106 public TreePath[] getSelectionPaths() {
107 return theTree.getSelectionPaths();
108 }
109
110 /* @see JTree#getPathForLocation
111 */
112 public TreePath getPathForLocation(final int x, final int y) {
113 return theTree.getPathForLocation(x, y);
114 }
115
116 /* @see JTree#startEditingAtPath
117 */
118 public void startEditingAtPath(final TreePath path) {
119 theTree.startEditingAtPath(path);
120 }
121
122 /* @see JTree#treeAddMouseListener
123 */
124 public void treeAddMouseListener(final MouseListener mouseListener) {
125 theTree.addMouseListener(mouseListener);
126 }
127
128 }
|