public class Grid extends Container implements Scrollable
Rect r = getClientRect(); String []gridCaptions = {" WPT "," HDG "," DST "," ETE "," FUEL "}; int gridWidths[] = { -25, // negative numbers are percentage of width fm.stringWidth(" 000 "), -25, -20, -20, }; int gridAligns[] = { LEFT, CENTER, RIGHT, CENTER, RIGHT }; grid = new Grid(gridCaptions, gridWidths, gridAligns, false); add(grid, LEFT+3,TOP+3,r.width/2,r.height/2); grid.secondStripeColor = Color.getRGB(235,235,235); String[][] data = new String[][] { {"0AAAA","000","000.0","00:00","00.0"}, {"1BBBB","111","111.1","11:11","11.1"}, {"2CCCC","222","222.2","22:22","22.2"}, {"3DDDD","333","333.3","33:33","33.3"}, {"4EEEE","444","444.4","44:44","44.4"}, {"5FFFF","555","555.5","55:55","55.5"}, }; grid.setItems(data);This will create a grid with the given captions, column widths, information alignment and a check column.
Don't forget to take a look at tc.samples.ui.grid.GridTest.
Also consider using the ListContainer instead of Grid if you're using devices with big screens. See the UIGadgets sample, click menu / Tests2 / ListContainer.
Modifier and Type | Class and Description |
---|---|
static class |
Grid.CellController
Abstract class that must be implemented if you want to get a fine control of
each cell in the grid.
|
static interface |
Grid.DataSource
Interface that can be used to fetch data on demmand.
|
Control.TranslucentShape
Modifier and Type | Field and Description |
---|---|
int[] |
aligns
The aligns that are used in the constructor.
|
static int |
ALL_CHECKED
When the user clicks on the header check to check all, a CHECK_CHANGED_EVENT is dispatched,
and the row is set as ALL_CHECKED.
|
static int |
ALL_UNCHECKED
When the user clicks on the header check, to uncheck all, a CHECK_CHANGED_EVENT is dispatched,
and the row is set as ALL_UNCHECKED.
|
boolean |
boldCheck
Set it to true to draw a bold check
|
int |
borderGap
Defines the border gap when using CellController.getBackColor.
|
boolean |
canClickSelectAll
Set to false to disable the click on the check column of the captions to
select all and unselect all
|
Image[] |
captionImages
A way to mix Images and Strings at the caption.
|
java.lang.String[] |
captions
The column captions.
|
int |
captionsBackColor
Sets the caption's box background color.
|
int |
checkColor
Check color.
|
static int |
columnResizeMargin
How many pixels are used to define the place where the column will be resized.
|
protected Control[] |
controls |
int[] |
currencyDecimalPlaces
Used to show a given (set of) column(s) formatted as currency.
|
protected Flick |
disabledFlick |
boolean |
disableSort
Set to true to disable sorting when clicking in the column's header.
|
boolean |
drawCheckBox
Set this to false if you dont want the check column to have the rect underneath the
check mark
|
boolean |
drawHighlight
Set to false do don't let the highlighted (selected) row be drawn.
|
boolean |
enableColumnResize
Set this to false if you dont want to let the user resize the columns
|
boolean |
enableSelectDisabledCell
Set to false to disallow the selection of a row if the selected cell is disabled (via CellController).
|
int |
extraHorizScrollButtonHeight
The extra height of the horizontal scroll buttons.
|
int |
firstStripeColor
first stripe color.
|
protected Flick |
flick
The Flick object listens and performs flick animations on PenUp events when appropriate.
|
int |
highlightColor
The color of the selected (highlighted) row.
|
int |
lastStartingRow
Stores the last line that was requested from the current data source.
|
boolean |
lineScroll
Set to true to enable navigation per line instead of per page when in non-penless mode.
|
protected int |
linesPerPage
How many lines fits in a page
|
boolean |
liveScrolling
Set to true before calling setDataSource to enable live scrolling when using a DataSource.
|
java.lang.String |
oldCellText
The text that was in the cell before the user had editted it.
|
int |
secondStripeColor
second stripe color.
|
protected int |
selectedLine
The current selected line, or -1 if none.
|
int[] |
sortTypes
Defines the sort type for each column of the grid.
|
ToolTip |
tip
The tooltip used to display a column's text when it exceeds the column width.
|
boolean |
titleMayBeClipped
When the width of a title is greater than the width you specified for a the column, the title's width
is used instead.
|
static boolean |
useHorizontalScrollBar
Set to true before constructing the Grids to use an horizontal scrollbar instead of the two left/right buttons.
|
static int |
VERT_DOT
Draws a dotted vertical line.
|
static int |
VERT_LINE
Draws a solid vertical line.
|
static int |
VERT_NONE
Draws no vertical lines.
|
int |
verticalLineStyle
Sets the vertical line style of the grid.
|
alwaysEraseBackground, BACKGROUND_CYLINDRIC_SHADED, BACKGROUND_SHADED, BACKGROUND_SHADED_INV, BACKGROUND_SOLID, backgroundStyle, BORDER_LOWERED, BORDER_NONE, BORDER_RAISED, BORDER_ROUNDED, BORDER_SIMPLE, BORDER_TOP, borderColor, borderRadius, children, controlFound, finishedStart, ignoreOnAddAgain, ignoreOnRemove, insets, lastScreenWidth, lastW, lastX, lastY, numChildren, started, tabOrder, tail, TRANSITION_TIME
AFTER, alphaValue, appId, appObj, asContainer, asWindow, backColor, BEFORE, BOTTOM, BOTTOM_OF, BRIGHTER_BACKGROUND, callListenersOnAllTargets, CENTER, CENTER_OF, clearValueInt, clearValueStr, DARKER_BACKGROUND, DP, effect, enableUpdateScreen, esce, eventsEnabled, FILL, fillColor, FIT, floating, fm, fmH, focusHandler, focusLess, focusOnPenDown, focusTraversable, font, FONTSIZE, foreColor, height, ignoreInsets, isHighlighting, isTablet, KEEP, keepDisabled, keepEnabled, LEFT, next, nextTabControl, npParts, offscreen, offscreen0, onEventFirst, parent, PARENTSIZE, PARENTSIZEMAX, PARENTSIZEMIN, PREFERRED, prev, RANGE, repositionAllowed, RIGHT, RIGHT_OF, SAME, SCREENSIZE, SCREENSIZEMAX, SCREENSIZEMIN, setFont, setH, setRel, setW, setX, SETX_NOT_SET, setY, tempW, textShadowColor, TOP, translucentShape, transparentBackground, uiAdjustmentsBasedOnFontHeightIsSupported, uiAndroid, UICONST, uiFlat, uiHolo, uiMaterial, uiVista, visible, width, WILL_RESIZE, x, y
Constructor and Description |
---|
Grid(java.lang.String[] captions,
boolean checkEnabled)
This will create a grid with the given captions
and an optional multi-selection check column so that the user can select
multiple lines of the grid.
|
Grid(java.lang.String[] captions,
int[] widths,
int[] aligns,
boolean checkEnabled)
This will create a grid with the given captions, column widths, information
alignment and an optional multi-selection check column so that the user can select
multiple lines of the grid
|
Modifier and Type | Method and Description |
---|---|
void |
add(java.lang.String[] item)
Add a new line to the end of the grid.
|
void |
add(java.lang.String[][] items)
Appends the give lines at the end of the grid.
Its up to the user to call Window.needsPaint = true afterwards. |
void |
add(java.lang.String[] item,
int row)
Add a new line at the given index position of the grid.
|
boolean |
canScrollContent(int direction,
java.lang.Object target)
Checks if there is room to flick this container in the given direction.
|
void |
clear()
Selects the clearValueInt row, which defaults to -1.
|
boolean |
del(int row)
Remove the given line index from the grid.
|
void |
disableFlick()
Disables the 'flick' behaviour from this scroll container.
|
void |
enableFlick()
Reenables the 'flick' behaviour of this container.
|
void |
flickEnded(boolean atPenDown)
Called when the flick animation is ended.
|
boolean |
flickStarted()
Called when the flick animation is started.
|
java.lang.String |
getCellText(int row,
int col)
Returns the text's column of the given row number.
|
int |
getCheckCount()
Returns the number of items checked.
|
int[] |
getColumnWidths()
Returns an array with the current column widths, not the original ones passed in the constructor.
|
Grid.DataSource |
getDataSource()
Returns the DataSource assigned for this grid, or null if there are none.
|
Flick |
getFlick()
Returns the current flick object.
|
void |
getFocusableControls(Vector v)
Get a list of child controls of this container which are focus candidates
|
java.lang.String[] |
getItem(int row)
Returns the line corresponding to the given index.
|
Vector |
getItemsVector()
Return a vector containing all information inside the grid.
|
int |
getPreferredHeight()
Returns the preferred height of this control.
|
int |
getPreferredWidth()
If all widths (passed in constructor) are positive (ie, not a percentage), then it will use the sum as the preferred width.
|
int |
getScrollPosition(int direction)
Returns the current position given the direction.
|
int |
getSelectedIndex()
Get the index of the currently selected row, or -1 if none is selected.
|
java.lang.String[] |
getSelectedItem()
Get the information on the currently selected line.
|
Control |
handleGeographicalFocusChangeKeys(KeyEvent ke)
Used by the main event loop to give the currently focused control an opportunity to act directly on
the KeyEvent.
|
boolean |
horizontalScroll(boolean toLeft)
Scrolls the grid horizontaly as needed
|
void |
initUI()
Called to initialize the User Interface of this container.
|
boolean |
isChecked(int row)
Check if a given row is checked
|
boolean |
isColumnEditable(int col)
Returns true if the given column is editable.
|
void |
markAll(boolean check)
Checks or unchecks all rows in this grid.
|
boolean |
move(int row,
boolean up)
Move the items at given indexes.
|
Control |
moveFocusToNextControl(Control c,
boolean forward)
Traverse throught the Edits of this Grid.
|
protected void |
onBoundsChanged(boolean screenChanged)
Called after a setRect.
|
protected void |
onColorsChanged(boolean colorsChanged)
Called after a setEnabled, setForeColor and setBackColor and when a control has
been added to a Container.
|
void |
onEvent(Event e)
Called to process key, pen, control and other posted events.
|
protected void |
onFontChanged()
Called after a setFont
|
void |
qsort(int col)
Performs a quicksort in the items of the given column.
|
void |
qsort(int col,
boolean ascending)
Performs a quicksort in the items of the given column in the given order.
|
void |
refreshDataSource()
Causes a refresh to be made in the items of the datasource.
|
void |
removeAll()
This method does nothing.
|
void |
removeAllElements()
Remove all elements from the grid, leaving it blank.
|
void |
replace(java.lang.String[] item,
int row)
Replace a given line by the specified by its index with the
supplied one.
|
void |
reposition()
Repositions this control in the screen.
|
boolean |
scrollContent(int dx,
int dy,
boolean fromFlick)
Performs a relative move.
|
void |
scrollTo(int row)
Scrolls the grid to the given row.
|
void |
setCellController(Grid.CellController cc)
Sets the CellController instance for this grid.
|
void |
setCellText(int row,
int col,
java.lang.String text)
Sets the text of a column.
|
void |
setChecked(int row,
boolean check)
Checks or unchecks the given index based on the second argument.
|
ComboBoxDropDown |
setColumnChoices(int col,
java.lang.String[] choices)
Makes the given column ComboBox-like.
|
Edit |
setColumnEditable(int col,
boolean editable)
Sets the given column as an editable one.
|
void |
setColumnWidth(int col,
int newWidth)
Sets the column width of the given column.
|
void |
setDataSource(Grid.DataSource ds,
int nrItems)
Sets the data source of this grid to be the given one.
|
void |
setImage(java.lang.String tag,
Image image)
Sets an image to be used in the Grid.
|
void |
setItems(java.lang.String[][] items)
Sets the grid items to be displayed.
|
void |
setNinePatch(Image img,
int corner,
int side)
Set the NinePatch of the control.
|
void |
setNinePatchCaption(Image img,
int corner,
int side) |
void |
setSelectedIndex(int row)
Sets the selected row index to the given one.
|
void |
setVisibleLines(int visibleLines)
Sets the number of visible lines (excluding the caption), used to make PREFERRED height return the given number of lines as the grid height.
|
int |
size()
Returns the number of lines in this grid
|
boolean |
wasScrolled()
Returns true if the control was scrolled since last pen down
|
add, add, add, add, add, broadcastEvent, fillBackground, findChild, findNearestChild, findNextFocusControl, getBorderRadius, getBorderStyle, getChildren, getChildrenCount, getClientRect, getClientRect, getFirstChild, getInsets, incLastX, incLastY, isPressed, moveFocusToNextEditable, onAddAgain, onPaint, onRemove, onSwapFinished, paintChildren, remove, resize, resizeHeight, resizeWidth, setBorderRadius, setBorderStyle, setEnabled, setFocusTraversable, setHighlighting, setInsets, setPressColor, setPressed, swapToTopmostWindow
_onEvent, addEnabledStateListener, addFocusListener, addFontChangeHandler, addGridListener, addHandler, addHighlightListener, addKeyListener, addListContainerListener, addMouseListener, addMultiTouchListener, addPenListener, addPressListener, addPushNotificationListener, addSizeChangeHandler, addTimer, addTimer, addTimerListener, addValueChangeHandler, addWindowListener, bringToFront, changeHighlighted, contains, drawTranslucentBackground, getAbsoluteRect, getBackColor, getDoEffect, getEffectH, getEffectW, getEffectX, getEffectY, getEventListeners, getFont, getForeColor, getGap, getGraphics, getHeight, getNext, getParent, getParentWindow, getPos, getPressedEvent, getPrev, getRect, getSize, getTextShadowColor, getWidth, getX, getX2, getY, getY2, hadParentScrolled, hasFocus, internalSetEnabled, intXYWH, isActionEvent, isChildOf, isDisplayed, isEnabled, isFloating, isInsideOrNear, isObscured, isTopMost, isVisible, isVisibleAndInside, onWindowPaintFinished, post, postEvent, postPressedEvent, releaseScreenShot, removeEnabledStateListener, removeFocusListener, removeGridListener, removeHandler, removeHighlightListener, removeKeyListener, removeListContainerListener, removeMouseListener, removeMultiTouchListener, removePenListener, removePressListener, removePushNotificationListener, removeTimer, removeTimerListener, removeWindowListener, repaint, repaintNow, reposition, repositionChildren, requestFocus, resetSetPositions, resetStyle, safeRepaintNow, safeUpdateScreen, sendToBack, setBackColor, setBackForeColors, setDoEffect, setFloating, setFocusLess, setFont, setForeColor, setNinePatch, setRect, setRect, setRect, setRect, setSet, setTextShadowColor, setTranslucent, setVisible, showTip, takeInitialScreenShot, takeScreenShot, translateFromOrigin, uiStyleChanged, updateScreen, updateTemporary, willOpenKeyboard
protected Flick flick
protected Flick disabledFlick
public static final int VERT_LINE
public static final int VERT_DOT
public static final int VERT_NONE
public static final int ALL_CHECKED
public static final int ALL_UNCHECKED
public boolean drawCheckBox
public int checkColor
public boolean disableSort
public boolean enableColumnResize
public static int columnResizeMargin
public java.lang.String[] captions
setWidths
method.public int firstStripeColor
public int secondStripeColor
public int highlightColor
public int captionsBackColor
public boolean drawHighlight
public int verticalLineStyle
protected int selectedLine
protected int linesPerPage
public java.lang.String oldCellText
public boolean canClickSelectAll
public boolean boldCheck
public ToolTip tip
public int extraHorizScrollButtonHeight
ListBox.EXTRA_HEIGHT_FACTOR
public int lastStartingRow
public int[] sortTypes
public static boolean useHorizontalScrollBar
public boolean liveScrolling
public int[] currencyDecimalPlaces
Grid g = new Grid(new String[]{"Name","Age","Salary"},false); g.currencyDecimalPlaces = new int[]{-1,-1,2}; // ignore name and age, and format salary with 2 decimal places.
public boolean enableSelectDisabledCell
public boolean lineScroll
public int borderGap
public int[] aligns
public boolean titleMayBeClipped
public Image[] captionImages
String[] tits = {"","Add","Minus",""}; captionImages = {img1, null,null, img2};
protected Control[] controls
public Grid(java.lang.String[] captions, int[] widths, int[] aligns, boolean checkEnabled)
captions
- Captions for the columns. Cannot be null!widths
- Widths of the columns. If the total width is less than the grid's width,
the last column will fill until the grid width. If null, the caption widths
will be computed and used as the row width. If a negative value is passed,
it will be computed as a percentage against the Grid's width.aligns
- Alignment of information on the given column. If null, all aligns will be LEFT.checkEnabled
- True if you want the multi-selection check column, false otherwisepublic Grid(java.lang.String[] captions, boolean checkEnabled)
captions
- Captions for the columnscheckEnabled
- True if you want the multi-selection check column, false otherwisepublic boolean flickStarted()
Scrollable
flickStarted
in interface Scrollable
public void flickEnded(boolean atPenDown)
Scrollable
flickEnded
in interface Scrollable
atPenDown
- Flag indicating if the animation ended due to a pendown event.public boolean canScrollContent(int direction, java.lang.Object target)
Scrollable
canScrollContent
in interface Scrollable
direction
- The direction we want to flick given by one of the following constants:target
- The target of the series of PEN events that triggered this flick attempt.public boolean scrollContent(int dx, int dy, boolean fromFlick)
Scrollable
scrollContent
in interface Scrollable
dx
- The relative amount of pixels to move in the X axis.dy
- The relative amount of pixels to move in the Y axis.public boolean wasScrolled()
Scrollable
wasScrolled
in interface Scrollable
public Flick getFlick()
Scrollable
getFlick
in interface Scrollable
public int getScrollPosition(int direction)
Scrollable
getScrollPosition
in interface Scrollable
public void setCellController(Grid.CellController cc)
Grid.CellController
public void setColumnWidth(int col, int newWidth)
public int[] getColumnWidths()
setColumnWidth(int, int)
public Edit setColumnEditable(int col, boolean editable)
public boolean isColumnEditable(int col)
public ComboBoxDropDown setColumnChoices(int col, java.lang.String[] choices)
col
- The column to set as a ComboBox columnchoices
- The choices that will be displayed. Passing a null value removes any ComboBox
assigned to the column.setCellController(totalcross.ui.Grid.CellController)
protected void onFontChanged()
Control
onFontChanged
in class Control
public void setItems(java.lang.String[][] items)
public void setDataSource(Grid.DataSource ds, int nrItems)
public void add(java.lang.String[] item)
item
- string containing the information of the rowpublic void add(java.lang.String[] item, int row)
item
- string containing the information of the rowrow
- index position to insert the row inpublic void add(java.lang.String[][] items)
items
- the lines to be appended to the grid.public void replace(java.lang.String[] item, int row)
item
- String containing the information of the new linerow
- Index position to insert the row inpublic boolean move(int row, boolean up)
public boolean del(int row)
public java.lang.String getCellText(int row, int col)
public java.lang.String[] getSelectedItem()
public int getSelectedIndex()
public void setChecked(int row, boolean check)
public boolean isChecked(int row)
public Vector getItemsVector()
public java.lang.String[] getItem(int row)
public void refreshDataSource()
public void scrollTo(int row)
protected void onColorsChanged(boolean colorsChanged)
Control
onColorsChanged
in class Container
public void setNinePatch(Image img, int corner, int side)
Control
setNinePatch
in class Control
img
- The image to make the NinePatch.
The image must be on a NinePatch format.corner
- The size, in pixels, of the NinePatch's cornerside
- The size, in pixels, of the NinePatch's side.public void setNinePatchCaption(Image img, int corner, int side)
public void initUI()
Container
public int getPreferredWidth()
getPreferredWidth
in class Control
public int getPreferredHeight()
Control
getPreferredHeight
in class Control
protected void onBoundsChanged(boolean screenChanged)
Control
onBoundsChanged
in class Control
screenChanged
- If the bounds were changed due to a screen change (rotation, collapse)public void removeAllElements()
public void clear()
public void markAll(boolean check)
public boolean horizontalScroll(boolean toLeft)
public void setCellText(int row, int col, java.lang.String text)
public void onEvent(Event e)
Control
public void qsort(int col, boolean ascending)
public void qsort(int col)
public void setSelectedIndex(int row)
public int size()
public void reposition()
reposition
in class Control
public void getFocusableControls(Vector v)
Container
getFocusableControls
in class Container
v
- A vector into which to add the focus candidates.public Control handleGeographicalFocusChangeKeys(KeyEvent ke)
Control
handleGeographicalFocusChangeKeys
in class Control
ke
- The KeyEvent to be processedSettings.geographicalFocus
public void setVisibleLines(int visibleLines)
public Grid.DataSource getDataSource()
public void removeAll()
removeAll
in class Container
removeAllElements()
public int getCheckCount()
public void setImage(java.lang.String tag, Image image) throws ImageException
try { String []gridCaptions = {"Image", "Name", "Details" }; int gridWidths[] = {-25, -50, -25}; int gridAligns[] = {CENTER,LEFT,LEFT}; String items[][] = { {"@foto1", "Car number one", "good car"}, {"@foto2", "Car number two", "great car"}, }; Grid grid = new Grid(gridCaptions, gridWidths, gridAligns, false); add(grid, LEFT+5, AFTER+2, FILL-10, PREFERRED); grid.setImage("@foto1",new Image("foto1.jpg")); grid.setImage("@foto2",new Image("foto2.jpg")); grid.setItems(items); } catch (Exception ee) { MessageBox.showException(ee,true); }
ImageException
public Control moveFocusToNextControl(Control c, boolean forward)
moveFocusToNextControl
in class Container
public void disableFlick()
enableFlick
public void enableFlick()