001 /* 002 * $Id: IconValues.java 3152 2008-12-23 18:12:39Z kschaefe $ 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 */ 021 package org.jdesktop.swingx.renderer; 022 023 import java.io.File; 024 025 import javax.swing.Icon; 026 import 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 */ 034 public 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 public Icon getIcon(Object value) { 043 return IconValue.NULL_ICON; 044 } 045 046 }; 047 048 /** 049 * Returns the value as Icon if possible or null. 050 */ 051 @SuppressWarnings("serial") 052 public static final IconValue ICON = new IconValue() { 053 054 public Icon getIcon(Object value) { 055 if (value instanceof Icon) { 056 return (Icon) value; 057 } 058 return null; 059 } 060 }; 061 062 /** 063 * An {@code IconValue} that presents the current L&F icon for a given file. 064 * If the value passed to {@code FILE_ICON} is not a {@link File}, this has 065 * the same effect as {@link IconValues#NONE}. 066 */ 067 @SuppressWarnings("serial") 068 public static final IconValue FILE_ICON = new IconValue() { 069 public Icon getIcon(Object value) { 070 if (value instanceof File) { 071 FileSystemView fsv = FileSystemView.getFileSystemView(); 072 073 return fsv.getSystemIcon((File) value); 074 } 075 076 return IconValues.NONE.getIcon(value); 077 } 078 }; 079 080 private IconValues() { 081 // does nothing 082 } 083 }