calculateThumbLocation();
}
protected void layout() {
SeaGlassContext context = getContext(slider);
SynthGraphicsUtils synthGraphics = style.getGraphicsUtils(context);
// Set the thumb size.
Dimension size = getThumbSize();
thumbRect.setSize(size.width, size.height);
// Get the insets for the track.
Insets trackInsets = new Insets(0, 0, 0, 0);
SeaGlassContext trackContext = getContext(slider, Region.SLIDER_TRACK);
style.getInsets(trackContext, trackInsets);
trackContext.dispose();
if (slider.getOrientation() == JSlider.HORIZONTAL) {
// Calculate the height of all the subcomponents so we can center
// them.
valueRect.height = 0;
if (paintValue) {
valueRect.height = synthGraphics.getMaximumCharHeight(context);
}
trackRect.height = trackHeight;
tickRect.height = 0;
if (slider.getPaintTicks()) {
tickRect.height = getTickLength();
}
labelRect.height = 0;
if (slider.getPaintLabels()) {
labelRect.height = getHeightOfTallestLabel();
}
contentDim.height = valueRect.height + trackRect.height + trackInsets.top + trackInsets.bottom + tickRect.height
+ labelRect.height + 4;
contentDim.width = slider.getWidth() - insetCache.left - insetCache.right;
// Check if any of the labels will paint out of bounds.
int pad = 0;
if (slider.getPaintLabels()) {
// Calculate the track rectangle. It is necessary for
// xPositionForValue to return correct values.
trackRect.x = insetCache.left;
trackRect.width = contentDim.width;
Dictionary dictionary = slider.getLabelTable();
if (dictionary != null) {
int minValue = slider.getMinimum();
int maxValue = slider.getMaximum();
// Iterate through the keys in the dictionary and find the
// first and last labels indices that fall within the
// slider range.
int firstLblIdx = Integer.MAX_VALUE;
int lastLblIdx = Integer.MIN_VALUE;
for (Enumeration keys = dictionary.keys(); keys.hasMoreElements();) {
int keyInt = ((Integer) keys.nextElement()).intValue();
if (keyInt >= minValue && keyInt < firstLblIdx) {
firstLblIdx = keyInt;
}
if (keyInt <= maxValue && keyInt > lastLblIdx) {
lastLblIdx = keyInt;
}
}
// Calculate the pad necessary for the labels at the first
// and last visible indices.
pad = getPadForLabel(firstLblIdx);
pad = Math.max(pad, getPadForLabel(lastLblIdx));
}
}
// Calculate the painting rectangles for each of the different
// slider areas.
valueRect.x = trackRect.x = tickRect.x = labelRect.x = (insetCache.left + pad);
valueRect.width = trackRect.width = tickRect.width = labelRect.width = (contentDim.width - (pad * 2));
int centerY = slider.getHeight() / 2 - contentDim.height / 2;
valueRect.y = centerY;
centerY += valueRect.height + 2;
trackRect.y = centerY + trackInsets.top;
centerY += trackRect.height + trackInsets.top + trackInsets.bottom;
tickRect.y = centerY;
centerY += tickRect.height + 2;
labelRect.y = centerY;
centerY += labelRect.height;
} else {
// Calculate the width of all the subcomponents so we can center
// them.
trackRect.width = trackHeight;
tickRect.width = 0;
if (slider.getPaintTicks()) {
tickRect.width = getTickLength();
}
labelRect.width = 0;
if (slider.getPaintLabels()) {
labelRect.width = getWidthOfWidestLabel();
}
valueRect.y = insetCache.top;
valueRect.height = 0;
if (paintValue) {
valueRect.height = synthGraphics.getMaximumCharHeight(context);
}
// Get the max width of the min or max value of the slider.
FontMetrics fm = slider.getFontMetrics(slider.getFont());
valueRect.width = Math.max(synthGraphics.computeStringWidth(context, slider.getFont(), fm, "" + slider.getMaximum()),
synthGraphics.computeStringWidth(context, slider.getFont(), fm, "" + slider.getMinimum()));
int l = valueRect.width / 2;
int w1 = trackInsets.left + trackRect.width / 2;
int w2 = trackRect.width / 2 + trackInsets.right + tickRect.width + labelRect.width;
contentDim.width = Math.max(w1, l) + Math.max(w2, l) + 2 + insetCache.left + insetCache.right;