Browse Source

make plain knob circle and fix the problem with repainting while dragging

master
Konstantin Bulenkov 8 years ago
parent
commit
7e95cbf661
  1. 38
      src/com/bulenkov/darcula/ui/DarculaSliderUI.java

38
src/com/bulenkov/darcula/ui/DarculaSliderUI.java

@ -27,6 +27,7 @@ import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicSliderUI; import javax.swing.plaf.basic.BasicSliderUI;
import java.awt.*; import java.awt.*;
import java.awt.geom.Area; import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D; import java.awt.geom.RoundRectangle2D;
@ -53,10 +54,10 @@ public class DarculaSliderUI extends BasicSliderUI {
public void paintTrack(Graphics g2d) { public void paintTrack(Graphics g2d) {
Graphics2D g = (Graphics2D) g2d; Graphics2D g = (Graphics2D) g2d;
Rectangle trackBounds = trackRect; Rectangle trackBounds = trackRect;
final int arc = JBUI.scale(5); final int arc = JBUI.scale(6);
int trackSize = JBUI.scale(5); int trackSize = JBUI.scale(6);
final GraphicsConfig config = GraphicsUtil.setupAAPainting(g); final GraphicsConfig config = GraphicsUtil.setupAAPainting(g);
final Color bg = ColorUtil.fromHex("2b2b2b"); final Color bg = getTrackBackground();
final Color selection = slider.isEnabled() ? getSelectedTrackColor() : getDisabledTickColor(); final Color selection = slider.isEnabled() ? getSelectedTrackColor() : getDisabledTickColor();
if (slider.getOrientation() == JSlider.HORIZONTAL) { if (slider.getOrientation() == JSlider.HORIZONTAL) {
int cy = (trackBounds.height / 2) - trackSize / 2; int cy = (trackBounds.height / 2) - trackSize / 2;
@ -81,6 +82,19 @@ public class DarculaSliderUI extends BasicSliderUI {
config.restore(); config.restore();
} }
@Override
protected Dimension getThumbSize() {
if (isPlainThumb()) {
return new Dimension(JBUI.scale(20), JBUI.scale(20));
}
return super.getThumbSize();
}
@NotNull
protected Color getTrackBackground() {
return ColorUtil.fromHex("2b2b2b");
}
@NotNull @NotNull
protected Color getSelectedTrackColor() { protected Color getSelectedTrackColor() {
return ColorUtil.fromHex("888888"); return ColorUtil.fromHex("888888");
@ -160,15 +174,11 @@ public class DarculaSliderUI extends BasicSliderUI {
g.setColor(slider.getBackground().darker()); g.setColor(slider.getBackground().darker());
} }
Boolean paintThumbArrowShape =
(Boolean)slider.getClientProperty("Slider.paintThumbArrowShape");
if ((!slider.getPaintTicks() && paintThumbArrowShape == null) ||
paintThumbArrowShape == Boolean.FALSE) {
// "plain" version if (isPlainThumb()) {
final RoundRectangle2D.Double thumb = new RoundRectangle2D.Double(0, 0, w, h, JBUI.scale(6), JBUI.scale(6)); double r = slider.getOrientation() == JSlider.HORIZONTAL ? h : w;
final RoundRectangle2D.Double innerThumb = new RoundRectangle2D.Double(1, 1, w-2, h-2, JBUI.scale(6)-2, JBUI.scale(6)-2); final Ellipse2D.Double thumb = new Ellipse2D.Double(0, 0, r, r);
final Ellipse2D.Double innerThumb = new Ellipse2D.Double(1, 1, r-2, r-2);
g.setColor(ColorUtil.fromHex("555555")); g.setColor(ColorUtil.fromHex("555555"));
((Graphics2D) g).fill(thumb); ((Graphics2D) g).fill(thumb);
g.setColor(slider.isEnabled() ? getSelectedTrackColor() : getDisabledTickColor()); g.setColor(slider.isEnabled() ? getSelectedTrackColor() : getDisabledTickColor());
@ -244,4 +254,10 @@ public class DarculaSliderUI extends BasicSliderUI {
g.translate(-knobBounds.x, -knobBounds.y); g.translate(-knobBounds.x, -knobBounds.y);
config.restore(); config.restore();
} }
protected boolean isPlainThumb() {
Boolean paintThumbArrowShape = (Boolean)slider.getClientProperty("Slider.paintThumbArrowShape");
return (!slider.getPaintTicks() && paintThumbArrowShape == null) ||
paintThumbArrowShape == Boolean.FALSE;
}
} }

Loading…
Cancel
Save