[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] FYI: Metal ScrollBar
From: |
Roman Kennke |
Subject: |
[cp-patches] FYI: Metal ScrollBar |
Date: |
Wed, 27 Apr 2005 14:40:03 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021204 |
The attached patch implements a nice metal-ish ScrollBar. I committed this.
2005-04-27 Roman Kennke <address@hidden>
* javax/swing/plaf/basic/BasicScrollBarUI
(getThumbBounds): Do not make thumb smaller than
minimumThumbSize.
* javax/swing/plaf/metal/MetalLookAndFeel
(initComponentDefaults): Added color defaults for ScrollBar.
* javax/swing/plaf/metal/MetalScrollBarUI
(paintThumb): Added.
(getMinimumThumbSize): Added.
/Roman
Index: javax/swing/plaf/basic/BasicScrollBarUI.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicScrollBarUI.java,v
retrieving revision 1.18
diff -u -r1.18 BasicScrollBarUI.java
--- javax/swing/plaf/basic/BasicScrollBarUI.java 27 Apr 2005 10:16:21
-0000 1.18
+++ javax/swing/plaf/basic/BasicScrollBarUI.java 27 Apr 2005 12:37:58
-0000
@@ -743,7 +743,8 @@
thumbRect.x += (value - min) * trackRect.width / (max - min);
thumbRect.y = trackRect.y;
- thumbRect.width = extent * trackRect.width / (max - min);
+ thumbRect.width = Math.max(extent * trackRect.width / (max - min),
+ getMinimumThumbSize().width);
thumbRect.height = trackRect.height;
}
else
@@ -752,7 +753,8 @@
thumbRect.y = trackRect.y + value * trackRect.height / (max - min);
thumbRect.width = trackRect.width;
- thumbRect.height = extent * trackRect.height / (max - min);
+ thumbRect.height = Math.max(extent * trackRect.height / (max - min),
+ getMinimumThumbSize().height);
}
return thumbRect;
}
Index: javax/swing/plaf/metal/MetalLookAndFeel.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalLookAndFeel.java,v
retrieving revision 1.20
diff -u -r1.20 MetalLookAndFeel.java
--- javax/swing/plaf/metal/MetalLookAndFeel.java 27 Apr 2005 10:21:29
-0000 1.20
+++ javax/swing/plaf/metal/MetalLookAndFeel.java 27 Apr 2005 12:37:59
-0000
@@ -495,6 +495,12 @@
"MenuItem.background", new ColorUIResource(getControl()),
"MenuItem.font", getControlTextFont(),
"ScrollBar.background", new ColorUIResource(getControl()),
+ "ScrollBar.shadow", new ColorUIResource(getControlShadow()),
+ "ScrollBar.thumb", new ColorUIResource(getPrimaryControlShadow()),
+ "ScrollBar.thumbDarkShadow",
+ new ColorUIResource(getPrimaryControlDarkShadow()),
+ "ScrollBar.thumbHighlight",
+ new ColorUIResource(getPrimaryControl()),
"PopupMenu.border", new MetalBorders.PopupMenuBorder()
};
defaults.putDefaults(myDefaults);
Index: javax/swing/plaf/metal/MetalScrollBarUI.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalScrollBarUI.java,v
retrieving revision 1.2
diff -u -r1.2 MetalScrollBarUI.java
--- javax/swing/plaf/metal/MetalScrollBarUI.java 18 Apr 2005 10:25:01
-0000 1.2
+++ javax/swing/plaf/metal/MetalScrollBarUI.java 27 Apr 2005 12:37:59
-0000
@@ -38,9 +38,14 @@
package javax.swing.plaf.metal;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Rectangle;
import java.util.HashMap;
import javax.swing.JComponent;
+import javax.swing.UIDefaults;
+import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicScrollBarUI;
@@ -48,6 +53,9 @@
extends BasicScrollBarUI
{
+ /** The minimum thumb size */
+ private static final Dimension MIN_THUMB_SIZE = new Dimension(18, 18);
+
// FIXME: maybe replace by a Map of instances when this becomes stateful
/** The shared UI instance for JScrollBars. */
private static HashMap instances = null;
@@ -84,4 +92,74 @@
return instance;
}
+
+ /**
+ * Paints the slider button of the ScrollBar.
+ *
+ * @param g the Graphics context to use
+ * @param c the JComponent on which we paint
+ * @param thumbBounds the rectangle that is the slider button
+ */
+ protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds)
+ {
+ // first we fill the background
+ g.setColor(thumbColor);
+ g.fillRect(thumbBounds.x, thumbBounds.y, thumbBounds.width,
+ thumbBounds.height);
+
+ // draw the outer dark line
+ g.setColor(thumbDarkShadowColor);
+ g.drawRect(thumbBounds.x, thumbBounds.y, thumbBounds.width - 1,
+ thumbBounds.height - 1);
+
+ // draw the inner light line
+ g.setColor(thumbHighlightColor);
+ g.drawLine(thumbBounds.x + 1, thumbBounds.y + 1,
+ thumbBounds.x + thumbBounds.width - 2,
+ thumbBounds.y + 1);
+ g.drawLine(thumbBounds.x + 1, thumbBounds.y + 1,
+ thumbBounds.x + 1,
+ thumbBounds.y + thumbBounds.height - 2);
+
+ // draw the shadow line
+ UIDefaults def = UIManager.getLookAndFeelDefaults();
+ g.setColor(def.getColor("ScrollBar.shadow"));
+ g.drawLine(thumbBounds.x + 1, thumbBounds.y + thumbBounds.height,
+ thumbBounds.x + thumbBounds.width,
+ thumbBounds.y + thumbBounds.height);
+
+ // draw the pattern
+ int xOff = 0;
+ for (int y = thumbBounds.y + 4;
+ y < (thumbBounds.y + thumbBounds.height - 4); y++)
+ {
+ // set color alternating with every line
+ if ((y % 2) == 0)
+ g.setColor(thumbHighlightColor);
+ else
+ g.setColor(thumbDarkShadowColor);
+
+ for (int x = thumbBounds.x + 3 + (xOff);
+ x < (thumbBounds.x + thumbBounds.width - 3); x = x + 4)
+ {
+ g.drawLine(x, y, x, y);
+ }
+
+ // increase x offset
+ xOff++;
+ if (xOff > 3)
+ xOff = 0;
+
+ }
+ }
+
+ /**
+ * This method returns the minimum thumb size.
+ *
+ * @return The minimum thumb size.
+ */
+ protected Dimension getMinimumThumbSize()
+ {
+ return MIN_THUMB_SIZE;
+ }
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [cp-patches] FYI: Metal ScrollBar,
Roman Kennke <=