FSF GCC merge 02/23/03
[official-gcc.git] / libjava / javax / swing / plaf / basic / BasicListUI.java
blobabac504503119617b683290356149cfa35abe226
1 package javax.swing.plaf.basic;
3 import javax.swing.plaf.*;
4 import javax.swing.*;
5 import java.awt.*;
8 public class BasicListUI extends ListUI
10 int gap_between_cells;
11 Color textColor, disabledTextColor, pressedBackgroundColor, normalBackgroundColor;
14 public static ComponentUI createUI(final JComponent c)
16 return new BasicButtonUI();
20 public void installUI(final JComponent c)
22 super.installUI(c);
24 textColor = new Color(0,0,0);
25 disabledTextColor = new Color(130, 130, 130);
26 pressedBackgroundColor = new Color(150,150,150);
27 normalBackgroundColor = new Color(192,192,192);
30 public Dimension getPreferredSize(JComponent c)
32 JList l = (JList) c;
34 System.out.println("XXXXXXXXXXXXXXXxx getPreferredSize------------> " + l);
37 int rows = l.getVisibleRowCount();
39 ListCellRenderer render = l.getCellRenderer();
41 int width = 200;
42 int height = rows * 16;
44 if (l.getModel().getSize() == 0)
46 return new Dimension(width, height);
49 System.out.println("BASIC_LIST_UI ====-> " + l.getModel().getElementAt(0));
51 Component elt = render.getListCellRendererComponent(l,
52 l.getModel().getElementAt(0),
53 0,
54 false,
55 false);
56 Dimension a = elt.getPreferredSize();
57 if (a == null)
59 return new Dimension(width, height);
62 return new Dimension(a.width,
63 a.height * rows);
66 public void paintBackground(Graphics g,
67 JComponent c)
69 Dimension size = getPreferredSize(c);
71 g.setColor(normalBackgroundColor);
72 g.fillRect(0,0,size.width, size.height);
75 public void paint(Graphics g,
76 JComponent c)
78 JList l = (JList) c;
80 int rows = l.getVisibleRowCount();
82 ListCellRenderer render = l.getCellRenderer();
84 System.out.println("RENDER-JLIST: " + rows + ", " + l.getModel().getSize());
86 paintBackground(g, c);
88 if (l.getModel().getSize() == 0)
89 return;
91 // use element 0 to figure out how big we are:
92 Component elt = render.getListCellRendererComponent(l,
93 l.getModel().getElementAt(0),
94 0,
95 false,
96 false);
97 Dimension dim = elt.getPreferredSize();
99 Rectangle a = new Rectangle(0,
101 dim.width,
102 dim.height);
104 for (int i=0;i<l.getModel().getSize();i++)
106 boolean is_sel = false;
107 boolean has_focus = false;
109 Component comp = render.getListCellRendererComponent(l,
110 l.getModel().getElementAt(i),
112 is_sel,
113 has_focus);
115 //System.out.println("AAAAA=> " + a + ", " + comp + ", index = " + i);
117 comp.setBounds(a);
119 comp.paint(g);
121 a.y += dim.height + gap_between_cells;