4252173: Inability to reuse the HorizontalSliderThumbIcon
Removed casting component to JSlider from MetalIconFactory Reviewed-by: alexp
This commit is contained in:
parent
8dff6c648b
commit
9d90ce5781
@ -2278,18 +2278,16 @@ private static class VerticalSliderThumbIcon implements Icon, Serializable, UIRe
|
||||
}
|
||||
|
||||
public void paintIcon( Component c, Graphics g, int x, int y ) {
|
||||
JSlider slider = (JSlider)c;
|
||||
|
||||
boolean leftToRight = MetalUtils.isLeftToRight(slider);
|
||||
boolean leftToRight = MetalUtils.isLeftToRight(c);
|
||||
|
||||
g.translate( x, y );
|
||||
|
||||
// Draw the frame
|
||||
if ( slider.hasFocus() ) {
|
||||
if ( c.hasFocus() ) {
|
||||
g.setColor( MetalLookAndFeel.getPrimaryControlInfo() );
|
||||
}
|
||||
else {
|
||||
g.setColor( slider.isEnabled() ? MetalLookAndFeel.getPrimaryControlInfo() :
|
||||
g.setColor( c.isEnabled() ? MetalLookAndFeel.getPrimaryControlInfo() :
|
||||
MetalLookAndFeel.getControlDarkShadow() );
|
||||
}
|
||||
|
||||
@ -2309,7 +2307,7 @@ private static class VerticalSliderThumbIcon implements Icon, Serializable, UIRe
|
||||
}
|
||||
|
||||
// Fill in the background
|
||||
if ( slider.hasFocus() ) {
|
||||
if ( c.hasFocus() ) {
|
||||
g.setColor( c.getForeground() );
|
||||
}
|
||||
else {
|
||||
@ -2338,8 +2336,8 @@ private static class VerticalSliderThumbIcon implements Icon, Serializable, UIRe
|
||||
|
||||
// Draw the bumps
|
||||
int offset = (leftToRight) ? 2 : 8;
|
||||
if ( slider.isEnabled() ) {
|
||||
if ( slider.hasFocus() ) {
|
||||
if ( c.isEnabled() ) {
|
||||
if ( c.hasFocus() ) {
|
||||
primaryBumps.paintIcon( c, g, offset, 2 );
|
||||
}
|
||||
else {
|
||||
@ -2348,8 +2346,8 @@ private static class VerticalSliderThumbIcon implements Icon, Serializable, UIRe
|
||||
}
|
||||
|
||||
// Draw the highlight
|
||||
if ( slider.isEnabled() ) {
|
||||
g.setColor( slider.hasFocus() ? MetalLookAndFeel.getPrimaryControl()
|
||||
if ( c.isEnabled() ) {
|
||||
g.setColor( c.hasFocus() ? MetalLookAndFeel.getPrimaryControl()
|
||||
: MetalLookAndFeel.getControlHighlight() );
|
||||
if (leftToRight) {
|
||||
g.drawLine( 1, 1, 8, 1 );
|
||||
@ -2389,16 +2387,14 @@ private static class HorizontalSliderThumbIcon implements Icon, Serializable, UI
|
||||
}
|
||||
|
||||
public void paintIcon( Component c, Graphics g, int x, int y ) {
|
||||
JSlider slider = (JSlider)c;
|
||||
|
||||
g.translate( x, y );
|
||||
|
||||
// Draw the frame
|
||||
if ( slider.hasFocus() ) {
|
||||
if ( c.hasFocus() ) {
|
||||
g.setColor( MetalLookAndFeel.getPrimaryControlInfo() );
|
||||
}
|
||||
else {
|
||||
g.setColor( slider.isEnabled() ? MetalLookAndFeel.getPrimaryControlInfo() :
|
||||
g.setColor( c.isEnabled() ? MetalLookAndFeel.getPrimaryControlInfo() :
|
||||
MetalLookAndFeel.getControlDarkShadow() );
|
||||
}
|
||||
|
||||
@ -2409,7 +2405,7 @@ private static class HorizontalSliderThumbIcon implements Icon, Serializable, UI
|
||||
g.drawLine( 7,15 , 14,8 ); // right slant
|
||||
|
||||
// Fill in the background
|
||||
if ( slider.hasFocus() ) {
|
||||
if ( c.hasFocus() ) {
|
||||
g.setColor( c.getForeground() );
|
||||
}
|
||||
else {
|
||||
@ -2425,8 +2421,8 @@ private static class HorizontalSliderThumbIcon implements Icon, Serializable, UI
|
||||
g.drawLine( 7,14 , 7,14 );
|
||||
|
||||
// Draw the bumps
|
||||
if ( slider.isEnabled() ) {
|
||||
if ( slider.hasFocus() ) {
|
||||
if ( c.isEnabled() ) {
|
||||
if ( c.hasFocus() ) {
|
||||
primaryBumps.paintIcon( c, g, 2, 2 );
|
||||
}
|
||||
else {
|
||||
@ -2435,8 +2431,8 @@ private static class HorizontalSliderThumbIcon implements Icon, Serializable, UI
|
||||
}
|
||||
|
||||
// Draw the highlight
|
||||
if ( slider.isEnabled() ) {
|
||||
g.setColor( slider.hasFocus() ? MetalLookAndFeel.getPrimaryControl()
|
||||
if ( c.isEnabled() ) {
|
||||
g.setColor( c.hasFocus() ? MetalLookAndFeel.getPrimaryControl()
|
||||
: MetalLookAndFeel.getControlHighlight() );
|
||||
g.drawLine( 1, 1, 13, 1 );
|
||||
g.drawLine( 1, 1, 1, 8 );
|
||||
|
58
jdk/test/javax/swing/JFileChooser/4252173/bug4252173.java
Normal file
58
jdk/test/javax/swing/JFileChooser/4252173/bug4252173.java
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||
* have any questions.
|
||||
*/
|
||||
|
||||
/* @test
|
||||
@bug 4252173
|
||||
@summary Inability to reuse the HorizontalSliderThumbIcon
|
||||
@author Pavel Porvatov
|
||||
@run main bug4252173
|
||||
*/
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.metal.DefaultMetalTheme;
|
||||
import javax.swing.plaf.metal.MetalLookAndFeel;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class bug4252173 {
|
||||
public static void main(String[] args) throws InvocationTargetException, InterruptedException {
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
public void run() {
|
||||
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
|
||||
|
||||
JComponent component = new JLabel();
|
||||
|
||||
Icon horizontalThumbIcon = UIManager.getIcon("Slider.horizontalThumbIcon");
|
||||
|
||||
Icon verticalThumbIcon = UIManager.getIcon("Slider.verticalThumbIcon");
|
||||
|
||||
Graphics g = new BufferedImage(100, 100, BufferedImage.TYPE_4BYTE_ABGR).getGraphics();
|
||||
|
||||
horizontalThumbIcon.paintIcon(component, g, 0, 0);
|
||||
|
||||
verticalThumbIcon.paintIcon(component, g, 0, 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user