001/* 002 * Copyright 2010-2015 Institut Pasteur. 003 * 004 * This file is part of Icy. 005 * 006 * Icy is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * Icy is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with Icy. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package icy.gui.component.renderer; 020 021import icy.resource.ResourceUtil; 022import icy.resource.icon.IcyIcon; 023 024import java.awt.Component; 025import java.awt.Rectangle; 026 027import javax.swing.JLabel; 028import javax.swing.JTable; 029import javax.swing.JTree; 030import javax.swing.table.TableCellRenderer; 031import javax.swing.tree.TreeCellRenderer; 032 033/** 034 * @author Stephane 035 */ 036public class VisibleCellRenderer extends JLabel implements TableCellRenderer, TreeCellRenderer 037{ 038 /** 039 * 040 */ 041 private static final long serialVersionUID = -5511881886845059452L; 042 043 int iconSize; 044 045 public VisibleCellRenderer(int iconSize) 046 { 047 super(); 048 049 this.iconSize = iconSize; 050 } 051 052 @Override 053 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, 054 int row, int column) 055 { 056 if (value instanceof Boolean) 057 { 058 final boolean b = ((Boolean) value).booleanValue(); 059 060 if (b) 061 setIcon(new IcyIcon(ResourceUtil.ICON_VISIBLE, iconSize)); 062 else 063 setIcon(new IcyIcon(ResourceUtil.ICON_NOT_VISIBLE, iconSize)); 064 } 065 066 return this; 067 } 068 069 @Override 070 public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, 071 boolean leaf, int row, boolean hasFocus) 072 { 073 if (value instanceof Boolean) 074 { 075 final boolean b = ((Boolean) value).booleanValue(); 076 077 if (b) 078 setIcon(new IcyIcon(ResourceUtil.ICON_VISIBLE, iconSize)); 079 else 080 setIcon(new IcyIcon(ResourceUtil.ICON_NOT_VISIBLE, iconSize)); 081 } 082 083 return this; 084 } 085 086 /** 087 * Overridden for performance reasons. 088 */ 089 @Override 090 public void invalidate() 091 { 092 } 093 094 /** 095 * Overridden for performance reasons. 096 */ 097 @Override 098 public void validate() 099 { 100 } 101 102 /** 103 * Overridden for performance reasons. 104 */ 105 @Override 106 public void revalidate() 107 { 108 } 109 110 /** 111 * Overridden for performance reasons. 112 */ 113 @Override 114 public void repaint(long tm, int x, int y, int width, int height) 115 { 116 } 117 118 /** 119 * Overridden for performance reasons. 120 */ 121 @Override 122 public void repaint(Rectangle r) 123 { 124 } 125 126 /** 127 * Overridden for performance reasons. 128 * 129 * @since 1.5 130 */ 131 @Override 132 public void repaint() 133 { 134 } 135}