/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Provides the Synth L&F UI delegate for
* {@link JSlider}.
*
* @author Joshua Outwater
* @since 1.7
*/
implements PropertyChangeListener, SynthUI {
private boolean paintValue;
/**
* When a JSlider is used as a renderer in a JTable, its layout is not
* being recomputed even though the size is changing. Even though there
* is a ComponentListener installed, it is not being notified. As such,
* at times when being asked to paint the layout should first be redone.
* At the end of the layout method we set this lastSize variable, which
* represents the size of the slider the last time it was layed out.
*
* In the paint method we then check to see that this is accurate, that
* the slider has not changed sizes since being last layed out. If necessary
* we recompute the layout.
*/
private int trackHeight;
private int trackBorder;
private int thumbWidth;
private int thumbHeight;
/** Used to determine the color to paint the thumb. */
///////////////////////////////////////////////////
// ComponentUI Interface Implementation methods
///////////////////////////////////////////////////
/**
* Creates a new UI object for the given component.
*
* @param c component to create UI object for
* @return the UI object
*/
return new SynthSliderUI((JSlider)c);
}
super(c);
}
/**
* @inheritDoc
*/
}
/**
* Uninstalls default setting. This method is called when a
* {@code LookAndFeel} is uninstalled.
*/
}
/**
* @inheritDoc
*/
super.installListeners(slider);
slider.addPropertyChangeListener(this);
}
/**
* @inheritDoc
*/
super.uninstallListeners(slider);
}
// handle scaling for sizeVarients for special case components. The
// components are based on Apples LAF
"JComponent.sizeVariant");
thumbWidth *= 1.15;
thumbHeight *= 1.15;
thumbWidth *= 0.857;
thumbHeight *= 0.857;
thumbWidth *= 0.784;
thumbHeight *= 0.784;
}
}
"Slider.paintValue", true);
}
}
}
/**
* @inheritDoc
*/
return new SynthTrackListener();
}
private void updateThumbState(int x, int y) {
}
updateThumbState(x, y);
}
if (thumbActive != active) {
}
}
if (thumbPressed != pressed) {
}
}
/**
* @inheritDoc
*/
if (c == null) {
throw new NullPointerException("Component must be non-null");
}
throw new IllegalArgumentException(
"Width and height must be >= 0");
}
// Get the insets for the track.
int valueHeight = 0;
if (paintValue) {
}
int tickHeight = 0;
if (slider.getPaintTicks()) {
tickHeight = getTickLength();
}
int labelHeight = getHeightOfTallestLabel();
}
else { // VERTICAL
int valueHeight = 0;
if (paintValue) {
}
}
}
}
return -1;
}
/**
* @inheritDoc
*/
d.height = 200;
} else {
d.width = 200;
}
return d;
}
/**
* @inheritDoc
*/
} else {
}
return d;
}
/**
* @inheritDoc
*/
protected void calculateGeometry() {
layout();
}
/**
* Lays out the slider.
*/
protected void layout() {
// Get the insets for the track.
// Calculate the height of all the subcomponents so we can center
// them.
if (paintValue) {
}
if (slider.getPaintTicks()) {
}
if (slider.getPaintLabels()) {
}
- 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.
if (dictionary != null) {
// Iterate through the keys in the dictionary and find the
// first and last labels indices that fall within the
// slider range.
keys.hasMoreElements(); ) {
}
lastLblIdx = keyInt;
}
}
// Calculate the pad necessary for the labels at the first
// and last visible indices.
}
}
// Calculate the painting rectangles for each of the different
// slider areas.
} else {
// Calculate the width of all the subcomponents so we can center
// them.
if (slider.getPaintTicks()) {
}
if (slider.getPaintLabels()) {
}
if (paintValue) {
}
// Get the max width of the min or max value of the slider.
// Layout the components.
if (l > w1) {
}
} else {
if (l > w2) {
}
}
}
}
/**
* Calculates the pad for the label at the specified index.
*
* @param i index of the label to calculate pad for.
* @return padding required to keep label visible.
*/
private int getPadForLabel(int i) {
int pad = 0;
if (c != null) {
int centerX = xPositionForValue(i);
}
}
}
return pad;
}
/**
* @inheritDoc
*/
protected void calculateThumbLocation() {
super.calculateThumbLocation();
thumbRect.y += trackBorder;
} else {
thumbRect.x += trackBorder;
}
if(mousePosition != null) {
}
}
/**
* @inheritDoc
*/
public void setThumbLocation(int x, int y) {
super.setThumbLocation(x, y);
// Value rect is tied to the thumb location. We need to repaint when
// the thumb repaints.
setThumbActive(false);
}
/**
* @inheritDoc
*/
- trackBorder;
int xPosition;
if (!drawInverted()) {
} else {
}
return xPosition;
}
/**
* @inheritDoc
*/
int yPosition;
if (!drawInverted()) {
} else {
}
return yPosition;
}
/**
* @inheritDoc
*/
int value;
} else if (yPos >= trackBottom) {
} else {
int valueFromTrackTop =
value = drawInverted() ?
}
return value;
}
/**
* @inheritDoc
*/
int value;
} else if (xPos >= trackRight) {
} else {
int valueFromTrackLeft =
value = drawInverted() ?
}
return value;
}
/**
* @inheritDoc
*/
} else {
}
return size;
}
/**
* @inheritDoc
*/
protected void recalculateIfInsetsChanged() {
}
}
/**
* @inheritDoc
*/
}
}
}
}
}
return state;
}
return SynthLookAndFeel.getComponentState(c);
}
/**
* Notifies this UI delegate to repaint the specified component.
* This method paints the component background, then calls
* the {@link #paint(SynthContext,Graphics)} method.
*
* <p>In general, this method does not need to be overridden by subclasses.
* All Look and Feel rendering code should reside in the {@code paint} method.
*
* @param g the {@code Graphics} object used for painting
* @param c the component being painted
* @see #paint(SynthContext,Graphics)
*/
slider.getOrientation());
}
/**
* Paints the specified component according to the Look and Feel.
* <p>This method is not used by Synth Look and Feel.
* Painting is handled by the {@link #paint(SynthContext,Graphics)} method.
*
* @param g the {@code Graphics} object used for painting
* @param c the component being painted
* @see #paint(SynthContext,Graphics)
*/
}
/**
* Paints the specified component.
*
* @param context context for the component being painted
* @param g the {@code Graphics} object used for painting
* @see #update(Graphics,JComponent)
*/
}
if (paintValue) {
// For horizontal sliders, make sure value is not painted
// outside slider bounds.
}
}
valueRect.y, -1);
}
}
}
paintTicks(g);
}
paintLabels(g);
}
}
/**
* @inheritDoc
*/
int y, int w, int h) {
slider.getOrientation());
}
/**
* Paints the slider thumb.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
* @param thumbBounds bounding box for the thumb
*/
}
/**
* Paints the slider track.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
* @param trackBounds bounding box for the track
*/
}
/**
* @inheritDoc
*/
if (SynthLookAndFeel.shouldUpdateStyle(e)) {
}
}
//////////////////////////////////////////////////
/// Track Listener Class
//////////////////////////////////////////////////
/**
* Track mouse movements.
*/
setThumbActive(false);
}
super.mousePressed(e);
}
super.mouseReleased(e);
}
int thumbMiddle;
return;
}
currentMouseX = e.getX();
currentMouseY = e.getY();
if (!isDragging()) {
return;
}
slider.setValueIsAdjusting(true);
switch (slider.getOrientation()) {
if (drawInverted()) {
trackBottom = vMax;
} else {
}
break;
case JSlider.HORIZONTAL:
if (drawInverted()) {
} else {
trackRight = hMax;
}
break;
default:
return;
}
if (slider.getValueIsAdjusting()) {
setThumbActive(true);
}
}
}
}
}