In this demo, it is not necessary to implement the usual updateGrp() method and call it from the draw() because, the scrollbars take care of any clicking on them and nothing else responds to clicks. |
Draggable is an abstract class that simplifies working with its extensions which include:
This demo includes the two ScrollBars and a ScrollSketch which are extensions of Draggable. On the other hand, the "Drag me" button is not so it has to be coded in somewhat different style. If you look at the DraggableDemo.pde code, you can see the difference in the coding style in the mousePressed and mouseDragged() methods. The Draggable class allows one to treat all of its extensions at one time - at least if special actions are not needed for any of the items. The red, aqua, and light greenish rectangles are just simple rectangle drawings. The option to allow clicks (or taps on a touch screen) to move the scroll buttons has not been used on any of the scroll bars in this demo. |
Display sketch code: DraggableDemo.pde | The Draggable code is in the file Dragger.pde |
abstract class Draggable
extends ClickablePanel
which extends Clickable
The Draggable class provides the same three constructors as the ClickablePanel. It only has three new methods that conveniently allow handling extensions with the same coding.
boolean processClicks - When true, the draggable panel will respond to clicks on the panel or bar. The default is false. |
** Draggable(int leftX, int topY,
int theWidth, int theHeight, String theLabel, color stdColor) - Creates a Draggable allowing the most generality. |
** Draggable(int leftX, int topY,
int theWidth, int theHeight, String theLabel) - Construct an invisible Draggable given its location, width, height, and label (which is not displayed) but without any color. |
** Draggable(String theLabel) - Makes the entire sketch an invisible Draggable given only a label (which is not displayed). |
** boolean readyForDrag(Dragger theTracker) - This "abstract" method simplifies working with items that can be dragged. It just returns false and MUST be overridden. It would be called by the mousePressed() method. |
** boolean moved(Dragger theTracker) - An "abstract" method that simplifies working with items that can be dragged. It just returns false and MUST be overridden. This method would be called by the mouseDragged() method. |
** void setProcessClicks(boolean clicks) - Sets processClicks true or false. When processClicks is true, the scroll button is moved to the location of a click on the bar. False is the default. (This option does not apply to up and down buttons if they are present.) |
Method use codes:
** This constructor or method is designed to be called in the user sketch.
* This method is normally not called in the user's sketch unless the Clickable item was not been included in a ClickableGroup. ClickableGroup automatically uses the method as needed. Exception: This method may be needed if the user is extending Clickable with a new class.
# This constructor or method is rarely used in the user program. In Java, it would probably marked "private". Clickable, ScrollBar, and some other abstract constructors would never be called directly by the user sketch because they do nothing useful unless the user is extending a class.
Inherited from ClickablePanel
Fields
clickX,
clickY,
invisible,
wholeSkectch
Constructors
ClickablePanel, ClickablePanel, ClickablePanel
Methods
adjustPanel,
checkForClick,
display,
drawOnPanel,
getClickX,
getClickY,
getPanelX,
getPanelY,
isOver,
setClickX,
setClickY,
setColor
Inherited from Clickable
Fields
NOTHING_CLICKED,
COMBO_BUTTON,
DISABLED_COLOR,
borderColor,
c,
clicked,
clickedItemNum,
colorState,
enabled,
h,
label,
over,
overC,
scrollable,
selected,
selectedItemNum,
visible,
w,
x,
y
Constructors
Clickable
Methods
checkForClick,
display,
doNotSelect,
getClickedItemNum,
getColorState,
getH,
getItem,
getLabel,
getSelected,
getSelectedItem,
getSelectedItemLabel,
getSelectedItemNum,
getW,
getX,
getY,
hasBeenClicked,
hideSomething,
isOver,
setBorderColor,
setColorState,
setH,
setLabel,
setScrollable,
setSelected,
setSelectedItemNum,
setEnabled,
setVisible,
setW,
setX,
setY,
sX,
sY
Revised: 04/11/2014