2001-04-22 05:05:39 +02:00
|
|
|
/* Copyright (C) 2000, 2001 Free Software Foundation
|
2000-07-23 02:24:14 +02:00
|
|
|
|
|
|
|
This file is part of libjava.
|
|
|
|
|
|
|
|
This software is copyrighted work licensed under the terms of the
|
|
|
|
Libjava License. Please consult the file "LIBJAVA_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
|
|
|
package java.awt;
|
|
|
|
import java.awt.event.*;
|
2000-07-31 01:19:57 +02:00
|
|
|
import java.awt.peer.ScrollbarPeer;
|
|
|
|
import java.awt.peer.ComponentPeer;
|
2000-07-23 02:24:14 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Tom Tromey <tromey@cygnus.com>
|
|
|
|
* @date April 12, 2000
|
|
|
|
*/
|
|
|
|
|
|
|
|
public class Scrollbar extends Component implements Adjustable
|
|
|
|
{
|
|
|
|
public Scrollbar ()
|
|
|
|
{
|
|
|
|
this (VERTICAL, 0, 10, 0, 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Scrollbar (int orientation)
|
|
|
|
{
|
|
|
|
this (orientation, 0, 10, 0, 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Scrollbar (int orientation, int value, int visible,
|
|
|
|
int minimum, int maximum)
|
|
|
|
{
|
|
|
|
if (orientation != HORIZONTAL && orientation != VERTICAL)
|
|
|
|
throw new IllegalArgumentException ();
|
|
|
|
|
|
|
|
if (maximum < minimum)
|
|
|
|
maximum = minimum;
|
|
|
|
if (value < minimum)
|
|
|
|
value = minimum;
|
|
|
|
if (value > maximum)
|
|
|
|
value = maximum;
|
|
|
|
|
|
|
|
this.orientation = orientation;
|
|
|
|
this.value = value;
|
|
|
|
this.visible = visible;
|
|
|
|
this.minimum = minimum;
|
|
|
|
this.maximum = maximum;
|
|
|
|
this.unit = 1;
|
|
|
|
|
|
|
|
this.block = 0; // FIXME
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addNotify ()
|
|
|
|
{
|
2000-07-31 04:03:51 +02:00
|
|
|
if (peer == null)
|
2000-12-18 23:17:25 +01:00
|
|
|
peer = getToolkit ().createScrollbar (this);
|
2001-04-22 05:05:39 +02:00
|
|
|
super.addNotify ();
|
2000-07-23 02:24:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getOrientation ()
|
|
|
|
{
|
|
|
|
return orientation;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setOrientation (int orientation)
|
|
|
|
{
|
|
|
|
if (orientation != HORIZONTAL && orientation != VERTICAL)
|
|
|
|
throw new IllegalArgumentException ();
|
|
|
|
this.orientation = orientation;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getValue ()
|
|
|
|
{
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setValue (int value)
|
|
|
|
{
|
2000-07-31 01:19:57 +02:00
|
|
|
setValues (value, visible, minimum, maximum);
|
2000-07-23 02:24:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getMinimum ()
|
|
|
|
{
|
|
|
|
return minimum;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setMinimum (int minimum)
|
|
|
|
{
|
2000-07-31 01:19:57 +02:00
|
|
|
setValues (value, visible, minimum, maximum);
|
2000-07-23 02:24:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getMaximum ()
|
|
|
|
{
|
|
|
|
return maximum;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setMaximum (int maximum)
|
|
|
|
{
|
2000-07-31 01:19:57 +02:00
|
|
|
setValues (value, visible, minimum, maximum);
|
2000-07-23 02:24:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getVisibleAmount ()
|
|
|
|
{
|
|
|
|
return visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getVisible ()
|
|
|
|
{
|
|
|
|
return visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setVisibleAmount (int visible)
|
|
|
|
{
|
2000-07-31 01:19:57 +02:00
|
|
|
setValues (value, visible, minimum, maximum);
|
2000-07-23 02:24:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setUnitIncrement (int v)
|
|
|
|
{
|
|
|
|
unit = v;
|
2000-07-31 01:19:57 +02:00
|
|
|
if (peer != null)
|
|
|
|
{
|
|
|
|
ScrollbarPeer sp = (ScrollbarPeer) peer;
|
|
|
|
sp.setLineIncrement (v);
|
|
|
|
}
|
2000-07-23 02:24:14 +02:00
|
|
|
}
|
|
|
|
|
2000-07-31 01:19:57 +02:00
|
|
|
/** @deprecated */
|
2000-07-23 02:24:14 +02:00
|
|
|
public void setLineIncrement (int v)
|
|
|
|
{
|
2000-07-31 01:19:57 +02:00
|
|
|
setUnitIncrement (v);
|
2000-07-23 02:24:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getUnitIncrement ()
|
|
|
|
{
|
|
|
|
return unit;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getLineIncrement ()
|
|
|
|
{
|
|
|
|
return unit;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setBlockIncrement (int v)
|
|
|
|
{
|
|
|
|
block = v;
|
2000-07-31 01:19:57 +02:00
|
|
|
if (peer != null)
|
|
|
|
{
|
|
|
|
ScrollbarPeer sp = (ScrollbarPeer) peer;
|
|
|
|
sp.setPageIncrement (v);
|
|
|
|
}
|
2000-07-23 02:24:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setPageIncrement (int v)
|
|
|
|
{
|
2000-07-31 01:19:57 +02:00
|
|
|
setBlockIncrement (v);
|
2000-07-23 02:24:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getBlockIncrement ()
|
|
|
|
{
|
|
|
|
return block;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getPageIncrement ()
|
|
|
|
{
|
|
|
|
return block;
|
|
|
|
}
|
|
|
|
|
|
|
|
public synchronized void setValues (int value, int visible,
|
|
|
|
int minimum, int maximum)
|
|
|
|
{
|
2000-07-31 01:19:57 +02:00
|
|
|
if (maximum < minimum)
|
|
|
|
maximum = minimum;
|
|
|
|
if (value < minimum)
|
|
|
|
value = minimum;
|
|
|
|
if (value > maximum)
|
|
|
|
value = maximum;
|
|
|
|
|
|
|
|
this.value = value;
|
|
|
|
this.visible = visible;
|
|
|
|
this.minimum = minimum;
|
|
|
|
this.maximum = maximum;
|
|
|
|
|
|
|
|
if (peer != null)
|
|
|
|
{
|
|
|
|
ScrollbarPeer sp = (ScrollbarPeer) peer;
|
|
|
|
sp.setValues (value, visible, minimum, maximum);
|
|
|
|
}
|
2000-07-23 02:24:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void addAdjustmentListener (AdjustmentListener l)
|
|
|
|
{
|
2000-07-31 01:19:57 +02:00
|
|
|
listeners = AWTEventMulticaster.add (listeners, l);
|
2000-07-23 02:24:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void removeAdjustmentListener (AdjustmentListener l)
|
|
|
|
{
|
2000-09-27 01:46:09 +02:00
|
|
|
listeners = AWTEventMulticaster.remove (listeners, l);
|
2000-07-23 02:24:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void processEvent (AWTEvent e)
|
|
|
|
{
|
|
|
|
if (e instanceof AdjustmentEvent)
|
|
|
|
processAdjustmentEvent ((AdjustmentEvent) e);
|
|
|
|
else
|
|
|
|
super.processEvent (e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void processAdjustmentEvent (AdjustmentEvent e)
|
|
|
|
{
|
2000-07-31 01:19:57 +02:00
|
|
|
if (listeners != null)
|
|
|
|
listeners.adjustmentValueChanged (e);
|
2000-07-23 02:24:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected String paramString ()
|
|
|
|
{
|
2000-07-31 01:19:57 +02:00
|
|
|
return ("Scrollbar["
|
|
|
|
+ ((orientation == VERTICAL) ? "VERTICAL" : "HORIZONTAL") + ","
|
|
|
|
+ value + ","
|
|
|
|
+ visible + ","
|
|
|
|
+ minimum + ","
|
|
|
|
+ maximum + ","
|
|
|
|
+ unit + ","
|
|
|
|
+ block + "]");
|
2000-07-23 02:24:14 +02:00
|
|
|
}
|
|
|
|
|
2000-07-31 01:19:57 +02:00
|
|
|
private AdjustmentListener listeners;
|
2000-07-23 02:24:14 +02:00
|
|
|
private int orientation;
|
|
|
|
private int value;
|
|
|
|
private int visible;
|
|
|
|
private int minimum;
|
|
|
|
private int maximum;
|
|
|
|
private int unit;
|
|
|
|
private int block;
|
|
|
|
}
|