View Javadoc

1   /*
2    *  Copyright (C) 2003-2005 SINTEF
3    *  Author:  Fredrik Vraalsen (fredrik dot vraalsen at sintef dot no)
4    *  Webpage: http://coras.sourceforge.net/
5    *
6    *  This program is free software; you can redistribute it and/or
7    *  modify it under the terms of the GNU Lesser General Public License
8    *  as published by the Free Software Foundation; either version 2.1
9    *  of the License, or (at your option) any later version.
10   *
11   *  This program is distributed in the hope that it will be useful,
12   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   *  Lesser General Public License for more details.
15   *
16   *  You should have received a copy of the GNU Lesser General Public
17   *  License along with this program; if not, write to the Free
18   *  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19   *  02111-1307 USA
20   */
21  package coras.table;
22  
23  import java.awt.Component;
24  import java.awt.Font;
25  
26  import javax.swing.JTable;
27  import javax.swing.JTextArea;
28  import javax.swing.table.TableCellRenderer;
29  
30  /***
31   * @author fvr
32   *
33   * To change the template for this generated type comment go to
34   * Window - Preferences - Java - Code Generation - Code and Comments
35   */
36  public class TextAreaRenderer extends JTextArea implements TableCellRenderer {
37  	
38  	public TextAreaRenderer() {
39  		super();
40  		setOpaque(true);
41  		setEditable(false);
42  		setLineWrap(true);
43  		setWrapStyleWord(true);
44  		setFont(new Font("SansSerif", Font.PLAIN, 12));
45  	}
46  	
47  	/* (non-Javadoc)
48  	 * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int)
49  	 */
50  	public Component getTableCellRendererComponent(JTable table, Object value,
51  			boolean isSelected, boolean hasFocus, int row, int column) {
52  		if (value instanceof String) {
53  			setText((String)value);
54  		} else {
55  			setText("NOT STRING: " + value);
56  		}
57  		/*
58  		if (table instanceof CorasTable) {
59  			CorasTableModel model = (CorasTableModel) table.getModel();
60  			Collection choices = model.getColumnChoices(column);
61  			setToolTipText(choices != null ? "Right click for choices" : null);
62  		} else {
63  			setToolTipText(null);
64  		}
65  		*/
66  		setForeground(isSelected ? table.getSelectionForeground() : table.getForeground());
67  		setBackground(isSelected ? table.getSelectionBackground() : table.getBackground());
68  		return this;
69  	}
70  	
71  }