Package totalcross.ui

Class Grid.CellController

  • Enclosing class:
    Grid

    public abstract static class Grid.CellController
    extends java.lang.Object
    Abstract class that must be implemented if you want to get a fine control of each cell in the grid. Note that you must keep track of the state of each cell in your code. How to proceed:
    • Create a class that extends CellController and implement each of the methods. Then call grid.setCellController passing an instance of the created class.
    • Each time a cell is drawn, the getForeColor, getBackColor and getFont methods are called. If you want to use the default values, return null.
    • If a column has choices activated (with setColumnChoices), each time the ComboBox will be opened, the getChoices method is called. This way, you can dynamically change the choices for each cell. If you want to use the default values, return null.
    • Each time a cell is clicked, the isEnabled method is called. If you return false to it, the event is not generated; also, when trying to open the ComboBox or the Edit assigned to the column, the control will not be activated. This is valid for a check column too.
    Note that using a CellControler makes the grid drawings a bit slower. Also, if the user sorts the columns, you may get scrambled. You can disable sort using grid.disableSort = true.
    • Constructor Summary

      Constructors 
      Constructor Description
      CellController()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract int getBackColor​(int row, int col)
      Must return the background color for the given cell, or -1 if none.
      abstract java.lang.String[] getChoices​(int row, int col)
      Must return the choices for a given line and column, if setColumnChoices was set to this column.
      Font getFont​(int row, int col)
      Must return the font to be used in this cell, or null to use the default control's font.
      abstract int getForeColor​(int row, int col)
      Must return the foreground color for the given cell, or -1 if none.
      abstract boolean isEnabled​(int row, int col)
      Must return if the given cell is enabled, ie, can have input and can be selected.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CellController

        public CellController()
    • Method Detail

      • getForeColor

        public abstract int getForeColor​(int row,
                                         int col)
        Must return the foreground color for the given cell, or -1 if none.
      • getBackColor

        public abstract int getBackColor​(int row,
                                         int col)
        Must return the background color for the given cell, or -1 if none. Note that if the grid has a check, the back color of the check cell will be requested passing col value as -1.
      • getChoices

        public abstract java.lang.String[] getChoices​(int row,
                                                      int col)
        Must return the choices for a given line and column, if setColumnChoices was set to this column.
      • isEnabled

        public abstract boolean isEnabled​(int row,
                                          int col)
        Must return if the given cell is enabled, ie, can have input and can be selected. If the grid has a check column, returning false will disable the check state change.
      • getFont

        public Font getFont​(int row,
                            int col)
        Must return the font to be used in this cell, or null to use the default control's font. Note: if you plan to use a font bigger than in the rest of the grid, be sure to follow these steps:
        1. Construct the grid and set the grid's font to be the one with bigger size
        2. Call add/setRect
        3. Restore the grid's default font
        Following this guide, the grid will have a height of the biggest font.
        Since:
        TotalCross 1.0