source: src/main/java/weka/gui/sql/InfoPanelCellRenderer.java @ 4

Last change on this file since 4 was 4, checked in by gnappo, 14 years ago

Import di weka.

File size: 2.4 KB
Line 
1/*
2 *    This program is free software; you can redistribute it and/or modify
3 *    it under the terms of the GNU General Public License as published by
4 *    the Free Software Foundation; either version 2 of the License, or
5 *    (at your option) any later version.
6 *
7 *    This program is distributed in the hope that it will be useful,
8 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 *    GNU General Public License for more details.
11 *
12 *    You should have received a copy of the GNU General Public License
13 *    along with this program; if not, write to the Free Software
14 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15 */
16
17/*
18 * InfoPanelCellRenderer.java
19 * Copyright (C) 2005 University of Waikato, Hamilton, New Zealand
20 *
21 */
22
23package weka.gui.sql;
24
25import java.awt.Component;
26
27import javax.swing.JLabel;
28import javax.swing.JList;
29import javax.swing.ListCellRenderer;
30
31/**
32 * A specialized renderer that takes care of JLabels in a JList.
33 *
34 * @author  FracPete (fracpete at waikato dot ac dot nz)
35 * @version $Revision: 1.2 $
36 */
37
38public class InfoPanelCellRenderer 
39  extends JLabel
40  implements ListCellRenderer {
41
42  /** for serialization */
43  private static final long serialVersionUID = -533380118807178531L;
44 
45  /**
46   * the constructor
47   */
48  public InfoPanelCellRenderer() {
49    super();
50    setOpaque(true);
51  }
52 
53  /**
54   * Return a component that has been configured to display the specified value.
55   * @param list The JList we're painting.
56   * @param value The value returned by list.getModel().getElementAt(index).
57   * @param index The cells index.
58   * @param isSelected True if the specified cell was selected.
59   * @param cellHasFocus True if the specified cell has the focus.
60   */
61  public Component getListCellRendererComponent(
62      JList list, Object value,
63      int index, boolean isSelected, boolean cellHasFocus) {
64
65    if (value instanceof JLabel) {
66      setIcon(((JLabel) value).getIcon());
67      setText(((JLabel) value).getText());
68    }
69    else {
70      setIcon(null);
71      setText(value.toString());
72    }
73
74    if (isSelected) {
75      setBackground(list.getSelectionBackground());
76      setForeground(list.getSelectionForeground());
77    }
78    else {
79      setBackground(list.getBackground());
80      setForeground(list.getForeground());
81    }
82    setEnabled(list.isEnabled());
83    setFont(list.getFont());
84
85    return this;
86  }
87}
88
Note: See TracBrowser for help on using the repository browser.