Methods Summary |
---|
public java.awt.Point | getPosition()
return new Point(grabberPosition + leftBorder, 10);
|
public java.awt.Dimension | getPreferredSize()
return dimension;
|
public boolean | isGrabberVisible()
return grabberVisible;
|
private int | limitGrabber(int mousex)
int x = mousex - leftBorder;
if (x < 0)
x = 0;
else if (x > sliderWidth)
x = sliderWidth;
return x;
|
public void | mouseClicked(java.awt.event.MouseEvent me)
|
public void | mouseDragged(java.awt.event.MouseEvent me)
int modifier = me.getModifiers();
if ((modifier & InputEvent.BUTTON2_MASK) == 0 &&
(modifier & InputEvent.BUTTON3_MASK) == 0 ) {
if (isEnabled()) {
dragging = true;
grabberPosition = limitGrabber(me.getX());
seek();
}
}
|
public void | mouseEntered(java.awt.event.MouseEvent me)
entered = true;
repaint();
|
public void | mouseExited(java.awt.event.MouseEvent me)
entered = false;
repaint();
|
public void | mouseMoved(java.awt.event.MouseEvent me)
|
public void | mousePressed(java.awt.event.MouseEvent me)MouseListener methods
int modifier = me.getModifiers();
if ((modifier & InputEvent.BUTTON2_MASK) == 0 &&
(modifier & InputEvent.BUTTON3_MASK) == 0 ) {
if (isEnabled()) {
dragging = false;
grabbed = true;
grabberPosition = limitGrabber(me.getX());
seek();
}
}
|
public void | mouseReleased(java.awt.event.MouseEvent me)
int modifier = me.getModifiers();
if ((modifier & InputEvent.BUTTON2_MASK) == 0 &&
(modifier & InputEvent.BUTTON3_MASK) == 0 ) {
if (isEnabled()) {
dragging = false;
grabbed = false;
repaint();
}
}
|
public void | paint(java.awt.Graphics g)
Dimension size = getSize();
int x;
int y = (size.height / 2) - 2;
paintG = g;
int grabberX = grabberPosition + leftBorder - 5;
// Draw the trough
g.setColor( getBackground().darker() );
g.drawRect (leftBorder, y, sliderWidth, 3);
g.setColor(getBackground());
g.draw3DRect(leftBorder, y, (int)(sliderWidth * displayPercent / 100), 3, false);
// Draw the marks for detents
if (detents != null && detents.length != 0) {
paintG.setColor(Color.black);
for (int i = 0; i < detents.length; i++) {
x = leftBorder + (int)(detents[i] * sliderWidth / range);
paintG.drawLine(x, 12, x, 15);
}
}
// Draw the grabber
if (grabberVisible) {
Image image;
if (isEnabled()) {
if (grabbed || entered)
image = imageGrabberDown;
else
image = imageGrabber;
} else {
image = imageGrabberX;
}
paintG.drawImage(image, grabberX, 4, this);
}
|
private void | seek()
if (control != null && control instanceof NumericControl) {
NumericControl nc = (NumericControl) control;
float lower = nc.getLowerLimit();
float upper = nc.getUpperLimit();
float value = ((float)grabberPosition/sliderWidth) * (upper - lower)
+ lower;
if (detents != null && detents.length > 0 && dragging) {
float tolerance = (upper - lower) * 0.05f;
for (int i = 0; i < detents.length; i++) {
if (Math.abs(detents[i] - value) <= tolerance)
value = detents[i];
}
}
float result = nc.setValue(value);
if (value != result)
setSliderPosition(result - lower, upper - lower);
}
repaint();
|
public void | setDisplayPercent(int percent)
if (percent != displayPercent) {
displayPercent = percent;
if (displayPercent > 100) {
displayPercent = 100;
} else if (displayPercent < 0) {
displayPercent = 0;
}
repaint();
}
|
public void | setEnabled(boolean state)
super.setEnabled(state);
repaint();
|
public void | setGrabberVisible(boolean visible)
if (grabberVisible != visible) {
grabberVisible = visible;
repaint();
}
|
public void | setSize(int width, int height)Component methods
super.setSize(width, height);
paintG = null;
repaint();
|
private void | setSliderPosition(float value, float range)
grabberPosition = (int) ( value / range * sliderWidth);
|