001/* 002 * $Id: IconValues.java 3927 2011-02-22 16:34:11Z kleopatra $ 003 * 004 * Copyright 2008 Sun Microsystems, Inc., 4150 Network Circle, 005 * Santa Clara, California 95054, U.S.A. All rights reserved. 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * You should have received a copy of the GNU Lesser General Public 018 * License along with this library; if not, write to the Free Software 019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 020 */ 021package org.jdesktop.swingx.renderer; 022 023import java.io.File; 024 025import javax.swing.Icon; 026import javax.swing.filechooser.FileSystemView; 027 028/** 029 * A collection of common {@code IconValue} implementations. 030 * 031 * @author Karl George Schaefer 032 * @author Jeanette Winzenburg 033 */ 034public final class IconValues { 035 /** 036 * Always NULL_ICON. This is useful to indicate that we really want 037 * no icon instead of f.i. a default provided by the CellContext. 038 */ 039 @SuppressWarnings("serial") 040 public static final IconValue NONE = new IconValue() { 041 042 @Override 043 public Icon getIcon(Object value) { 044 return IconValue.NULL_ICON; 045 } 046 047 }; 048 049 /** 050 * Returns the value as Icon if possible or null. 051 */ 052 @SuppressWarnings("serial") 053 public static final IconValue ICON = new IconValue() { 054 055 @Override 056 public Icon getIcon(Object value) { 057 if (value instanceof Icon) { 058 return (Icon) value; 059 } 060 return null; 061 } 062 }; 063 064 /** 065 * An {@code IconValue} that presents the current L&F icon for a given file. 066 * If the value passed to {@code FILE_ICON} is not a {@link File}, this has 067 * the same effect as {@link IconValues#NONE}. 068 */ 069 @SuppressWarnings("serial") 070 public static final IconValue FILE_ICON = new IconValue() { 071 @Override 072 public Icon getIcon(Object value) { 073 if (value instanceof File) { 074 FileSystemView fsv = FileSystemView.getFileSystemView(); 075 076 return fsv.getSystemIcon((File) value); 077 } 078 079 return IconValues.NONE.getIcon(value); 080 } 081 }; 082 083 private IconValues() { 084 // does nothing 085 } 086}