KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > jclasslib > browser > detail > attributes > LinkRenderer


1 /*
2     This library is free software; you can redistribute it and/or
3     modify it under the terms of the GNU General Public
4     License as published by the Free Software Foundation; either
5     version 2 of the license, or (at your option) any later version.
6 */

7
8 package org.gjt.jclasslib.browser.detail.attributes;
9
10 import org.gjt.jclasslib.browser.AbstractDetailPane;
11 import org.gjt.jclasslib.browser.detail.ListDetailPane;
12 import org.gjt.jclasslib.util.ExtendedTableCellRenderer;
13
14 import javax.swing.*;
15 import javax.swing.table.TableCellRenderer JavaDoc;
16 import java.awt.*;
17
18 /**
19     Renderer for links in <tt>ListDetailPane</tt>s.
20
21     @author <a HREF="mailto:jclasslib@ej-technologies.com">Ingo Kegel</a>
22     @version $Revision: 1.1 $ $Date: 2003/08/18 08:17:02 $
23 */

24 public class LinkRenderer implements TableCellRenderer {
25
26     private ExtendedTableCellRenderer linkLineRenderer;
27     private ExtendedTableCellRenderer infoLineRenderer;
28     private Color standardForeground;
29     private JPanel panel;
30
31     /**
32      * Constructor.
33      */

34     public LinkRenderer() {
35
36         linkLineRenderer = new ExtendedTableCellRenderer();
37         linkLineRenderer.setVerticalAlignment(JLabel.TOP);
38         infoLineRenderer = new ExtendedTableCellRenderer();
39
40         standardForeground = linkLineRenderer.getForeground();
41
42         panel = new JPanel(new BorderLayout());
43         panel.add(linkLineRenderer, BorderLayout.NORTH);
44         panel.add(infoLineRenderer, BorderLayout.SOUTH);
45     }
46
47     public Component getTableCellRendererComponent(JTable table,
48                                                    Object JavaDoc value,
49                                                    boolean isSelected,
50                                                    boolean hasFocus,
51                                                    int row,
52                                                    int column)
53     {
54
55         boolean standardLabel = value.toString().equals(ListDetailPane.CPINFO_LINK_TEXT + "0");
56         linkLineRenderer.setForeground(standardLabel ? standardForeground : AbstractDetailPane.COLOR_LINK);
57         linkLineRenderer.setUnderlined(!standardLabel);
58         linkLineRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
59
60         if (value instanceof LinkCommentValue) {
61             infoLineRenderer.getTableCellRendererComponent(table, ((LinkCommentValue)value).commentValue, isSelected, false, row, column);
62             panel.setBorder(linkLineRenderer.getBorder());
63             linkLineRenderer.setBorder(infoLineRenderer.getBorder());
64             infoLineRenderer.setVisible(true);
65         } else {
66             infoLineRenderer.setVisible(false);
67         }
68
69         panel.setBackground(linkLineRenderer.getBackground());
70
71         return panel;
72     }
73
74     /**
75      * Value object for a link with a comment.
76      */

77     public static class LinkCommentValue {
78
79         private String JavaDoc linkValue;
80         private String JavaDoc commentValue;
81
82         /**
83          * Constructor.
84          * @param linkValue the text for the link.
85          * @param commentValue the text for the comment.
86          */

87         public LinkCommentValue(String JavaDoc linkValue, String JavaDoc commentValue) {
88             this.linkValue = linkValue;
89             this.commentValue = commentValue;
90         }
91
92         public String JavaDoc toString() {
93             return linkValue;
94         }
95     }
96
97 }
98
Popular Tags