01: //Copyright (c) Hans-Joachim Daniels 2005
02: //
03: //This program is free software; you can redistribute it and/or modify
04: //it under the terms of the GNU General Public License as published by
05: //the Free Software Foundation; either version 2 of the License, or
06: //(at your option) any later version.
07: //
08: //This program is distributed in the hope that it will be useful,
09: //but WITHOUT ANY WARRANTY; without even the implied warranty of
10: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11: //GNU General Public License for more details.
12: //
13: //You can either finde the file LICENSE or LICENSE.TXT in the source
14: //distribution or in the .jar file of this application
15:
16: package de.uka.ilkd.key.ocl.gf;
17:
18: import java.awt.Component;
19:
20: import javax.swing.JLabel;
21: import javax.swing.JList;
22: import javax.swing.ListCellRenderer;
23:
24: /**
25: * A cell renderer, that returns JLables, that put everything after the first
26: * '$' character into their tooltip
27: * @author daniels
28: */
29: public class ToolTipCellRenderer extends JLabel implements
30: ListCellRenderer {
31:
32: /**
33: * Returns a JLabel with a tooltip, which is given by the GFCommand
34: * @param list Well, the list this cell belongs to
35: * @param value value to display
36: * @param index cell index
37: * @param isSelected is the cell selected
38: * @param cellHasFocus the list and the cell have the focus
39: * @return a suiting JLabel
40: */
41: public Component getListCellRendererComponent(JList list,
42: Object value, int index, boolean isSelected,
43: boolean cellHasFocus) {
44: if (isSelected) {
45: setBackground(list.getSelectionBackground());
46: setForeground(list.getSelectionForeground());
47: } else {
48: setBackground(list.getBackground());
49: setForeground(list.getForeground());
50: }
51: setEnabled(list.isEnabled());
52: setFont(list.getFont());
53: setOpaque(true);
54:
55: if (value == null) {
56: setText("Null-Value!!! Something went terribly wrong here!");
57: } else if (value instanceof GFCommand) {
58: GFCommand gfc = (GFCommand) value;
59: String disText = gfc.getDisplayText();
60: if (gfc instanceof LinkCommand) {
61: //italic font could be an alternative
62: disText = "-> " + disText;
63: }
64: setText(disText);
65: setToolTipText(gfc.getTooltipText());
66: } else {
67: setText(value.toString());
68: setToolTipText("Strange thing of class '"
69: + value.getClass() + "'");
70: }
71: return this;
72: }
73:
74: }
|