abstract class Clickable Documentation

Clickable is an abstract class so it cannot be implemented directly. However, almost all of the classes in this package are extensions of Clickable. Its major advantage is that it provides a common environment for all those classes.

In addition to the classes in the Clickable.pde file, there are additional classes in the ClickableMeter.pde and Dragger.pde. The latter file includes classes that implement drags and scrollbars.

Definitions

item
or
clickable

A Clickable item. That is, an item that can respond to a mouse clicks and has been declared as a descendant of the Clickable.
compound item An item that is composed of or contains other items. Examples: ButtonGroup, ListBox.
simple item An item that is not a compound item. Examples: Button, ClickablePanel.
draggable An item that also can be dragged or scrolled.

abstract class Clickable

Global Fields and Methods

The global fields and methods are all suffixed with "_" in hopes that it will help distinguish them from fields and methods in the user's sketch.

# boolean stillSearching_ - Global variable used both by Clickable items and ClickableGroup
** float round2_(float x)
- A general purpose routine that rounds x to 2 decimal places.
** int select_(boolean vert, int trueValue, int falseValue)
- This method is used to determine the appropriate value for the width and height in simplified constructors. If vert is true, trueValue is selected and returned. If it is false, falseValue is selected.
(The following fields and methods are only needed when the ScrollSketch class is used.)

** soX_ - The scroll offset for X - to be subtracted from the unscrolled x coordinate.
** soY_ - The scroll offset for Y - to be subtracted from the unscrolled y coordinate.
** sX_(int locX) - used by the user program to adjust the x coordinate for scrolling. locX is the unscrolled x coordinate.
** sY_(int locY) - used by the user program to adjust the y coordinate for scrolling. locY is the unscrolled y coordinate.

Class Description

Note: Several fields and methods are primarily for compound items. These fields and methods are included here as kind of abstract method and allows ClickableGroup to use them without first determining if they are really needed.

The table of fields and properties below is in two columns. The first column gives the interpretation in a simple item. The second column gives the interpretation in a compound item when it is different.

Simple items Compound items
Clickable fiields

public static final int NOTHING_CLICKED = -1 - Initial value of clickedItemNum before anything has been clicked.
public static final int COMBO_BUTTON = 10000 - Denotes the "always" visible button of a ComboBox or Menu.
public static final int DISABLED_COLOR = #EEEEEE - The color used for disabled buttons.
String label - The item's label.
int x, y, w, h - typically the left x, top y, width and height but usage depends on the class.
boolean visible - The item is visible.
boolean enabled - The item is enabled.
boolean over - The mouse cursor is over the item.
boolean clicked - The item has been clicked.
boolean selected - Item has been selected. False by default.
color[] c, overC - Array of colors. c is used normally, overC is used when the mouse cursor is over the item.
color borderColor - Color of the border. Default is black.
int colorState - Specifies which of colors in the "c" and "overC" arrays should be used. State = 0 is the normal state, state = 1 is the selected state. Multistate buttons can have additional states.
int selectedItemNum - 0 for simple items indicating itself.
int clickedItemNum - 0 for simple items
boolean scrollable - Determines if the item is scrollable.

















Number of the subitem selected.
Number of the subitem clicked.

# Clickable(String theLabel)
- The constructor sets label and defaults.
** void setVisible(boolean b)
- Sets visibility of the item.
not visible implies none of the sub items are visible.
** void setEnabled(boolean b)
- Sets enabled for the item.
not enabled implies none of the sub items are enabled.
** void setX(int xVal)
- Sets the x value. (Usage depends on the class but typically the left x value.)
** int getX()
- Gets the x value. (Usage depends on the class but typically the left x value.)
** void setY(int yVal)
- Sets the y value. (Usage depends on the class but typically the top y value.)
** int getY()
- Gets the y value. (Usage depends on the class but typically the top y value.)
** void setW(int wVal)
- Sets the w value. (Usage depends on the class but typically the width.)
** int getW()
- Gets the w value. (Usage depends on the class but typically the width.)
** void setH(int hVal)
- Sets the h value. (Usage depends on the class but typically the height.)
** int getH()
- Gets the h value. (Usage depends on the class but typically the height.)
** void setLabel(String theLabel)
- Sets the label as specified.
** String getLabel()
- Returns (trimmed) label.
* boolean checkForClick()
- Can only be called in mouseReleased! Assuming the item is not hidden or disabled, it returns true if the mouse cursor is over the item when clicked after setting "clicked" to true. It carries out any special action needed for the clicked item. E.g. it toggles a Checkbox. (Sketches typically use ClickableGroup's checkForClick().)
Can only be called in mouseReleased! Assuming the item is not hidden or disabled it uses a depth first search for a clicked item and returns true if the mouse cursor is over the item or any of its subitems. Uses each item's checkForClick on the way down. On the way back up, it marks the item as clicked and selected (if appropriate) and sets both clickedItemNum and selectedItemNum (if appropriate).
* boolean hasBeenClicked()
- Returns true if the item has been clicked after setting "clicked" to false. Must be called when processing clicks - typically in user's draw() method or a method called by draw(). (Sketches typically use ClickableGroup's hasBeenClicked().)
Returns true if the item or any subitems in the compound item have been clicked after setting the clicked field to false.
** int getClickedItemNum()
- Returns 0 (its own number).
Returns the number of the (last) subitem clicked.
# void setSelected(boolean b)
- Sets "selected".
** boolean getSelected()
- Returns "selected".
** void setSelectedItemNum(int item)
- Sets selectedItemNum to "item".
Could be overridden to provide error control.
** int getSelectedItemNum()
- Returns selected item number.
** Clickable getSelectedItem()
- Returns itself.
Returns selected item.
* String getSelectedItemLabel()
- Returns its own label.
Returns the selected item's label.
** Clickable getItem(int b)
- Returns itself.
Returns the subitem whose subscript is b.
** void setColorState(int state)
- Sets colorState to value of "colorState". States: 0 normal. 1 selected. Multistate buttons may have more states.
** int getColorState()
- Returns the colorState.
* boolean isOver()
- Returns false but must be overridden to return true if mouse is over the item. Is often called by checkForClick and must be called by the user's draw() method to update the over field before it is drawn. (Sketches typically use ClickableGroup's isOver().)
It must check to see if the mouse is over any of its subitems.
** boolean doNotSelect()
- Returns false.
Override for a toggled item that should not be selected when it is in some kind of list box.
# void hideSomething()
- Can be called even if there is nothing to hide - (used to simplify handling of ClickableGroup.)
Normally does nothing except for ComboBoxes and Menus where it hides the ListBox. Could be used to hide anything that need hiding. Must be called in mouseRelease so that every item needing to have some hidden is hidden.
* void display()
- By default pastes the label but must be overridden to do display the item appropriately when called by the user's draw() method. Ignored by items that are not visible and uses a special color for items that are not enabled. (Sketches typically use ClickableGroup's display().)
Display all subitems (that are not hidden).
** int sX(int locX)
- (Scroll X.) Adjusts the item's x coordinate when the item is scrolled. It changes nothing if the item is not scrollable. Notice that it is a little more sophisticated than the global method sX_. Note: User programs will normally use the global method sX_(locX).
** int sY(int locX)
- (Scroll Y.) Adjusts the item's y coordinate when the item is scrolled. It changes nothing if the item is not scrollable. Notice that it is a little more sophisticated than the global method sY_. Note: User programs will normally use the global method sY_(locY).
** void setScrollable (boolean canScroll)
- Used to specify that this item is or is not scrollable. May need to be overridden by compound items.
** void setBorderColor (color theBorderColor)
- Sets the border color. It is not used by all Clickable items but is for Buttons, CircleButtons, ClickablePanels and scroll bars.. The default is black.

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.

Return to the top of the page

Revised: 04/11/2014