org.rosuda.ibase
Class SMarker

java.lang.Object
  extended by org.rosuda.ibase.Notifier
      extended by org.rosuda.ibase.SMarker
All Implemented Interfaces:
Commander

public class SMarker
extends Notifier
implements Commander

Maintains a fixed list of markers, i.e. an array of 0..xxx indices that can be marked each. It uses both a fixed map and dynamic list of marked positions. Moreover it extends Notifier class to allow notification upon changes of state.

This marker class implements two independent ways of tagging individual cases: primary and secondary markings.

primary marks are binary only (i.e. on/off) and are implemented in a fashion that allows efficient access to both list of marked cases and fast query for a mark of a case. Main use is to implement highlighting.

secondary marks allow (almost) arbitrary integers to be associated with individual cases. This kind of mark is not specially efficient. Main use is to implement color brushing.

Version:
$Id: SMarker.java 2484 2006-06-01 12:16:00Z wichtreyt $

Field Summary
static int MASK_PRIMARY
           
static int MASK_RAW
           
static int MASK_SECONDARY
           
 
Constructor Summary
SMarker(int reqsize)
          The only constructor, allocates a new marker
 
Method Summary
 boolean at(int pos)
          checks whether index pos has any mark
 java.util.Enumeration elements()
          returns Enumeration of the marked indices.
 int get(int pos)
          gets mark at index pos
 java.util.Vector getList()
          returns a list of all marked indices
 int[] getMaskCopy(int maskType)
          get mask of the mark entries (as a newly allocated copy) - that is an array of the same size as the data containing a mark for each case.
 SVarSet getMasterSet()
          returns master dataset associated with this marker.
 int getMaxMark()
          returns the highest secondary mark.
 int getSec(int pos)
          gets secondary mask at insex pos
 int getSecCount()
          returns the number of cases having a secondary mark (irrespective of any primary mark).
 int[] getSelectedIDs()
          returns an array with all selected IDs
 int marked()
          returns the number of marked cases
 void resetSec()
          removes all secondary marks
 void resize(int newsize)
          This methods allows to resize the marker.
 java.lang.Object run(java.lang.Object o, java.lang.String cmd)
          run command cmd issued by another object
 void selectAll()
          marks all indices as marked with the specified mark
 void selectInverse()
           
 void selectNone()
          clears entire selection (i.e. sets all primary marks to 0)
 void set(int pos, boolean pMark)
          sets the primary mark at specified index
 void setSec(int pos, int mark)
          sets secondary mark
 void setSecBySelection(int markSel, int markNonsel)
           
 void setSelected(int mark)
          sets secondary mark of all selected cases
 int size()
          returns size of the marker array
 
Methods inherited from class org.rosuda.ibase.Notifier
addDepend, beginBatch, delDepend, endBatch, NotifyAll, NotifyAll, NotifyAll, NotifyAll, startCascadedNotifyAll
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MASK_PRIMARY

public static final int MASK_PRIMARY
See Also:
Constant Field Values

MASK_SECONDARY

public static final int MASK_SECONDARY
See Also:
Constant Field Values

MASK_RAW

public static final int MASK_RAW
See Also:
Constant Field Values
Constructor Detail

SMarker

public SMarker(int reqsize)
The only constructor, allocates a new marker

Parameters:
reqsize - desired size of the marker array (# of indices)
Method Detail

resize

public void resize(int newsize)
This methods allows to resize the marker. To ensure consistency the marker is never downsized.


size

public int size()
returns size of the marker array


marked

public int marked()
returns the number of marked cases


get

public int get(int pos)
gets mark at index pos

Parameters:
pos - desired index
Returns:
mark at the index pos. primary mask always returns -1 regardless of secondary mark

getSec

public int getSec(int pos)
gets secondary mask at insex pos


at

public boolean at(int pos)
checks whether index pos has any mark

Parameters:
pos - desired index
Returns:
true if there is a primary mark at the index pos

getList

public java.util.Vector getList()
returns a list of all marked indices

Returns:
Vector of Integer objects

getSelectedIDs

public int[] getSelectedIDs()
returns an array with all selected IDs


getMaskCopy

public int[] getMaskCopy(int maskType)
get mask of the mark entries (as a newly allocated copy) - that is an array of the same size as the data containing a mark for each case. The values depend on the mask type specified by the parameter:

Parameters:
maskType - one of the constants MASK_PRIMARY,MASK_SECONDARY or MASK_RAW, see above

set

public void set(int pos,
                boolean pMark)
sets the primary mark at specified index

Parameters:
pos - desired index
pMark - whether the primary mark is set

setSec

public void setSec(int pos,
                   int mark)
sets secondary mark


setSelected

public void setSelected(int mark)
sets secondary mark of all selected cases


getMaxMark

public int getMaxMark()
returns the highest secondary mark. The return value does not necessarily reflect the highest currently used mark - it should be used as upper bound only.


getSecCount

public int getSecCount()
returns the number of cases having a secondary mark (irrespective of any primary mark).


elements

public java.util.Enumeration elements()
returns Enumeration of the marked indices.

Returns:
of marked indices (which are a list of Integer objects). Analogous to emelents() method of a Vector

selectNone

public void selectNone()
clears entire selection (i.e. sets all primary marks to 0)


selectAll

public void selectAll()
marks all indices as marked with the specified mark

Parameters:
mark - mark to be used for the selection (passing 0 results in a call to selectNone() method instead)

selectInverse

public void selectInverse()

resetSec

public void resetSec()
removes all secondary marks


getMasterSet

public SVarSet getMasterSet()
returns master dataset associated with this marker. Please note that a marker doesn't have to be associated with any SVarSet


run

public java.lang.Object run(java.lang.Object o,
                            java.lang.String cmd)
Description copied from interface: Commander
run command cmd issued by another object

Specified by:
run in interface Commander
Parameters:
o - origin of the command
cmd - command string
Returns:
any object, the actual interpretation is up to the calling object

setSecBySelection

public void setSecBySelection(int markSel,
                              int markNonsel)