author | alexsch |
Fri, 15 Apr 2016 19:15:12 +0400 | |
changeset 37698 | 4d798c873df0 |
parent 36461 | a66465d5a442 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23697 | 2 |
* Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
package javax.swing.plaf.synth; |
|
27 |
||
28 |
import java.awt.*; |
|
29 |
import java.beans.*; |
|
30 |
import javax.swing.*; |
|
31 |
import javax.swing.border.*; |
|
32 |
import javax.swing.plaf.*; |
|
33 |
import javax.swing.plaf.basic.*; |
|
34 |
import javax.swing.table.*; |
|
35 |
import sun.swing.table.*; |
|
36 |
||
37 |
/** |
|
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
38 |
* Provides the Synth L&F UI delegate for |
4394 | 39 |
* {@link javax.swing.table.JTableHeader}. |
2 | 40 |
* |
41 |
* @author Alan Chung |
|
42 |
* @author Philip Milne |
|
4394 | 43 |
* @since 1.7 |
2 | 44 |
*/ |
4394 | 45 |
public class SynthTableHeaderUI extends BasicTableHeaderUI |
46 |
implements PropertyChangeListener, SynthUI { |
|
2 | 47 |
|
48 |
// |
|
49 |
// Instance Variables |
|
50 |
// |
|
51 |
||
52 |
private TableCellRenderer prevRenderer = null; |
|
53 |
||
54 |
private SynthStyle style; |
|
55 |
||
4394 | 56 |
/** |
57 |
* Creates a new UI object for the given component. |
|
58 |
* |
|
59 |
* @param h component to create UI object for |
|
60 |
* @return the UI object |
|
61 |
*/ |
|
2 | 62 |
public static ComponentUI createUI(JComponent h) { |
63 |
return new SynthTableHeaderUI(); |
|
64 |
} |
|
65 |
||
4394 | 66 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
67 |
* {@inheritDoc} |
4394 | 68 |
*/ |
69 |
@Override |
|
2 | 70 |
protected void installDefaults() { |
71 |
prevRenderer = header.getDefaultRenderer(); |
|
72 |
if (prevRenderer instanceof UIResource) { |
|
73 |
header.setDefaultRenderer(new HeaderRenderer()); |
|
74 |
} |
|
75 |
updateStyle(header); |
|
76 |
} |
|
77 |
||
78 |
private void updateStyle(JTableHeader c) { |
|
79 |
SynthContext context = getContext(c, ENABLED); |
|
80 |
SynthStyle oldStyle = style; |
|
81 |
style = SynthLookAndFeel.updateStyle(context, this); |
|
82 |
if (style != oldStyle) { |
|
83 |
if (oldStyle != null) { |
|
84 |
uninstallKeyboardActions(); |
|
85 |
installKeyboardActions(); |
|
86 |
} |
|
87 |
} |
|
88 |
} |
|
89 |
||
4394 | 90 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
91 |
* {@inheritDoc} |
4394 | 92 |
*/ |
93 |
@Override |
|
2 | 94 |
protected void installListeners() { |
95 |
super.installListeners(); |
|
96 |
header.addPropertyChangeListener(this); |
|
97 |
} |
|
98 |
||
4394 | 99 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
100 |
* {@inheritDoc} |
4394 | 101 |
*/ |
102 |
@Override |
|
2 | 103 |
protected void uninstallDefaults() { |
104 |
if (header.getDefaultRenderer() instanceof HeaderRenderer) { |
|
105 |
header.setDefaultRenderer(prevRenderer); |
|
106 |
} |
|
107 |
||
108 |
SynthContext context = getContext(header, ENABLED); |
|
109 |
||
110 |
style.uninstallDefaults(context); |
|
111 |
style = null; |
|
112 |
} |
|
113 |
||
4394 | 114 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
115 |
* {@inheritDoc} |
4394 | 116 |
*/ |
117 |
@Override |
|
2 | 118 |
protected void uninstallListeners() { |
119 |
header.removePropertyChangeListener(this); |
|
120 |
super.uninstallListeners(); |
|
121 |
} |
|
122 |
||
4394 | 123 |
/** |
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
124 |
* Notifies this UI delegate to repaint the specified component. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
125 |
* This method paints the component background, then calls |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
126 |
* the {@link #paint(SynthContext,Graphics)} method. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
127 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
128 |
* <p>In general, this method does not need to be overridden by subclasses. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
129 |
* All Look and Feel rendering code should reside in the {@code paint} method. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
130 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
131 |
* @param g the {@code Graphics} object used for painting |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
132 |
* @param c the component being painted |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
133 |
* @see #paint(SynthContext,Graphics) |
4394 | 134 |
*/ |
135 |
@Override |
|
2 | 136 |
public void update(Graphics g, JComponent c) { |
137 |
SynthContext context = getContext(c); |
|
138 |
||
139 |
SynthLookAndFeel.update(context, g); |
|
140 |
context.getPainter().paintTableHeaderBackground(context, |
|
141 |
g, 0, 0, c.getWidth(), c.getHeight()); |
|
142 |
paint(context, g); |
|
143 |
} |
|
144 |
||
4394 | 145 |
/** |
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
146 |
* Paints the specified component according to the Look and Feel. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
147 |
* <p>This method is not used by Synth Look and Feel. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
148 |
* Painting is handled by the {@link #paint(SynthContext,Graphics)} method. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
149 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
150 |
* @param g the {@code Graphics} object used for painting |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
151 |
* @param c the component being painted |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
152 |
* @see #paint(SynthContext,Graphics) |
4394 | 153 |
*/ |
154 |
@Override |
|
2 | 155 |
public void paint(Graphics g, JComponent c) { |
156 |
SynthContext context = getContext(c); |
|
157 |
||
158 |
paint(context, g); |
|
159 |
} |
|
160 |
||
4394 | 161 |
/** |
162 |
* Paints the specified component. |
|
163 |
* |
|
164 |
* @param context context for the component being painted |
|
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
165 |
* @param g the {@code Graphics} object used for painting |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
166 |
* @see #update(Graphics,JComponent) |
4394 | 167 |
*/ |
2 | 168 |
protected void paint(SynthContext context, Graphics g) { |
169 |
super.paint(g, context.getComponent()); |
|
170 |
} |
|
171 |
||
4394 | 172 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
173 |
* {@inheritDoc} |
4394 | 174 |
*/ |
175 |
@Override |
|
2 | 176 |
public void paintBorder(SynthContext context, Graphics g, int x, |
177 |
int y, int w, int h) { |
|
178 |
context.getPainter().paintTableHeaderBorder(context, g, x, y, w, h); |
|
179 |
} |
|
180 |
// |
|
181 |
// SynthUI |
|
182 |
// |
|
4394 | 183 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
184 |
* {@inheritDoc} |
4394 | 185 |
*/ |
186 |
@Override |
|
2 | 187 |
public SynthContext getContext(JComponent c) { |
4394 | 188 |
return getContext(c, SynthLookAndFeel.getComponentState(c)); |
2 | 189 |
} |
190 |
||
191 |
private SynthContext getContext(JComponent c, int state) { |
|
25100 | 192 |
return SynthContext.getContext(c, style, state); |
2 | 193 |
} |
194 |
||
4394 | 195 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
196 |
* {@inheritDoc} |
4394 | 197 |
*/ |
198 |
@Override |
|
199 |
protected void rolloverColumnUpdated(int oldColumn, int newColumn) { |
|
200 |
header.repaint(header.getHeaderRect(oldColumn)); |
|
201 |
header.repaint(header.getHeaderRect(newColumn)); |
|
2 | 202 |
} |
203 |
||
4394 | 204 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
205 |
* {@inheritDoc} |
4394 | 206 |
*/ |
207 |
@Override |
|
2 | 208 |
public void propertyChange(PropertyChangeEvent evt) { |
209 |
if (SynthLookAndFeel.shouldUpdateStyle(evt)) { |
|
210 |
updateStyle((JTableHeader)evt.getSource()); |
|
211 |
} |
|
212 |
} |
|
213 |
||
23697 | 214 |
@SuppressWarnings("serial") // Superclass is not serializable across versions |
2 | 215 |
private class HeaderRenderer extends DefaultTableCellHeaderRenderer { |
216 |
HeaderRenderer() { |
|
217 |
setHorizontalAlignment(JLabel.LEADING); |
|
2658 | 218 |
setName("TableHeader.renderer"); |
2 | 219 |
} |
220 |
||
221 |
@Override |
|
222 |
public Component getTableCellRendererComponent(JTable table, Object value, |
|
223 |
boolean isSelected, |
|
224 |
boolean hasFocus, |
|
225 |
int row, int column) { |
|
226 |
||
227 |
boolean hasRollover = (column == getRolloverColumn()); |
|
228 |
if (isSelected || hasRollover || hasFocus) { |
|
36461
a66465d5a442
8020039: SynthTableHeaderUI refers to possibly null parameter in cell renderer
psadhukhan
parents:
25859
diff
changeset
|
229 |
boolean enabled = (table == null)? true : table.isEnabled(); |
2 | 230 |
SynthLookAndFeel.setSelectedUI((SynthLabelUI)SynthLookAndFeel. |
231 |
getUIOfType(getUI(), SynthLabelUI.class), |
|
36461
a66465d5a442
8020039: SynthTableHeaderUI refers to possibly null parameter in cell renderer
psadhukhan
parents:
25859
diff
changeset
|
232 |
isSelected, hasFocus, enabled, |
2 | 233 |
hasRollover); |
234 |
} else { |
|
235 |
SynthLookAndFeel.resetSelectedUI(); |
|
236 |
} |
|
237 |
||
2658 | 238 |
//stuff a variable into the client property of this renderer indicating the sort order, |
239 |
//so that different rendering can be done for the header based on sorted state. |
|
25565
ce603b34c98d
8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents:
25100
diff
changeset
|
240 |
RowSorter<?> rs = table == null ? null : table.getRowSorter(); |
2658 | 241 |
java.util.List<? extends RowSorter.SortKey> sortKeys = rs == null ? null : rs.getSortKeys(); |
242 |
if (sortKeys != null && sortKeys.size() > 0 && sortKeys.get(0).getColumn() == |
|
243 |
table.convertColumnIndexToModel(column)) { |
|
244 |
switch(sortKeys.get(0).getSortOrder()) { |
|
245 |
case ASCENDING: |
|
246 |
putClientProperty("Table.sortOrder", "ASCENDING"); |
|
247 |
break; |
|
248 |
case DESCENDING: |
|
249 |
putClientProperty("Table.sortOrder", "DESCENDING"); |
|
250 |
break; |
|
251 |
case UNSORTED: |
|
252 |
putClientProperty("Table.sortOrder", "UNSORTED"); |
|
253 |
break; |
|
254 |
default: |
|
255 |
throw new AssertionError("Cannot happen"); |
|
256 |
} |
|
257 |
} else { |
|
258 |
putClientProperty("Table.sortOrder", "UNSORTED"); |
|
259 |
} |
|
260 |
||
2 | 261 |
super.getTableCellRendererComponent(table, value, isSelected, |
262 |
hasFocus, row, column); |
|
263 |
||
264 |
return this; |
|
265 |
} |
|
266 |
||
2658 | 267 |
@Override |
2 | 268 |
public void setBorder(Border border) { |
269 |
if (border instanceof SynthBorder) { |
|
270 |
super.setBorder(border); |
|
271 |
} |
|
272 |
} |
|
273 |
} |
|
274 |
} |