Class FormulaBar

All Implemented Interfaces:
Animation, Editable, StyleListener, Iterable<Component>

public class FormulaBar extends Container

The bar a spreadsheet application has over its cells: the address of the selected cell, and its formula, or its value, in an editor of one line. What is typed there is edited as in a cell -- references colored and outlined in the grid, functions completed, arguments hinted, a tap on a cell putting its address in -- and Enter writes it to the cell.

Workbook book = new Workbook();
// com.codename1.ui has a Sheet too, hence the full name
com.codename1.spreadsheet.Sheet sheet = book.addSheet("Prices");
sheet.setCellValue("A1", Double.valueOf(3.5));
sheet.setCellValue("B1", "=A1*2");
DataGrid grid = new DataGrid(sheet);
grid.setColumns(sheet.createColumns());
Form form = new Form("Prices", new BorderLayout());
form.add(BorderLayout.NORTH, new FormulaBar(sheet, grid));
form.add(BorderLayout.CENTER, grid);
form.show();

The bar follows the grid's selection and the sheet's changes. Escape puts back what the cell holds; a formula that cannot be read is not written, and the bar says why. The name box is a Label with the UIID FormulaBarName, the fx before the editor one with FormulaBarFx, and the bar itself has the UIID FormulaBar.

  • Constructor Details

    • FormulaBar

      public FormulaBar(Sheet sheet, DataGrid grid)

      Creates a bar for a sheet shown in a grid.

      Parameters
      • sheet: the sheet, which is the grid's model

      • grid: the grid that shows it

  • Method Details

    • getAddress

      public String getAddress()

      The address of the cell the bar shows, as B4, or an empty string when no cell is selected.

      Returns

      the address

    • getText

      public String getText()

      The text in the bar now: what was typed, or what the selected cell holds.

      Returns

      the text

    • setText

      public void setText(String text)

      Puts text into the bar as if it had been typed, so that it is edited as typing it would be: Enter, or #enter(), writes it to the cell.

      Parameters
      • text: the text
    • enter

      public boolean enter()

      Writes what is in the bar to the selected cell, as Enter does. Text that is what the cell holds writes nothing.

      Returns

      false when the text is a formula that cannot be read, which is then not written

    • initComponent

      protected void initComponent()
      Description copied from class: Component
      Allows subclasses to bind functionality that relies on fully initialized and "ready for action" component state
      Overrides:
      initComponent in class Component
    • deinitialize

      protected void deinitialize()
      Description copied from class: Component
      Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy. This allows the component to deregister animators and cleanup after itself. This method is the opposite of the initComponent() method.
      Overrides:
      deinitialize in class Component