Normand Briere
2019-07-01 9079880942d022ee32fd3a543843e132e52deb1a
Tree icons.
1 files deleted
5 files modified
1 files added
966 ■■■■■ changed files
CameraPane.java 128 ●●●●● patch | view | raw | blame | history
GroupEditor.java 3 ●●●●● patch | view | raw | blame | history
ObjEditor.java 30 ●●●●● patch | view | raw | blame | history
cFileSystemModel.java 112 ●●●● patch | view | raw | blame | history
cTools.java 214 ●●●●● patch | view | raw | blame | history
cTreeDirectoryModel.java 352 ●●●●● patch | view | raw | blame | history
cTreeModel.java 127 ●●●● patch | view | raw | blame | history
CameraPane.java
....@@ -2398,128 +2398,6 @@
23982398 return currentGL;
23992399 }
24002400
2401
- private void GetRemoteZip(String url, String name, boolean unzip, boolean save)
2402
- {
2403
- java.net.URL u;
2404
- InputStream is = null;
2405
- DataInputStream dis;
2406
- java.util.zip.ZipInputStream zis;
2407
- //String s;
2408
-
2409
- System.out.println("GetRemoteZip " + name);
2410
-
2411
- int total = 0; // dis.available();
2412
-
2413
- byte[] bytes = new byte[16384];
2414
-
2415
- try
2416
- {
2417
- u = new java.net.URL(url + name);
2418
- is = u.openStream();
2419
-
2420
- System.out.println(url + name);
2421
-
2422
- if (unzip)
2423
- {
2424
- //dis = new DataInputStream(new BufferedInputStream(is));
2425
- zis = new java.util.zip.ZipInputStream(new BufferedInputStream(is));
2426
- //while ((s = dis.readLine()) != null)
2427
-
2428
- if (save)
2429
- new java.io.File(name).mkdirs();
2430
-
2431
- // FileOutputStream stream = new FileOutputStream("test.zip");
2432
- //
2433
- // int count;
2434
- //
2435
- // while ((count = dis.read(bytes)) != -1)
2436
- // {
2437
- // //System.out.println(s);
2438
- // System.out.println(count);
2439
- // total += count;
2440
- // stream.write(bytes);
2441
- // }
2442
- //
2443
- // stream.close();
2444
-
2445
- // now iterate through each item in the stream. The get next
2446
- // entry call will return a ZipEntry for each file in the
2447
- // stream
2448
- java.util.zip.ZipEntry entry;
2449
- while((entry = zis.getNextEntry())!=null)
2450
- {
2451
- if (entry.getName().endsWith(".gsm"))
2452
- {
2453
- continue;
2454
- }
2455
-
2456
- String s = String.format("Entry: %s len %d added %TD",
2457
- entry.getName(), entry.getSize(),
2458
- new java.util.Date(entry.getTime()));
2459
- System.out.println(s);
2460
-
2461
- if (save)
2462
- {
2463
- // Once we get the entry from the stream, the stream is
2464
- // positioned read to read the raw data, and we keep
2465
- // reading until read returns 0 or less.
2466
- String outpath = name + "/" + entry.getName();
2467
- FileOutputStream output = null;
2468
- try
2469
- {
2470
- output = new FileOutputStream(outpath);
2471
- int len = 0;
2472
- while ((len = zis.read(bytes)) > 0)
2473
- {
2474
- output.write(bytes, 0, len);
2475
- }
2476
- }
2477
- finally
2478
- {
2479
- // we must always close the output file
2480
- if(output!=null) output.close();
2481
- }
2482
- }
2483
- }
2484
- }
2485
- }
2486
- catch (java.net.MalformedURLException mue)
2487
- {
2488
- System.err.println("Ouch - a MalformedURLException happened.");
2489
- mue.printStackTrace();
2490
- //System.exit(2);
2491
- }
2492
- catch (IOException ioe)
2493
- {
2494
- //System.err.println("Oops - an IOException happened.");
2495
- //ioe.printStackTrace();
2496
- //System.exit(3);
2497
- }
2498
- finally
2499
- {
2500
- try
2501
- {
2502
- if (is != null)
2503
- is.close();
2504
- }
2505
- catch (IOException ioe)
2506
- {
2507
- }
2508
- }
2509
-
2510
- // System.out.println("length = " + total);
2511
-
2512
-// try
2513
-// {
2514
-// Runtime.getRuntime().exec("/usr/local/bin/wget https://archive3d.net/?a=download&do=get&id=7caca905");
2515
-// }
2516
-// catch (Exception e)
2517
-// {
2518
-// e.printStackTrace();
2519
-// }
2520
-
2521
- }
2522
-
25232401 /**/
25242402 class CacheTexture
25252403 {
....@@ -15295,12 +15173,6 @@
1529515173 break;
1529615174 case '+':
1529715175
15298
- //for (int i=0; i<0x7FFFFFFF; i++)
15299
- {
15300
- //String.format("%08X", i); // "7caca905"
15301
- GetRemoteZip("https://archive3d.net/?a=download&do=get&id=", "7caca905", true, true);
15302
- }
15303
-
1530415176 /*
1530515177 //fontsize += 1;
1530615178 bbzoom *= 2;
GroupEditor.java
....@@ -1472,6 +1472,9 @@
14721472 animationItem.addItemListener(this);
14731473 animationItem.setState(Globals.ANIMATION);
14741474
1475
+ menu.add(archiveItem = new CheckboxMenuItem("Archive3D..."));
1476
+ archiveItem.addItemListener(this);
1477
+
14751478 menu.add("-");
14761479 parseverticesItem = menu.add(new MenuItem("Multiplicity"));
14771480 parseverticesItem.addActionListener(this);
ObjEditor.java
....@@ -350,7 +350,7 @@
350350 frame.setMenuBar(menuBar = new MenuBar());
351351 menuBar.add(fileMenu = new Menu("File"));
352352 fileMenu.add(newItem = new MenuItem("New"));
353
- fileMenu.add(loadItem = new MenuItem("Open..."));
353
+ fileMenu.add(openItem = new MenuItem("Open..."));
354354
355355 //oe.menuBar.add(menu = new Menu("Include"));
356356 Menu menu = new Menu("Import");
....@@ -382,7 +382,7 @@
382382 }
383383
384384 newItem.addActionListener(this);
385
- loadItem.addActionListener(this);
385
+ openItem.addActionListener(this);
386386 saveItem.addActionListener(this);
387387 saveAsItem.addActionListener(this);
388388 exportAsItem.addActionListener(this);
....@@ -780,7 +780,7 @@
780780 // X frame.getContentPane().remove(/*"Center",*/bigThree);
781781 // X framePanel.add(bigThree);
782782 // X frame.getContentPane().add(/*"Center",*/framePanel);
783
- framePanel.setDividerLocation(1);
783
+ framePanel.setDividerLocation(46);
784784
785785 //frame.setVisible(true);
786786 radio.layout = keepButton;
....@@ -1493,7 +1493,10 @@
14931493 // north.add(ctrlPanel, BorderLayout.NORTH);
14941494 // objectPanel.add(north);
14951495 objectPanel.add(editPanel);
1496
- objectPanel.add(infoPanel);
1496
+
1497
+ if (Globals.ADVANCED)
1498
+ objectPanel.add(infoPanel);
1499
+
14971500 objectPanel.add(toolboxPanel);
14981501
14991502 /*
....@@ -1602,9 +1605,9 @@
16021605 // aConstraints.gridheight = 1;
16031606
16041607 framePanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, toolbarPanel, bigThree);
1605
- framePanel.setContinuousLayout(true);
1606
- framePanel.setOneTouchExpandable(true);
1607
- framePanel.setDividerLocation(0.8);
1608
+ framePanel.setContinuousLayout(false);
1609
+ framePanel.setOneTouchExpandable(false);
1610
+ //.setDividerLocation(0.8);
16081611 //framePanel.setDividerSize(15);
16091612 //framePanel.setResizeWeight(0.15);
16101613 framePanel.setName("Frame");
....@@ -3198,6 +3201,10 @@
31983201 {
31993202 ToggleAnimation();
32003203 return;
3204
+ } else if (event.getSource() == archiveItem)
3205
+ {
3206
+ cTools.Archive(frame);
3207
+ return;
32013208 } else if (event.getSource() == flipVCB)
32023209 {
32033210 copy.flipV ^= true;
....@@ -3391,9 +3398,9 @@
33913398 {
33923399 Close();
33933400 //return true;
3394
- } else if (source == loadItem)
3401
+ } else if (source == openItem)
33953402 {
3396
- load();
3403
+ Open();
33973404 //return true;
33983405 } else if (source == newItem)
33993406 {
....@@ -4720,7 +4727,7 @@
47204727 }
47214728 }
47224729
4723
- void load() // throws ClassNotFoundException
4730
+ void Open() // throws ClassNotFoundException
47244731 {
47254732 if (Grafreed.standAlone)
47264733 {
....@@ -5005,7 +5012,7 @@
50055012 MenuBar menuBar;
50065013 Menu fileMenu;
50075014 MenuItem newItem;
5008
- MenuItem loadItem;
5015
+ MenuItem openItem;
50095016 MenuItem saveItem;
50105017 MenuItem saveAsItem;
50115018 MenuItem exportAsItem;
....@@ -5028,6 +5035,7 @@
50285035 CheckboxMenuItem toggleSwitchItem;
50295036 CheckboxMenuItem toggleRootItem;
50305037 CheckboxMenuItem animationItem;
5038
+ CheckboxMenuItem archiveItem;
50315039 CheckboxMenuItem toggleHandleItem;
50325040 CheckboxMenuItem togglePaintItem;
50335041 JSplitPane mainPanel;
cFileSystemModel.java
....@@ -1,10 +1,12 @@
11
22 import java.io.*;
3
+import javax.swing.Icon;
34 import javax.swing.event.*;
45 import javax.swing.tree.*;
56
67 class cFileSystemModel implements TreeModel
78 {
9
+
810 File root;
911 cFilter filter;
1012
....@@ -23,88 +25,136 @@
2325 {
2426 }
2527
26
- public Object getChild(Object parent, int index)
28
+ public Object getChild(Object parent, int index)
2729 {
2830 //new Exception().printStackTrace();
29
-
31
+
3032 //System.out.println("child[" + index + "] = " + ((File) parent).listFiles(filter)[index]);
31
-
33
+
3234 File[] files = table.get(parent);
33
- assert(files != null);
35
+ assert (files != null);
3436 //return ((File) parent).listFiles(filter)[index];
3537 return files[index];
36
-
37
- }
3838
39
+ }
3940 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)
4243 {
43
- if( isLeaf(parent) )
44
+ if (isLeaf(parent))
45
+ {
4446 return 0;
45
- else
47
+ } else
4648 {
4749 //System.out.println(parent + " childcount = " + ((File) parent).listFiles(filter).length);
4850 File[] files = table.get(parent);
49
-
50
- if(files == null)
51
+
52
+ if (files == null)
5153 {
5254 files = ((File) parent).listFiles(filter);
5355 table.put(((File) parent), files);
5456 }
55
-
57
+
5658 return files.length;
5759 }
5860 }
5961
60
- public int getIndexOfChild(Object parent, Object child)
62
+ public int getIndexOfChild(Object parent, Object child)
6163 {
6264 assert false;
6365 return 0;
6466 }
6567
66
- public Object getRoot()
68
+ public Object getRoot()
6769 {
6870 return root;
6971 }
7072
71
- public boolean isLeaf(Object node)
73
+ public boolean isLeaf(Object node)
7274 {
7375 return !((File) node).isDirectory();
7476 }
7577
76
- public void removeTreeModelListener(TreeModelListener l)
78
+ public void removeTreeModelListener(TreeModelListener l)
7779 {
7880 }
7981
80
- public void valueForPathChanged(TreePath path, Object newValue)
82
+ public void valueForPathChanged(TreePath path, Object newValue)
8183 {
8284 }
8385
86
+ static java.util.Hashtable<String, javax.swing.ImageIcon> icons = new java.util.Hashtable<String, javax.swing.ImageIcon>();
87
+
88
+
8489 static class Renderer extends DefaultTreeCellRenderer
8590 {
86
- public Renderer() {
91
+
92
+ public Renderer()
93
+ {
8794 }
8895
8996 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)
97105 {
98
- System.out.println(value);
106
+ //System.out.println(value);
99107 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
+
114
+ if (valueString.toLowerCase().endsWith(".gfd") || valueString.toLowerCase().endsWith(".obj") || valueString.toLowerCase().endsWith(".3ds"))
115
+ {
116
+ String valueTruncated = valueString.substring(0, valueString.length()-4);
117
+
118
+ System.out.println(valueTruncated);
119
+
120
+ javax.swing.ImageIcon rendererIcon = icons.get(valueTruncated);
121
+
122
+ if (rendererIcon == null)
123
+ {
124
+ if (new File(valueTruncated + ".jpg").exists())
125
+ {
126
+ rendererIcon = new javax.swing.ImageIcon(valueTruncated + ".jpg");
127
+ }
128
+ else
129
+ {
130
+ if (new File(valueTruncated + ".png").exists())
131
+ {
132
+ rendererIcon = new javax.swing.ImageIcon(valueTruncated + ".png");
133
+ }
134
+ }
135
+
136
+ if (rendererIcon == null)
137
+ {
138
+ rendererIcon = new javax.swing.ImageIcon();
139
+ }
140
+
141
+ icons.put(valueTruncated, rendererIcon);
142
+ }
143
+
144
+ setIcon(rendererIcon);
145
+ }
146
+ else
147
+ {
148
+ //setIcon(null);
149
+// Icon systemIcon = javax.swing.filechooser.FileSystemView.getFileSystemView().getSystemIcon( new File(valueString) );
150
+// setIcon(systemIcon);
151
+ }
152
+
103153 setToolTipText("This book is in the Tutorial series.");
104154
105155 return this;
106156 }
107
-
157
+
108158 public void setText(String text)
109159 {
110160 //System.out.println(text);
cTools.java
....@@ -0,0 +1,214 @@
1
+
2
+import java.io.*;
3
+import java.awt.*;
4
+import java.util.zip.ZipInputStream;
5
+
6
+public class cTools
7
+{
8
+ static byte[] bytes = new byte[16384];
9
+
10
+ static private void GetRemoteZip(String url, String dir, String id, String name, String icon)
11
+ {
12
+ String filename = name + "_" + id;
13
+
14
+ String location = dir + "/" + filename;
15
+
16
+ java.net.URL u;
17
+ InputStream is = null;
18
+
19
+ java.util.zip.ZipInputStream zis;
20
+
21
+ String modelName = null;
22
+
23
+ try
24
+ {
25
+ u = new java.net.URL(url + id);
26
+ is = u.openStream();
27
+
28
+ zis = new java.util.zip.ZipInputStream(is);
29
+
30
+ new java.io.File(location).mkdirs();
31
+
32
+ // now iterate through each item in the stream. The get next
33
+ // entry call will return a ZipEntry for each file in the stream
34
+ java.util.zip.ZipEntry entry;
35
+ while ((entry = zis.getNextEntry()) != null)
36
+ {
37
+ String entryName = entry.getName().toLowerCase();
38
+
39
+ if (entryName.endsWith(".gsm"))
40
+ {
41
+ // ArchiCAD
42
+ // continue;
43
+ }
44
+
45
+ if (entryName.endsWith(".max"))
46
+ {
47
+ // 3DS MAX
48
+ // continue;
49
+ }
50
+
51
+ if (entryName.endsWith(".3ds") || entryName.endsWith(".obj"))
52
+ {
53
+ modelName = entry.getName();
54
+ }
55
+
56
+ String s = String.format("Entry: %s len %d added %TD",
57
+ entry.getName(), entry.getSize(),
58
+ new java.util.Date(entry.getTime()));
59
+ System.out.println(s);
60
+
61
+ // Once we get the entry from the stream, the stream is
62
+ // positioned read to read the raw data, and we keep
63
+ // reading until read returns 0 or less.
64
+ String outpath = location + "/" + entry.getName();
65
+
66
+ TransferFile(outpath, zis);
67
+ }
68
+ } catch (java.net.MalformedURLException mue)
69
+ {
70
+ System.err.println("Ouch - a MalformedURLException happened.");
71
+ mue.printStackTrace();
72
+ //System.exit(2);
73
+ } catch (IOException ioe)
74
+ {
75
+ //System.err.println("Oops - an IOException happened.");
76
+ //ioe.printStackTrace();
77
+ //System.exit(3);
78
+ } finally
79
+ {
80
+ try
81
+ {
82
+ if (is != null)
83
+ {
84
+ is.close();
85
+ }
86
+ } catch (IOException ioe)
87
+ {
88
+ }
89
+ }
90
+
91
+ // System.out.println("length = " + total);
92
+
93
+// try
94
+// {
95
+// Runtime.getRuntime().exec("/usr/local/bin/wget https://archive3d.net/?a=download&do=get&id=7caca905");
96
+// }
97
+// catch (Exception e)
98
+// {
99
+// e.printStackTrace();
100
+// }
101
+ java.awt.image.BufferedImage image;
102
+
103
+ try
104
+ {
105
+ u = new java.net.URL(icon);
106
+ is = u.openStream();
107
+
108
+// image = (java.awt.image.BufferedImage)javax.imageio.ImageIO.read(u);
109
+//
110
+// //String[] g = javax.imageio.ImageIO.getWriterFormatNames();
111
+//
112
+// javax.imageio.ImageIO.write(image, "jpg", new File(location + "/" + name + id + ".jpg"));
113
+
114
+ modelName = modelName.substring(0, modelName.length() - 4);
115
+
116
+ TransferFile(location + "/" + modelName + ".jpg", is);
117
+ }
118
+ catch (Exception e)
119
+ {
120
+ e.printStackTrace();
121
+ }
122
+ }
123
+
124
+ static private void TransferFile(String outpath, InputStream zis) throws IOException
125
+ {
126
+ FileOutputStream output = null;
127
+ try
128
+ {
129
+ output = new FileOutputStream(outpath);
130
+ int len = 0;
131
+ while ((len = zis.read(bytes)) > 0)
132
+ {
133
+ output.write(bytes, 0, len);
134
+ }
135
+ } finally
136
+ {
137
+ // we must always close the output file
138
+ if (output != null)
139
+ {
140
+ output.close();
141
+ }
142
+ }
143
+ }
144
+
145
+ static void Archive(javax.swing.JFrame frame)
146
+ {
147
+ FileDialog browser = new FileDialog(frame, "Select archive to extract...", FileDialog.LOAD);
148
+ browser.setVisible(true);
149
+ String filename = browser.getFile();
150
+ if (filename != null && filename.length() > 0)
151
+ {
152
+ try
153
+ {
154
+ RandomAccessFile file = new RandomAccessFile(browser.getDirectory() + filename, "r");
155
+ String str;
156
+ while ((str = file.readLine()) != null)
157
+ {
158
+ System.out.println(str);
159
+
160
+ String cat = "nocat";
161
+
162
+ String[] split = str.split("category=");
163
+
164
+ if (split.length > 1)
165
+ {
166
+ String[] split2 = split[1].split(":");
167
+
168
+ cat = split2[0];
169
+
170
+ String[] split3 = cat.split("&");
171
+
172
+ cat = split3[0];
173
+
174
+ ////
175
+ str = split2[1];
176
+
177
+ int i = 2;
178
+ while (i < split2.length)
179
+ {
180
+ str += ":" + split2[i++];
181
+ }
182
+ }
183
+
184
+ split = str.split("id=");
185
+
186
+ str = split[1];
187
+ split = str.split("\" title=\"Download ");
188
+
189
+ String id = split[0];
190
+
191
+ str = split[1];
192
+ split = str.split(" 3D Model\"><img src=\"");
193
+
194
+ String name = split[0];
195
+
196
+ str = split[1];
197
+ split = str.split("\" alt");
198
+
199
+ String icon = split[0];
200
+
201
+ GetRemoteZip("https://archive3d.net/?a=download&do=get&id=", browser.getDirectory() + "/" + cat, id, name, icon);
202
+
203
+ // To avoid network overload.
204
+ Thread.sleep(2000);
205
+ }
206
+
207
+ file.close();
208
+ } catch (Exception e)
209
+ {
210
+ e.printStackTrace();
211
+ }
212
+ }
213
+ }
214
+}
cTreeDirectoryModel.java
deleted file mode 100644
....@@ -1,352 +0,0 @@
1
-/*
2
- * @(#)BasicDirectoryModel.java 1.31 04/05/05
3
- *
4
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5
- * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6
- */
7
-
8
-//package javax.swing.plaf.basic;
9
-
10
-import java.io.File;
11
-import java.util.*;
12
-import javax.swing.*;
13
-import javax.swing.tree.*;
14
-import javax.swing.filechooser.*;
15
-import javax.swing.event.*;
16
-import java.beans.*;
17
-
18
-import sun.awt.shell.ShellFolder;
19
-
20
-/**
21
- * Basic implementation of a file list.
22
- *
23
- * @version %i% %g%
24
- * @author Jeff Dinkins
25
- */
26
-public class cTreeDirectoryModel extends DefaultTreeModel implements PropertyChangeListener {
27
-
28
- private JFileChooser filechooser = null;
29
- // PENDING(jeff) pick the size more sensibly
30
- private Vector fileCache = new Vector(50);
31
- private LoadFilesThread loadThread = null;
32
- private Vector files = null;
33
- private Vector directories = null;
34
- private int fetchID = 0;
35
-
36
- public cTreeDirectoryModel(JFileChooser filechooser) {
37
- super(null);
38
- this.filechooser = filechooser;
39
- validateFileCache();
40
- }
41
-
42
- public void propertyChange(PropertyChangeEvent e) {
43
- String prop = e.getPropertyName();
44
- if(prop == JFileChooser.DIRECTORY_CHANGED_PROPERTY ||
45
- prop == JFileChooser.FILE_VIEW_CHANGED_PROPERTY ||
46
- prop == JFileChooser.FILE_FILTER_CHANGED_PROPERTY ||
47
- prop == JFileChooser.FILE_HIDING_CHANGED_PROPERTY ||
48
- prop == JFileChooser.FILE_SELECTION_MODE_CHANGED_PROPERTY) {
49
- validateFileCache();
50
- }
51
- }
52
-
53
- /**
54
- * Obsolete - not used.
55
- */
56
- public void invalidateFileCache() {
57
- }
58
-
59
- public Vector<File> getDirectories() {
60
- synchronized(fileCache) {
61
- if (directories != null) {
62
- return directories;
63
- }
64
- Vector fls = getFiles();
65
- return directories;
66
- }
67
- }
68
-
69
- public Vector<File> getFiles() {
70
- synchronized(fileCache) {
71
- if (files != null) {
72
- return files;
73
- }
74
- files = new Vector();
75
- directories = new Vector();
76
- directories.addElement(filechooser.getFileSystemView().createFileObject(
77
- filechooser.getCurrentDirectory(), "..")
78
- );
79
-
80
- for (int i = 0; i < getSize(); i++) {
81
- File f = (File)fileCache.get(i);
82
- if (filechooser.isTraversable(f)) {
83
- directories.add(f);
84
- } else {
85
- files.add(f);
86
- }
87
- }
88
- return files;
89
- }
90
- }
91
-
92
- public void validateFileCache() {
93
- File currentDirectory = filechooser.getCurrentDirectory();
94
- if (currentDirectory == null) {
95
- return;
96
- }
97
- if (loadThread != null) {
98
- loadThread.interrupt();
99
- loadThread.cancelRunnables();
100
- }
101
- fetchID++;
102
- loadThread = new LoadFilesThread(currentDirectory, fetchID);
103
- loadThread.start();
104
- }
105
-
106
- /**
107
- * Renames a file in the underlying file system.
108
- *
109
- * @param oldFile a <code>File</code> object representing
110
- * the existing file
111
- * @param newFile a <code>File</code> object representing
112
- * the desired new file name
113
- * @return <code>true</code> if rename succeeded,
114
- * otherwise <code>false</code>
115
- * @since 1.4
116
- */
117
- public boolean renameFile(File oldFile, File newFile) {
118
- synchronized(fileCache) {
119
- if (oldFile.renameTo(newFile)) {
120
- validateFileCache();
121
- return true;
122
- }
123
- return false;
124
- }
125
- }
126
-
127
-
128
- public void fireContentsChanged() {
129
- // System.out.println("BasicDirectoryModel: firecontentschanged");
130
- //fireContentsChanged(this, 0, getSize()-1);
131
- }
132
-
133
- public int getSize() {
134
- return fileCache.size();
135
- }
136
-
137
- public boolean contains(Object o) {
138
- return fileCache.contains(o);
139
- }
140
-
141
- public int indexOf(Object o) {
142
- return fileCache.indexOf(o);
143
- }
144
-
145
- public Object getElementAt(int index) {
146
- return fileCache.get(index);
147
- }
148
-
149
- /**
150
- * Obsolete - not used.
151
- */
152
- public void intervalAdded(ListDataEvent e) {
153
- }
154
-
155
- /**
156
- * Obsolete - not used.
157
- */
158
- public void intervalRemoved(ListDataEvent e) {
159
- }
160
-
161
- protected void sort(Vector<? extends File> v){
162
- ShellFolder.sortFiles(v);
163
- }
164
-
165
- // Obsolete - not used
166
- protected boolean lt(File a, File b) {
167
- // First ignore case when comparing
168
- int diff = a.getName().toLowerCase().compareTo(b.getName().toLowerCase());
169
- if (diff != 0) {
170
- return diff < 0;
171
- } else {
172
- // May differ in case (e.g. "mail" vs. "Mail")
173
- return a.getName().compareTo(b.getName()) < 0;
174
- }
175
- }
176
-
177
-
178
- class LoadFilesThread extends Thread {
179
- File currentDirectory = null;
180
- int fid;
181
- Vector runnables = new Vector(10);
182
-
183
- public LoadFilesThread(File currentDirectory, int fid) {
184
- super("Basic L&F File Loading Thread");
185
- this.currentDirectory = currentDirectory;
186
- this.fid = fid;
187
- }
188
-
189
- private void invokeLater(Runnable runnable) {
190
- runnables.addElement(runnable);
191
- SwingUtilities.invokeLater(runnable);
192
- }
193
-
194
- public void run() {
195
- FileSystemView fileSystem = filechooser.getFileSystemView();
196
-
197
- File[] list = fileSystem.getFiles(currentDirectory, filechooser.isFileHidingEnabled());
198
-
199
- Vector<File> acceptsList = new Vector<File>();
200
-
201
- if (isInterrupted()) {
202
- return;
203
- }
204
-
205
- // run through the file list, add directories and selectable files to fileCache
206
- for (int i = 0; i < list.length; i++) {
207
- if(filechooser.accept(list[i])) {
208
- acceptsList.addElement(list[i]);
209
- }
210
- }
211
-
212
- if (isInterrupted()) {
213
- return;
214
- }
215
-
216
- // First sort alphabetically by filename
217
- sort(acceptsList);
218
-
219
- Vector newDirectories = new Vector(50);
220
- Vector newFiles = new Vector();
221
- // run through list grabbing directories in chunks of ten
222
- for(int i = 0; i < acceptsList.size(); i++) {
223
- File f = (File) acceptsList.elementAt(i);
224
- boolean isTraversable = filechooser.isTraversable(f);
225
- if (isTraversable) {
226
- newDirectories.addElement(f);
227
- } else if (!isTraversable && filechooser.isFileSelectionEnabled()) {
228
- newFiles.addElement(f);
229
- }
230
- if(isInterrupted()) {
231
- return;
232
- }
233
- }
234
-
235
- Vector newFileCache = new Vector(newDirectories);
236
- newFileCache.addAll(newFiles);
237
-
238
- int newSize = newFileCache.size();
239
- int oldSize = fileCache.size();
240
-
241
- if (newSize > oldSize) {
242
- //see if interval is added
243
- int start = oldSize;
244
- int end = newSize;
245
- for (int i = 0; i < oldSize; i++) {
246
- if (!newFileCache.get(i).equals(fileCache.get(i))) {
247
- start = i;
248
- for (int j = i; j < newSize; j++) {
249
- if (newFileCache.get(j).equals(fileCache.get(i))) {
250
- end = j;
251
- break;
252
- }
253
- }
254
- break;
255
- }
256
- }
257
- if (start >= 0 && end > start
258
- && newFileCache.subList(end, newSize).equals(fileCache.subList(start, oldSize))) {
259
- if(isInterrupted()) {
260
- return;
261
- }
262
- invokeLater(new DoChangeContents(newFileCache.subList(start, end), start, null, 0, fid));
263
- newFileCache = null;
264
- }
265
- } else if (newSize < oldSize) {
266
- //see if interval is removed
267
- int start = -1;
268
- int end = -1;
269
- for (int i = 0; i < newSize; i++) {
270
- if (!newFileCache.get(i).equals(fileCache.get(i))) {
271
- start = i;
272
- end = i + oldSize - newSize;
273
- break;
274
- }
275
- }
276
- if (start >= 0 && end > start
277
- && fileCache.subList(end, oldSize).equals(newFileCache.subList(start, newSize))) {
278
- if(isInterrupted()) {
279
- return;
280
- }
281
- invokeLater(new DoChangeContents(null, 0, new Vector(fileCache.subList(start, end)),
282
- start, fid));
283
- newFileCache = null;
284
- }
285
- }
286
- if (newFileCache != null && !fileCache.equals(newFileCache)) {
287
- if (isInterrupted()) {
288
- cancelRunnables(runnables);
289
- }
290
- invokeLater(new DoChangeContents(newFileCache, 0, fileCache, 0, fid));
291
- }
292
- }
293
-
294
-
295
- public void cancelRunnables(Vector runnables) {
296
- for(int i = 0; i < runnables.size(); i++) {
297
- ((DoChangeContents)runnables.elementAt(i)).cancel();
298
- }
299
- }
300
-
301
- public void cancelRunnables() {
302
- cancelRunnables(runnables);
303
- }
304
- }
305
-
306
- class DoChangeContents implements Runnable {
307
- private List addFiles;
308
- private List remFiles;
309
- private boolean doFire = true;
310
- private int fid;
311
- private int addStart = 0;
312
- private int remStart = 0;
313
- private int change;
314
-
315
- public DoChangeContents(List addFiles, int addStart, List remFiles, int remStart, int fid) {
316
- this.addFiles = addFiles;
317
- this.addStart = addStart;
318
- this.remFiles = remFiles;
319
- this.remStart = remStart;
320
- this.fid = fid;
321
- }
322
-
323
- synchronized void cancel() {
324
- doFire = false;
325
- }
326
-
327
- public synchronized void run() {
328
- if (fetchID == fid && doFire) {
329
- int remSize = (remFiles == null) ? 0 : remFiles.size();
330
- int addSize = (addFiles == null) ? 0 : addFiles.size();
331
- synchronized(fileCache) {
332
- if (remSize > 0) {
333
- fileCache.removeAll(remFiles);
334
- }
335
- if (addSize > 0) {
336
- fileCache.addAll(addStart, addFiles);
337
- }
338
- files = null;
339
- directories = null;
340
- }
341
- if (remSize > 0 && addSize == 0) {
342
- //fireIntervalRemoved(BasicDirectoryModel.this, remStart, remStart + remSize - 1);
343
- } else if (addSize > 0 && remSize == 0 && fileCache.size() > addSize) {
344
- //fireIntervalAdded(BasicDirectoryModel.this, addStart, addStart + addSize - 1);
345
- } else {
346
- fireContentsChanged();
347
- }
348
- }
349
- }
350
- }
351
-}
352
-
cTreeModel.java
....@@ -8,101 +8,100 @@
88
99 public cTreeModel(Object3D owner)
1010 {
11
- root = owner;
11
+ root = owner;
1212 }
1313
1414 public void addTreeModelListener(TreeModelListener l)
1515 {
1616 }
1717
18
- public Object getChild(Object parent, int index)
18
+ public Object getChild(Object parent, int index)
1919 {
20
- Object3D /*Composite*/ group = (Object3D /*Composite*/) parent;
20
+ Object3D /*Composite*/ group = (Object3D /*Composite*/) parent;
2121
22
- return group./*children.*/get(index);
22
+ return group./*children.*/get(index);
2323 }
2424
25
- public int getChildCount(Object parent)
25
+ public int getChildCount(Object parent)
2626 {
27
- //if (parent instanceof Composite)
28
- {
29
- return ((Object3D /*Composite*/) parent)/*.children*/.Size();
30
- }
27
+ //if (parent instanceof Composite)
28
+ {
29
+ return ((Object3D /*Composite*/) parent)/*.children*/.Size();
30
+ }
3131
32
- //return 0;
32
+ //return 0;
3333 }
3434
35
- public int getIndexOfChild(Object parent, Object child)
35
+ public int getIndexOfChild(Object parent, Object child)
3636 {
37
- Object3D /*Composite*/ group = (Object3D /*Composite*/) parent;
37
+ Object3D /*Composite*/ group = (Object3D /*Composite*/) parent;
3838
39
- return group./*GetObject().*/indexOf(child);
39
+ return group./*GetObject().*/indexOf(child);
4040 }
4141
42
- public Object getRoot()
42
+ public Object getRoot()
4343 {
44
- return root;
44
+ return root;
4545 }
4646
47
- public boolean isLeaf(Object node)
47
+ public boolean isLeaf(Object node)
4848 {
49
- return ((Object3D)node).Size() == 0; // !(node instanceof Composite);
49
+ return ((Object3D) node).Size() == 0; // !(node instanceof Composite);
5050 }
5151
52
- public void removeTreeModelListener(TreeModelListener l)
52
+ public void removeTreeModelListener(TreeModelListener l)
5353 {
5454 }
5555
56
- public void valueForPathChanged(TreePath path, Object newValue)
56
+ public void valueForPathChanged(TreePath path, Object newValue)
5757 {
5858 }
5959
6060 static class Renderer extends DefaultTreeCellRenderer
6161 {
62
- public Renderer() {
62
+ public Renderer()
63
+ {
6364 }
6465
6566 public java.awt.Component getTreeCellRendererComponent(
66
- javax.swing.JTree tree,
67
- Object value,
68
- boolean sel,
69
- boolean expanded,
70
- boolean leaf,
71
- int row,
72
- boolean hasFocus)
67
+ javax.swing.JTree tree,
68
+ Object value,
69
+ boolean sel,
70
+ boolean expanded,
71
+ boolean leaf,
72
+ int row,
73
+ boolean hasFocus)
7374 {
7475 //System.out.println(value.getClass());
75
- super.getTreeCellRendererComponent(
76
- tree, value, sel,
77
- expanded, leaf, row,
78
- hasFocus);
79
- String stringValue = tree.convertValueToText(value, sel,
80
- expanded, leaf, row, hasFocus);
76
+ super.getTreeCellRendererComponent(tree, value, sel,
77
+ expanded, leaf, row, hasFocus);
78
+ String stringValue = tree.convertValueToText(value, sel,
79
+ expanded, leaf, row, hasFocus);
8180
82
- //this.tree = tree;
83
- this.hasFocus = hasFocus;
84
- setText(stringValue);
81
+ //this.tree = tree;
82
+ this.hasFocus = hasFocus;
83
+ setText(stringValue);
8584
86
- Object3D obj = (Object3D) value;
87
-
88
- int r = 0, g = 0, b = 0;
85
+ Object3D obj = (Object3D) value;
8986
90
- if (obj.live)
91
- {
92
- g = 192;
93
- }
94
-
95
- if (obj.hide)
96
- {
97
- r = 192;
98
- }
99
-
100
- if (obj.link2master)
101
- {
102
- b = 192;
103
- }
104
-
105
- java.awt.Color fg = new java.awt.Color(r,g,b);
87
+ int r = 0, g = 0, b = 0;
88
+
89
+ if (obj.live)
90
+ {
91
+ g = 192;
92
+ }
93
+
94
+ if (obj.hide)
95
+ {
96
+ r = 192;
97
+ }
98
+
99
+ if (obj.link2master)
100
+ {
101
+ b = 192;
102
+ }
103
+
104
+ java.awt.Color fg = new java.awt.Color(r, g, b);
106105
107106 // isDropCell = false;
108107 // JTree.DropLocation dropLocation = tree.getDropLocation();
....@@ -126,9 +125,9 @@
126125 // }
127126
128127 // setBackground(fg);
129
- setForeground(fg);
128
+ setForeground(fg);
130129
131
- // There needs to be a way to specify disabled icons.
130
+ // There needs to be a way to specify disabled icons.
132131 // if (!tree.isEnabled()) {
133132 // setEnabled(false);
134133 //
....@@ -152,20 +151,22 @@
152151 // }
153152 // }
154153
155
- setComponentOrientation(tree.getComponentOrientation());
154
+ setComponentOrientation(tree.getComponentOrientation());
156155
157
- selected = sel;
156
+ selected = sel;
158157
159158 //Object3D obj = (Object3D) value;
160
-
161
- if(obj.material == null)
159
+
160
+ if (obj.material == null)
161
+ {
162162 setIcon(null);
163
-
163
+ }
164
+
164165 setToolTipText("This book is in the Tutorial series.");
165166
166167 return this;
167168 }
168
-
169
+
169170 public void setText(String text)
170171 {
171172 //System.out.println(text);