1 /*
2 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package sun.swing.table;
26
27 import sun.swing.DefaultLookup;
28
29 import java.awt.Component;
30 import java.awt.Color;
31 import java.awt.FontMetrics;
32 import java.awt.Graphics;
33 import java.awt.Insets;
34 import java.awt.Point;
35 import java.awt.Rectangle;
36 import java.io.Serializable;
37 import javax.swing.*;
38 import javax.swing.plaf.UIResource;
39 import javax.swing.border.Border;
40 import javax.swing.table.*;
41
42 public class DefaultTableCellHeaderRenderer extends DefaultTableCellRenderer
43 implements UIResource {
44 private boolean horizontalTextPositionSet;
45 private Icon sortArrow;
46 private EmptyIcon emptyIcon = new EmptyIcon();
47
48 public DefaultTableCellHeaderRenderer() {
49 setHorizontalAlignment(JLabel.CENTER);
50 }
51
52 public void setHorizontalTextPosition(int textPosition) {
53 horizontalTextPositionSet = true;
54 super.setHorizontalTextPosition(textPosition);
55 }
56
57 public Component getTableCellRendererComponent(JTable table, Object value,
58 boolean isSelected, boolean hasFocus, int row, int column) {
59 Icon sortIcon = null;
60
61 boolean isPaintingForPrint = false;
170 viewR.width = getWidth() - (i.left + i.right);
171 viewR.height = getHeight() - (i.top + i.bottom);
172 SwingUtilities.layoutCompoundLabel(
173 this,
174 fontMetrics,
175 getText(),
176 sortArrow,
177 getVerticalAlignment(),
178 getHorizontalAlignment(),
179 getVerticalTextPosition(),
180 getHorizontalTextPosition(),
181 viewR,
182 iconR,
183 textR,
184 getIconTextGap());
185 int x = getWidth() - i.right - sortArrow.getIconWidth();
186 int y = iconR.y;
187 return new Point(x, y);
188 }
189
190 private class EmptyIcon implements Icon, Serializable {
191 int width = 0;
192 int height = 0;
193 public void paintIcon(Component c, Graphics g, int x, int y) {}
194 public int getIconWidth() { return width; }
195 public int getIconHeight() { return height; }
196 }
197 }
|
1 /*
2 * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package sun.swing.table;
26
27 import sun.swing.DefaultLookup;
28
29 import java.awt.Component;
30 import java.awt.Color;
31 import java.awt.FontMetrics;
32 import java.awt.Graphics;
33 import java.awt.Insets;
34 import java.awt.Point;
35 import java.awt.Rectangle;
36 import java.io.Serializable;
37 import javax.swing.*;
38 import javax.swing.plaf.UIResource;
39 import javax.swing.border.Border;
40 import javax.swing.table.*;
41
42 @SuppressWarnings("serial") // JDK-implementation class
43 public class DefaultTableCellHeaderRenderer extends DefaultTableCellRenderer
44 implements UIResource {
45 private boolean horizontalTextPositionSet;
46 private Icon sortArrow;
47 private EmptyIcon emptyIcon = new EmptyIcon();
48
49 public DefaultTableCellHeaderRenderer() {
50 setHorizontalAlignment(JLabel.CENTER);
51 }
52
53 public void setHorizontalTextPosition(int textPosition) {
54 horizontalTextPositionSet = true;
55 super.setHorizontalTextPosition(textPosition);
56 }
57
58 public Component getTableCellRendererComponent(JTable table, Object value,
59 boolean isSelected, boolean hasFocus, int row, int column) {
60 Icon sortIcon = null;
61
62 boolean isPaintingForPrint = false;
171 viewR.width = getWidth() - (i.left + i.right);
172 viewR.height = getHeight() - (i.top + i.bottom);
173 SwingUtilities.layoutCompoundLabel(
174 this,
175 fontMetrics,
176 getText(),
177 sortArrow,
178 getVerticalAlignment(),
179 getHorizontalAlignment(),
180 getVerticalTextPosition(),
181 getHorizontalTextPosition(),
182 viewR,
183 iconR,
184 textR,
185 getIconTextGap());
186 int x = getWidth() - i.right - sortArrow.getIconWidth();
187 int y = iconR.y;
188 return new Point(x, y);
189 }
190
191 @SuppressWarnings("serial") // JDK-implementation class
192 private class EmptyIcon implements Icon, Serializable {
193 int width = 0;
194 int height = 0;
195 public void paintIcon(Component c, Graphics g, int x, int y) {}
196 public int getIconWidth() { return width; }
197 public int getIconHeight() { return height; }
198 }
199 }
|