Managing graphical selections: Selector

The Selector interactor selects and highlights (and deselects and unhighights) items on the Slate, and, if the mouse is moved when a selection is made, moves those items. It can be cascaded with another interactor to implement drag-selecting of multiple items. Apart from the usual interactor machinery, it has methods to query, set, and clear the set of selected items.

The Selector is still under development: it turns out that abstracting this kind of behavior and allowing arbitrary composition with other interactors is quite difficult.

The Selector has the following options:

The selector has a number of methods available to clients and other interactors:

To enable selection of items, all candidate items musts be bound to the Selector interactor. Usually, all candidate will share a single tag, such as "selectable." To perform drag-selecting, the Selector must be cascaded with another interactor, which drives the Selector's click, drag, and release methods.

To support de-selecting of items, the bind method understands the -toggle flag: if present, a mouse click with the given buttons and modifiers toggles items into and out of the selection. Thus, a Selector is usually bound twice: once with the button and options used to select items, and once with the buttons and options used to toggle-select items. This option can also be given to the bind method of the drag-selector interactor: it will be forwarded by the drag-selector to the Selector, which will toggle the state of any item that moves into or out of the drag-selection region.

Enhancements: (i) Setting up the interaction between the Selector and other interactors is rather clumsy -- we need to examine this again (see below). (ii) Highlighting of selected items needs to be parameterized somehow.

Note on mediation: Although the selector certainly works, it has been awkward to use it together with other interactors. We are trying to decide whether its functionality should be built directly into the Slate, or whether we need to create special Mediator objects to manage the Selector and a bunch of other interactors. For the record, here is the code that mediates between the Selector, Follower, and Editor interactors; you can see why we need to rethink the mediation problem:

# Create the selector. Shift-click toggles selected items.
set selector [$slate interact create Selector \
    -dragcolor grey60 -highlightcolor black -highlightwidth 1]
$selector bind selectable -button 1
$selector bind selectable -button 1 -modifiers shift -toggle

# Move selected items only if all are tagged "moveable"
$selector configure -movepredicate \
    "lnull \[lsubtract \[$selector contents\] \[$slate find withtag moveable\]\]"

# Create the background item used for drag-selecting. This is resized
# (elsewhere) when the slate is mapped to the screen or changes size.
$slate create rect 0 0 0 0 -outline "" -tags background
::bind $slate <Configure> \
    "$slate coords background 0 0 \
    \[winfo width $slate\] \[winfo height $slate\]"

# Create the drag-selector. Shift-click or button 2 toggles items
set dragselector [$slate interact create Follower]
$dragselector bind background -button 1
$dragselector bind background -button 1 -modifiers shift -toggle
$dragselector cascade $selector

# Create an editor for text items. Button 2 activates
set lineeditor [$slate interact create Editor]
$lineeditor bind editable -button 2

# Starting editing clears all selected items and prevents
# selection on the text item
$lineeditor configure -activatecommand \
    "$selector clear; $slate dtag \[$lineeditor target\] selectable"

# Stopping editing makes the text item selectable again
$lineeditor configure -deactivatecommand \
    "$slate addtag selectable withtag \[$lineeditor target\]"

# Selecting or deselecting an item deactivates the text editor
$selector configure -selectcommand "$lineeditor stop"

# Using the drag-selector deactivates the text editor
$dragselector configure -activatecommand "$lineeditor stop"

Back up
Tycho Home Page


Copyright © 1996, The Regents of the University of California. All rights reserved.
Last updated: 96/12/11, comments to: johnr@eecs.berkeley.edu