ScrollPane.java: Wrote.
* java/awt/ScrollPane.java: Wrote. * java/awt/peer/ScrollPanePeer.java (setBlockIncrement): New method. * java/awt/Panel.java (Panel()): Fixed. * java/awt/Component.java (isShowing): Return false if no peer exists, and true if component is visible and no parent exists. (getLocationOnScreen): Wrote. (getPreferredSize): Removed FIXME comment. (getMinimumSize): Likewise. (getAlignmentX, getAlignmentY): Wrote. (list): Wrote. (requestFocus): Wrote. (transferFocus): Wrote. (findNextFocusComponent): New method. (hasFocus()): Wrote. (checkImage): Wrote. (enableEvents): Call setEventMask on the peer. * java/awt/Container.java (list): Use super.list() to print self. (findNextFocusComponent): New method. (setLayout): Call invalidate. (findComponentAt): Wrote. From-SVN: r38639
This commit is contained in:
parent
4f78b9a896
commit
f5826791be
7 changed files with 547 additions and 98 deletions
|
@ -1,3 +1,30 @@
|
||||||
|
2001-01-02 Tom Tromey <tromey@redhat.com>
|
||||||
|
|
||||||
|
* java/awt/ScrollPane.java: Wrote.
|
||||||
|
* java/awt/peer/ScrollPanePeer.java (setBlockIncrement): New
|
||||||
|
method.
|
||||||
|
|
||||||
|
* java/awt/Panel.java (Panel()): Fixed.
|
||||||
|
|
||||||
|
* java/awt/Component.java (isShowing): Return false if no peer
|
||||||
|
exists, and true if component is visible and no parent exists.
|
||||||
|
(getLocationOnScreen): Wrote.
|
||||||
|
(getPreferredSize): Removed FIXME comment.
|
||||||
|
(getMinimumSize): Likewise.
|
||||||
|
(getAlignmentX, getAlignmentY): Wrote.
|
||||||
|
(list): Wrote.
|
||||||
|
(requestFocus): Wrote.
|
||||||
|
(transferFocus): Wrote.
|
||||||
|
(findNextFocusComponent): New method.
|
||||||
|
(hasFocus()): Wrote.
|
||||||
|
(checkImage): Wrote.
|
||||||
|
(enableEvents): Call setEventMask on the peer.
|
||||||
|
|
||||||
|
* java/awt/Container.java (list): Use super.list() to print self.
|
||||||
|
(findNextFocusComponent): New method.
|
||||||
|
(setLayout): Call invalidate.
|
||||||
|
(findComponentAt): Wrote.
|
||||||
|
|
||||||
2000-12-30 Bryce McKinlay <bryce@albatross.co.nz>
|
2000-12-30 Bryce McKinlay <bryce@albatross.co.nz>
|
||||||
|
|
||||||
* Makefile.am (libgcj_la_LIBADD): Add $(THREADLIBS). This ensures that
|
* Makefile.am (libgcj_la_LIBADD): Add $(THREADLIBS). This ensures that
|
||||||
|
|
|
@ -205,13 +205,10 @@ public abstract class Component implements ImageObserver, MenuContainer,
|
||||||
|
|
||||||
public boolean isShowing()
|
public boolean isShowing()
|
||||||
{
|
{
|
||||||
if (! visible)
|
if (! visible || peer == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (parent != null)
|
return parent == null ? true : parent.isShowing ();
|
||||||
return (parent.isShowing());
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEnabled()
|
public boolean isEnabled()
|
||||||
|
@ -377,8 +374,11 @@ public abstract class Component implements ImageObserver, MenuContainer,
|
||||||
|
|
||||||
public Point getLocationOnScreen()
|
public Point getLocationOnScreen()
|
||||||
{
|
{
|
||||||
// FIXME
|
if (! isShowing ())
|
||||||
return null;
|
throw new IllegalComponentStateException ("component not showing");
|
||||||
|
|
||||||
|
// We know peer != null here.
|
||||||
|
return peer.getLocationOnScreen ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @deprecated Use getLocation() instead. */
|
/** @deprecated Use getLocation() instead. */
|
||||||
|
@ -560,7 +560,6 @@ public abstract class Component implements ImageObserver, MenuContainer,
|
||||||
|
|
||||||
public Dimension getPreferredSize()
|
public Dimension getPreferredSize()
|
||||||
{
|
{
|
||||||
// FIXME?
|
|
||||||
if (peer == null)
|
if (peer == null)
|
||||||
return new Dimension(width, height);
|
return new Dimension(width, height);
|
||||||
else
|
else
|
||||||
|
@ -575,7 +574,6 @@ public abstract class Component implements ImageObserver, MenuContainer,
|
||||||
|
|
||||||
public Dimension getMinimumSize()
|
public Dimension getMinimumSize()
|
||||||
{
|
{
|
||||||
// FIXME?
|
|
||||||
if (peer == null)
|
if (peer == null)
|
||||||
return new Dimension(width, height);
|
return new Dimension(width, height);
|
||||||
else
|
else
|
||||||
|
@ -595,14 +593,12 @@ public abstract class Component implements ImageObserver, MenuContainer,
|
||||||
|
|
||||||
public float getAlignmentX()
|
public float getAlignmentX()
|
||||||
{
|
{
|
||||||
// FIXME
|
return CENTER_ALIGNMENT;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getAlignmentY()
|
public float getAlignmentY()
|
||||||
{
|
{
|
||||||
// FIXME
|
return CENTER_ALIGNMENT;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doLayout()
|
public void doLayout()
|
||||||
|
@ -626,7 +622,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
|
||||||
valid = false;
|
valid = false;
|
||||||
|
|
||||||
if ((parent != null) && parent.valid)
|
if ((parent != null) && parent.valid)
|
||||||
parent.invalidate ();
|
parent.invalidate ();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Graphics getGraphics()
|
public Graphics getGraphics()
|
||||||
|
@ -724,7 +720,8 @@ public abstract class Component implements ImageObserver, MenuContainer,
|
||||||
paintAll(g);
|
paintAll(g);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h)
|
public boolean imageUpdate (Image img, int infoflags, int x, int y,
|
||||||
|
int w, int h)
|
||||||
{
|
{
|
||||||
// FIXME
|
// FIXME
|
||||||
return false;
|
return false;
|
||||||
|
@ -759,13 +756,14 @@ public abstract class Component implements ImageObserver, MenuContainer,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int checkImage(Image image, int width, int height, ImageObserver observer)
|
public int checkImage (Image image, int width, int height, ImageObserver observer)
|
||||||
{
|
{
|
||||||
// FIXME
|
if (peer != null)
|
||||||
return 0;
|
return peer.checkImage (image, width, height, observer);
|
||||||
|
return getToolkit ().checkImage (image, width, height, observer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean contains(int x, int y)
|
public boolean contains (int x, int y)
|
||||||
{
|
{
|
||||||
return (x >= 0) && (y >= 0) && (x < width) && (y < height);
|
return (x >= 0) && (y >= 0) && (x < width) && (y < height);
|
||||||
}
|
}
|
||||||
|
@ -1054,6 +1052,8 @@ public abstract class Component implements ImageObserver, MenuContainer,
|
||||||
|
|
||||||
if (isLightweight() && (parent != null))
|
if (isLightweight() && (parent != null))
|
||||||
parent.enableEvents(eventsToEnable);
|
parent.enableEvents(eventsToEnable);
|
||||||
|
else if (peer != null)
|
||||||
|
peer.setEventMask (eventMask);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final void disableEvents(long eventsToDisable)
|
protected final void disableEvents(long eventsToDisable)
|
||||||
|
@ -1437,18 +1437,35 @@ public abstract class Component implements ImageObserver, MenuContainer,
|
||||||
|
|
||||||
public boolean isFocusTraversable()
|
public boolean isFocusTraversable()
|
||||||
{
|
{
|
||||||
// FIXME
|
return enabled && visible && (peer == null || peer.isFocusTraversable ());
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void requestFocus()
|
public void requestFocus()
|
||||||
{
|
{
|
||||||
// FIXME
|
// If there's no peer then this component can't get the focus. We
|
||||||
|
// treat it as a silent rejection of the request.
|
||||||
|
if (peer != null)
|
||||||
|
peer.requestFocus ();
|
||||||
|
}
|
||||||
|
|
||||||
|
// This method is used to implement transferFocus().
|
||||||
|
// CHILD is the child making the request.
|
||||||
|
// This is overridden by Container; when called for an ordinary
|
||||||
|
// component there is no child and so we always return null.
|
||||||
|
Component findNextFocusComponent (Component child)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void transferFocus()
|
public void transferFocus()
|
||||||
{
|
{
|
||||||
// FIXME
|
Component next;
|
||||||
|
if (parent == null)
|
||||||
|
next = findNextFocusComponent (null);
|
||||||
|
else
|
||||||
|
next = parent.findNextFocusComponent (this);
|
||||||
|
if (next != null && next != this)
|
||||||
|
next.requestFocus ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @deprecated */
|
/** @deprecated */
|
||||||
|
@ -1460,8 +1477,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
|
||||||
/** @since 1.2 */
|
/** @since 1.2 */
|
||||||
public boolean hasFocus()
|
public boolean hasFocus()
|
||||||
{
|
{
|
||||||
// FIXME
|
return hasFocus;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void add(PopupMenu popup)
|
public synchronized void add(PopupMenu popup)
|
||||||
|
@ -1512,26 +1528,33 @@ public abstract class Component implements ImageObserver, MenuContainer,
|
||||||
return this.getClass().getName() + "[" + paramString() + "]";
|
return this.getClass().getName() + "[" + paramString() + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void list()
|
public void list ()
|
||||||
{
|
{
|
||||||
list(System.out);
|
list (System.out, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void list(PrintStream out)
|
public void list (PrintStream out)
|
||||||
{
|
{
|
||||||
list(out, 0);
|
list (out, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void list(PrintStream out, int indent)
|
public void list (PrintStream out, int indent)
|
||||||
{
|
{
|
||||||
|
for (int i = 0; i < indent; ++i)
|
||||||
|
out.print (' ');
|
||||||
|
out.println (toString ());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void list(PrintWriter out)
|
public void list (PrintWriter out)
|
||||||
{
|
{
|
||||||
|
list (out, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void list(PrintWriter out, int indent)
|
public void list (PrintWriter out, int indent)
|
||||||
{
|
{
|
||||||
|
for (int i = 0; i < indent; ++i)
|
||||||
|
out.print (' ');
|
||||||
|
out.println (toString ());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPropertyChangeListener(PropertyChangeListener listener)
|
public void addPropertyChangeListener(PropertyChangeListener listener)
|
||||||
|
|
|
@ -127,7 +127,7 @@ public class Container extends Component
|
||||||
invalidate ();
|
invalidate ();
|
||||||
|
|
||||||
if (component == null)
|
if (component == null)
|
||||||
component = new Component[4]; // FIXME, better initial size?
|
component = new Component[4]; // FIXME, better initial size?
|
||||||
|
|
||||||
// This isn't the most efficient implementation. We could do less
|
// This isn't the most efficient implementation. We could do less
|
||||||
// copying when growing the array. It probably doesn't matter.
|
// copying when growing the array. It probably doesn't matter.
|
||||||
|
@ -213,7 +213,7 @@ public class Container extends Component
|
||||||
public void setLayout(LayoutManager mgr)
|
public void setLayout(LayoutManager mgr)
|
||||||
{
|
{
|
||||||
layoutMgr = mgr;
|
layoutMgr = mgr;
|
||||||
// FIXME
|
invalidate ();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doLayout()
|
public void doLayout()
|
||||||
|
@ -516,10 +516,33 @@ public class Container extends Component
|
||||||
return getComponentAt(p.x, p.y);
|
return getComponentAt(p.x, p.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Component findComponentAt(int x, int y)
|
public Component findComponentAt (int x, int y)
|
||||||
{
|
{
|
||||||
// FIXME
|
if (! contains (x, y))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
for (int i = 0; i < ncomponents; ++i)
|
||||||
|
{
|
||||||
|
// Ignore invisible children...
|
||||||
|
if (!component[i].isVisible())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
int x2 = x - component[i].x;
|
||||||
|
int y2 = y - component[i].y;
|
||||||
|
// We don't do the contains() check right away because
|
||||||
|
// findComponentAt would redundantly do it first thing.
|
||||||
|
if (component[i] instanceof Container)
|
||||||
|
{
|
||||||
|
Container k = (Container) component[i];
|
||||||
|
Component r = k.findComponentAt (x2, y2);
|
||||||
|
if (r != null)
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
else if (component[i].contains (x2, y2))
|
||||||
|
return component[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Component findComponentAt(Point p)
|
public Component findComponentAt(Point p)
|
||||||
|
@ -572,18 +595,14 @@ public class Container extends Component
|
||||||
|
|
||||||
public void list (PrintStream out, int indent)
|
public void list (PrintStream out, int indent)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < indent; ++i)
|
super.list (out, indent);
|
||||||
out.print (' ');
|
|
||||||
out.println (toString ());
|
|
||||||
for (int i = 0; i < ncomponents; ++i)
|
for (int i = 0; i < ncomponents; ++i)
|
||||||
component[i].list (out, indent + 2);
|
component[i].list (out, indent + 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void list(PrintWriter out, int indent)
|
public void list(PrintWriter out, int indent)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < indent; ++i)
|
super.list (out, indent);
|
||||||
out.print (' ');
|
|
||||||
out.println (toString ());
|
|
||||||
for (int i = 0; i < ncomponents; ++i)
|
for (int i = 0; i < ncomponents; ++i)
|
||||||
component[i].list (out, indent + 2);
|
component[i].list (out, indent + 2);
|
||||||
}
|
}
|
||||||
|
@ -622,4 +641,52 @@ public class Container extends Component
|
||||||
public static final GfxVisitor INSTANCE = new GfxPrintAllVisitor();
|
public static final GfxVisitor INSTANCE = new GfxPrintAllVisitor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is used to implement Component.transferFocus.
|
||||||
|
Component findNextFocusComponent (Component child)
|
||||||
|
{
|
||||||
|
int start, end;
|
||||||
|
if (child != null)
|
||||||
|
{
|
||||||
|
for (start = 0; start < ncomponents; ++start)
|
||||||
|
{
|
||||||
|
if (component[start] == child)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
end = start;
|
||||||
|
// This special case lets us be sure to terminate.
|
||||||
|
if (end == 0)
|
||||||
|
end = ncomponents;
|
||||||
|
++start;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
start = 0;
|
||||||
|
end = ncomponents;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j = start; j != end; ++j)
|
||||||
|
{
|
||||||
|
if (j >= ncomponents)
|
||||||
|
{
|
||||||
|
// The JCL says that we should wrap here. However, that
|
||||||
|
// seems wrong. To me it seems that focus order should be
|
||||||
|
// global within in given window. So instead if we reach
|
||||||
|
// the end we try to look in our parent, if we have one.
|
||||||
|
if (parent != null)
|
||||||
|
return parent.findNextFocusComponent (this);
|
||||||
|
j -= ncomponents;
|
||||||
|
}
|
||||||
|
if (component[j] instanceof Container)
|
||||||
|
{
|
||||||
|
Component c = component[j];
|
||||||
|
c = c.findNextFocusComponent (null);
|
||||||
|
if (c != null)
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
else if (component[j].isFocusTraversable ())
|
||||||
|
return component[j];
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,16 +10,13 @@ package java.awt;
|
||||||
|
|
||||||
import java.awt.peer.ComponentPeer;
|
import java.awt.peer.ComponentPeer;
|
||||||
|
|
||||||
/* An incomplete placeholder. */
|
/* This class is complete to 1.2. */
|
||||||
|
|
||||||
public class Panel extends Container
|
public class Panel extends Container
|
||||||
{
|
{
|
||||||
public Panel()
|
public Panel()
|
||||||
{
|
{
|
||||||
this(
|
this (new FlowLayout ());
|
||||||
// should be: new FlowLayout()
|
|
||||||
null // FIXME
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Panel(LayoutManager layout)
|
public Panel(LayoutManager layout)
|
||||||
|
|
|
@ -8,8 +8,340 @@ details. */
|
||||||
|
|
||||||
package java.awt;
|
package java.awt;
|
||||||
|
|
||||||
/* A very incomplete placeholder. */
|
import java.awt.event.AdjustmentListener;
|
||||||
|
import java.awt.peer.ScrollPanePeer;
|
||||||
|
|
||||||
|
/** A ScrollPane is a component that has vertical and horizontal
|
||||||
|
* scrollbars as well as a single child which is scrolled by them.
|
||||||
|
* @author Tom Tromey <tromey@redhat.com>
|
||||||
|
* @date December 31, 2000
|
||||||
|
* Status: Unfinished. The Adjustables are probably wrong (there
|
||||||
|
* isn't a mechanism for scrollbar events to affect them), and also
|
||||||
|
* doLayout() is not finished.
|
||||||
|
*/
|
||||||
public class ScrollPane extends Container
|
public class ScrollPane extends Container
|
||||||
{
|
{
|
||||||
|
/** This indicates that scrollbars should only be displayed when
|
||||||
|
* needed. */
|
||||||
|
public static final int SCROLLBARS_AS_NEEDED = 0;
|
||||||
|
/** This indicates that scrollbars should always be displayed. */
|
||||||
|
public static final int SCROLLBARS_ALWAYS = 1;
|
||||||
|
/** This indicates that scrollbars should never be displayed. */
|
||||||
|
public static final int SCROLLBARS_NEVER = 2;
|
||||||
|
|
||||||
|
/** Create a new ScrollPane object using the indicated scrollbar
|
||||||
|
* display policy. If the policy is not specified it defaults to
|
||||||
|
* SCROLLBARS_AS_NEEDED. The default size of this component is
|
||||||
|
* 100x100.
|
||||||
|
* @param policy The scrollbar display policy
|
||||||
|
*/
|
||||||
|
public ScrollPane ()
|
||||||
|
{
|
||||||
|
this (SCROLLBARS_AS_NEEDED);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScrollPane (int policy)
|
||||||
|
{
|
||||||
|
if (policy != SCROLLBARS_AS_NEEDED
|
||||||
|
&& policy != SCROLLBARS_ALWAYS
|
||||||
|
&& policy != SCROLLBARS_NEVER)
|
||||||
|
throw new IllegalArgumentException ("invalid value for policy");
|
||||||
|
|
||||||
|
this.policy = policy;
|
||||||
|
setSize (100, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Add a component to this ScrollPane.
|
||||||
|
* @param comp The component to add
|
||||||
|
* @param constraints Constraints. This is ignored.
|
||||||
|
* @param pos Position. This must be <= 0, but is otherwise ignored.
|
||||||
|
*/
|
||||||
|
protected final void addImpl (Component comp, Object constraints,
|
||||||
|
int pos)
|
||||||
|
{
|
||||||
|
if (pos > 0)
|
||||||
|
throw new IllegalArgumentException ("pos must be <= 0");
|
||||||
|
|
||||||
|
if (ncomponents > 0)
|
||||||
|
remove (component[0]);
|
||||||
|
|
||||||
|
if (comp.isLightweight ())
|
||||||
|
{
|
||||||
|
Panel p = new Panel ();
|
||||||
|
p.add (comp);
|
||||||
|
comp = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
super.addImpl (comp, constraints, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** This creates the component's peer. */
|
||||||
|
public void addNotify ()
|
||||||
|
{
|
||||||
|
if (peer == null)
|
||||||
|
peer = getToolkit ().createScrollPane (this);
|
||||||
|
super.addNotify ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Lays out the components in this container. */
|
||||||
|
public void doLayout ()
|
||||||
|
{
|
||||||
|
ScrollPanePeer spp = (ScrollPanePeer) peer;
|
||||||
|
Dimension c = component[0].getPreferredSize ();
|
||||||
|
component[0].setSize (c.width, c.height);
|
||||||
|
spp.childResized (c.width, c.height);
|
||||||
|
// FIXME
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns an Adjustable representing the horizontal scrollbar.
|
||||||
|
* The methods setMaximum, setMinimum, and setVisibleAmount should
|
||||||
|
* not be called on this Adjustable. They will throw AWTError if
|
||||||
|
* called.
|
||||||
|
*/
|
||||||
|
public Adjustable getHAdjustable ()
|
||||||
|
{
|
||||||
|
return hscroll;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns the height of the horizontal scrollbar. */
|
||||||
|
public int getHScrollbarHeight ()
|
||||||
|
{
|
||||||
|
if (peer == null)
|
||||||
|
return 0;
|
||||||
|
ScrollPanePeer spp = (ScrollPanePeer) peer;
|
||||||
|
return spp.getHScrollbarHeight ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns the scrollbar display policy. */
|
||||||
|
public int getScrollbarDisplayPolicy ()
|
||||||
|
{
|
||||||
|
return policy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns the viewport's scroll position. */
|
||||||
|
public Point getScrollPosition ()
|
||||||
|
{
|
||||||
|
// FIXME
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns an Adjustable representing the vertical scrollbar.
|
||||||
|
* The methods setMaximum, setMinimum, and setVisibleAmount should
|
||||||
|
* not be called on this Adjustable. They will throw AWTError if
|
||||||
|
* called.
|
||||||
|
*/
|
||||||
|
public Adjustable getVAdjustable ()
|
||||||
|
{
|
||||||
|
return vscroll;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns the size of the viewport. */
|
||||||
|
public Dimension getViewportSize ()
|
||||||
|
{
|
||||||
|
Insets ins = getInsets ();
|
||||||
|
int myw = width - ins.left - ins.right;
|
||||||
|
int myh = height - ins.top - ins.bottom;
|
||||||
|
|
||||||
|
Dimension cs;
|
||||||
|
if (ncomponents > 0)
|
||||||
|
cs = component[0].getPreferredSize ();
|
||||||
|
else
|
||||||
|
cs = new Dimension (myw, myh);
|
||||||
|
|
||||||
|
if (policy == SCROLLBARS_ALWAYS
|
||||||
|
|| (policy == SCROLLBARS_AS_NEEDED && myw < cs.width))
|
||||||
|
myw -= getVScrollbarWidth ();
|
||||||
|
|
||||||
|
if (policy == SCROLLBARS_ALWAYS
|
||||||
|
|| (policy == SCROLLBARS_AS_NEEDED && myh < cs.height))
|
||||||
|
myh -= getHScrollbarHeight ();
|
||||||
|
|
||||||
|
// A little optimization -- reuse the Dimension.
|
||||||
|
cs.setSize (myw, myh);
|
||||||
|
return cs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns the width of the vertical scrollbar. */
|
||||||
|
public int getVScrollbarWidth ()
|
||||||
|
{
|
||||||
|
if (peer == null)
|
||||||
|
return 0;
|
||||||
|
ScrollPanePeer spp = (ScrollPanePeer) peer;
|
||||||
|
return spp.getVScrollbarWidth ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Generates a String representation of this ScrollPane's state. */
|
||||||
|
public String paramString ()
|
||||||
|
{
|
||||||
|
return ("[" + getClass ().getName ()
|
||||||
|
+ ": " + ((ncomponents > 0) ? component[0].paramString () : "")
|
||||||
|
+ "]");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Set the layout manager for this component. ScrollPane has its
|
||||||
|
* own layout manager and overrides this method so that the layout
|
||||||
|
* manager cannot be changed.
|
||||||
|
* @param m The new layout manager (ignored)
|
||||||
|
*/
|
||||||
|
public final void setLayout (LayoutManager m)
|
||||||
|
{
|
||||||
|
// Nothing.
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sets the scroll position for this ScrollPane. If the point if
|
||||||
|
* out of range it is silently moved within range.
|
||||||
|
* @param x The x coordinate
|
||||||
|
* @param y The y coordinate
|
||||||
|
*/
|
||||||
|
public void setScrollPosition (int x, int y)
|
||||||
|
{
|
||||||
|
// According to the JCL we throw a NullPointerException if there
|
||||||
|
// is no child.
|
||||||
|
if (ncomponents == 0)
|
||||||
|
throw new NullPointerException ("no child in ScrollPane");
|
||||||
|
|
||||||
|
Dimension child_d = component[0].getPreferredSize ();
|
||||||
|
Dimension our_d = getViewportSize ();
|
||||||
|
|
||||||
|
int xmax = Math.max (0, child_d.width - our_d.width);
|
||||||
|
int ymax = Math.max (0, child_d.height - our_d.height);
|
||||||
|
|
||||||
|
if (x < 0)
|
||||||
|
x = 0;
|
||||||
|
else if (x > xmax)
|
||||||
|
x = xmax;
|
||||||
|
if (y < 0)
|
||||||
|
y = 0;
|
||||||
|
else if (y > ymax)
|
||||||
|
y = ymax;
|
||||||
|
|
||||||
|
ScrollPanePeer spp = (ScrollPanePeer) peer;
|
||||||
|
spp.setScrollPosition (x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sets the scroll position for this ScrollPane. If the point if
|
||||||
|
* out of range it is silently moved within range.
|
||||||
|
* @param p The new point
|
||||||
|
*/
|
||||||
|
public void setScrollPosition (Point p)
|
||||||
|
{
|
||||||
|
setScrollPosition (p.x, p.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
class ScrollPaneAdjustable implements Adjustable
|
||||||
|
{
|
||||||
|
AdjustmentListener listeners;
|
||||||
|
int orient;
|
||||||
|
int unit;
|
||||||
|
int block;
|
||||||
|
int value;
|
||||||
|
|
||||||
|
public ScrollPaneAdjustable (int orient)
|
||||||
|
{
|
||||||
|
this.orient = orient;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addAdjustmentListener (AdjustmentListener l)
|
||||||
|
{
|
||||||
|
listeners = AWTEventMulticaster.add (listeners, l);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBlockIncrement ()
|
||||||
|
{
|
||||||
|
return block;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaximum ()
|
||||||
|
{
|
||||||
|
Dimension child_d = component[0].getPreferredSize ();
|
||||||
|
Dimension our_d = getViewportSize ();
|
||||||
|
|
||||||
|
int xmax = Math.max (0, child_d.width - our_d.width);
|
||||||
|
int ymax = Math.max (0, child_d.height - our_d.height);
|
||||||
|
|
||||||
|
return (orient == Adjustable.HORIZONTAL) ? xmax : ymax;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMinimum ()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getOrientation ()
|
||||||
|
{
|
||||||
|
return orient;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getUnitIncrement ()
|
||||||
|
{
|
||||||
|
return unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getValue ()
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getVisibleAmount ()
|
||||||
|
{
|
||||||
|
Dimension d = getViewportSize ();
|
||||||
|
return (orient == Adjustable.HORIZONTAL) ? d.width : d.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeAdjustmentListener (AdjustmentListener l)
|
||||||
|
{
|
||||||
|
listeners = AWTEventMulticaster.remove (listeners, l);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBlockIncrement (int b)
|
||||||
|
{
|
||||||
|
block = b;
|
||||||
|
if (peer != null)
|
||||||
|
{
|
||||||
|
ScrollPanePeer spp = (ScrollPanePeer) peer;
|
||||||
|
spp.setBlockIncrement (this, b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaximum (int max)
|
||||||
|
{
|
||||||
|
throw new AWTError ("can't use setMaximum on this Adjustable");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMinimum (int min)
|
||||||
|
{
|
||||||
|
throw new AWTError ("can't use setMinimum on this Adjustable");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUnitIncrement (int u)
|
||||||
|
{
|
||||||
|
unit = u;
|
||||||
|
if (peer != null)
|
||||||
|
{
|
||||||
|
ScrollPanePeer spp = (ScrollPanePeer) peer;
|
||||||
|
spp.setUnitIncrement (this, u);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue (int v)
|
||||||
|
{
|
||||||
|
value = v;
|
||||||
|
if (peer != null)
|
||||||
|
{
|
||||||
|
ScrollPanePeer spp = (ScrollPanePeer) peer;
|
||||||
|
spp.setValue (this, v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVisibleAmount (int v)
|
||||||
|
{
|
||||||
|
throw new AWTError ("can't use setVisibleAmount on this Adjustable");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ScrollPaneAdjustable hscroll
|
||||||
|
= new ScrollPaneAdjustable (Adjustable.HORIZONTAL);
|
||||||
|
ScrollPaneAdjustable vscroll
|
||||||
|
= new ScrollPaneAdjustable (Adjustable.VERTICAL);
|
||||||
|
int policy;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,8 @@ public interface ComponentPeer
|
||||||
Dimension getMinimumSize();
|
Dimension getMinimumSize();
|
||||||
Dimension getPreferredSize();
|
Dimension getPreferredSize();
|
||||||
Toolkit getToolkit();
|
Toolkit getToolkit();
|
||||||
|
// The JCL says that handleEvent returns boolean. However, we've
|
||||||
|
// experimentally determined that it in fact actually returns void.
|
||||||
void handleEvent(AWTEvent e);
|
void handleEvent(AWTEvent e);
|
||||||
boolean isFocusTraversable();
|
boolean isFocusTraversable();
|
||||||
void paint(Graphics graphics);
|
void paint(Graphics graphics);
|
||||||
|
|
|
@ -17,5 +17,6 @@ public interface ScrollPanePeer extends ContainerPeer
|
||||||
int getVScrollbarWidth();
|
int getVScrollbarWidth();
|
||||||
void setScrollPosition(int x, int y);
|
void setScrollPosition(int x, int y);
|
||||||
void setUnitIncrement(Adjustable adj, int increment);
|
void setUnitIncrement(Adjustable adj, int increment);
|
||||||
|
void setBlockIncrement(Adjustable adj, int increment);
|
||||||
void setValue(Adjustable adj, int value);
|
void setValue(Adjustable adj, int value);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue