001package jmri.profile; 002 003import java.io.File; 004import javax.swing.Icon; 005import javax.swing.ImageIcon; 006import javax.swing.filechooser.FileView; 007import jmri.util.FileUtil; 008import org.slf4j.Logger; 009import org.slf4j.LoggerFactory; 010 011/** 012 * FileView for use in a JFileChooser. 013 * 014 * @author Randall Wood Copyright (C) 2013, 2014 015 */ 016public class ProfileFileView extends FileView { 017 018 private static final Logger log = LoggerFactory.getLogger(ProfileFileView.class); 019 020 @Override 021 public String getDescription(File f) { 022 if (!this.isTraversable(f)) { 023 return Bundle.getMessage("FileViewDescription", f.getName()); 024 } else { 025 return null; 026 } 027 } 028 029 @Override 030 public Boolean isTraversable(File f) { 031 try { 032 if (Profile.isProfile(f)) { 033 return false; 034 } 035 } catch (NullPointerException ex) { 036 // this is most likely caused by virtual folders like Networks in Windows 7 037 log.debug("Unable to list contents of {}", f.getPath()); 038 } 039 return true; 040 } 041 042 @Override 043 public Icon getIcon(File f) { 044 if (!isTraversable(f)) { 045 return new ImageIcon(FileUtil.findURL("resources/jmri16x16.gif")); // NOI18N 046 } 047 return null; 048 } 049}