diff options
Diffstat (limited to 'javax/swing/plaf/basic/BasicSliderUI.java')
-rw-r--r-- | javax/swing/plaf/basic/BasicSliderUI.java | 94 |
1 files changed, 49 insertions, 45 deletions
diff --git a/javax/swing/plaf/basic/BasicSliderUI.java b/javax/swing/plaf/basic/BasicSliderUI.java index 073e42c0f..7334b2e0e 100644 --- a/javax/swing/plaf/basic/BasicSliderUI.java +++ b/javax/swing/plaf/basic/BasicSliderUI.java @@ -58,7 +58,6 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.Dictionary; import java.util.Enumeration; - import javax.swing.BoundedRangeModel; import javax.swing.JComponent; import javax.swing.JLabel; @@ -152,7 +151,6 @@ public class BasicSliderUI extends SliderUI { // Maximum, minimum, and extent values will be taken // care of automatically when the slider is repainted. - // Only thing that needs recalculation is the thumb. calculateThumbLocation(); slider.repaint(); @@ -232,12 +230,12 @@ public class BasicSliderUI extends SliderUI slider.getModel().addChangeListener(changeListener); calculateThumbLocation(); } + // elif the componentOrientation changes (this is a bound property, // just undocumented) we change leftToRightCache. In Sun's // implementation, the LTR cache changes on a repaint. This is strange // since there is no need to do so. We could events here and // update the cache. - // elif the border/insets change, we recalculateInsets. slider.repaint(); } @@ -330,8 +328,9 @@ public class BasicSliderUI extends SliderUI /** The current Y position of the mouse. */ protected int currentMouseY; - /** The offset between the current slider value - and the cursor's position. */ + /** + * The offset between the current slider value and the cursor's position. + */ protected int offset; /** @@ -390,9 +389,6 @@ public class BasicSliderUI extends SliderUI if (slider.getSnapToTicks()) value = findClosestTick(value); - if (value == slider.getValue()) - return; - // If the thumb is hit, then we don't need to set the timers to move it. if (!thumbRect.contains(e.getPoint())) { @@ -857,8 +853,8 @@ public class BasicSliderUI extends SliderUI */ /** - * This method returns the preferred size when the slider is - * horizontally oriented. + * This method returns the preferred size when the slider is horizontally + * oriented. * * @return The dimensions of the preferred horizontal size. */ @@ -868,8 +864,9 @@ public class BasicSliderUI extends SliderUI // The width should cover all the labels (which are usually the // deciding factor of the width) - int width = getWidthOfWidestLabel() * (slider.getLabelTable() == null ? - 0 : slider.getLabelTable().size()); + int width = getWidthOfWidestLabel() * (slider.getLabelTable() == null ? 0 + : slider.getLabelTable() + .size()); // If there are not enough labels. // This number is pretty much arbitrary, but it looks nice. @@ -878,28 +875,27 @@ public class BasicSliderUI extends SliderUI // We can only draw inside of the focusRectangle, so we have to // pad it with insets. - width += insets.left + insets.right + focusInsets.left + - focusInsets.right; + width += insets.left + insets.right + focusInsets.left + focusInsets.right; // Height is determined by the thumb, the ticks and the labels. int height = thumbHeight; - if (slider.getPaintTicks() && slider.getMajorTickSpacing() > 0 || - slider.getMinorTickSpacing() > 0) + if (slider.getPaintTicks() && slider.getMajorTickSpacing() > 0 + || slider.getMinorTickSpacing() > 0) height += tickHeight; if (slider.getPaintLabels()) height += getHeightOfTallestLabel(); - height += insets.top + insets.bottom + focusInsets.top + - focusInsets.bottom; + height += insets.top + insets.bottom + focusInsets.top + + focusInsets.bottom; return new Dimension(width, height); } /** - * This method returns the preferred size when the slider is - * vertically oriented. + * This method returns the preferred size when the slider is vertically + * oriented. * * @return The dimensions of the preferred vertical size. */ @@ -907,33 +903,33 @@ public class BasicSliderUI extends SliderUI { Insets insets = slider.getInsets(); - int height = getHeightOfTallestLabel() * (slider.getLabelTable() == null ? - 0 : slider.getLabelTable().size()); + int height = getHeightOfTallestLabel() * (slider.getLabelTable() == null + ? 0 : slider.getLabelTable() + .size()); if (height < 200) height = 200; - height += insets.top + insets.bottom + focusInsets.top + - focusInsets.bottom; + height += insets.top + insets.bottom + focusInsets.top + + focusInsets.bottom; int width = thumbHeight; - if (slider.getPaintTicks() && slider.getMajorTickSpacing() > 0 || - slider.getMinorTickSpacing() > 0) + if (slider.getPaintTicks() && slider.getMajorTickSpacing() > 0 + || slider.getMinorTickSpacing() > 0) width += tickHeight; if (slider.getPaintLabels()) width += getWidthOfWidestLabel(); - width += insets.left + insets.right + focusInsets.left + - focusInsets.right; + width += insets.left + insets.right + focusInsets.left + focusInsets.right; return new Dimension(width, height); } /** - * This method returns the minimum size when the slider is - * horizontally oriented. + * This method returns the minimum size when the slider is horizontally + * oriented. * * @return The dimensions of the minimum horizontal size. */ @@ -943,8 +939,8 @@ public class BasicSliderUI extends SliderUI } /** - * This method returns the minimum size of the slider when it - * is vertically oriented. + * This method returns the minimum size of the slider when it is vertically + * oriented. * * @return The dimensions of the minimum vertical size. */ @@ -1005,8 +1001,8 @@ public class BasicSliderUI extends SliderUI } /** - * This method calculates all the sizes of the rectangles by delegating - * to the helper methods calculateXXXRect. + * This method calculates all the sizes of the rectangles by delegating to + * the helper methods calculateXXXRect. */ protected void calculateGeometry() { @@ -1539,18 +1535,17 @@ public class BasicSliderUI extends SliderUI c.translate((trackRect.width / 2) + (width / 2), trackRect.height); d.translate((trackRect.width / 2) + (width / 2), 0); } - high = new Polygon(new int[] { b.x, c.x, d.x }, - new int[] { b.y, c.y, d.y }, 3); - shadow = new Polygon(new int[] { b.x, a.x, d.x }, - new int[] { b.y, a.y, d.y }, 3); + g.setColor(Color.GRAY); + g.fillRect(a.x, a.y, width, height); g.setColor(getHighlightColor()); - g.drawPolygon(high); + g.drawLine(b.x, b.y, c.x, c.y); + g.drawLine(c.x, c.y, d.x, d.y); + g.setColor(getShadowColor()); - g.drawPolygon(shadow); + g.drawLine(b.x, b.y, a.x, a.y); + g.drawLine(a.x, a.y, d.x, d.y); - g.setColor(Color.GRAY); - g.fillRect(a.x + 1, a.y + 1, width - 2, height - 2); g.setColor(saved_color); } @@ -1662,8 +1657,11 @@ public class BasicSliderUI extends SliderUI Rectangle tickBounds, int x) { int y = tickRect.y + tickRect.height / 4; + Color saved = g.getColor(); + g.setColor(Color.BLACK); g.drawLine(x, y, x, y + tickRect.height / 4); + g.setColor(saved); } /** @@ -1678,8 +1676,11 @@ public class BasicSliderUI extends SliderUI Rectangle tickBounds, int x) { int y = tickRect.y + tickRect.height / 4; + Color saved = g.getColor(); + g.setColor(Color.BLACK); g.drawLine(x, y, x, y + tickRect.height / 2); + g.setColor(saved); } /** @@ -1694,8 +1695,11 @@ public class BasicSliderUI extends SliderUI int y) { int x = tickRect.x + tickRect.width / 4; + Color saved = g.getColor(); + g.setColor(Color.BLACK); g.drawLine(x, y, x + tickRect.width / 4, y); + g.setColor(saved); } /** @@ -1710,8 +1714,11 @@ public class BasicSliderUI extends SliderUI int y) { int x = tickRect.x + tickRect.width / 4; + Color saved = g.getColor(); + g.setColor(Color.BLACK); g.drawLine(x, y, x + tickRect.width / 2, y); + g.setColor(saved); } /** @@ -1786,7 +1793,6 @@ public class BasicSliderUI extends SliderUI // the labels may not fit inside the slider's bounds. Rather than mucking // with font sizes and possible icon sizes, we'll set the bounds for // the label and let it get clipped. - Dimension dim = label.getPreferredSize(); int w = (int) dim.getWidth(); int h = (int) dim.getHeight(); @@ -1804,8 +1810,6 @@ public class BasicSliderUI extends SliderUI // | | // | | // The label must move w/2 to the right to fit directly under the value. - - int xpos = xPositionForValue(value) - w / 2; int ypos = labelRect.y; |