ewe.ui
Class ChoiceControl

java.lang.Object
  extended byewe.ui.ControlBase
      extended byewe.ui.Control
          extended byewe.ui.ChoiceControl
All Implemented Interfaces:
CellConstants, ControlConstants, EventListener, ImageRefresher, Intable, TimerProc, UIConstants
Direct Known Subclasses:
mChoice, Menu

public class ChoiceControl
extends Control
implements Intable

This is a BaseClass for mChoice and Menu controls.


Field Summary
 Color blockColor
          If this is null then the Foreground color will be used.
protected  boolean blockSelected
           
 boolean calculateWidth
           
protected static Rect clipBuffer
           
 Control container
           
protected static Rect dimRect
           
 int displayRows
           
 boolean dontAutoScroll
           
 boolean dropDownButton
           
protected static MenuItem dummyItem
           
protected  int firstItem
           
static int INDENT_ITEM_FLAG
           
 boolean indentDropItems
           
protected static Rect innerRect
           
protected  boolean isAList
           
protected  boolean isSingleLine
           
 int itemHeight
          If you set this to a value >= 0 then this will be taken to be the fixed item height.
 Vector items
           
protected static Rect newClip
           
 boolean notifyDataChangeOnSelect
          This tells the control to generate a DataChangeEvent when the selection has changed.
 boolean noWrapAround
          This applies to Menus.
 int selectedIndex
           
 boolean shortenItems
           
 int spacing
           
 boolean useMenuItems
           
 int xOffset
           
protected  int xShift
           
 
Fields inherited from class ewe.ui.Control
_debug, backGround, beforeRemoved, borderColor, borderStyle, borderWidth, children, columns, constraints, DoPaintMethod, dragging, dragResolution, dragTime, exitKeys, fieldTransfer, font, foreGround, haveNativePaint, height, holdDownPause, holdTick, hotKey, image, lastSelected, listeners, maxHeight, maxWidth, menuState, minHeight, minWidth, modifiers, MyClass, name, next, np, parent, penStatus, popupSound, popupSoundClip, preferredHeight, preferredWidth, prev, prompt, promptControl, rows, ss, standardBorder, standardEdge, startDragResolution, tags, tail, text, toolTip, width, x, y
 
Fields inherited from class ewe.ui.ControlBase
clipItems, clipObject, clipOwner, curPoint, currentPenEvent, debugControl, debugFlag, DidHoldDown, doubleBuffer, doubleClickTime, firstPress, globalDrawFlat, globalEditable, globalEnabled, globalPalmStyle, globalSmallControls, GotPenDown, PenIsOn, pressPoint, TAG_LAST_USER_DATA, TAG_USER_DATA, TAKE_FIRST_PRESS, unnamed, useNativeTextInput
 
Fields inherited from interface ewe.ui.UIConstants
BDR_DOTTED, BDR_INNER, BDR_NOBORDER, BDR_OUTER, BDR_OUTLINE, BDR_RAISEDINNER, BDR_RAISEDOUTER, BDR_SUNKENINNER, BDR_SUNKENOUTER, BF_BOTTOM, BF_BOTTOMLEFT, BF_BOTTOMRIGHT, BF_BUTTON, BF_DIAGONAL, BF_DIAGONAL_ENDBOTTOMLEFT, BF_DIAGONAL_ENDBOTTOMRIGHT, BF_DIAGONAL_ENDTOPLEFT, BF_DIAGONAL_ENDTOPRIGHT, BF_EXACT, BF_FLAT, BF_LEFT, BF_MIDDLE, BF_MONO, BF_PALM, BF_RECT, BF_RIGHT, BF_SOFT, BF_SQUARE, BF_TOP, BF_TOPLEFT, BF_TOPRIGHT, EDGE_BUMP, EDGE_ETCHED, EDGE_RAISED, EDGE_SUNKEN
 
Fields inherited from interface ewe.ui.CellConstants
BORDER, BOTTOM, CELLFLAG, CELLMASK, CENTER, CONTROLMASK, DONTCHANGE, DONTFILL, DONTSTRETCH, EAST, FILL, FIXEDSIZE, GROW, HCENTER, HCONTRACT, HEXPAND, HFILL, HGROW, HSHRINK, HSTRETCH, INITIALLY_CLOSED, INITIALLY_MINIMIZED, INITIALLY_PREFERRED_SIZE, INSETS, LEFT, MAXIMUMSIZE, MINIMUMSIZE, NORTH, NORTHEAST, NORTHWEST, PREFERREDSIZE, RECT, RIGHT, SHRINK, SOUTH, SOUTHEAST, SOUTHWEST, SPAN, STRETCH, TEXTSIZE, TOP, VCENTER, VCONTRACT, VEXPAND, VFILL, VGROW, VSHRINK, VSTRETCH, WEST
 
Fields inherited from interface ewe.ui.ControlConstants
All, AlwaysEnabled, AlwaysRecalculateSizes, ByDeferredMouse, ByDeferredPen, ByFrameChange, ByKeyboard, ByMouse, ByPen, ByRequest, CalculatedSizes, Disabled, DisablePopupMenu, DisplayOnly, Down, DrawFlat, Flag, ForceResize, HasData, Invisible, KeepImage, KeepSIP, Left, MakeMenuAtLeastAsWide, Maximize, Minimize, MouseSensitive, NoFocus, NotAnEditor, NotEditable, PaintDataOnly, PaintOutsideOnly, PenTransparent, PreferredSizeOnly, Right, SendUpKeyEvents, SendUpPenEvents, ShowSIP, ShrinkToNothing, SmallControl, SpecialBackground, TakeControlEvents, TakesKeyFocus, Transparent, Up, WantDrag, WantHoldDown
 
Fields inherited from interface ewe.fx.ImageRefresher
KEEP_VISIBLE
 
Constructor Summary
ChoiceControl()
           
 
Method Summary
 MenuItem addItem(Object what)
          Insert an item in the control.
 MenuItem[] addItems(String[] what)
          This add items but does not update the screen.
 void addSection(Object[] items, boolean separator)
          Add a section to the list/menu.
protected  void calculateSizes()
          Override this to calculate the preferred, minimum and maximum size of your control.
 boolean centerSelected()
           
 void changeItem(int index, Object newText)
          Changes the text associated with an item.
 void changeModifiers(int toSet, int toClear)
           
 boolean checkOnlyOne(Object[] items, Object toCheck, boolean onlyIfInArray)
           
 boolean deleteItem(int index)
          Delete an item from the control.
 void doActionKey(int key)
           
 void doPaint(Graphics gr, Rect area)
           
protected  void doPaintData(Graphics gr)
          Repaint the "data" part of the Control.
 MenuItem findItem(String name, boolean searchChildMenus)
           
protected  int findKeyed(int start, int key)
           
 Color getBlockColor()
           
protected  Rect getDataRect(Rect dest)
          Get the rectangle, relative to the Control, of the area considered to be the "data" part of the control.
 int getDisplayRows()
           
protected  String getDisplayString()
           
 int getInt()
           
 MenuItem getItemAt(int where)
           
protected  int getItemHeight()
          This is used to calculate the height of the line used for each item.
protected  Object getItemToAdd(Object forWhat)
           
 int getMenuHeight()
           
protected  int getMenuWidth()
           
 int getMenuWidth(boolean subMenus, boolean topLevel)
           
 int getScreenRows()
           
 Object getSelectedItem()
           
 String getText()
           
 int indexOf(Object what)
          Find the index of this object.
 MenuItem insertItemAt(Object what, int index)
          Insert an item in the control.
 boolean isSelected(int idx)
           
 boolean itemIsVisible(int row, boolean isFullyVisible)
           
 int itemsSize()
           
 void make(boolean reMake)
          This is used to "make" the control before being displayed.
 void makeItemVisible(int row)
          This makes the item visible and updates the screen as well.
 boolean makeVisible(int row)
          This places the item in the visible range but does not update the screen.
 void modifyItems(String[] items, int switchOn, int switchOff, boolean searchChildMenus)
           
 void notifySelection(int index, int type)
           
protected  void paintBox(Graphics g)
           
 void paintItem(Graphics g, int index)
           
 void paintItem(Graphics graphics, int index, boolean checksOnly)
           
 void refresh(IImage image, int options)
          The default version of this method simpy repaints the control - however for controls which may display multiple images a better refresh scheme would be needed.
 boolean removeAll()
          Removes all items from the control.
 void repaintItem(int index)
           
 void select(int which)
           
 void select(int which, boolean select)
           
 void selectItem(int index, boolean selected)
           
 void selectItem(String label)
           
 void selectItems(int first, int last, boolean selected)
           
 void selectNext()
           
 void selectOrUnselect(int item)
           
 void selectPrev()
           
 void setData(Object data)
          Sets the data for the ChoiceControl.
 void setInt(int value)
           
 void setText(String text)
           
 boolean trySelectItem(String label)
           
 void updateItems()
          This updates the control to new choices added and then refreshes it on screen.
 
Methods inherited from class ewe.ui.Control
acceptsData, activate, addListener, addTimer, amOnTopFrame, calculateTextSize, cancelCut, cancelHoldDown, canEdit, chainDataChange, change, checkClipboardOperations, checkExitKey, checkMenu, checkMenuKey, checkModifiers, checkPenTransparent, clearTag, clipboardToString, clipboardTransfer, closeMenu, contains, contains, createGraphics, dataAccepted, dataBeingRemoved, dataDraggedOff, dataDraggedOver, dataDraggedOver, dataDroppedOn, dataTransferCancelled, deactivate, defaultTo, doAction, doBackground, doBorder, doHotKey, doMenu, dontAcceptDrop, doPaintChildren, doPaintChildren, doPaintChildren, doPaintData, doShowMenu, dragged, exitEntry, fillBackground, formClosing, fromClipboard, fromField, fromField, getAllDescendants, getAllSubControls, getBackground, getChildren, getChildrenBackwards, getClipboardMenu, getClipObject, getControlBuffer, getControlBuffer, getDataToCopy, getDataToDragAndDrop, getDim, getDisplayText, getDragAndDropContext, getFont, getFontMetrics, getFontMetrics, getForeground, getFrame, getFrameOrContainer, getGraphics, getImage, getLastSelected, getLocation, getMaximumSize, getMenu, getMinimumSize, getModifiers, getNext, getNextKeyFocus, getParent, getPasswordCharacter, getPosInFrame, getPosInParent, getPreferredSize, getPrompt, getPromptText, getRect, getRect, getServer, getSize, getSizes, getSubControls, getTag, getToolTip, getWindow, gotFocus, hasModifier, hasPopupFormAttached, hasTag, inheritModifiers, isChildOf, isModal, isOnMe, isSomeonesHotKey, lostFocus, makeFrameTopMost, makeHot, menuIsActive, modify, modifyAll, modifyAll, notifyAction, notifyDataChange, notifyDataChange, notNative_doPaintChildren, oldButWorksDoPaintChildren, oldPaintChildren, oldPostEvent, onControlEvent, onEvent, onKeyEvent, onLabelPenEvent, onPaint, onPenEvent, paintBackground, paintChildren, penClicked, penDoubleClicked, penHeld, penPressed, penReleased, penRightReleased, popupBeep, popupMenuClosed, popupMenuEvent, popupMenuEvent, postEvent, recalculatePreferredSize, redisplay, removeListener, removeTimer, repaint, repaintDataNow, repaintNow, repaintNow, repaintNow, requestPaint, requestResizeTo, resetRect, resizeTo, restore, scrollAndRepaint, sendToListeners, set, setBorder, setCell, setClipObject, setControl, setCursor, setFixedSize, setFont, setHotKey, setHotKey, setLocation, setMaximumSize, setMenu, setMinimumSize, setPreferredSize, setPromptControl, setRect, setRect, setServer, setTag, setTags, setTextSize, setToolTip, show, shown, standardOnKeyEvent, startDragAndDrop, startDragAndDrop, startDragging, stopDragging, takeData, takeFocus, takeFromClipboard, takePromptControl, testDim, ticked, toClipboard, toField, toField, toString, toTextData, transferPenPress, transferPenPress, tryDragAndDrop, tryNext, tryStartMenu, updateData, willAcceptDrop, willShowFrame
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode
 

Field Detail

blockSelected

protected boolean blockSelected

isAList

protected boolean isAList

isSingleLine

protected boolean isSingleLine

useMenuItems

public boolean useMenuItems

dropDownButton

public boolean dropDownButton

calculateWidth

public boolean calculateWidth

indentDropItems

public boolean indentDropItems

shortenItems

public boolean shortenItems

items

public Vector items

spacing

public int spacing

xOffset

public int xOffset

selectedIndex

public int selectedIndex

dontAutoScroll

public boolean dontAutoScroll

container

public Control container

noWrapAround

public boolean noWrapAround
This applies to Menus. If it is true, then wrapping from the top to the bottom using the cursor keys will be disabled.


INDENT_ITEM_FLAG

public static final int INDENT_ITEM_FLAG
See Also:
Constant Field Values

itemHeight

public int itemHeight
If you set this to a value >= 0 then this will be taken to be the fixed item height. See getItemHeight().


blockColor

public Color blockColor
If this is null then the Foreground color will be used. By default it is set to Color.DarkBlue.


displayRows

public int displayRows

firstItem

protected int firstItem

xShift

protected int xShift

dummyItem

protected static MenuItem dummyItem

clipBuffer

protected static Rect clipBuffer

newClip

protected static Rect newClip

dimRect

protected static Rect dimRect

innerRect

protected static Rect innerRect

notifyDataChangeOnSelect

public boolean notifyDataChangeOnSelect
This tells the control to generate a DataChangeEvent when the selection has changed. By default this is true except for anything inheriting from BasicList

Constructor Detail

ChoiceControl

public ChoiceControl()
Method Detail

getDataRect

protected Rect getDataRect(Rect dest)
Description copied from class: Control
Get the rectangle, relative to the Control, of the area considered to be the "data" part of the control. This is only used for Controls with the HasData modifier. These are controls that distinguish between their data (e.g. contained text) and non-data (e.g. border) on-screen display.

Overrides:
getDataRect in class Control
Parameters:
dest - The destination rectangle.
Returns:
The destination rectangle or a new rectangle if the destination is null.

getBlockColor

public Color getBlockColor()

modifyItems

public void modifyItems(String[] items,
                        int switchOn,
                        int switchOff,
                        boolean searchChildMenus)

itemsSize

public int itemsSize()

indexOf

public int indexOf(Object what)
Find the index of this object. Returns -1 if it is not found.


insertItemAt

public MenuItem insertItemAt(Object what,
                             int index)
Insert an item in the control. This does not call a repaint.


getSelectedItem

public Object getSelectedItem()

getItemToAdd

protected Object getItemToAdd(Object forWhat)

addItem

public MenuItem addItem(Object what)
Insert an item in the control. This does not call a repaint - call updateItems() to do that.


setData

public void setData(Object data)
Sets the data for the ChoiceControl. The supplied data can be a Vector or an array of Strings/MenuItems. This WILL call a repaint.


addItems

public MenuItem[] addItems(String[] what)
This add items but does not update the screen. Call updateItems for that.


deleteItem

public boolean deleteItem(int index)
Delete an item from the control. This does not call a repaint.


removeAll

public boolean removeAll()
Removes all items from the control. This does not call a repaint.


trySelectItem

public boolean trySelectItem(String label)

selectNext

public void selectNext()

selectPrev

public void selectPrev()

notifySelection

public void notifySelection(int index,
                            int type)

doActionKey

public void doActionKey(int key)
Overrides:
doActionKey in class Control

select

public void select(int which,
                   boolean select)

select

public void select(int which)

setText

public void setText(String text)
Overrides:
setText in class Control

getText

public String getText()
Overrides:
getText in class Control

selectItem

public void selectItem(String label)

selectItems

public void selectItems(int first,
                        int last,
                        boolean selected)

selectItem

public void selectItem(int index,
                       boolean selected)

changeItem

public void changeItem(int index,
                       Object newText)
Changes the text associated with an item.


getDisplayRows

public int getDisplayRows()

getScreenRows

public int getScreenRows()

calculateSizes

protected void calculateSizes()
Description copied from class: Control
Override this to calculate the preferred, minimum and maximum size of your control. This is only called once unless the modifier flag AlwaysRecalculateSizes is true. During the calculation you will set the variables preferredWidth, preferredHeight, etc. directly.

Overrides:
calculateSizes in class Control

getMenuWidth

protected int getMenuWidth()

getMenuWidth

public int getMenuWidth(boolean subMenus,
                        boolean topLevel)

getMenuHeight

public int getMenuHeight()

getItemHeight

protected int getItemHeight()
This is used to calculate the height of the line used for each item. If you explicitly set itemHeight to a value >= 0 then that value will be used. Otherwise it calculates the height of the current font and also checks each item (if items is non-null) to see if it has an image associated with it. If any item has an image that is greater than the font height, then that height will be used.

After calculating the height it is stored in itemHeight so the next time it is called it will not calculate it again, but it will return the value of itemHeight instead.

To avoid any calculations at all, you can explicitly set itemHeight to a value >= 0.


getItemAt

public MenuItem getItemAt(int where)

findItem

public MenuItem findItem(String name,
                         boolean searchChildMenus)

checkOnlyOne

public boolean checkOnlyOne(Object[] items,
                            Object toCheck,
                            boolean onlyIfInArray)

selectOrUnselect

public void selectOrUnselect(int item)

isSelected

public boolean isSelected(int idx)

paintBox

protected void paintBox(Graphics g)

getDisplayString

protected String getDisplayString()

repaintItem

public void repaintItem(int index)

paintItem

public void paintItem(Graphics g,
                      int index)

paintItem

public void paintItem(Graphics graphics,
                      int index,
                      boolean checksOnly)

doPaintData

protected void doPaintData(Graphics gr)
Description copied from class: Control
Repaint the "data" part of the Control. This is only used for Controls with the HasData modifier. These are controls that distinguish between their data (e.g. contained text) and non-data (e.g. border) on-screen display.

Overrides:
doPaintData in class Control
Parameters:
gr - The Graphics object to paint to.

refresh

public void refresh(IImage image,
                    int options)
Description copied from class: Control
The default version of this method simpy repaints the control - however for controls which may display multiple images a better refresh scheme would be needed.

Specified by:
refresh in interface ImageRefresher
Overrides:
refresh in class Control
Parameters:
image - the image to refresh.
options -
Returns:

doPaint

public void doPaint(Graphics gr,
                    Rect area)
Overrides:
doPaint in class Control

makeItemVisible

public void makeItemVisible(int row)
This makes the item visible and updates the screen as well.


makeVisible

public boolean makeVisible(int row)
This places the item in the visible range but does not update the screen. It returns true if you should call updateItems() after.


itemIsVisible

public boolean itemIsVisible(int row,
                             boolean isFullyVisible)

centerSelected

public boolean centerSelected()

changeModifiers

public void changeModifiers(int toSet,
                            int toClear)

setInt

public void setInt(int value)
Specified by:
setInt in interface Intable

getInt

public int getInt()
Specified by:
getInt in interface Intable

make

public void make(boolean reMake)
Description copied from class: Control
This is used to "make" the control before being displayed. This is usually only overridden by containers.

Overrides:
make in class Control
Parameters:
reMake - if this is true then you should do a full re-make.

addSection

public void addSection(Object[] items,
                       boolean separator)
Add a section to the list/menu. If there were already items then a '-' item is added (which looks like a horizontal line in a Menu) first, otherwise no '-' is added.

Parameters:
items - the items to add.
separator - set this to true if you want a separator before this section.
Returns:

updateItems

public void updateItems()
This updates the control to new choices added and then refreshes it on screen.


findKeyed

protected int findKeyed(int start,
                        int key)