View Javadoc

1   // %11693975:hoplugins.commons.ui.renderer%
2   package hoplugins.commons.ui.renderer;
3   
4   import java.awt.Component;
5   import java.awt.Insets;
6   
7   import javax.swing.JEditorPane;
8   import javax.swing.JTable;
9   import javax.swing.table.TableCellRenderer;
10  
11  
12  /***
13   * HTML cell renderer. Renders HTML source into a table cell.
14   *
15   * @author <a href="mailto:kenmooda@users.sourceforge.net">Tommi Rautava</a>
16   */
17  public class HtmlCellRenderer extends JEditorPane implements TableCellRenderer {
18      //~ Constructors -------------------------------------------------------------------------------
19  
20      /***
21       * Constructor
22       */
23      public HtmlCellRenderer() {
24          super();
25          this.setContentType("text/html");
26          this.setAlignmentY(HtmlCellRenderer.CENTER_ALIGNMENT);
27          this.setMargin(new Insets(0, 1, 0, 1));
28      }
29  
30      //~ Methods ------------------------------------------------------------------------------------
31  
32      /*
33       * (non-Javadoc)
34       *
35       * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable,
36       *      java.lang.Object, boolean, boolean, int, int)
37       */
38      public Component getTableCellRendererComponent(JTable table, Object object, boolean isSelected,
39                                                     boolean hasFocus, int row, int column) {
40          // Set text/html.
41          this.setText((String) object);
42  
43          // Set background color.
44          if (isSelected) {
45              this.setBackground(table.getSelectionBackground());
46          } else {
47              this.setBackground(table.getBackground());
48          }
49  
50          return this;
51      }
52  }