[duke~source:5] Create

  • From: jag@kenai.com
  • To: commits@duke.kenai.com
  • Subject: [duke~source:5] Create
  • Date: Sun, 9 Aug 2009 15:35:55 +0000

Project:    duke
Repository: source
Revision:   5
Author:     jag
Date:       2009-08-09 15:35:53 UTC
Link:       

Log Message:
------------
Create


Revisions:
----------
5


Modified Paths:
---------------
src/duke/Main.java


Diffs:
------
Index: src/duke/Main.java
===================================================================
--- src/duke/Main.java  (revision 4)
+++ src/duke/Main.java  (revision 5)
@@ -25,7 +25,8 @@
      * @param args the command line arguments
      */
     public static void main(String[] args) {
-        new Main().process(new 
File(System.getProperty("user.dir"),"www/images"), null);
+//        new Main().process(new 
File(System.getProperty("user.dir"),"www/images"), null);
+        new Main().process(new File("/Volumes/duke"), null);
     }
 
     private DirEntry process(File root, String handle) {
@@ -75,13 +76,14 @@
     private int generateEntry(File root, File thumbnails,
             String name, String handle, Writer out,DirEntry dir) throws 
IOException {
         int ret = 0;
-        if(name.startsWith(".")) return 0;
-        File f = new File(root,name);
+        if(name.startsWith(".") || "RES".equals(name)) return 0;
+        final File f = new File(root,name);
         boolean isDirectory = f.isDirectory();
+        String ext = null;
         if(!isDirectory) {
             int lastdot = name.lastIndexOf('.');
             if(lastdot<=0) return 0;
-            String ext = name.substring(lastdot+1).toLowerCase();
+            ext = name.substring(lastdot+1).toLowerCase();
             if(!imageExts.contains(ext)) return 0;
         }
 //        out.write("<div class=entry>");
@@ -90,71 +92,81 @@
             DirEntry de = process(f, handle==null?name:handle+" - "+name);
             ret=de.nfiles;
             out.write("<a href="+name+"/index.html>" +
-                    "<img src="+name+"/"+de.icon+" 
border=0>\n<br>"+name+"</a>" +
+                    "<img src="+name+"/"+(de.icon==null ? "/RES/folder.png" 
: de.icon) + " border=0><br>"+name+"</a>" +
                     "<br>(" + de.nfiles +
                     " files)\n");
         }
         else {
             System.out.println("  File: "+f);
             ret=1;
-            String note=null;
-            File thumbFile = new File(thumbnails,name+".png");
+            final File thumbFile = new File(thumbnails,name+".png");
             boolean haveThumb = false;
-            if(thumbFile.exists()) haveThumb = true;
-            else try {
-                BufferedImage img = javax.imageio.ImageIO.read(f);
-                if(img!=null) {
-                    note = img.getWidth()+"x"+img.getHeight();
-                    
javax.imageio.ImageIO.write(resize(img,iconSize,iconSize),"png",thumbFile);
-                    haveThumb = true;
-                }
-            } catch(Throwable ioe) { System.out.println(ioe+": "+f); }
+            if(thumbFile.lastModified()>f.lastModified()) haveThumb = true;
+            else if(readableImages.contains(ext) && f.length()<15000000) {
+//                new Thread() {
+//                    public void run() {
+                        try {
+                            System.out.println("     Making thumbnail for 
"+name+"  "+f.length());
+                            BufferedImage img = 
javax.imageio.ImageIO.read(f);
+                            if(img!=null)
+                                
javax.imageio.ImageIO.write(resize(img,iconSize,iconSize),"png",thumbFile);
+                        } catch(Throwable ioe) { System.out.println(ioe+": 
"+f); }
+//                    }
+//                }.start();
+                haveThumb = true;
+            }
+            else System.out.println("**Skipping read of**"+name);
             out.write("<a href="+name+">");
             if(haveThumb) {
                 String iName = thumbdir+"/"+name+".png";
                     out.write("<img src=" + iName+" border=0><br>");
                     if(dir.icon==null) dir.icon = iName;
-            }
+            } else if(ext.equals("mov") || ext.equals("avi"))
+                out.write("<img src=/RES/video.png border=0><br>");
+            else if(ext.equals("pdf") || ext.equals("ai"))
+                out.write("<img src=/RES/pdf.png border=0><br>");
+            else if(ext.equals("lwo") || ext.equals("lws"))
+                out.write("<img src=/RES/lightwave.png border=0><br>");
+            else if(ext.equals("psd") || ext.equals("tiff"))
+                out.write("<img src=/RES/photoshop.png border=0><br>");
             char lastC = ' ';
             int limit = name.length();
             for(int i = 0; i<limit; i++) {
                 char c = name.charAt(i);
-                if(c=='_' || c=='-') c = ' ';
-                if(c=='.') break;
-                if(Character.isUpperCase(c) && Character.isLowerCase(lastC))
-                    out.write(' ');
+                if(c=='_' || c=='-' || c=='.'
+                        || Character.isUpperCase(c) && 
Character.isLowerCase(lastC)) out.write("&#8203;");
                 out.write(c);
                 lastC = c;
             }
-            out.write("</a>\n");
-            if(note!=null) {
-                out.write(" ");
-                out.write(note);
-            }
-            out.write(" "+human(f.length()));
+            out.write("</a> "+human(f.length()));
         }
 //        out.write("</div>\n");
         out.write("</table>\n");
         dir.nfiles+=ret;
         return ret;
     }
-    String human(long l) {
-        if(l<10000) return l+"b";
-        char s;
-        double v;
-        if(l<1000000) { s = 'K'; v = l/1e3; }
-        else if(l<1000000000) { s = 'M'; v = l/1e6; }
-        else { s = 'G'; v = l/1e9; }
-        String d = String.valueOf(v);
-        if(d.length()>4) {
-            int dot = d.indexOf('.');
+    static final HashSet<String> readableImages = new HashSet<String>();
+    static {
+        for(String s:javax.imageio.ImageIO.getReaderFormatNames())
+            readableImages.add(s.toLowerCase());
+    }
+    String human(long value) {
+        if(value<10000) return value+"b";
+        char scaleSignifier;
+        double scaledValue;
+        if(value<1000000) { scaleSignifier = 'K'; scaledValue = value/1e3; }
+        else if(value<1000000000) { scaleSignifier = 'M'; scaledValue = 
value/1e6; }
+        else { scaleSignifier = 'G'; scaledValue = value/1e9; }
+        String forattedValue = String.valueOf(scaledValue);
+        if(forattedValue.length()>4) {
+            int dot = forattedValue.indexOf('.');
             if(dot>=0)
                 if(dot<2)
-                    d = d.substring(0,3);
+                    forattedValue = forattedValue.substring(0,3);
                 else
-                    d = d.substring(0,dot);
+                    forattedValue = forattedValue.substring(0,dot);
         }
-        return d+s+'b';
+        return forattedValue+scaleSignifier+'b';
     }
     private BufferedImage resize(BufferedImage in, int maxw, int maxh) {
         if(in.getWidth()<=maxw && in.getHeight()<=maxh) return in;





[duke~source:5] Create

jag 08/09/2009
  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20120518.3c65429)
 
 
Close
loading
Please Confirm
Close