Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / classpath / javax / swing / plaf / basic / BasicTableHeaderUI.java
blobec0467a74f3bdc22246c7ecaa27acf364c8b7195
1 /* BasicTableHeaderUI.java --
2 Copyright (C) 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package javax.swing.plaf.basic;
41 import java.awt.Component;
42 import java.awt.Dimension;
43 import java.awt.Graphics;
44 import java.awt.Rectangle;
45 import java.awt.event.MouseEvent;
47 import javax.swing.CellRendererPane;
48 import javax.swing.JComponent;
49 import javax.swing.LookAndFeel;
50 import javax.swing.UIManager;
51 import javax.swing.border.Border;
52 import javax.swing.event.MouseInputListener;
53 import javax.swing.plaf.ComponentUI;
54 import javax.swing.plaf.TableHeaderUI;
55 import javax.swing.table.JTableHeader;
56 import javax.swing.table.TableCellRenderer;
57 import javax.swing.table.TableColumn;
58 import javax.swing.table.TableColumnModel;
60 public class BasicTableHeaderUI extends TableHeaderUI
63 public static ComponentUI createUI(JComponent h)
65 return new BasicTableHeaderUI();
68 protected JTableHeader header;
69 protected MouseInputListener mouseInputListener;
70 protected CellRendererPane rendererPane;
71 protected Border cellBorder;
73 public class MouseInputHandler implements MouseInputListener
75 public void mouseClicked(MouseEvent e)
77 // TODO: Implement this properly.
80 public void mouseDragged(MouseEvent e)
82 // TODO: Implement this properly.
85 public void mouseEntered(MouseEvent e)
87 // TODO: Implement this properly.
90 public void mouseExited(MouseEvent e)
92 // TODO: Implement this properly.
95 public void mouseMoved(MouseEvent e)
97 // TODO: Implement this properly.
100 public void mousePressed(MouseEvent e)
102 // TODO: Implement this properly.
105 public void mouseReleased(MouseEvent e)
107 // TODO: Implement this properly.
111 protected MouseInputListener createMouseInputListener()
113 return new MouseInputHandler();
116 public BasicTableHeaderUI()
118 mouseInputListener = createMouseInputListener();
121 protected void installDefaults()
123 LookAndFeel.installColorsAndFont(header, "TableHeader.background",
124 "TableHeader.foreground",
125 "TableHeader.font");
126 cellBorder = UIManager.getBorder("TableHeader.cellBorder");
129 protected void installKeyboardActions()
131 // TODO: Implement this properly.
134 protected void installListeners()
136 header.addMouseListener(mouseInputListener);
139 public void installUI(JComponent c)
141 header = (JTableHeader) c;
142 installDefaults();
143 installKeyboardActions();
144 installListeners();
147 protected void uninstallDefaults()
149 header.setBackground(null);
150 header.setForeground(null);
151 header.setFont(null);
154 protected void uninstallKeyboardActions()
156 // TODO: Implement this properly.
159 protected void uninstallListeners()
161 header.removeMouseListener(mouseInputListener);
164 public void uninstallUI(JComponent c)
166 uninstallListeners();
167 uninstallKeyboardActions();
168 uninstallDefaults();
171 public void paint(Graphics gfx, JComponent c)
173 TableColumnModel cmod = header.getColumnModel();
174 int ncols = cmod.getColumnCount();
175 if (ncols == 0)
176 return;
178 Rectangle clip = gfx.getClipBounds();
179 TableCellRenderer defaultRend = header.getDefaultRenderer();
181 for (int i = 0; i < ncols; ++i)
183 Rectangle bounds = header.getHeaderRect(i);
184 if (bounds.intersects(clip))
186 Rectangle oldClip = gfx.getClipBounds();
187 TableColumn col = cmod.getColumn(i);
188 TableCellRenderer rend = col.getHeaderRenderer();
189 if (rend == null)
190 rend = defaultRend;
191 Object val = col.getHeaderValue();
192 Component comp = rend.getTableCellRendererComponent(header.getTable(),
193 val,
194 false, // isSelected
195 false, // isFocused
196 -1, i);
197 comp.setFont(header.getFont());
198 comp.setBackground(header.getBackground());
199 comp.setForeground(header.getForeground());
200 if (comp instanceof JComponent)
201 ((JComponent)comp).setBorder(cellBorder);
202 gfx.translate(bounds.x, bounds.y);
203 gfx.setClip(0, 0, bounds.width, bounds.height);
204 comp.setSize(bounds.width, bounds.height);
205 comp.setLocation(0,0);
206 comp.paint(gfx);
207 gfx.translate(-bounds.x, -bounds.y);
208 gfx.setClip(oldClip);
214 public Dimension getPreferredSize(JComponent c)
216 TableColumnModel cmod = header.getColumnModel();
217 TableCellRenderer defaultRend = header.getDefaultRenderer();
218 int ncols = cmod.getColumnCount();
219 Dimension ret = new Dimension(0,0);
220 int spacing = 0;
222 if (header.getTable() != null
223 && header.getTable().getIntercellSpacing() != null)
224 spacing = header.getTable().getIntercellSpacing().width;
226 for (int i = 0; i < ncols; ++i)
228 TableColumn col = cmod.getColumn(i);
229 TableCellRenderer rend = col.getHeaderRenderer();
230 if (rend == null)
231 rend = defaultRend;
232 Object val = col.getHeaderValue();
233 Component comp = rend.getTableCellRendererComponent(header.getTable(),
234 val,
235 false, // isSelected
236 false, // isFocused
237 -1, i);
238 comp.setFont(header.getFont());
239 comp.setBackground(header.getBackground());
240 comp.setForeground(header.getForeground());
241 if (comp instanceof JComponent)
242 ((JComponent)comp).setBorder(cellBorder);
244 Dimension d = comp.getPreferredSize();
245 ret.width += spacing;
246 ret.height = Math.max(d.height, ret.height);
248 ret.width = cmod.getTotalColumnWidth();
249 return ret;