DraggablePanel Demo and Documentation

    

The DraggablePanel extends Draggable which extends ClickablePanel. Hence it has draggable properties in addition to all the ClickablePanel's capabilities.

This demo has three DraggablePanels.

The green panel is draggable and also responds to clicks. If it is clicked, it jumps to the upper left corner of the sketch. This response is handled in the updateGrp() method which is called by the draw() method.

The unframed flower image consists of the flower image superimposed on top of an invisible DraggablePanel. The upper left coordinates of the panel are used for coordinates of the image. Its DraggablePanel uses the processClicks option and responds to clicks by centering the panel (and hence the picture) on the click.

The framed image takes advantage of the ClickablePanel's drawOnPanel() method. The demo defines a MyDraggablePanel class which includes the required constructor and the drawOnPanel() method. That method simply draws the image on top of the panel. This panel does not use the processClicks option and hence ignores clicks.

Display sketch code: DraggablePanelDemo.pde The DraggablePanel code is in the file Dragger.pde

class DraggablePanel
extends Draggable
which extends ClickablePanel
which extends Clickable

DraggablePanel extends Draggable which extends ClickablePanel. Because it inherits all the methods of ClickablePanel and Draggable, it is very simple consisting of just two constructors and two methods. The order of panels in the ClickableGroup and Dragger becomes important if the panel can be moved on top or below another Clickable and draggable items.

Additional fields

int upDownDivisor - movement divisor for up/down buttons.
** DraggablePanel(int leftX, int topY, int theWidth, int theHeight,
                    String theLabel, color stdColor)
- Constructs a panel which can be dragged. It uses the same parameters as the first constructors of ClickablePanel and Draggable.
** DraggablePanel(int leftX, int topY, int theWidth, int theHeight,
                    String theLabel, color stdColor)
- Constructs an invisible panel which can be dragged. It use the same parameters as the second constructors of ClickablePanel and Draggable. Because it is invisible, no color is specified. It particularly useful for making things that are not draggable appear to be draggable.
** boolean checkForClick()
- Allows the user sketch to respond to clicks and also implements the process clicks option. If needed, call from draw() or a submethod.
** boolean readyForDrag(Dragger theTracker)
- Determines if the panel has experienced a mousePressed event and could be ready for a mouse drag. It sets the starting point position of a drag. The minimumForDrag specifies the minimal drag that qualifies as a drag. It is called by mousePressed(). Returns true if the cursor is above the panel and thus the panel is ready to be dragged.
** boolean moved(Dragger theTracker)
- If the panel is the current draggable item, it moves the panel and returns true. It is called by mouseDragged().

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 DraggablePanel

Fields
upDownDivisor

Constructors
DraggablePanel, DraggablePanel

Methods
checkForClick, moved, readyForDrag


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

Return to the top of the page

Revised: 04/11/2014