40 |
|
|
41 |
import java.awt.Dimension; |
import java.awt.Dimension; |
42 |
import java.awt.Rectangle; |
import java.awt.Rectangle; |
43 |
|
import java.util.Enumeration; |
44 |
import java.util.Hashtable; |
import java.util.Hashtable; |
45 |
|
import java.util.Iterator; |
46 |
import java.util.Vector; |
import java.util.Vector; |
47 |
|
|
48 |
import javax.accessibility.Accessible; |
import javax.accessibility.Accessible; |
54 |
import javax.swing.event.TreeWillExpandListener; |
import javax.swing.event.TreeWillExpandListener; |
55 |
import javax.swing.plaf.TreeUI; |
import javax.swing.plaf.TreeUI; |
56 |
import javax.swing.tree.ExpandVetoException; |
import javax.swing.tree.ExpandVetoException; |
57 |
|
import javax.swing.tree.DefaultMutableTreeNode; |
58 |
|
import javax.swing.tree.DefaultTreeCellRenderer; |
59 |
|
import javax.swing.tree.DefaultTreeModel; |
60 |
import javax.swing.tree.TreeCellEditor; |
import javax.swing.tree.TreeCellEditor; |
61 |
import javax.swing.tree.TreeCellRenderer; |
import javax.swing.tree.TreeCellRenderer; |
62 |
import javax.swing.tree.TreeModel; |
import javax.swing.tree.TreeModel; |
64 |
import javax.swing.tree.TreePath; |
import javax.swing.tree.TreePath; |
65 |
import javax.swing.tree.TreeSelectionModel; |
import javax.swing.tree.TreeSelectionModel; |
66 |
|
|
67 |
|
|
68 |
public class JTree extends JComponent |
public class JTree extends JComponent |
69 |
implements Scrollable, Accessible |
implements Scrollable, Accessible |
70 |
{ |
{ |
87 |
public static final String TREE_MODEL_PROPERTY = "model"; |
public static final String TREE_MODEL_PROPERTY = "model"; |
88 |
public static final String VISIBLE_ROW_COUNT_PROPERTY = "visibleRowCount"; |
public static final String VISIBLE_ROW_COUNT_PROPERTY = "visibleRowCount"; |
89 |
|
|
90 |
|
private boolean dragEnabled; |
91 |
|
private boolean expandsSelectedPaths; |
92 |
|
private TreePath anchorSelectionPath; |
93 |
|
private TreePath leadSelectionPath; |
94 |
|
|
95 |
protected TreeCellEditor cellEditor; |
protected TreeCellEditor cellEditor; |
96 |
protected TreeCellRenderer cellRenderer; |
protected TreeCellRenderer cellRenderer; |
97 |
protected boolean editable; |
protected boolean editable; |
111 |
*/ |
*/ |
112 |
public JTree() |
public JTree() |
113 |
{ |
{ |
114 |
treeModel = createTreeModel(null); |
this(createTreeModel(null)); |
115 |
} |
} |
116 |
|
|
117 |
/** |
/** |
121 |
*/ |
*/ |
122 |
public JTree(Hashtable value) |
public JTree(Hashtable value) |
123 |
{ |
{ |
124 |
treeModel = createTreeModel(value); |
this(createTreeModel(value)); |
125 |
} |
} |
126 |
|
|
127 |
/** |
/** |
131 |
*/ |
*/ |
132 |
public JTree(Object[] value) |
public JTree(Object[] value) |
133 |
{ |
{ |
134 |
treeModel = createTreeModel(value); |
this(createTreeModel(value)); |
135 |
} |
} |
136 |
|
|
137 |
/** |
/** |
142 |
public JTree(TreeModel model) |
public JTree(TreeModel model) |
143 |
{ |
{ |
144 |
treeModel = model; |
treeModel = model; |
145 |
|
setCellRenderer(new DefaultTreeCellRenderer()); |
146 |
|
updateUI(); |
147 |
} |
} |
148 |
|
|
149 |
/** |
/** |
165 |
*/ |
*/ |
166 |
public JTree(TreeNode root, boolean asksAllowChildren) |
public JTree(TreeNode root, boolean asksAllowChildren) |
167 |
{ |
{ |
168 |
|
this(new DefaultTreeModel(root, asksAllowChildren)); |
169 |
} |
} |
170 |
|
|
171 |
/** |
/** |
175 |
*/ |
*/ |
176 |
public JTree(Vector value) |
public JTree(Vector value) |
177 |
{ |
{ |
178 |
treeModel = createTreeModel(value); |
this(createTreeModel(value)); |
179 |
|
} |
180 |
|
|
181 |
|
public static class DynamicUtilTreeNode |
182 |
|
extends DefaultMutableTreeNode |
183 |
|
{ |
184 |
|
protected Object childValue; |
185 |
|
protected boolean loadedChildren; |
186 |
|
public DynamicUtilTreeNode(Object value, |
187 |
|
Object children) |
188 |
|
{ |
189 |
|
super(value); |
190 |
|
childValue = children; |
191 |
|
loadedChildren = false; |
192 |
|
} |
193 |
|
|
194 |
|
public int getChildCount() |
195 |
|
{ |
196 |
|
loadChildren(); |
197 |
|
return super.getChildCount(); |
198 |
|
} |
199 |
|
|
200 |
|
protected void loadChildren() |
201 |
|
{ |
202 |
|
if (!loadedChildren) |
203 |
|
{ |
204 |
|
createChildren(this, childValue); |
205 |
|
loadedChildren = true; |
206 |
|
} |
207 |
|
} |
208 |
|
|
209 |
|
public Enumeration children() |
210 |
|
{ |
211 |
|
loadChildren(); |
212 |
|
return super.children(); |
213 |
|
} |
214 |
|
|
215 |
|
public boolean isLeaf() |
216 |
|
{ |
217 |
|
return (childValue == null || |
218 |
|
!(childValue instanceof Hashtable |
219 |
|
|| childValue instanceof Vector |
220 |
|
|| childValue.getClass().isArray())); |
221 |
|
} |
222 |
|
|
223 |
|
public static void createChildren(DefaultMutableTreeNode parent, |
224 |
|
Object children) |
225 |
|
{ |
226 |
|
if (children instanceof Hashtable) |
227 |
|
{ |
228 |
|
Hashtable tab = (Hashtable) children; |
229 |
|
Enumeration e = tab.keys(); |
230 |
|
while (e.hasMoreElements()) |
231 |
|
{ |
232 |
|
Object key = e.nextElement(); |
233 |
|
Object val = tab.get(key); |
234 |
|
parent.add(new DynamicUtilTreeNode(key, val)); |
235 |
|
} |
236 |
|
} |
237 |
|
else if (children instanceof Vector) |
238 |
|
{ |
239 |
|
Iterator i = ((Vector)children).iterator(); |
240 |
|
while (i.hasNext()) |
241 |
|
{ |
242 |
|
Object n = i.next(); |
243 |
|
parent.add(new DynamicUtilTreeNode(n,n)); |
244 |
|
} |
245 |
|
} |
246 |
|
else if (children.getClass().isArray()) |
247 |
|
{ |
248 |
|
Object[] arr = (Object[]) children; |
249 |
|
for (int i = 0; i < arr.length; ++i) |
250 |
|
parent.add(new DynamicUtilTreeNode(arr[i], arr[i])); |
251 |
|
} |
252 |
|
} |
253 |
|
} |
254 |
|
|
255 |
|
public int getRowForPath(TreePath path) |
256 |
|
{ |
257 |
|
TreeUI ui = getUI(); |
258 |
|
|
259 |
|
if (ui != null) |
260 |
|
return ui.getRowForPath(this, path); |
261 |
|
|
262 |
|
return -1; |
263 |
|
} |
264 |
|
|
265 |
|
public TreePath getPathForRow(int row) |
266 |
|
{ |
267 |
|
TreeUI ui = getUI(); |
268 |
|
return ui != null ? ui.getPathForRow(this, row) : null; |
269 |
} |
} |
270 |
|
|
271 |
|
protected TreePath[] getPathBetweenRows(int index0, int index1) |
272 |
|
{ |
273 |
|
TreeUI ui = getUI(); |
274 |
|
|
275 |
|
if (ui == null) |
276 |
|
return null; |
277 |
|
|
278 |
|
int minIndex = Math.min(index0, index1); |
279 |
|
int maxIndex = Math.max(index0, index1); |
280 |
|
TreePath[] paths = new TreePath[maxIndex - minIndex + 1]; |
281 |
|
|
282 |
|
for (int i = minIndex; i <= maxIndex; ++i) |
283 |
|
paths[i - minIndex] = ui.getPathForRow(this, i); |
284 |
|
|
285 |
|
return paths; |
286 |
|
} |
287 |
|
|
288 |
/** |
/** |
289 |
* Creates a new <code>TreeModel</code> object. |
* Creates a new <code>TreeModel</code> object. |
290 |
* |
* |
292 |
*/ |
*/ |
293 |
protected static TreeModel createTreeModel(Object value) |
protected static TreeModel createTreeModel(Object value) |
294 |
{ |
{ |
295 |
// FIXME: Implement this. |
return new DefaultTreeModel(new DynamicUtilTreeNode(value, value)); |
|
return null; |
|
296 |
} |
} |
297 |
|
|
298 |
/** |
/** |
321 |
public void updateUI() |
public void updateUI() |
322 |
{ |
{ |
323 |
setUI((TreeUI) UIManager.getUI(this)); |
setUI((TreeUI) UIManager.getUI(this)); |
324 |
|
revalidate(); |
325 |
|
repaint(); |
326 |
} |
} |
327 |
|
|
328 |
/** |
/** |
555 |
*/ |
*/ |
556 |
public void setModel(TreeModel model) |
public void setModel(TreeModel model) |
557 |
{ |
{ |
558 |
|
if (treeModel == model) |
559 |
|
return; |
560 |
|
|
561 |
|
TreeModel oldValue = treeModel; |
562 |
treeModel = model; |
treeModel = model; |
563 |
|
firePropertyChange(TREE_MODEL_PROPERTY, oldValue, model); |
564 |
} |
} |
565 |
|
|
566 |
/** |
/** |
587 |
|
|
588 |
boolean oldValue = editable; |
boolean oldValue = editable; |
589 |
editable = flag; |
editable = flag; |
590 |
firePropertyChange("editable", oldValue, editable); |
firePropertyChange(EDITABLE_PROPERTY, oldValue, editable); |
591 |
} |
} |
592 |
|
|
593 |
/** |
/** |
603 |
|
|
604 |
public void setRootVisible(boolean flag) |
public void setRootVisible(boolean flag) |
605 |
{ |
{ |
606 |
|
if (rootVisible == flag) |
607 |
|
return; |
608 |
|
|
609 |
|
boolean oldValue = rootVisible; |
610 |
rootVisible = flag; |
rootVisible = flag; |
611 |
|
firePropertyChange(ROOT_VISIBLE_PROPERTY, oldValue, flag); |
612 |
} |
} |
613 |
|
|
614 |
public boolean getShowsRootHandles() |
public boolean getShowsRootHandles() |
618 |
|
|
619 |
public void setShowsRootHandles(boolean flag) |
public void setShowsRootHandles(boolean flag) |
620 |
{ |
{ |
621 |
|
if (showsRootHandles == flag) |
622 |
|
return; |
623 |
|
|
624 |
|
boolean oldValue = showsRootHandles; |
625 |
showsRootHandles = flag; |
showsRootHandles = flag; |
626 |
|
firePropertyChange(SHOWS_ROOT_HANDLES_PROPERTY, oldValue, flag); |
627 |
} |
} |
628 |
|
|
629 |
public TreeCellEditor getCellEditor() |
public TreeCellEditor getCellEditor() |
633 |
|
|
634 |
public void setCellEditor(TreeCellEditor editor) |
public void setCellEditor(TreeCellEditor editor) |
635 |
{ |
{ |
636 |
|
if (cellEditor == editor) |
637 |
|
return; |
638 |
|
|
639 |
|
TreeCellEditor oldValue = cellEditor; |
640 |
cellEditor = editor; |
cellEditor = editor; |
641 |
|
firePropertyChange(CELL_EDITOR_PROPERTY, oldValue, editor); |
642 |
} |
} |
643 |
|
|
644 |
public TreeCellRenderer getCellRenderer() |
public TreeCellRenderer getCellRenderer() |
648 |
|
|
649 |
public void setCellRenderer(TreeCellRenderer newRenderer) |
public void setCellRenderer(TreeCellRenderer newRenderer) |
650 |
{ |
{ |
651 |
|
if (cellRenderer == newRenderer) |
652 |
|
return; |
653 |
|
|
654 |
|
TreeCellRenderer oldValue = cellRenderer; |
655 |
cellRenderer = newRenderer; |
cellRenderer = newRenderer; |
656 |
|
firePropertyChange(CELL_RENDERER_PROPERTY, oldValue, newRenderer); |
657 |
} |
} |
658 |
|
|
659 |
public TreeSelectionModel getSelectionModel() |
public TreeSelectionModel getSelectionModel() |
663 |
|
|
664 |
public void setSelectionModel(TreeSelectionModel model) |
public void setSelectionModel(TreeSelectionModel model) |
665 |
{ |
{ |
666 |
|
if (selectionModel == model) |
667 |
|
return; |
668 |
|
|
669 |
|
TreeSelectionModel oldValue = selectionModel; |
670 |
selectionModel = model; |
selectionModel = model; |
671 |
|
firePropertyChange(SELECTION_MODEL_PROPERTY, oldValue, model); |
672 |
} |
} |
673 |
|
|
674 |
public int getVisibleRowCount() |
public int getVisibleRowCount() |
678 |
|
|
679 |
public void setVisibleRowCount(int rows) |
public void setVisibleRowCount(int rows) |
680 |
{ |
{ |
681 |
|
if (visibleRowCount == rows) |
682 |
|
return; |
683 |
|
|
684 |
|
int oldValue = visibleRowCount; |
685 |
visibleRowCount = rows; |
visibleRowCount = rows; |
686 |
|
firePropertyChange(VISIBLE_ROW_COUNT_PROPERTY, oldValue, rows); |
687 |
} |
} |
688 |
|
|
689 |
public boolean isLargeModel() |
public boolean isLargeModel() |
693 |
|
|
694 |
public void setLargeModel(boolean large) |
public void setLargeModel(boolean large) |
695 |
{ |
{ |
696 |
|
if (largeModel == large) |
697 |
|
return; |
698 |
|
|
699 |
|
boolean oldValue = largeModel; |
700 |
largeModel = large; |
largeModel = large; |
701 |
|
firePropertyChange(LARGE_MODEL_PROPERTY, oldValue, large); |
702 |
} |
} |
703 |
|
|
704 |
public int getRowHeight() |
public int getRowHeight() |
708 |
|
|
709 |
public void setRowHeight(int height) |
public void setRowHeight(int height) |
710 |
{ |
{ |
711 |
|
if (rowHeight == height) |
712 |
|
return; |
713 |
|
|
714 |
|
int oldValue = rowHeight; |
715 |
rowHeight = height; |
rowHeight = height; |
716 |
|
firePropertyChange(ROW_HEIGHT_PROPERTY, oldValue, height); |
717 |
|
} |
718 |
|
|
719 |
|
public boolean isFixedRowHeight() |
720 |
|
{ |
721 |
|
return rowHeight > 0; |
722 |
} |
} |
723 |
|
|
724 |
public boolean getInvokesStopCellEditing() |
public boolean getInvokesStopCellEditing() |
728 |
|
|
729 |
public void setInvokesStopCellEditing(boolean invoke) |
public void setInvokesStopCellEditing(boolean invoke) |
730 |
{ |
{ |
731 |
|
if (invokesStopCellEditing == invoke) |
732 |
|
return; |
733 |
|
|
734 |
|
boolean oldValue = invokesStopCellEditing; |
735 |
invokesStopCellEditing = invoke; |
invokesStopCellEditing = invoke; |
736 |
|
firePropertyChange(INVOKES_STOP_CELL_EDITING_PROPERTY, oldValue, invoke); |
737 |
} |
} |
738 |
|
|
739 |
/** |
/** |
749 |
*/ |
*/ |
750 |
public void setToggleClickCount(int count) |
public void setToggleClickCount(int count) |
751 |
{ |
{ |
752 |
|
if (toggleClickCount == count) |
753 |
|
return; |
754 |
|
|
755 |
|
int oldValue = toggleClickCount; |
756 |
toggleClickCount = count; |
toggleClickCount = count; |
757 |
|
firePropertyChange(TOGGLE_CLICK_COUNT_PROPERTY, oldValue, count); |
758 |
} |
} |
759 |
|
|
760 |
public boolean getScrollsOnExpand() |
public boolean getScrollsOnExpand() |
764 |
|
|
765 |
public void setScrollsOnExpand(boolean scroll) |
public void setScrollsOnExpand(boolean scroll) |
766 |
{ |
{ |
767 |
|
if (scrollsOnExpand == scroll) |
768 |
|
return; |
769 |
|
|
770 |
|
boolean oldValue = scrollsOnExpand; |
771 |
scrollsOnExpand = scroll; |
scrollsOnExpand = scroll; |
772 |
|
firePropertyChange(SCROLLS_ON_EXPAND_PROPERTY, oldValue, scroll); |
773 |
|
} |
774 |
|
|
775 |
|
public void setSelectionPath(TreePath path) |
776 |
|
{ |
777 |
|
selectionModel.setSelectionPath(path); |
778 |
|
} |
779 |
|
|
780 |
|
public void setSelectionPaths(TreePath[] paths) |
781 |
|
{ |
782 |
|
selectionModel.setSelectionPaths(paths); |
783 |
|
} |
784 |
|
|
785 |
|
public void setSelectionRow(int row) |
786 |
|
{ |
787 |
|
TreePath path = getPathForRow(row); |
788 |
|
|
789 |
|
if (path != null) |
790 |
|
selectionModel.setSelectionPath(path); |
791 |
|
} |
792 |
|
|
793 |
|
public void setSelectionRows(int[] rows) |
794 |
|
{ |
795 |
|
// Make sure we have an UI so getPathForRow() does not return null. |
796 |
|
if (rows == null || getUI() == null) |
797 |
|
return; |
798 |
|
|
799 |
|
TreePath[] paths = new TreePath[rows.length]; |
800 |
|
|
801 |
|
for (int i = rows.length - 1; i >= 0; --i) |
802 |
|
paths[i] = getPathForRow(rows[i]); |
803 |
|
|
804 |
|
setSelectionPaths(paths); |
805 |
|
} |
806 |
|
|
807 |
|
public void setSelectionInterval(int index0, int index1) |
808 |
|
{ |
809 |
|
TreePath[] paths = getPathBetweenRows(index0, index1); |
810 |
|
|
811 |
|
if (paths != null) |
812 |
|
setSelectionPaths(paths); |
813 |
|
} |
814 |
|
|
815 |
|
public void addSelectionPath(TreePath path) |
816 |
|
{ |
817 |
|
selectionModel.addSelectionPath(path); |
818 |
|
} |
819 |
|
|
820 |
|
public void addSelectionPaths(TreePath[] paths) |
821 |
|
{ |
822 |
|
selectionModel.addSelectionPaths(paths); |
823 |
|
} |
824 |
|
|
825 |
|
public void addSelectionRow(int row) |
826 |
|
{ |
827 |
|
TreePath path = getPathForRow(row); |
828 |
|
|
829 |
|
if (path != null) |
830 |
|
selectionModel.addSelectionPath(path); |
831 |
|
} |
832 |
|
|
833 |
|
public void addSelectionRows(int[] rows) |
834 |
|
{ |
835 |
|
// Make sure we have an UI so getPathForRow() does not return null. |
836 |
|
if (rows == null || getUI() == null) |
837 |
|
return; |
838 |
|
|
839 |
|
TreePath[] paths = new TreePath[rows.length]; |
840 |
|
|
841 |
|
for (int i = rows.length - 1; i >= 0; --i) |
842 |
|
paths[i] = getPathForRow(rows[i]); |
843 |
|
|
844 |
|
addSelectionPaths(paths); |
845 |
|
} |
846 |
|
|
847 |
|
public void addSelectionInterval(int index0, int index1) |
848 |
|
{ |
849 |
|
TreePath[] paths = getPathBetweenRows(index0, index1); |
850 |
|
|
851 |
|
if (paths != null) |
852 |
|
addSelectionPaths(paths); |
853 |
|
} |
854 |
|
|
855 |
|
public void removeSelectionPath(TreePath path) |
856 |
|
{ |
857 |
|
selectionModel.removeSelectionPath(path); |
858 |
|
} |
859 |
|
|
860 |
|
public void removeSelectionPaths(TreePath[] paths) |
861 |
|
{ |
862 |
|
selectionModel.removeSelectionPaths(paths); |
863 |
|
} |
864 |
|
|
865 |
|
public void removeSelectionRow(int row) |
866 |
|
{ |
867 |
|
TreePath path = getPathForRow(row); |
868 |
|
|
869 |
|
if (path != null) |
870 |
|
selectionModel.removeSelectionPath(path); |
871 |
|
} |
872 |
|
|
873 |
|
public void removeSelectionRows(int[] rows) |
874 |
|
{ |
875 |
|
// Make sure we have an UI so getPathForRow() does not return null. |
876 |
|
if (rows == null || getUI() == null) |
877 |
|
return; |
878 |
|
|
879 |
|
TreePath[] paths = new TreePath[rows.length]; |
880 |
|
|
881 |
|
for (int i = rows.length - 1; i >= 0; --i) |
882 |
|
paths[i] = getPathForRow(rows[i]); |
883 |
|
|
884 |
|
removeSelectionPaths(paths); |
885 |
|
} |
886 |
|
|
887 |
|
public void removeSelectionInterval(int index0, int index1) |
888 |
|
{ |
889 |
|
TreePath[] paths = getPathBetweenRows(index0, index1); |
890 |
|
|
891 |
|
if (paths != null) |
892 |
|
removeSelectionPaths(paths); |
893 |
|
} |
894 |
|
|
895 |
|
public void clearSelection() |
896 |
|
{ |
897 |
|
selectionModel.clearSelection(); |
898 |
|
} |
899 |
|
|
900 |
|
public TreePath getLeadSelectionPath() |
901 |
|
{ |
902 |
|
return leadSelectionPath; |
903 |
|
} |
904 |
|
|
905 |
|
/** |
906 |
|
* @since 1.3 |
907 |
|
*/ |
908 |
|
public void setLeadSelectionPath(TreePath path) |
909 |
|
{ |
910 |
|
if (leadSelectionPath == path) |
911 |
|
return; |
912 |
|
|
913 |
|
TreePath oldValue = leadSelectionPath; |
914 |
|
leadSelectionPath = path; |
915 |
|
firePropertyChange(LEAD_SELECTION_PATH_PROPERTY, oldValue, path); |
916 |
|
} |
917 |
|
|
918 |
|
/** |
919 |
|
* @since 1.3 |
920 |
|
*/ |
921 |
|
public TreePath getAnchorSelectionPath() |
922 |
|
{ |
923 |
|
return anchorSelectionPath; |
924 |
|
} |
925 |
|
|
926 |
|
/** |
927 |
|
* @since 1.3 |
928 |
|
*/ |
929 |
|
public void setAnchorSelectionPath(TreePath path) |
930 |
|
{ |
931 |
|
if (anchorSelectionPath == path) |
932 |
|
return; |
933 |
|
|
934 |
|
TreePath oldValue = anchorSelectionPath; |
935 |
|
anchorSelectionPath = path; |
936 |
|
firePropertyChange(ANCHOR_SELECTION_PATH_PROPERTY, oldValue, path); |
937 |
|
} |
938 |
|
|
939 |
|
public int getLeadSelectionRow() |
940 |
|
{ |
941 |
|
return selectionModel.getLeadSelectionRow(); |
942 |
|
} |
943 |
|
|
944 |
|
public int getMaxSelectionRow() |
945 |
|
{ |
946 |
|
return selectionModel.getMaxSelectionRow(); |
947 |
|
} |
948 |
|
|
949 |
|
public int getMinSelectionRow() |
950 |
|
{ |
951 |
|
return selectionModel.getMinSelectionRow(); |
952 |
|
} |
953 |
|
|
954 |
|
public int getSelectionCount() |
955 |
|
{ |
956 |
|
return selectionModel.getSelectionCount(); |
957 |
|
} |
958 |
|
|
959 |
|
public TreePath getSelectionPath() |
960 |
|
{ |
961 |
|
return selectionModel.getSelectionPath(); |
962 |
|
} |
963 |
|
|
964 |
|
public TreePath[] getSelectionPaths() |
965 |
|
{ |
966 |
|
return selectionModel.getSelectionPaths(); |
967 |
|
} |
968 |
|
|
969 |
|
public int[] getSelectionRows() |
970 |
|
{ |
971 |
|
return selectionModel.getSelectionRows(); |
972 |
|
} |
973 |
|
|
974 |
|
public boolean isPathSelected(TreePath path) |
975 |
|
{ |
976 |
|
return selectionModel.isPathSelected(path); |
977 |
|
} |
978 |
|
|
979 |
|
public boolean isRowSelected(int row) |
980 |
|
{ |
981 |
|
return selectionModel.isRowSelected(row); |
982 |
|
} |
983 |
|
|
984 |
|
public boolean isSelectionEmpty() |
985 |
|
{ |
986 |
|
return selectionModel.isSelectionEmpty(); |
987 |
|
} |
988 |
|
|
989 |
|
/** |
990 |
|
* Return the value of the <code>dragEnabled</code> property. |
991 |
|
* |
992 |
|
* @return the value |
993 |
|
* |
994 |
|
* @since 1.4 |
995 |
|
*/ |
996 |
|
public boolean getDragEnabled() |
997 |
|
{ |
998 |
|
return dragEnabled; |
999 |
|
} |
1000 |
|
|
1001 |
|
/** |
1002 |
|
* Set the <code>dragEnabled</code> property. |
1003 |
|
* |
1004 |
|
* @param enabled new value |
1005 |
|
* |
1006 |
|
* @since 1.4 |
1007 |
|
*/ |
1008 |
|
public void setDragEnabled(boolean enabled) |
1009 |
|
{ |
1010 |
|
dragEnabled = enabled; |
1011 |
|
} |
1012 |
|
|
1013 |
|
public int getRowCount() |
1014 |
|
{ |
1015 |
|
TreeUI ui = getUI(); |
1016 |
|
|
1017 |
|
if (ui != null) |
1018 |
|
return ui.getRowCount(this); |
1019 |
|
|
1020 |
|
return 0; |
1021 |
|
} |
1022 |
|
|
1023 |
|
/** |
1024 |
|
* @since 1.3 |
1025 |
|
*/ |
1026 |
|
public boolean getExpandsSelectedPaths() |
1027 |
|
{ |
1028 |
|
return expandsSelectedPaths; |
1029 |
|
} |
1030 |
|
|
1031 |
|
/** |
1032 |
|
* @since 1.3 |
1033 |
|
*/ |
1034 |
|
public void setExpandsSelectedPaths(boolean flag) |
1035 |
|
{ |
1036 |
|
if (expandsSelectedPaths == flag) |
1037 |
|
return; |
1038 |
|
|
1039 |
|
boolean oldValue = expandsSelectedPaths; |
1040 |
|
expandsSelectedPaths = flag; |
1041 |
|
firePropertyChange(EXPANDS_SELECTED_PATHS_PROPERTY, oldValue, flag); |
1042 |
|
} |
1043 |
|
|
1044 |
|
public Rectangle getPathBounds(TreePath path) |
1045 |
|
{ |
1046 |
|
TreeUI ui = getUI(); |
1047 |
|
|
1048 |
|
if (ui == null) |
1049 |
|
return null; |
1050 |
|
|
1051 |
|
return ui.getPathBounds(this, path); |
1052 |
|
} |
1053 |
|
|
1054 |
|
public Rectangle getRowBounds(int row) |
1055 |
|
{ |
1056 |
|
TreePath path = getPathForRow(row); |
1057 |
|
|
1058 |
|
if (path != null) |
1059 |
|
return getPathBounds(path); |
1060 |
|
|
1061 |
|
return null; |
1062 |
|
} |
1063 |
|
|
1064 |
|
public boolean isEditing() |
1065 |
|
{ |
1066 |
|
TreeUI ui = getUI(); |
1067 |
|
|
1068 |
|
if (ui != null) |
1069 |
|
return ui.isEditing(this); |
1070 |
|
|
1071 |
|
return false; |
1072 |
|
} |
1073 |
|
|
1074 |
|
public boolean stopEditing() |
1075 |
|
{ |
1076 |
|
TreeUI ui = getUI(); |
1077 |
|
|
1078 |
|
if (ui != null) |
1079 |
|
return ui.stopEditing(this); |
1080 |
|
|
1081 |
|
return false; |
1082 |
|
} |
1083 |
|
|
1084 |
|
public void cancelEditing() |
1085 |
|
{ |
1086 |
|
TreeUI ui = getUI(); |
1087 |
|
|
1088 |
|
if (ui != null) |
1089 |
|
ui.cancelEditing(this); |
1090 |
|
} |
1091 |
|
|
1092 |
|
public void startEditingAtPath(TreePath path) |
1093 |
|
{ |
1094 |
|
TreeUI ui = getUI(); |
1095 |
|
|
1096 |
|
if (ui != null) |
1097 |
|
ui.startEditingAtPath(this, path); |
1098 |
|
} |
1099 |
|
|
1100 |
|
public TreePath getEditingPath() |
1101 |
|
{ |
1102 |
|
TreeUI ui = getUI(); |
1103 |
|
|
1104 |
|
if (ui != null) |
1105 |
|
return ui.getEditingPath(this); |
1106 |
|
|
1107 |
|
return null; |
1108 |
|
} |
1109 |
|
|
1110 |
|
public TreePath getPathForLocation(int x, int y) |
1111 |
|
{ |
1112 |
|
TreePath path = getClosestPathForLocation(x, y); |
1113 |
|
|
1114 |
|
if (path != null) |
1115 |
|
{ |
1116 |
|
Rectangle rect = getPathBounds(path); |
1117 |
|
|
1118 |
|
if ((rect != null) && rect.contains(x, y)) |
1119 |
|
return path; |
1120 |
|
} |
1121 |
|
|
1122 |
|
return null; |
1123 |
|
} |
1124 |
|
|
1125 |
|
public int getRowForLocation(int x, int y) |
1126 |
|
{ |
1127 |
|
TreePath path = getPathForLocation(x, y); |
1128 |
|
|
1129 |
|
if (path != null) |
1130 |
|
return getRowForPath(path); |
1131 |
|
|
1132 |
|
return -1; |
1133 |
|
} |
1134 |
|
|
1135 |
|
public TreePath getClosestPathForLocation(int x, int y) |
1136 |
|
{ |
1137 |
|
TreeUI ui = getUI(); |
1138 |
|
|
1139 |
|
if (ui != null) |
1140 |
|
return ui.getClosestPathForLocation(this, x, y); |
1141 |
|
|
1142 |
|
return null; |
1143 |
|
} |
1144 |
|
|
1145 |
|
public int getClosestRowForLocation(int x, int y) |
1146 |
|
{ |
1147 |
|
TreePath path = getClosestPathForLocation(x, y); |
1148 |
|
|
1149 |
|
if (path != null) |
1150 |
|
return getRowForPath(path); |
1151 |
|
|
1152 |
|
return -1; |
1153 |
|
} |
1154 |
|
|
1155 |
|
public Object getLastSelectedPathComponent() |
1156 |
|
{ |
1157 |
|
TreePath path = getSelectionPath(); |
1158 |
|
|
1159 |
|
if (path != null) |
1160 |
|
return path.getLastPathComponent(); |
1161 |
|
|
1162 |
|
return null; |
1163 |
} |
} |
1164 |
} |
} |