CameraPane.java | ●●●●● patch | view | raw | blame | history | |
GroupEditor.java | ●●●●● patch | view | raw | blame | history | |
ObjEditor.java | ●●●●● patch | view | raw | blame | history | |
cFileSystemModel.java | ●●●●● patch | view | raw | blame | history | |
cTools.java | ●●●●● patch | view | raw | blame | history | |
cTreeDirectoryModel.java | ●●●●● patch | view | raw | blame | history | |
cTreeModel.java | ●●●●● patch | view | raw | blame | history |
CameraPane.java
.. .. @@ -2398,128 +2398,6 @@ 2398 2398 return currentGL; 2399 2399 } 2400 2400 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 - try2416 - {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 next2446 - // entry call will return a ZipEntry for each file in the2447 - // stream2448 - 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 is2464 - // positioned read to read the raw data, and we keep2465 - // reading until read returns 0 or less.2466 - String outpath = name + "/" + entry.getName();2467 - FileOutputStream output = null;2468 - try2469 - {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 - finally2478 - {2479 - // we must always close the output file2480 - 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 - finally2499 - {2500 - try2501 - {2502 - if (is != null)2503 - is.close();2504 - }2505 - catch (IOException ioe)2506 - {2507 - }2508 - }2509 -2510 - // System.out.println("length = " + total);2511 -2512 -// try2513 -// {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 -2523 2401 /**/ 2524 2402 class CacheTexture 2525 2403 { .. .. @@ -15295,12 +15173,6 @@ 15295 15173 break; 15296 15174 case '+': 15297 15175 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 -15304 15176 /* 15305 15177 //fontsize += 1; 15306 15178 bbzoom *= 2; GroupEditor.java
.. .. @@ -1472,6 +1472,9 @@ 1472 1472 animationItem.addItemListener(this); 1473 1473 animationItem.setState(Globals.ANIMATION); 1474 1474 1475 + menu.add(archiveItem = new CheckboxMenuItem("Archive3D..."));1476 + archiveItem.addItemListener(this);1477 +1475 1478 menu.add("-"); 1476 1479 parseverticesItem = menu.add(new MenuItem("Multiplicity")); 1477 1480 parseverticesItem.addActionListener(this); ObjEditor.java
.. .. @@ -350,7 +350,7 @@ 350 350 frame.setMenuBar(menuBar = new MenuBar()); 351 351 menuBar.add(fileMenu = new Menu("File")); 352 352 fileMenu.add(newItem = new MenuItem("New")); 353 - fileMenu.add(loadItem = new MenuItem("Open..."));353 + fileMenu.add(openItem = new MenuItem("Open..."));354 354 355 355 //oe.menuBar.add(menu = new Menu("Include")); 356 356 Menu menu = new Menu("Import"); .. .. @@ -382,7 +382,7 @@ 382 382 } 383 383 384 384 newItem.addActionListener(this); 385 - loadItem.addActionListener(this);385 + openItem.addActionListener(this);386 386 saveItem.addActionListener(this); 387 387 saveAsItem.addActionListener(this); 388 388 exportAsItem.addActionListener(this); .. .. @@ -780,7 +780,7 @@ 780 780 // X frame.getContentPane().remove(/*"Center",*/bigThree); 781 781 // X framePanel.add(bigThree); 782 782 // X frame.getContentPane().add(/*"Center",*/framePanel); 783 - framePanel.setDividerLocation(1);783 + framePanel.setDividerLocation(46);784 784 785 785 //frame.setVisible(true); 786 786 radio.layout = keepButton; .. .. @@ -1493,7 +1493,10 @@ 1493 1493 // north.add(ctrlPanel, BorderLayout.NORTH); 1494 1494 // objectPanel.add(north); 1495 1495 objectPanel.add(editPanel); 1496 - objectPanel.add(infoPanel);1496 +1497 + if (Globals.ADVANCED)1498 + objectPanel.add(infoPanel);1499 +1497 1500 objectPanel.add(toolboxPanel); 1498 1501 1499 1502 /* .. .. @@ -1602,9 +1605,9 @@ 1602 1605 // aConstraints.gridheight = 1; 1603 1606 1604 1607 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);1608 1611 //framePanel.setDividerSize(15); 1609 1612 //framePanel.setResizeWeight(0.15); 1610 1613 framePanel.setName("Frame"); .. .. @@ -3198,6 +3201,10 @@ 3198 3201 { 3199 3202 ToggleAnimation(); 3200 3203 return; 3204 + } else if (event.getSource() == archiveItem)3205 + {3206 + cTools.Archive(frame);3207 + return;3201 3208 } else if (event.getSource() == flipVCB) 3202 3209 { 3203 3210 copy.flipV ^= true; .. .. @@ -3391,9 +3398,9 @@ 3391 3398 { 3392 3399 Close(); 3393 3400 //return true; 3394 - } else if (source == loadItem)3401 + } else if (source == openItem)3395 3402 { 3396 - load();3403 + Open();3397 3404 //return true; 3398 3405 } else if (source == newItem) 3399 3406 { .. .. @@ -4720,7 +4727,7 @@ 4720 4727 } 4721 4728 } 4722 4729 4723 - void load() // throws ClassNotFoundException4730 + void Open() // throws ClassNotFoundException4724 4731 { 4725 4732 if (Grafreed.standAlone) 4726 4733 { .. .. @@ -5005,7 +5012,7 @@ 5005 5012 MenuBar menuBar; 5006 5013 Menu fileMenu; 5007 5014 MenuItem newItem; 5008 - MenuItem loadItem;5015 + MenuItem openItem;5009 5016 MenuItem saveItem; 5010 5017 MenuItem saveAsItem; 5011 5018 MenuItem exportAsItem; .. .. @@ -5028,6 +5035,7 @@ 5028 5035 CheckboxMenuItem toggleSwitchItem; 5029 5036 CheckboxMenuItem toggleRootItem; 5030 5037 CheckboxMenuItem animationItem; 5038 + CheckboxMenuItem archiveItem;5031 5039 CheckboxMenuItem toggleHandleItem; 5032 5040 CheckboxMenuItem togglePaintItem; 5033 5041 JSplitPane mainPanel; cFileSystemModel.java
.. .. @@ -1,10 +1,12 @@ 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,88 +25,136 @@ 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 - else47 + } else46 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 +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 + else129 + {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 + else147 + {148 + //setIcon(null);149 +// Icon systemIcon = javax.swing.filechooser.FileSystemView.getFileSystemView().getSystemIcon( new File(valueString) );150 +// setIcon(systemIcon);151 + }152 +103 153 setToolTipText("This book is in the Tutorial series."); 104 154 105 155 return this; 106 156 } 107 -157 +108 158 public void setText(String text) 109 159 { 110 160 //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 cTools7 +{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 + try24 + {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 next33 + // entry call will return a ZipEntry for each file in the stream34 + 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 + // ArchiCAD42 + // continue;43 + }44 +45 + if (entryName.endsWith(".max"))46 + {47 + // 3DS MAX48 + // 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 is62 + // positioned read to read the raw data, and we keep63 + // 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 + } finally79 + {80 + try81 + {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 +// try94 +// {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 + try104 + {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 IOException125 + {126 + FileOutputStream output = null;127 + try128 + {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 + } finally136 + {137 + // we must always close the output file138 + 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 + try153 + {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.javadeleted file mode 100644
.. .. @@ -1,352 +0,0 @@ 1 -/*2 - * @(#)BasicDirectoryModel.java 1.31 04/05/053 - *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 Dinkins25 - */26 -public class cTreeDirectoryModel extends DefaultTreeModel implements PropertyChangeListener {27 -28 - private JFileChooser filechooser = null;29 - // PENDING(jeff) pick the size more sensibly30 - 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 representing110 - * the existing file111 - * @param newFile a <code>File</code> object representing112 - * the desired new file name113 - * @return <code>true</code> if rename succeeded,114 - * otherwise <code>false</code>115 - * @since 1.4116 - */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 used166 - protected boolean lt(File a, File b) {167 - // First ignore case when comparing168 - 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 fileCache206 - 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 filename217 - sort(acceptsList);218 -219 - Vector newDirectories = new Vector(50);220 - Vector newFiles = new Vector();221 - // run through list grabbing directories in chunks of ten222 - 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 added243 - 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 > start258 - && 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 removed267 - 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 > start277 - && 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 @@ 8 8 9 9 public cTreeModel(Object3D owner) 10 10 { 11 - root = owner;11 + root = owner;12 12 } 13 13 14 14 public void addTreeModelListener(TreeModelListener l) 15 15 { 16 16 } 17 17 18 - public Object getChild(Object parent, int index)18 + public Object getChild(Object parent, int index)19 19 { 20 - Object3D /*Composite*/ group = (Object3D /*Composite*/) parent;20 + Object3D /*Composite*/ group = (Object3D /*Composite*/) parent;21 21 22 - return group./*children.*/get(index);22 + return group./*children.*/get(index);23 23 } 24 24 25 - public int getChildCount(Object parent)25 + public int getChildCount(Object parent)26 26 { 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 + }31 31 32 - //return 0;32 + //return 0;33 33 } 34 34 35 - public int getIndexOfChild(Object parent, Object child)35 + public int getIndexOfChild(Object parent, Object child)36 36 { 37 - Object3D /*Composite*/ group = (Object3D /*Composite*/) parent;37 + Object3D /*Composite*/ group = (Object3D /*Composite*/) parent;38 38 39 - return group./*GetObject().*/indexOf(child);39 + return group./*GetObject().*/indexOf(child);40 40 } 41 41 42 - public Object getRoot()42 + public Object getRoot()43 43 { 44 - return root;44 + return root;45 45 } 46 46 47 - public boolean isLeaf(Object node)47 + public boolean isLeaf(Object node)48 48 { 49 - return ((Object3D)node).Size() == 0; // !(node instanceof Composite);49 + return ((Object3D) node).Size() == 0; // !(node instanceof Composite);50 50 } 51 51 52 - public void removeTreeModelListener(TreeModelListener l)52 + public void removeTreeModelListener(TreeModelListener l)53 53 { 54 54 } 55 55 56 - public void valueForPathChanged(TreePath path, Object newValue)56 + public void valueForPathChanged(TreePath path, Object newValue)57 57 { 58 58 } 59 59 60 60 static class Renderer extends DefaultTreeCellRenderer 61 61 { 62 - public Renderer() {62 + public Renderer()63 + {63 64 } 64 65 65 66 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)73 74 { 74 75 //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);81 80 82 - //this.tree = tree;83 - this.hasFocus = hasFocus;84 - setText(stringValue);81 + //this.tree = tree;82 + this.hasFocus = hasFocus;83 + setText(stringValue);85 84 86 - Object3D obj = (Object3D) value;87 -88 - int r = 0, g = 0, b = 0;85 + Object3D obj = (Object3D) value;89 86 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);106 105 107 106 // isDropCell = false; 108 107 // JTree.DropLocation dropLocation = tree.getDropLocation(); .. .. @@ -126,9 +125,9 @@ 126 125 // } 127 126 128 127 // setBackground(fg); 129 - setForeground(fg);128 + setForeground(fg);130 129 131 - // There needs to be a way to specify disabled icons.130 + // There needs to be a way to specify disabled icons.132 131 // if (!tree.isEnabled()) { 133 132 // setEnabled(false); 134 133 // .. .. @@ -152,20 +151,22 @@ 152 151 // } 153 152 // } 154 153 155 - setComponentOrientation(tree.getComponentOrientation());154 + setComponentOrientation(tree.getComponentOrientation());156 155 157 - selected = sel;156 + selected = sel;158 157 159 158 //Object3D obj = (Object3D) value; 160 -161 - if(obj.material == null)159 +160 + if (obj.material == null)161 + {162 162 setIcon(null); 163 -163 + }164 +164 165 setToolTipText("This book is in the Tutorial series."); 165 166 166 167 return this; 167 168 } 168 -169 +169 170 public void setText(String text) 170 171 { 171 172 //System.out.println(text);