001 ////////////////////////////////////////////////// 002 // This file is part of Sears project. 003 // Subtitle Editor And Re-Synch 004 // A tool to easily modify and resynch movies subtitles. 005 ///////////////////////////////////////////////// 006 //This program is free software; 007 //you can redistribute it and/or modify it under the terms 008 //of the GNU General Public License 009 //as published by the Free Software Foundation; 010 //either version 2 of the License, or (at your option) any later version. 011 ///////////////////////////////////////////////// 012 //Sears project is available under sourceforge 013 // at adress: http://sourceforge.net/projects/sears/ 014 //Copyright (C) 2005 Booba Skaya 015 //Mail: booba.skaya@gmail.com 016 //////////////////////////////////////////////// 017 package sears.gui; 018 019 import java.awt.Component; 020 021 import javax.swing.Icon; 022 import javax.swing.ImageIcon; 023 import javax.swing.JLabel; 024 import javax.swing.JTable; 025 import javax.swing.table.DefaultTableCellRenderer; 026 import javax.swing.table.TableCellRenderer; 027 028 import sears.gui.resources.SearsResources; 029 030 /** 031 * @author booba 032 * 033 */ 034 public class SubtitleAnchorHeaderTableCellRenderer extends 035 DefaultTableCellRenderer { 036 037 /** (<b>long</b>) serialVersionUID: The serialVersionUID */ 038 private static final long serialVersionUID = -5783426661310517302L; 039 040 /** (<b>ImageIcon</b>) anchorIcon: The anchorIcon */ 041 private static ImageIcon anchorIcon; 042 043 private TableCellRenderer oldHeaderRenderer; 044 045 public SubtitleAnchorHeaderTableCellRenderer(TableCellRenderer headerRenderer) { 046 oldHeaderRenderer = headerRenderer; 047 } 048 049 /** 050 * Method getAnchorIcon. <br> 051 * <b>Summary:</b><br> 052 * Return the anchor icon. Use a cache to increase performance since the 053 * anchor icon is always the same. 054 * 055 * @return (<b>Icon</b>) The anchor icon. 056 */ 057 private Icon getAnchorIcon() { 058 if (anchorIcon == null) { 059 anchorIcon = SearsResources.getIcon("AnchorIcon"); 060 } 061 return anchorIcon; 062 } 063 064 /* (non-Javadoc) 065 * @see javax.swing.table.DefaultTableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int) 066 */ 067 @Override 068 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { 069 Component result = oldHeaderRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, 070 row, column); 071 if(column == SubtitleTableModel.ANCHOR_COLUMN){ 072 ((JLabel) result).setIcon(getAnchorIcon()); 073 }else{ 074 ((JLabel) result).setIcon(null); 075 } 076 return result; 077 } 078 079 080 081 }