.. | .. |
---|
1 | 1 | |
---|
2 | 2 | import java.io.*; |
---|
| 3 | +import javax.swing.Icon; |
---|
3 | 4 | import javax.swing.event.*; |
---|
4 | 5 | import javax.swing.tree.*; |
---|
5 | 6 | |
---|
6 | 7 | class cFileSystemModel implements TreeModel |
---|
7 | 8 | { |
---|
| 9 | + |
---|
8 | 10 | File root; |
---|
9 | 11 | cFilter filter; |
---|
10 | 12 | |
---|
.. | .. |
---|
23 | 25 | { |
---|
24 | 26 | } |
---|
25 | 27 | |
---|
26 | | - public Object getChild(Object parent, int index) |
---|
| 28 | + public Object getChild(Object parent, int index) |
---|
27 | 29 | { |
---|
28 | 30 | //new Exception().printStackTrace(); |
---|
29 | | - |
---|
| 31 | + |
---|
30 | 32 | //System.out.println("child[" + index + "] = " + ((File) parent).listFiles(filter)[index]); |
---|
31 | | - |
---|
| 33 | + |
---|
32 | 34 | File[] files = table.get(parent); |
---|
33 | | - assert(files != null); |
---|
| 35 | + assert (files != null); |
---|
34 | 36 | //return ((File) parent).listFiles(filter)[index]; |
---|
35 | 37 | return files[index]; |
---|
36 | | - |
---|
37 | | - } |
---|
38 | 38 | |
---|
| 39 | + } |
---|
39 | 40 | java.util.Hashtable<File, File[]> table = new java.util.Hashtable<File, File[]>(); |
---|
40 | | - |
---|
41 | | - public int getChildCount(Object parent) |
---|
| 41 | + |
---|
| 42 | + public int getChildCount(Object parent) |
---|
42 | 43 | { |
---|
43 | | - if( isLeaf(parent) ) |
---|
| 44 | + if (isLeaf(parent)) |
---|
| 45 | + { |
---|
44 | 46 | return 0; |
---|
45 | | - else |
---|
| 47 | + } else |
---|
46 | 48 | { |
---|
47 | 49 | //System.out.println(parent + " childcount = " + ((File) parent).listFiles(filter).length); |
---|
48 | 50 | File[] files = table.get(parent); |
---|
49 | | - |
---|
50 | | - if(files == null) |
---|
| 51 | + |
---|
| 52 | + if (files == null) |
---|
51 | 53 | { |
---|
52 | 54 | files = ((File) parent).listFiles(filter); |
---|
53 | 55 | table.put(((File) parent), files); |
---|
54 | 56 | } |
---|
55 | | - |
---|
| 57 | + |
---|
56 | 58 | return files.length; |
---|
57 | 59 | } |
---|
58 | 60 | } |
---|
59 | 61 | |
---|
60 | | - public int getIndexOfChild(Object parent, Object child) |
---|
| 62 | + public int getIndexOfChild(Object parent, Object child) |
---|
61 | 63 | { |
---|
62 | 64 | assert false; |
---|
63 | 65 | return 0; |
---|
64 | 66 | } |
---|
65 | 67 | |
---|
66 | | - public Object getRoot() |
---|
| 68 | + public Object getRoot() |
---|
67 | 69 | { |
---|
68 | 70 | return root; |
---|
69 | 71 | } |
---|
70 | 72 | |
---|
71 | | - public boolean isLeaf(Object node) |
---|
| 73 | + public boolean isLeaf(Object node) |
---|
72 | 74 | { |
---|
73 | 75 | return !((File) node).isDirectory(); |
---|
74 | 76 | } |
---|
75 | 77 | |
---|
76 | | - public void removeTreeModelListener(TreeModelListener l) |
---|
| 78 | + public void removeTreeModelListener(TreeModelListener l) |
---|
77 | 79 | { |
---|
78 | 80 | } |
---|
79 | 81 | |
---|
80 | | - public void valueForPathChanged(TreePath path, Object newValue) |
---|
| 82 | + public void valueForPathChanged(TreePath path, Object newValue) |
---|
81 | 83 | { |
---|
82 | 84 | } |
---|
83 | 85 | |
---|
| 86 | + static java.util.Hashtable<String, javax.swing.ImageIcon> icons = new java.util.Hashtable<String, javax.swing.ImageIcon>(); |
---|
| 87 | + |
---|
| 88 | + |
---|
84 | 89 | static class Renderer extends DefaultTreeCellRenderer |
---|
85 | 90 | { |
---|
86 | | - public Renderer() { |
---|
| 91 | + |
---|
| 92 | + public Renderer() |
---|
| 93 | + { |
---|
87 | 94 | } |
---|
88 | 95 | |
---|
89 | 96 | public java.awt.Component getTreeCellRendererComponent( |
---|
90 | | - cTree tree, |
---|
91 | | - Object value, |
---|
92 | | - boolean sel, |
---|
93 | | - boolean expanded, |
---|
94 | | - boolean leaf, |
---|
95 | | - int row, |
---|
96 | | - boolean hasFocus) |
---|
| 97 | + //cTree tree, |
---|
| 98 | + javax.swing.JTree tree, |
---|
| 99 | + Object value, |
---|
| 100 | + boolean sel, |
---|
| 101 | + boolean expanded, |
---|
| 102 | + boolean leaf, |
---|
| 103 | + int row, |
---|
| 104 | + boolean hasFocus) |
---|
97 | 105 | { |
---|
98 | | - System.out.println(value); |
---|
| 106 | + //System.out.println(value); |
---|
99 | 107 | super.getTreeCellRendererComponent( |
---|
100 | | - tree, value, sel, |
---|
101 | | - expanded, leaf, row, |
---|
102 | | - hasFocus); |
---|
| 108 | + tree, value, sel, |
---|
| 109 | + expanded, leaf, row, |
---|
| 110 | + hasFocus); |
---|
| 111 | + |
---|
| 112 | + String valueString = value.toString(); |
---|
| 113 | + String lcString = valueString.toLowerCase(); |
---|
| 114 | + |
---|
| 115 | + if (lcString.endsWith(".gfd") || lcString.endsWith(".obj") || lcString.endsWith(".3ds")) |
---|
| 116 | + { |
---|
| 117 | + if (true) |
---|
| 118 | + { |
---|
| 119 | + // Small icons |
---|
| 120 | + String valueTruncated = valueString.substring(0, valueString.length()-4); |
---|
| 121 | + |
---|
| 122 | + //System.out.println("valueTruncated = " + valueTruncated); |
---|
| 123 | + |
---|
| 124 | + javax.swing.ImageIcon rendererIcon = icons.get(valueTruncated); |
---|
| 125 | + |
---|
| 126 | + if (rendererIcon == null) |
---|
| 127 | + { |
---|
| 128 | + if (new File(valueTruncated + ".jpg").exists()) |
---|
| 129 | + { |
---|
| 130 | + rendererIcon = new javax.swing.ImageIcon(valueTruncated + ".jpg"); |
---|
| 131 | + } |
---|
| 132 | + else |
---|
| 133 | + { |
---|
| 134 | + if (new File(valueTruncated + ".png").exists()) |
---|
| 135 | + { |
---|
| 136 | + rendererIcon = new javax.swing.ImageIcon(valueTruncated + ".png"); |
---|
| 137 | + } |
---|
| 138 | + } |
---|
| 139 | + |
---|
| 140 | + if (rendererIcon == null) |
---|
| 141 | + { |
---|
| 142 | + rendererIcon = ObjEditor.GetIcon("icons/primitives.png"); |
---|
| 143 | + } |
---|
| 144 | + |
---|
| 145 | + icons.put(valueTruncated, rendererIcon); |
---|
| 146 | + } |
---|
| 147 | + |
---|
| 148 | + setIcon(rendererIcon); |
---|
| 149 | + } |
---|
| 150 | + else |
---|
| 151 | + { |
---|
| 152 | + // Large icons |
---|
| 153 | + String[] split = valueString.split("/"); |
---|
| 154 | + |
---|
| 155 | + String valueTruncated = ""; |
---|
| 156 | + |
---|
| 157 | + for (int i=1; i<split.length-1; i++) |
---|
| 158 | + { |
---|
| 159 | + valueTruncated += "/" + split[i]; |
---|
| 160 | + } |
---|
| 161 | + |
---|
| 162 | + valueTruncated += "/icon.jpg"; |
---|
| 163 | + |
---|
| 164 | + System.out.println(valueTruncated); |
---|
| 165 | + |
---|
| 166 | + javax.swing.ImageIcon rendererIcon = icons.get(valueTruncated); |
---|
| 167 | + |
---|
| 168 | + if (rendererIcon == null) |
---|
| 169 | + { |
---|
| 170 | + if (new File(valueTruncated).exists()) |
---|
| 171 | + { |
---|
| 172 | + rendererIcon = new javax.swing.ImageIcon(valueTruncated); |
---|
| 173 | + } |
---|
| 174 | + |
---|
| 175 | + if (rendererIcon == null) |
---|
| 176 | + { |
---|
| 177 | + rendererIcon = new javax.swing.ImageIcon(); |
---|
| 178 | + } |
---|
| 179 | + |
---|
| 180 | + icons.put(valueTruncated, rendererIcon); |
---|
| 181 | + } |
---|
| 182 | + |
---|
| 183 | + setIcon(rendererIcon); |
---|
| 184 | + } |
---|
| 185 | + } |
---|
| 186 | + else |
---|
| 187 | + { |
---|
| 188 | + //setIcon(null); |
---|
| 189 | +// Icon systemIcon = javax.swing.filechooser.FileSystemView.getFileSystemView().getSystemIcon( new File(valueString) ); |
---|
| 190 | +// setIcon(systemIcon); |
---|
| 191 | + } |
---|
| 192 | + |
---|
103 | 193 | setToolTipText("This book is in the Tutorial series."); |
---|
104 | 194 | |
---|
105 | 195 | return this; |
---|
106 | 196 | } |
---|
107 | | - |
---|
| 197 | + |
---|
108 | 198 | public void setText(String text) |
---|
109 | 199 | { |
---|
110 | 200 | //System.out.println(text); |
---|