1 /* 2 * UnBBayes 3 * Copyright (C) 2002, 2008 Universidade de Brasilia - http://www.unb.br 4 * 5 * This file is part of UnBBayes. 6 * 7 * UnBBayes is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * UnBBayes is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with UnBBayes. If not, see <http://www.gnu.org/licenses/>. 19 * 20 */ 21 package unbbayes.gui; 22 23 import java.awt.Component; 24 import java.awt.Graphics; 25 import java.awt.Image; 26 import java.io.File; 27 import java.util.ResourceBundle; 28 29 import javax.swing.Icon; 30 import javax.swing.ImageIcon; 31 import javax.swing.JFileChooser; 32 import javax.swing.filechooser.FileView; 33 34 import unbbayes.controller.IconController; 35 /** 36 * Essa classe extende o <code>FileView</code> que é o responsável por 37 * mostrar os ícones correspondentes para cada tipo de aquivo e pasta. 38 * 39 *@author Rommel Novaes Carvalho, Michael S. Onishi 40 *@created 27 de Junho de 2001 41 *@see FileView 42 *@version 1.0 06/07/2001 43 */ 44 public class FileIcon extends FileView { 45 46 private JFileChooser fc; 47 private Component observer; 48 protected IconController iconController = IconController.getInstance(); 49 50 /** Load resource file from this package */ 51 private static ResourceBundle resource = unbbayes.util.ResourceController.newInstance().getBundle( 52 unbbayes.gui.resources.GuiResources.class.getName()); 53 54 /** 55 * Constroi um observer para desenhar ícones e um JFileChooser para pegar 56 * ícones (<code>Icon</code>) padrões. 57 * 58 *@param c o componente (<code>Component</code>) que sera o observer para desenhar icones. 59 *@see Component 60 *@see Icon 61 */ 62 public FileIcon(Component c) { 63 //componente para criar icones de arquivos 64 observer = c; 65 fc = new JFileChooser(); 66 } 67 68 69 /** 70 * Retorna a descricao do arquivo desejado. 71 * 72 *@param f o arquivo (<code>File</code>) ao qual se deseja a descricao 73 *@return a descricao do arquivo (<code>String</code>) 74 *@see File 75 *@see String 76 */ 77 public String getDescription(File f) { 78 return getTypeDescription(f); 79 } 80 81 82 /** 83 * Retorna o icone (<code>Icon</code>) correnspondente ao arquivo desejado. 84 * 85 *@param f o arquivo (<code>File</code>) que se deseja pegar o icone 86 *@return o icone correspondente ao arquivo f 87 *@see Icon 88 *@see File 89 */ 90 public Icon getIcon(File f) { 91 /* 92 * if (f.isDirectory()) 93 * { 94 * return directoryIcon; 95 * } 96 */ 97 String name = f.getName(); 98 if (name.endsWith(".arff")) { 99 return iconController.getArffFileIcon(); 100 } 101 if (name.toLowerCase().endsWith(".txt")) { 102 return iconController.getTxtFileIcon(); 103 } 104 if (name.toLowerCase().endsWith(".net")) { 105 return iconController.getNetFileIcon(); 106 } 107 return fc.getIcon(f); 108 } 109 110 111 /** 112 * Retorna o name do arquivo desejado. 113 * 114 *@param f o arquivo (<code>File</code>) que se deseja receber o name 115 *@return o name do arquivo (<code>String</code>) 116 *@see String 117 *@see File 118 */ 119 public String getName(File f) { 120 String name = f.getName(); 121 return name.equals("") ? f.getPath() : name; 122 } 123 124 125 /** 126 * Retorna o tipo do arquivo. 127 * 128 *@param f o arquivo (<code>File</code>) que se deseja descricao do tipo 129 *@return o tipo do arquivo (<code>String</code>) 130 *@see String 131 *@see File 132 */ 133 public String getTypeDescription(File f) { 134 String name = f.getName().toLowerCase(); 135 if (f.isDirectory()) { 136 return resource.getString("fileDirectoryType"); 137 } 138 139 if (name.endsWith(".arff")) { 140 return resource.getString("fileARFFType"); 141 } 142 143 if (name.endsWith(".txt")) { 144 return resource.getString("fileTXTType"); 145 } 146 147 if (name.endsWith(".net")) { 148 return resource.getString("fileNETType"); 149 } 150 return resource.getString("fileGenericType"); 151 } 152 153 154 /** 155 * Retorna se e tranversable ou nao. 156 * 157 *@param f o arquivo (<code>File</code>) que se deseja saber se e tranversable 158 *@return true se for tranversable e falso caso contrario 159 *@see File 160 */ 161 public boolean isTranversable(File f) { 162 //todos diretorios serao transversable 163 return f.isDirectory() ? true : false; 164 } 165 166 167 /** 168 * Classe que extende <code>ImageIcon</code> responsavel por desenhar 169 * um icone. 170 * 171 *@author Rommel Novaes Carvalho, Michael S. Onishi 172 *@created 27 de Junho de 2001 173 *@see ImageIcon 174 */ 175 public class Icon16 extends ImageIcon { 176 177 /** Serialization runtime version number */ 178 private static final long serialVersionUID = 0; 179 180 /** 181 * Cria e desenha um icone para o arquivo desejado. 182 * 183 *@param f o arquivo (<code>String</code>) que deseja-se criar um icone 184 *@see String 185 */ 186 public Icon16(String f) { 187 super(f); 188 Image i = observer.createImage(16, 16); 189 i.getGraphics().drawImage(getImage(), 0, 0, 16, 16, observer); 190 setImage(i); 191 } 192 193 194 /** 195 * Retorna altura do icone 196 * 197 *@return a altura do icone (int) 198 */ 199 public int getIconHeight() { 200 return 16; 201 } 202 203 204 /** 205 * Retorna a largura do icone 206 * 207 *@return a altura do icone (int) 208 */ 209 public int getIconWidth() { 210 return 16; 211 } 212 213 214 /** 215 * Desenha o icone. 216 * 217 *@param c o componente (<code>Component</code>) 218 *@param g o grafico (<code>Graphics</code>) 219 *@param x a largura do icone (int) 220 *@param y a altura do icone (int) 221 *@see Component 222 *@see Graphics 223 */ 224 public void paintIcon(Component c, Graphics g, int x, int y) { 225 g.drawImage(getImage(), x, y, c); 226 } 227 } 228 229 } 230