WinScrollbar.java revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* ident "%Z%%M% %I% %E% SMI"
*
*
* Copyright (c) 1994-1995, 2001 by Sun Microsystems, Inc.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for NON-COMMERCIAL purposes and without
* fee is hereby granted provided that this copyright notice
* appears in all copies. Please refer to the file "copyright.html"
* for further important copyright and licensing information.
*
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
* THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES
*
*
* Copyright (C) 1996 Active Software, Inc.
* All rights reserved.
*
* @(#) WinScrollbar.java 1.13 - last change made 05/02/97
*/
/**
* The horizontal Scrollbar variable.
*/
/**
* The vertical Scrollbar variable.
*/
/**
* The value of the Scrollbar.
*/
int value;
/**
* The maximum value of the Scrollbar.
*/
int maximum; // doesn't include the visible area
/**
* The minimum value of the Scrollbar.
*/
int minimum;
/**
* The size of the visible portion of the Scrollbar.
*/
int sVisible;
/**
* The Scrollbar's orientation--being either horizontal or vertical.
*/
int orientation;
/**
* The amount by which the scrollbar value will change when going
* up or down by a line.
*/
int lineIncrement = 1;
/**
* The amount by which the scrollbar value will change when going
* up or down by a page.
*/
int pageIncrement = 10;
/**
* Are we running on WindowsNT
*/
private boolean winNT;
private static WinScrollbar threadScrollbar;
private static Thread scrollThread;
private WinScrollbar currentScrollbar;
private int currentScrollAction;
private int currentScrollPosition;
private static final int SCROLL_DELAY = 250;
private static final int SCROLL_INTERVAL = 40;
/**
* Constructs a new vertical Scrollbar.
*/
public WinScrollbar() {
this(VERTICAL);
}
/**
* Constructs a new Scrollbar with the specified orientation.
* @param orientation either Scrollbar.HORIZONTAL
* or Scrollbar.VERTICAL
* @exception IllegalArgumentException When an
* illegal scrollbar orientation is given.
*/
public WinScrollbar(int orientation) {
switch (orientation) {
case Scrollbar.HORIZONTAL:
this.orientation = orientation;
break;
default:
/* JSTYLED */
throw new IllegalArgumentException(Global.getMsg("sunsoft.jws.visual.rt.awt.WinScrollbar.IllegalOrientation"));
}
}
/**
* Constructs a new Scrollbar with the specified orientation,
* value, page size, and minumum and maximum values.
* @param orientation either Scrollbar.HORIZONTAL
* or Scrollbar.VERTICAL
* @param value the scrollbar's value
* @param visible the size of the visible portion of the
* scrollable area. The scrollbar will use this value when paging up
* or down by a page.
* @param minimum the minimum value of the scrollbar
* @param maximum the maximum value of the scrollbar
*/
this(orientation);
}
/**
* Returns the orientation for this Scrollbar.
*/
public int getOrientation() {
return orientation;
}
/**
* Returns the current value of this Scrollbar.
* @see #getMinimum
* @see #getMaximum
*/
public int getValue() {
return value;
}
/**
* Sets the value of this Scrollbar to the specified value.
* @param value the new value of the Scrollbar. If this value is
* below the current minimum or above
* the current maximum, it becomes the
* new one of those values, respectively.
* @see #getValue
*/
}
}
}
}
/**
* Returns the minimum value of this Scrollbar.
* @see #getMaximum
* @see #getValue
*/
public int getMinimum() {
return minimum;
}
/**
* Returns the maximum value of this Scrollbar.
* @see #getMinimum
* @see #getValue
*/
public int getMaximum() {
return maximum;
}
/**
* Returns the visible amount of the Scrollbar.
*/
public int getVisible() {
return sVisible;
}
/**
* Sets the line increment for this scrollbar. This is the value
* that will be added (subtracted) when the user hits the line down
* (up) gadgets.
*/
public void setLineIncrement(int l) {
lineIncrement = l;
}
/**
* Gets the line increment for this scrollbar.
*/
public int getLineIncrement() {
return lineIncrement;
}
/**
* Sets the page increment for this scrollbar. This is the value
* that will be added (subtracted) when the user hits the page down
* (up) gadgets.
*/
public void setPageIncrement(int l) {
pageIncrement = l;
}
/**
* Gets the page increment for this scrollbar.
*/
public int getPageIncrement() {
return pageIncrement;
}
/**
* Sets the values for this Scrollbar.
* @param value is the position in the current window.
* @param visible is the amount visible per page
* @param minimum is the minimum value of the scrollbar
* @param maximum is the maximum value of the scrollbar
*/
int maximum) {
if (visible < 0)
visible = 0;
}
}
}
}
/**
* Returns the String parameters for this Scrollbar.
*/
protected String paramString() {
return super.paramString() +
",vert" : /* NOI18N */",horz");
}
/**
* Returns the minimum size for the scrollbar
*/
public Dimension minimumSize() {
if (orientation == VERTICAL)
else
}
/**
* Returns the preferred size for the scrollbar
*/
public Dimension preferredSize() {
return minimumSize();
}
// The rest of this code does the things
// that the peer would normally
// if the peer weren't so badly broken.
private int prevWidth = 0;
private int prevHeight = 0;
private int action = 0;
private int anchorPos;
private int anchorValue;
private int dragSpace;
private static final int UP = 10;
private static final int DOWN = 11;
private static final int LEFT = 12;
private static final int RIGHT = 13;
private static final int LINEUP = 20;
private static final int LINEDOWN = 21;
private static final int PAGEUP = 22;
private static final int PAGEDOWN = 23;
private static final int DRAG = 24;
private void peerSetValue(int value) {
repaint();
}
private void peerSetLineIncrement(int l) {
}
private void peerSetPageIncrement(int l) {
}
repaint();
}
else
prevHeight = height;
}
}
g = getGraphics();
draw(g);
}
g = getGraphics();
draw(g);
}
return;
}
private void drawScrollbar() {
// Erase the old version
g.setColor(getBackground());
int info[] = getDragBoxInfo();
fillPageBox(g, w, h, info);
}
private void drawOutline(Graphics g, int w, int h) {
if (orientation == VERTICAL) {
g.drawRect(0, h-w, w, w);
} else {
g.drawRect(w-h, 0, h, h);
}
}
private void drawEndBoxes(Graphics g, int w, int h) {
if (orientation == VERTICAL) {
} else {
}
drawBox(g, 0, h-w, w, w);
} else {
}
} else {
} else {
}
drawBox(g, w-h, 0, h, h);
} else {
}
}
}
if (orientation == VERTICAL) {
}
} else {
}
}
}
if (orientation == VERTICAL) {
} else {
}
}
private int [] getDragBoxInfo() {
int info[] = new int[2];
int minpix;
int deltapix;
if (orientation == VERTICAL) {
} else {
}
return info;
}
g.setColor(getBackground());
if (true)
return;
else {
g.drawLine(x, y, x+w-1, y);
g.drawLine(x, y, x, y+h-1);
g.drawLine(x+w, y, x+w, y+h);
g.drawLine(x, y+h, x+w, y+h);
}
}
int direction) {
// xoff=4 and yoff=4 for the default case where w=15 and y=15
int bd = 2;
switch (direction) {
case LEFT:
if (winNT) {
x -= xoff/4;
}
break;
case RIGHT:
if (winNT) {
}
break;
case UP:
if (winNT) {
}
break;
case DOWN:
if (winNT) {
}
break;
}
g.fillPolygon(p);
}
private static final double PAGE_DFACTOR = 0.8;
/**
* Returns a darker version of this color used for the paging
* highlight color.
*/
}
if (orientation == VERTICAL) {
if (y < w) {
lineUp(y);
} else if (y >= (h-w)) {
lineDown(y);
} else {
int info[] = getDragBoxInfo();
pageUp(y);
pageDown(y);
dragStart(x, y);
}
}
} else {
if (x < h) {
lineUp(x);
} else if (x >= (w-h)) {
lineDown(x);
} else {
int info[] = getDragBoxInfo();
pageUp(x);
pageDown(x);
dragStart(x, y);
}
}
}
return false;
}
drag(x, y);
return true;
} else if (threadScrollbar != null &&
threadScrollbar.currentScrollbar == this) {
synchronized (threadScrollbar) {
if (orientation == VERTICAL)
else
}
}
return false;
}
dragStop(x, y);
}
action = 0;
repaint();
return false;
}
boolean status = false;
status = true;
}
repaint();
return status;
}
boolean status = false;
status = true;
}
repaint();
return status;
}
boolean status = false;
status = true;
}
repaint();
return status;
}
boolean status = false;
status = true;
}
repaint();
return status;
}
private void dragStart(int x, int y) {
if (orientation == VERTICAL)
anchorPos = y;
else
anchorPos = x;
anchorValue = value;
int info[] = getDragBoxInfo();
if (orientation == VERTICAL)
else
}
private void drag(int x, int y) {
if (orientation == VERTICAL)
newDragValue(y);
else
newDragValue(x);
}
private void dragStop(int x, int y) {
action = 0;
drag(x, y);
}
private void newDragValue(int pos) {
if (valDiff < 0)
else
repaint();
}
return;
if (threadScrollbar == null) {
threadScrollbar = this;
"WindowsScrollbarThread");
scrollThread.setDaemon(true);
}
synchronized (threadScrollbar) {
threadScrollbar.currentScrollbar = this;
}
}
private void cancelAutoScroll() {
if (threadScrollbar != null) {
synchronized (threadScrollbar) {
}
}
}
public synchronized void run() {
boolean scrolling = false;
long waitTime;
if (currentScrollbar == null) {
waitTime = 0;
scrolling = false;
} else {
if (scrolling) {
if (!doScroll(currentScrollbar,
waitTime = 0;
} else {
}
} else {
scrolling = true;
}
}
// Wait for "waitTime" milliseconds.
// But if "waitTime" is zero,
// then just wait for a notify. If
// the currentScrollbar changes,
// then don't wait any longer.
try { wait(0); }
catch (InterruptedException ex) {}
} else {
catch (InterruptedException ex) {}
}
if (currentScrollbar != initScrollbar)
scrolling = false;
}
}
}
boolean status = false;
switch (action) {
case LINEUP:
break;
case LINEDOWN:
break;
case PAGEUP:
} else {
// Keep trying to scroll for the case
// where the user drags
// the mouse while paging. We want to
// track the drag position
// in the direction of the original paging action.
status = true;
}
break;
case PAGEDOWN:
} else {
// Keep trying to scroll for the case
// where the user drags
// the mouse while paging. We want to
// track the drag position
// in the direction of the original paging action.
status = true;
}
break;
default:
break;
}
return status;
}
int pos) {
boolean status = false;
}
return status;
}
}