Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/livingpaper/hansa/ColorCellRenderer.java


1   //
2   //  ColorCellRenderer.java
3   //  Hansa
4   //
5   //  Created by mikel evins
6   //  Copyright (c) 2002 whoever owns this copyright
7   //  under whatever terms
8   //
9   
10  package org.livingpaper.hansa;
11  
12  import java.awt.*;
13  import javax.swing.*;
14  
15  public class ColorCellRenderer extends JLabel implements ListCellRenderer {
16    public ColorCellRenderer() {
17      }
18  
19    public static ColoredBox makeColoredBox(Color color, String description){
20      return new ColoredBox(color, description);
21    }
22  
23      public Component getListCellRendererComponent(
24                            JList list,
25                            Object value,
26                            int index,
27                            boolean isSelected,
28                            boolean cellHasFocus)
29      {
30          if (isSelected) {
31              setBackground(list.getSelectionBackground());
32              setForeground(list.getSelectionForeground());
33          } else {
34              setBackground(list.getBackground());
35              setForeground(list.getForeground());
36          }
37      
38      ColoredBox icon = (ColoredBox)value;
39      setText(icon.getDescription());
40          setIcon(icon);
41          return this; 
42      }   
43  
44    public static class ColoredBox implements Icon {
45      Color color;
46      String mDescription;
47      public ColoredBox (Color c, String desc) {
48        color = c;
49        mDescription = desc;
50      }
51      public void paintIcon (Component c, Graphics g, int x, int y) {
52        g.setColor(color);
53        g.fillRect (x, y, getIconWidth(), getIconHeight());
54      }
55      public int getIconWidth() {
56        return 40;
57      }
58      public int getIconHeight() { 
59        return 10;
60      }
61      public String getDescription(){
62        return mDescription;
63      }
64    }
65  }