Methods Summary |
---|
public java.awt.Point | getPosition()
return new Point(grabberPosition + leftBorder, 10);
|
public java.awt.Dimension | getPreferredSize()
return dimension;
|
public float | getValue()
return value;
|
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());
y = (getSize().height / 2) - 2;
g.draw3DRect(2, y, size.width - 4, 3, false);
// Draw the display in the trough
if (displayPercent < 100) {
g.setColor(Color.green);
x = sliderWidth * displayPercent / 100 + 3;
y += 2;
g.drawLine(x, y, size.width - 4, y);
}
// 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()
value = ((float)grabberPosition/sliderWidth);
if (detents != null && detents.length > 0 && dragging) {
float tolerance = 0.05f;
for (int i = 0; i < detents.length; i++) {
if (Math.abs(detents[i] - value) <= tolerance)
value = detents[i];
}
}
repaint();
if (actionListener != null)
actionListener.actionPerformed(new ActionEvent(this,
ActionEvent.ACTION_PERFORMED,
"scroll"));
|
public void | setActionListener(java.awt.event.ActionListener al)
actionListener = al;
|
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 | 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);
|
public void | setValue(float value)
lower = 0.0f;
upper = 1.0f;
range = upper - lower;
setSliderPosition(value - lower, range);
repaint();
|