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 * 032 */ 033 public class SubtitleAnchorHeaderTableCellRenderer extends 034 DefaultTableCellRenderer { 035 036 /** (<b>long</b>) serialVersionUID: The serialVersionUID */ 037 private static final long serialVersionUID = -5783426661310517302L; 038 039 /** (<b>ImageIcon</b>) anchorIcon: The anchorIcon */ 040 private static ImageIcon anchorIcon; 041 042 private TableCellRenderer oldHeaderRenderer; 043 044 /** 045 * Constructs a new renderer for table hearder 046 * @param headerRenderer the table header renderer 047 */ 048 public SubtitleAnchorHeaderTableCellRenderer(TableCellRenderer headerRenderer) { 049 oldHeaderRenderer = headerRenderer; 050 } 051 052 /** 053 * Method getAnchorIcon. <br> 054 * <b>Summary:</b><br> 055 * Return the anchor icon. Use a cache to increase performance since the 056 * anchor icon is always the same. 057 * 058 * @return (<b>Icon</b>) The anchor icon. 059 */ 060 private Icon getAnchorIcon() { 061 if (anchorIcon == null) { 062 anchorIcon = SearsResources.getIcon("AnchorIcon"); 063 } 064 return anchorIcon; 065 } 066 067 /* (non-Javadoc) 068 * @see javax.swing.table.DefaultTableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int) 069 */ 070 @Override 071 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { 072 Component result = oldHeaderRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, 073 row, column); 074 if(column == SubtitleTableModel.ANCHOR_COLUMN){ 075 ((JLabel) result).setIcon(getAnchorIcon()); 076 }else{ 077 ((JLabel) result).setIcon(null); 078 } 079 return result; 080 } 081 082 083 084 }