sub_arctic.lib
Class multi_button

java.lang.Object
  |
  +--sub_arctic.lib.min_interactor
        |
        +--sub_arctic.lib.base_interactor
              |
              +--sub_arctic.lib.multi_button
Direct Known Subclasses:
button, menu_button, palette_button, toggle

public class multi_button
extends base_interactor
implements inout_draggable, pressable, does_callback

This class implements a multi-state button object. It can have any number of states and may have transitions between those states with individual looks.


Field Summary
protected  callback_object _callback_obj
          Object we make callbacks to
protected  int _cur_state
          Index of current state.
protected  boolean _in_transition
          Internal indicator of whether we are currently in transition from one state to the next.
protected  loaded_image[] _state_looks
          Image set for "normal" appearance in each state.
protected  loaded_image[] _transition_looks
          Image set for "transition" appearance from each state.
static int BUTTON_ACTION_CALLBACK
          Callback number constant for the button state transition callback.
 
Fields inherited from class sub_arctic.lib.base_interactor
_child_index, _child_list, _clip_bounds, _constraint_flags, _enabled_constraint, _flags, _h, _h_constraint, _parent, _part_a_constraint, _part_b_constraint, _user_data, _visible_constraint, _w, _w_constraint, _x, _x_constraint, _y, _y_constraint, default_child_hint
 
Constructor Summary
multi_button(int x, int y, loaded_image[] st_looks, loaded_image[] trans_looks, callback_object call_obj)
          Full constructor.
 
Method Summary
protected  void calc_size()
          (Re)calculate size as max of images.
 callback_object callback_obj()
          Object that this button makes callbacks to when pressed.
 int cur_state()
          Index of current state.
 void do_action(int action_num, event evt, java.lang.Object parm)
          Perform the (only) action associated with this interactor.
 void do_callback(event evt)
          Invoke the callback object.
protected  void draw_self_local(drawable d)
          Draw the button
 int first_callback_num()
          First valid callback number
 loaded_image get_state_look(int indx)
          Get the "normal" appearance image for a given state.
 loaded_image get_transition_look(int indx)
          Get the "transition" appearance image from a given state.
 boolean inout_drag_end(event evt, boolean ended_inside, java.lang.Object user_info)
          Handle input corresponding to the end of an inout drag.
 boolean inout_drag_enter(event evt, java.lang.Object user_info)
          Handle "drag" into the bounds of the object.
 boolean inout_drag_exit(event evt, java.lang.Object user_info)
          Handle "drag" out of the bounds of the object.
 boolean inout_drag_start(event evt, boolean starts_inside, java.lang.Object user_info)
          Handle input corresponding to the start of an inout tracking drag.
 int intrinsic_constraints()
          This interactor determines width and height internally, and does not intrinsically constrain part_a.
 int last_callback_num()
          Last valid callback number
 int next_state()
          Indicate what the next state will be.
 int part_a()
          Return the value of the part_a component of this object.
 boolean press(event evt, java.lang.Object user_info)
          Handle mouse presses in our bounds.
 boolean release(event evt, java.lang.Object user_info)
          Companion for press() -- ignore here.
 void set_callback_obj(callback_object cb)
          Set the callback object that this button makes callbacks to when pressed.
 void set_cur_state(int st)
          Set index of current state.
 void set_looks(loaded_image[] st_looks, loaded_image[] trans_looks)
          Set both "normal" and "transition" image sets.
 void set_part_a(int v)
          Set the part_a component of this object.
protected  void set_raw_part_a(int v)
          Set part_a value directly bypassing the constraint system (but doing damage).
 void set_state_look(int indx, loaded_image img)
          Set the "normal" appearance image for a given state.
 void set_transition_look(int indx, loaded_image img)
          Set the "transition" appearance image from a given state.
 loaded_image[] state_looks()
          Image set for "normal" appearance in each state.
 loaded_image[] transition_looks()
          Image set for "transition" appearance from each state.
 
Methods inherited from class sub_arctic.lib.base_interactor
active_constraints, add_child, add_user_datum, attach_dependent, bound, child_index, child, clear_child_list, clear_constraint_flag_bit, clear_flag_bit, configure, constraint_flag_is_set, constraint_flag_string, constraint_on, custom_fun1, custom_fun2, damage_fixed, damage_from_child, damage_self, damage_self, damage_self, damage_self, damage_self, detach_dependent, do_action, do_callback, drag_feature_point, draw_children, draw_self, enabled_constraint, enabled, enter_local_coordinates, eval_enabled, eval_h, eval_part_a, eval_part_b, eval_visible, eval_w, eval_x, eval_y, eval, exit_local_coords, feature_point_enabled, feature_point, filter_pt, find_child, fixed_children, flag_is_set, flag_string, focus_set_enter, focus_set_exit, get_awt_component, get_external_constraint, get_part, get_top_level, get_value, global_to_local, global_to_local, h_constraint, h, handle_cycle, inform_ood, insert_child, inside_bounds, into_local, into_local, into_parent, into_parent, is_constrained, local_to_global, local_to_global, mark_all_ood, mark_enabled_ood, mark_h_ood, mark_ood, mark_part_a_ood, mark_part_b_ood, mark_reparented_ood, mark_visible_ood, mark_w_ood, mark_x_ood, mark_y_ood, marked_ood, move_child_downward, move_child_downward, move_child_to_bottom, move_child_to_bottom, move_child_to_top, move_child_to_top, move_child_upward, move_child_upward, move_downward, move_to_bottom, move_to_top, move_upward, new_look_configure, next_sibling, num_actions, num_children, num_feature_points, ood_inform_all, parent, part_a_constraint, part_b_constraint, part_b, pick_within_children, pick, picked_by, pos, prev_sibling, register_resource_names, remove_child, remove_child, remove_user_datum, restyle_look_resources, restyle, set_child_index, set_child, set_constraint_flag_bit, set_constraint_flag_bit, set_constraint, set_constraint, set_enabled_constraint, set_enabled_constraint, set_enabled_constraint, set_enabled, set_flag_bit, set_flag_bit, set_h_constraint, set_h_constraint, set_h_constraint, set_h, set_intrinsic_h, set_intrinsic_size, set_intrinsic_w, set_parent, set_part_a_constraint, set_part_a_constraint, set_part_a_constraint, set_part_b_constraint, set_part_b_constraint, set_part_b_constraint, set_part_b, set_pos, set_pos, set_raw_enabled, set_raw_h, set_raw_part_b, set_raw_visible, set_raw_w, set_raw_x, set_raw_y, set_size, set_style_lock, set_user_info, set_visible_constraint, set_visible_constraint, set_visible_constraint, set_visible, set_w_constraint, set_w_constraint, set_w_constraint, set_w, set_x_constraint, set_x_constraint, set_x_constraint, set_x, set_y_constraint, set_y_constraint, set_y_constraint, set_y, setup_for_children, setup_for_children, setup_for_fixed_children, size, style_change_local, style_change, supports_children, tag_str, toString, traverse_and_collect_children, traverse_and_collect_parent, traverse_and_collect, trivial_reject, trivial_reject, user_data, user_info, value_ood, visible_constraint, visible, w_constraint, w, x_constraint, x_into_local, x_into_parent, x, y_constraint, y_into_local, y_into_parent, y
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_in_transition

protected boolean _in_transition
Internal indicator of whether we are currently in transition from one state to the next.

_cur_state

protected int _cur_state
Index of current state.

_state_looks

protected loaded_image[] _state_looks
Image set for "normal" appearance in each state.

_transition_looks

protected loaded_image[] _transition_looks
Image set for "transition" appearance from each state.

_callback_obj

protected callback_object _callback_obj
Object we make callbacks to

BUTTON_ACTION_CALLBACK

public static final int BUTTON_ACTION_CALLBACK
Callback number constant for the button state transition callback.
Constructor Detail

multi_button

public multi_button(int x,
                    int y,
                    loaded_image[] st_looks,
                    loaded_image[] trans_looks,
                    callback_object call_obj)
Full constructor. The two image sets provided give normal appearance for each state of the button, and a transition appearance out of each state of the button. The transition set may be coded as null in which case the next state image is used when a transition is needed. Otherwise the two image sets must be the same size.
Parameters:
int - x x position of this object
int - y y position of this object
loaded_image[] - st_looks the set of images for the looks of this object
loaded_image[] - trans_looks the set of images for the looks of transitions of this object.
callback_object - call_obj the object to send the callbacks to.
Method Detail

intrinsic_constraints

public int intrinsic_constraints()
This interactor determines width and height internally, and does not intrinsically constrain part_a.
Returns:
int the constant mask for an internal width and height
Overrides:
intrinsic_constraints in class base_interactor

part_a

public int part_a()
Return the value of the part_a component of this object. In our case this is stored in _cur_state.
Overrides:
part_a in class base_interactor

set_raw_part_a

protected void set_raw_part_a(int v)
Set part_a value directly bypassing the constraint system (but doing damage). In this case part_a is stored in _cur_state.
Parameters:
int - v the new value for part_a.
Overrides:
set_raw_part_a in class base_interactor

set_part_a

public void set_part_a(int v)
Set the part_a component of this object. In our case this is stored in _cur_state.
Parameters:
int - v the new value of part_a.
Overrides:
set_part_a in class base_interactor

cur_state

public int cur_state()
Index of current state. For toggles, "off" or "unchecked" is zero. The object starts in state 0 by default. This is mirrored as part_a for this object.
Returns:
int the current state from 0 to n-1

set_cur_state

public void set_cur_state(int st)
Set index of current state. For toggles, "off" or "unchecked" is zero. This is mirrored as part_a for this object.
Parameters:
int - the new current state.

next_state

public int next_state()
Indicate what the next state will be. Be default we just increment wrapping back to zero as needed.
Returns:
int the next state.

do_action

public void do_action(int action_num,
                      event evt,
                      java.lang.Object parm)
Perform the (only) action associated with this interactor. For this interactor, we move to the next state by calling set_cur_state(next_state()) then invoke the callback. All the parameters to this routine except the event are ignored in this case.
Parameters:
int - action_num which action type this is (the interpretation of this value is subclass dependent. 0 is always interpreted as the primary or default action of this interactor.
event - evt the event which "caused" the action.
Object - parm additional information to serve as a parameter to the action (the exact type of this information is determined by the subclass).
Overrides:
do_action in class base_interactor
See Also:
do_callback(sub_arctic.input.event)

state_looks

public loaded_image[] state_looks()
Image set for "normal" appearance in each state.
Returns:
the array of images for the normal states

get_state_look

public loaded_image get_state_look(int indx)
Get the "normal" appearance image for a given state.
Returns:
loaded_image the image for the asked for state

set_state_look

public void set_state_look(int indx,
                           loaded_image img)
Set the "normal" appearance image for a given state.
Parameters:
int - index the state being modified
int - loaded_image img the new image to use for this state

transition_looks

public loaded_image[] transition_looks()
Image set for "transition" appearance from each state.
Returns:
loaded_image the set of images for the transitions

get_transition_look

public loaded_image get_transition_look(int indx)
Get the "transition" appearance image from a given state.
Parameters:
int - indx the state transition of interest
Returns:
loaded_image the image for the given state

set_transition_look

public void set_transition_look(int indx,
                                loaded_image img)
Set the "transition" appearance image from a given state.
Parameters:
int - indx the index of the transition to be modified
loaded_image - img the new image to use for that transition

set_looks

public void set_looks(loaded_image[] st_looks,
                      loaded_image[] trans_looks)
Set both "normal" and "transition" image sets. The normal image for each state is displayed when the button is quiescent in that state. The transition image is shown when the mouse button has been depressed over the button and releasing it would cause a transition to the next state. The transition set may be coded as null in which case the next state image is used when a transition is needed. Otherwise the two image sets must be the same size.
Parameters:
loaded_image[] - st_looks the looks for the states.
loaded_image[] - trans_looks the looks for the transitions.

callback_obj

public callback_object callback_obj()
Object that this button makes callbacks to when pressed. All callbacks have a callback number of 0 and the callback_info field contains an Integer object indicating the new state of the button.
Specified by:
callback_obj in interface does_callback
Returns:
callback_object the object to send the callbacks to
Overrides:
callback_obj in class base_interactor

set_callback_obj

public void set_callback_obj(callback_object cb)
Set the callback object that this button makes callbacks to when pressed. All callbacks have a callback number of 0 and the callback_info field contains an Integer object indicating the new state of the button.
Specified by:
set_callback_obj in interface does_callback
Parameters:
callback_object - the new receiver of callbacks
Overrides:
set_callback_obj in class base_interactor

calc_size

protected void calc_size()
(Re)calculate size as max of images.

press

public boolean press(event evt,
                     java.lang.Object user_info)
Handle mouse presses in our bounds. This makes us the inout drag focus (most of the work is handled via the inout_drag protocol.
Specified by:
press in interface pressable
Parameters:
event - evt the event to be dispatched.
Object - user_info the object passed to the pick_collector at pick time.
Returns:
boolean true if this event has been handled.

release

public boolean release(event evt,
                       java.lang.Object user_info)
Companion for press() -- ignore here.
Specified by:
release in interface pressable
Parameters:
event - evt the event to be dispatched.
Object - user_info the object passed to the pick_collector at pick time.
Returns:
boolean true if this event has been handled.

inout_drag_start

public boolean inout_drag_start(event evt,
                                boolean starts_inside,
                                java.lang.Object user_info)
Handle input corresponding to the start of an inout tracking drag.
Specified by:
inout_drag_start in interface inout_draggable
Parameters:
event - evt the event to be dispatched
boolean - starts_inside true if the drag starts inside the object
Object - user_info the object passed to the inout_drag agent when this object came into the focus set.
Returns:
boolean true if this event has been handled

inout_drag_enter

public boolean inout_drag_enter(event evt,
                                java.lang.Object user_info)
Handle "drag" into the bounds of the object.
Specified by:
inout_drag_enter in interface inout_draggable
Parameters:
event - evt the event to be dispatched
Object - user_info the object passed to the inout_drag agent when this object came into the focus set.
Returns:
boolean true if this event has been handled

inout_drag_exit

public boolean inout_drag_exit(event evt,
                               java.lang.Object user_info)
Handle "drag" out of the bounds of the object.
Specified by:
inout_drag_exit in interface inout_draggable
Parameters:
event - evt the event to be dispatched.
Object - user_info the object passed to the inout_drag agent when this object came into the focus set.
Returns:
boolean true if this event has been handled

first_callback_num

public int first_callback_num()
First valid callback number
Specified by:
first_callback_num in interface does_callback
Overrides:
first_callback_num in class base_interactor

last_callback_num

public int last_callback_num()
Last valid callback number
Specified by:
last_callback_num in interface does_callback
Overrides:
last_callback_num in class base_interactor

do_callback

public void do_callback(event evt)
Invoke the callback object. This is basically here as a hook for subclasses to override if they would prefer to do something other than a normal callback.
Specified by:
do_callback in interface does_callback
Parameters:
event - evt the event causing the callback
Overrides:
do_callback in class base_interactor

inout_drag_end

public boolean inout_drag_end(event evt,
                              boolean ended_inside,
                              java.lang.Object user_info)
Handle input corresponding to the end of an inout drag. Invokes the callback if we ended up inside the object.
Specified by:
inout_drag_end in interface inout_draggable
Parameters:
event - evt the event to be dispatched.
boolean - ended_inside true if the drag ended inside the object.
Object - user_info the object passed to the inout_drag agent when this object came into the focus set.
Returns:
boolean true if this event has been handled

draw_self_local

protected void draw_self_local(drawable d)
Draw the button
Parameters:
drawable - d the surface to draw the object on
Overrides:
draw_self_local in class base_interactor