Managing graphical selections: Selector

The Selector interactor selects and highlights (and deselects and unhighlights) items on the Slate. It provides a standard drag-selection operation, and coordinates other interactors that need to operate on selected items. Apart from the usual interactor machinery, it has methods to query, set, and clear the set of selected items. The Slate's selector method provides a simple interface to a single selector, which is all that you will need for most applications. The Slate also has some other methods, such as select, deselect, selection, which interface to the default Selector.

To enable selection of items, all candidate items must be bound to the Selector interactor with the bind method. Below are two examples illustrating a reasonably complex interaction setup. They differ in the ways that the modal interaction needed for editing text items is provided.

Example 1: Delayed activation

In this example, clicking on a text item selects it for moving just like any other item. Shift-clicking and shift-dragging can be used to toggle items into and out of the selection. (Note that the arrow item cannot be moved.) To edit a text item, select it, and then click on it again -- provided that the text item is the only item selected, it goes into text editing mode. Clicking on the background or any other item will make it non-editable again. The Escape key always clears the selection.

set slate [::tycho::Slate::demoslate]

set follower [$slate interactor Follower]
set lineeditor [$slate interactor TextItemEdit]
set selector [$slate interactor Selector]

# Enable selection and drag-selection with button 1; shift-click toggles
$selector bind selectable -button 1
$selector bind selectable -button 1 \
        -modifiers shift -toggle 1

# Delegation with regular click
$selector delegate $follower moveable -button 1 
$selector delegate $follower editable -button 1 -mode {0 +}
$selector delegate $lineeditor editable -button 1 -mode 1

# Delegation with shift-click
$selector delegate $follower moveable -button 1 \
    -modifiers shift
$selector delegate $follower editable -button 1 -mode {0 +} \
    -modifiers shift
$selector delegate $lineeditor editable -button 1 -mode 1 \
    -modifiers shift

# To illustrate, here are some items. The green frame and the labeled
# rectangle can be moved; the arrow can be selected but not moved, and
# the plain text item can be selected and edited but not moved.
$slate create Frame 120 120 150 140 -borderwidth 4 -color green \
	-tags {moveable selectable}
$slate create Solid 100 20 120 20 120 10 140 30 120 50 120 40 100 40 \
	-tags selectable
$slate create text 50 50 -text {Fred said hello} -anchor w \
	-tags {selectable editable}
$slate create text 150 200 -text {Over to you, Spencer!} \
	-tags {selectable editable}
$slate create LabeledRect 170 65 239 105 -fill blue -outline red \
	-anchor nw -text Foo \
	-graphics "line 0 0 100 100; line 0 100 100 0" \
	-tags {moveable selectable}

Example 2: Alternate activation

In this example, clicking on a text item selects it for editing immediately. To select the item for moving, either drag-select it or use Control-click to select it. Once selected, the text item can be moved like any other item. This setup has the advantage that text can be edited immediately, but requires dexterous (IMHO) use of the control key if moving text items.

set slate [::tycho::Slate::demoslate]

set follower [$slate interactor Follower]
set lineeditor [$slate interactor TextItemEdit]
set selector [$slate interactor Selector]

# Enable selection and drag-selection with button 1; shift-click toggles
$selector bind selectable -button 1
$selector bind selectable -button 1 \
        -modifiers shift -toggle 1

# Delegation with regular click
$selector delegate $follower moveable -button 1 
$selector delegate $follower editable -button 1 -mode {1 +}
$selector delegate $lineeditor editable -button 1 -mode 0

# Delegation with shift-click
$selector delegate $follower moveable -button 1 \
    -modifiers shift
$selector delegate $follower editable -button 1 -mode {1 +} \
    -modifiers shift
$selector delegate $lineeditor editable -button 1 -mode 0 \
    -modifiers shift

# Enable selection and drag-selection with control-button 1;
# shift-control-click toggles
$selector bind selectable -button 1 \
        -modifiers control
$selector bind selectable -button 1 \
        -modifiers {shift control} -toggle 1

# Delegation with control-click
$selector delegate $follower moveable -button 1 \
    -modifiers control
$selector delegate $follower editable -button 1 \
    -modifiers control

# Delegation with shift-control-click
$selector delegate $follower moveable -button 1 \
    -modifiers {shift control} -toggle 1
$selector delegate $follower editable -button 1 \
    -modifiers {shift control} -toggle 1

# To illustrate, here are some items. The green frame and the labeled
# rectangle can be moved; the arrow can be selected but not moved, and
# the plain text item can be selected and edited but not moved.
$slate create Frame 120 120 150 140 -borderwidth 4 -color green \
	-tags {moveable selectable}
$slate create Solid 100 20 120 20 120 10 140 30 120 50 120 40 100 40 \
	-tags selectable
$slate create text 50 50 -text {Fred said hello} -anchor w \
	-tags {selectable editable}
$slate create text 150 200 -text {Over to you, Spencer!} \
	-tags {selectable editable}
$slate create LabeledRect 170 65 239 105 -fill blue -outline red \
	-anchor nw -text Foo \
	-graphics "line 0 0 100 100; line 0 100 100 0" \
	-tags {moveable selectable}

Back up
Tycho Home Page


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