1 31 32 package org.opencms.applet.upload; 33 34 import java.io.File ; 35 import java.net.URL ; 36 import java.util.HashMap ; 37 import java.util.StringTokenizer ; 38 39 import javax.swing.Icon ; 40 import javax.swing.ImageIcon ; 41 import javax.swing.filechooser.FileView ; 42 43 54 public class ImageFileView extends FileView { 55 56 57 private HashMap m_extensions; 58 59 60 private String m_opencms; 61 62 65 public ImageFileView() { 66 67 super(); 68 } 69 70 76 public ImageFileView(String opencms, String fileExtensions) { 77 78 super(); 79 80 m_opencms = opencms; 81 m_extensions = extractExtensions(fileExtensions); 82 83 } 84 85 88 public String getDescription(File f) { 89 90 return null; 91 } 92 93 96 public Icon getIcon(File f) { 97 98 String extension = FileUploadUtils.getExtension(f); 99 Icon icon = null; 101 102 if (f.isDirectory()) { 103 104 icon = (Icon )m_extensions.get("FOLDER"); 105 } else { 106 107 icon = (Icon )m_extensions.get(extension); 108 } 109 if (icon == null) { 111 112 icon = (Icon )m_extensions.get("txt"); 113 } 114 115 return icon; 116 } 117 118 121 public String getName(File f) { 122 123 return null; 124 } 125 126 129 public Boolean isTraversable(File f) { 130 131 return null; 132 } 133 134 142 private ImageIcon createImageIcon(String path) { 143 144 try { 145 URL imgURL = new URL (path); 146 ImageIcon img = new ImageIcon (imgURL); 147 return img; 148 } catch (Exception e) { 149 System.err.println(e); 150 return null; 151 } 152 } 153 154 160 private HashMap extractExtensions(String fileExtensions) { 161 162 HashMap extensions = new HashMap (); 163 fileExtensions += ",FOLDER=folder,"; 165 StringTokenizer tok = new StringTokenizer (fileExtensions, ","); 166 while (tok.hasMoreElements()) { 169 String token = tok.nextToken(); 170 String extension = token.substring(0, token.indexOf("=")); 172 String type = token.substring(token.indexOf("=") + 1); 173 ImageIcon icon = createImageIcon(m_opencms + type + ".gif"); 175 extensions.put(extension, icon); 176 177 } 178 return extensions; 179 } 180 } | Popular Tags |