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