Class JRDesignCrosstab

All Implemented Interfaces:
Serializable, Cloneable, JRCrosstab, JRChangeEventsSupport, JRBoxContainer, JRChild, JRCloneable, JRCommonElement, JRElement, JRIdentifiable, JRPropertiesHolder, JRStyleContainer, JRVisitable

public class JRDesignCrosstab extends JRDesignElement implements JRCrosstab
Design-time crosstab implementation.
Author:
Lucian Chirita (lucianc@users.sourceforge.net)
See Also:
  • Field Details

  • Constructor Details

    • JRDesignCrosstab

      public JRDesignCrosstab(JRDefaultStyleProvider defaultStyleProvider)
      Creates a new crosstab.
      Parameters:
      defaultStyleProvider - default style provider
    • JRDesignCrosstab

      public JRDesignCrosstab()
      Creates a new crosstab.
  • Method Details

    • getId

      public int getId()
      The ID of the crosstab is only generated at compile time.
      Specified by:
      getId in interface JRCrosstab
      Returns:
      the ID of the crosstab
    • getDataset

      public JRCrosstabDataset getDataset()
      Description copied from interface: JRCrosstab
      Returns the input dataset of the crosstab.
      Specified by:
      getDataset in interface JRCrosstab
      Returns:
      the input dataset of the crosstab
    • getDesignDataset

      public JRDesignCrosstabDataset getDesignDataset()
      Returns the crosstab dataset object to be used for report designing.
      Returns:
      the crosstab dataset design object
    • getRowGroups

      public JRCrosstabRowGroup[] getRowGroups()
      Description copied from interface: JRCrosstab
      Returns the row groups of the crosstab.
      Specified by:
      getRowGroups in interface JRCrosstab
      Returns:
      the row groups
    • getColumnGroups

      public JRCrosstabColumnGroup[] getColumnGroups()
      Description copied from interface: JRCrosstab
      Returns the column groups of the crosstab.
      Specified by:
      getColumnGroups in interface JRCrosstab
      Returns:
      the column groups
    • getMeasures

      public JRCrosstabMeasure[] getMeasures()
      Description copied from interface: JRCrosstab
      Returns the crosstab measures.
      Specified by:
      getMeasures in interface JRCrosstab
      Returns:
      the crosstab measures
    • collectExpressions

      public void collectExpressions(JRExpressionCollector collector)
      Specified by:
      collectExpressions in interface JRElement
    • visit

      public void visit(JRVisitor visitor)
      Specified by:
      visit in interface JRVisitable
    • setDataset

      public void setDataset(JRDesignCrosstabDataset dataset)
      Sets the crosstab input dataset.
      Parameters:
      dataset - the dataset
      See Also:
    • addRowGroup

      public void addRowGroup(JRDesignCrosstabRowGroup group) throws JRException
      Adds a row group.

      This group will be a sub group of the last row group, if any.

      Parameters:
      group - the group
      Throws:
      JRException
      See Also:
    • addRowGroup

      public void addRowGroup(int index, JRDesignCrosstabRowGroup group) throws JRException
      Adds a row group.

      This group will be a sub group of the last row group, if any.

      Parameters:
      index - position
      group - the group
      Throws:
      JRException
      See Also:
    • addRowGroupVars

      protected void addRowGroupVars(JRDesignCrosstabRowGroup rowGroup)
    • addColumnGroup

      public void addColumnGroup(JRDesignCrosstabColumnGroup group) throws JRException
      Adds a column group.

      This group will be a sub group of the last column group, if any.

      Parameters:
      group - the group
      Throws:
      JRException
      See Also:
    • addColumnGroup

      public void addColumnGroup(int index, JRDesignCrosstabColumnGroup group) throws JRException
      Adds a column group.

      This group will be a sub group of the last column group, if any.

      Parameters:
      group - the group
      Throws:
      JRException
      See Also:
    • addColGroupVars

      protected void addColGroupVars(JRDesignCrosstabColumnGroup colGroup)
    • addMeasure

      public void addMeasure(JRDesignCrosstabMeasure measure) throws JRException
      Adds a measure to the crosstab.
      Parameters:
      measure - the measure
      Throws:
      JRException
      See Also:
    • addMeasure

      public void addMeasure(int index, JRDesignCrosstabMeasure measure) throws JRException
      Adds a measure to the crosstab.
      Parameters:
      measure - the measure
      Throws:
      JRException
      See Also:
    • addMeasureVars

      protected void addMeasureVars(JRDesignCrosstabMeasure measure)
    • addTotalVar

      protected void addTotalVar(JRCrosstabMeasure measure, JRCrosstabRowGroup rowGroup, JRCrosstabColumnGroup colGroup)
    • removeTotalVar

      protected void removeTotalVar(JRCrosstabMeasure measure, JRCrosstabRowGroup rowGroup, JRCrosstabColumnGroup colGroup)
    • getTotalVariableName

      public static String getTotalVariableName(JRCrosstabMeasure measure, JRCrosstabRowGroup rowGroup, JRCrosstabColumnGroup colGroup)
    • removeRowGroup

      public JRCrosstabRowGroup removeRowGroup(String groupName)
      Removes a row group.
      Parameters:
      groupName - the group name
      Returns:
      the removed group
    • removeRowGroupVars

      protected void removeRowGroupVars(JRCrosstabRowGroup rowGroup)
    • removeRowGroup

      public JRCrosstabRowGroup removeRowGroup(JRCrosstabRowGroup group)
      Removes a row group.
      Parameters:
      group - the group to be removed
      Returns:
      the removed group
    • removeColumnGroup

      public JRCrosstabColumnGroup removeColumnGroup(String groupName)
      Removes a column group.
      Parameters:
      groupName - the group name
      Returns:
      the removed group
    • removeColGroupVars

      protected void removeColGroupVars(JRCrosstabColumnGroup colGroup)
    • removeColumnGroup

      public JRCrosstabColumnGroup removeColumnGroup(JRCrosstabColumnGroup group)
      Removes a column group.
      Parameters:
      group - the group
      Returns:
      the removed group
    • removeMeasure

      public JRCrosstabMeasure removeMeasure(String measureName)
      Removes a measure.
      Parameters:
      measureName - the measure name
      Returns:
      the removed measure
    • removeMeasureVars

      protected void removeMeasureVars(JRDesignCrosstabMeasure measure)
    • removeMeasure

      public JRCrosstabMeasure removeMeasure(JRCrosstabMeasure measure)
      Removes a measure.
      Parameters:
      measure - the measure
      Returns:
      the removed measure
    • isRepeatColumnHeaders

      public boolean isRepeatColumnHeaders()
      Description copied from interface: JRCrosstab
      Returns whether to repeat the column headers after a row break.
      Specified by:
      isRepeatColumnHeaders in interface JRCrosstab
      Returns:
      whether to repeat the column headers after a row break
    • setRepeatColumnHeaders

      public void setRepeatColumnHeaders(boolean repeatColumnHeaders)
      Sets the repeat column headers flag.
      Parameters:
      repeatColumnHeaders - whether to repeat the column headers on row breaks
      See Also:
    • isRepeatRowHeaders

      public boolean isRepeatRowHeaders()
      Description copied from interface: JRCrosstab
      Returns whether to repeat the row headers after a column break.
      Specified by:
      isRepeatRowHeaders in interface JRCrosstab
      Returns:
      whether to repeat the row headers after a column break
    • setRepeatRowHeaders

      public void setRepeatRowHeaders(boolean repeatRowHeaders)
      Sets the repeat row headers flag.
      Parameters:
      repeatRowHeaders - whether to repeat the row headers on column breaks
      See Also:
    • getCells

      public JRCrosstabCell[][] getCells()
      Description copied from interface: JRCrosstab
      Returns the data cell matrix.

      A crosstab can have multiple data cells for row/groups totals. These cells are organized in a (rowGroupCount + 1) x (columnGroupCount + 1) matrix as following:

      • the row index of a cell is
        • the row group index, if the cell corresponds to a total row
        • rowGroupCount, otherwise
      • the column index of a cell is
        • the column group index, if the cell corresponds to a total column
        • columnGroupCount, otherwise

      E.g. if the crosstab has Country and City (subgroup of Country) row groups and Year and Month column groups, the cells will be organized in the following matrix

      0/Years total 1/Months total 2/Base
      0/Countries total Total for all countries and all years Total for all countries and a year Total for all countries and a month
      1/Cities total Total for a country and all years Total for a country and a year Total for a country and a month
      2/Base Total for a city and all years Total for a city and a year Total for a city and a month

      If the data cell for a total row/column is not specified, the cell will be inherited from lower levels, if possible. For example, if the "Total for all countries and a year" cell is not specified, the "Total for a country and a year" or "Total for a city and a year" cell will be used (in this order).

      The data cell sizes are calculated from the base data cell sizes, i.e. the height of all data cells for a row will be the height of the base cell of that row. The base cell sizes are also inherited, e.g. if the height of a total row is not specified the height of the base row will be used.

      Specified by:
      getCells in interface JRCrosstab
      Returns:
      the data cell matrix
    • getCellsList

      public List<JRCrosstabCell> getCellsList()
      Returns the data cells list.
      Returns:
      the data cells list
      See Also:
    • getCellsMap

      public Map<Pair<String,String>,JRCrosstabCell> getCellsMap()
      Returns the crosstab cells indexed by corresponding row total group/ column total group pairs.
      Returns:
      the crosstab cells indexed by row/column total groups
      See Also:
    • addCell

      public void addCell(JRDesignCrosstabCell cell) throws JRException
      Adds a data cell to the crosstab.
      Parameters:
      cell - the cell
      Throws:
      JRException
      See Also:
    • removeCell

      public JRCrosstabCell removeCell(String rowTotalGroup, String columnTotalGroup)
      Removes a data cell.
      Parameters:
      rowTotalGroup - the cell's total row group
      columnTotalGroup - the cell's total column group
      Returns:
      the removed cell
    • removeCell

      public JRCrosstabCell removeCell(JRCrosstabCell cell)
      Removes a data cell.
      Parameters:
      cell - the cell to be removed
      Returns:
      the removed cell
    • getParameters

      public JRCrosstabParameter[] getParameters()
      Description copied from interface: JRCrosstab
      Returns the crosstab parameters.

      Crosstabs have separate expression evaluators and cannot access the parameters/fields/variables of the report. In order to use a value from the report inside a crosstab, it should be passed as parameter to the crosstab.

      A crosstab parameters has a name and a value expression.

      Specified by:
      getParameters in interface JRCrosstab
      Returns:
      the crosstab parameters
    • getParametersList

      public List<JRCrosstabParameter> getParametersList()
      Returns the paremeters list.
      Returns:
      the paremeters list
    • getParametersMap

      public Map<String,JRCrosstabParameter> getParametersMap()
      Returns the parameters indexed by names.
      Returns:
      the parameters indexed by names
    • getParametersMapExpression

      public JRExpression getParametersMapExpression()
      Description copied from interface: JRCrosstab
      Returns the parameters map expression.

      The set of values for crosstab parameters can be set using a map. If a parameter has also a value expression, it will overwrite the value from the map.

      Specified by:
      getParametersMapExpression in interface JRCrosstab
      Returns:
      the parameters map expression
    • addParameter

      public void addParameter(JRCrosstabParameter parameter) throws JRException
      Adds a parameter to the crosstab.
      Parameters:
      parameter - the parameter
      Throws:
      JRException
      See Also:
    • addParameter

      public void addParameter(int index, JRCrosstabParameter parameter) throws JRException
      Adds a parameter to the crosstab.
      Parameters:
      parameter - the parameter
      Throws:
      JRException
      See Also:
    • removeParameter

      public JRCrosstabParameter removeParameter(String parameterName)
      Removes a parameter.
      Parameters:
      parameterName - the name of the parameter to be removed
      Returns:
      the removed parameter
    • removeParameter

      public JRCrosstabParameter removeParameter(JRCrosstabParameter parameter)
      Removes a parameter.
      Parameters:
      parameter - the parameter to be removed
      Returns:
      the removed parameter
    • setParametersMapExpression

      public void setParametersMapExpression(JRExpression expression)
      Sets the parameters map expression.
      Parameters:
      expression - the parameters map expression
      See Also:
    • getVariablesMap

      public Map<String,JRVariable> getVariablesMap()
      Returns the variables of this crosstab indexed by name.
      Returns:
      the variables of this crosstab indexed by name
    • getVariables

      public JRVariable[] getVariables()
      Returns the list of variables created for this crosstab.
      Specified by:
      getVariables in interface JRCrosstab
      Returns:
      the list of variables created for this crosstab
      See Also:
    • getColumnBreakOffset

      public Integer getColumnBreakOffset()
      Description copied from interface: JRCrosstab
      Returns the column break offset.

      When the crosstab columns do not fit the width, the crosstab breaks the columns and prints the ones that don't fit after printing the first set of columns for all rows. This method returns the offset to be used when continuing the printing after a column break.

      Specified by:
      getColumnBreakOffset in interface JRCrosstab
      Returns:
      the column break offset
    • setColumnBreakOffset

      public void setColumnBreakOffset(Integer columnBreakOffset)
      Sets the column break offset.
      Parameters:
      columnBreakOffset - the offset
      See Also:
    • preprocess

      public void preprocess()
      Performs all the calculations required for report compilation.
    • setGroupVariablesClass

      protected <T> void setGroupVariablesClass(List<T> groups)
    • calculateSizes

      protected void calculateSizes()
    • setWhenNoDataCellSize

      protected void setWhenNoDataCellSize()
    • createCellMatrix

      protected void createCellMatrix()
    • getRowGroup

      protected JRDesignCrosstabRowGroup getRowGroup(int rowGroupIndex)
    • getColumnGroup

      protected JRDesignCrosstabColumnGroup getColumnGroup(int columnGroupIndex)
    • inheritCells

      protected void inheritCells()
    • inheritCellSize

      protected void inheritCellSize(int i, int j)
    • inheritCell

      protected void inheritCell(int i, int j)
    • calculateRowHeadersSizes

      protected int calculateRowHeadersSizes()
    • calculateColumnHeadersSizes

      protected int calculateColumnHeadersSizes(int rowHeadersWidth)
    • setTitleSize

      protected void setTitleSize(int rowHeadersWidth)
    • getWhenNoDataCell

      public JRCellContents getWhenNoDataCell()
      Description copied from interface: JRCrosstab
      Returns a cell which will be rendered when no data was fed to the crosstab.

      If this cell is not specified for a crosstab, nothing will be rendered for an empty crosstab.

      The cell sizes are the same as the crosstab element sizes.

      Specified by:
      getWhenNoDataCell in interface JRCrosstab
      Returns:
      a cell which will be rendered when no data was fed to the crosstab
    • setWhenNoDataCell

      public void setWhenNoDataCell(JRDesignCellContents whenNoDataCell)
      Sets the "No data" cell.
      Parameters:
      whenNoDataCell - the cell
      See Also:
    • getElementByKey

      public JRElement getElementByKey(String elementKey)
      Description copied from interface: JRCrosstab
      Searches for an element inside all crosstab cells.
      Specified by:
      getElementByKey in interface JRCrosstab
      Parameters:
      elementKey - the element key
      Returns:
      the first element having the specified key
    • getMode

      public ModeEnum getMode()
      Description copied from interface: JRCommonElement
      Returns the element transparency mode. The default value depends on the type of the report element. Graphic elements like rectangles and lines are opaque by default, but the images are transparent. Both static texts and text fields are transparent by default, and so are the subreport elements.
      Specified by:
      getMode in interface JRCommonElement
      Overrides:
      getMode in class JRBaseElement
    • getTitleCell

      public CrosstabColumnCell getTitleCell()
      Description copied from interface: JRCrosstab
      Returns the title cell, which renders once at the beginning of the crosstab.
      Specified by:
      getTitleCell in interface JRCrosstab
      Returns:
      the title cell
    • setTitleCell

      public void setTitleCell(DesignCrosstabColumnCell titleCell)
    • getHeaderCell

      public JRCellContents getHeaderCell()
      Description copied from interface: JRCrosstab
      Returns a cell which will be rendered at the upper-left corner of the crosstab.

      The cell size will be calculated based on the row/column header cell widths/heights.

      Specified by:
      getHeaderCell in interface JRCrosstab
      Returns:
      a cell which will be rendered at the upper-left corner of the crosstab
    • setHeaderCell

      public void setHeaderCell(JRDesignCellContents headerCell)
      Sets the crosstab header cell (this cell will be rendered at the upper-left corder of the crosstab).
      Parameters:
      headerCell - the cell
      See Also:
    • measureClassChanged

      protected void measureClassChanged(JRDesignCrosstabMeasure measure, String valueClassName)
    • setTotalVarClass

      protected void setTotalVarClass(JRCrosstabMeasure measure, JRCrosstabRowGroup rowGroup, JRCrosstabColumnGroup colGroup, String valueClassName)
    • getRunDirection

      public RunDirectionEnum getRunDirection()
      Description copied from interface: JRCrosstab
      Retrieves the run direction of this crosstab
      Specified by:
      getRunDirection in interface JRCrosstab
      Returns:
      a value representing one of the run direction constants in RunDirectionEnum
    • setRunDirection

      public void setRunDirection(RunDirectionEnum runDirection)
      Description copied from interface: JRCrosstab
      Sets the run direction of the crosstab.

      Crosstabs can either be filled from left to right (the default) or from right to left (mainly for reports in RTL languages).

      Specified by:
      setRunDirection in interface JRCrosstab
      Parameters:
      runDirection - a value representing one of the run direction constants in RunDirectionEnum
    • getHorizontalPosition

      public HorizontalPosition getHorizontalPosition()
      Description copied from interface: JRCrosstab
      Returns the position of the crosstab within its element box.
      Specified by:
      getHorizontalPosition in interface JRCrosstab
      Returns:
      the position of the crosstab within its element box, null if no position is specified
    • setHorizontalPosition

      public void setHorizontalPosition(HorizontalPosition horizontalPosition)
      Description copied from interface: JRCrosstab
      Sets the position of the crosstab within its element box.
      Specified by:
      setHorizontalPosition in interface JRCrosstab
      Parameters:
      horizontalPosition - the crosstab position, if null the default position is applied
    • setCellOrigin

      protected void setCellOrigin(JRCellContents cell, JRCrosstabOrigin origin)
    • setCellOrigin

      protected void setCellOrigin(JRDesignCellContents cell, JRCrosstabOrigin origin)
    • setParent

      protected void setParent(JRDesignCrosstabGroup group)
    • clone

      public Object clone()
      Specified by:
      clone in interface JRCloneable
      Overrides:
      clone in class JRDesignElement
    • getRowGroupsList

      public List<JRCrosstabRowGroup> getRowGroupsList()
    • getRowGroupIndicesMap

      public Map<String,Integer> getRowGroupIndicesMap()
    • getColumnGroupsList

      public List<JRCrosstabColumnGroup> getColumnGroupsList()
    • getColumnGroupIndicesMap

      public Map<String,Integer> getColumnGroupIndicesMap()
    • getMesuresList

      public List<JRCrosstabMeasure> getMesuresList()
    • getMeasureIndicesMap

      public Map<String,Integer> getMeasureIndicesMap()
    • getIgnoreWidth

      public Boolean getIgnoreWidth()
      Description copied from interface: JRCrosstab
      Returns the ignore width flag for the crosstab.
      Specified by:
      getIgnoreWidth in interface JRCrosstab
      Returns:
      the ignore width flag, or null is the crosstab does not specify a flag value
      See Also:
    • setIgnoreWidth

      public void setIgnoreWidth(Boolean ignoreWidth)
      Description copied from interface: JRCrosstab
      Set the ignore width crosstab flag.

      This flag determines whether the crosstab will break at the width set for the crosstab element, or whether the crosstab is to expand over this width (and over the page width as well).

      If this flag is set to true, the crosstab will expand towards the right (or towards the left if the crosstab direction is RTL) as long as it needs to. This would result in crosstab cells being rendered over the page boundary; such elements will be exported by certain grid-based exporters such as the HTML or XLS ones, but will not be visible in export formats that observe the page width, such as the PDF exporter.

      The default value of this flag is given by the JRCrosstab.PROPERTY_IGNORE_WIDTH property and the JRParameter.IS_IGNORE_PAGINATION parameter.

      Specified by:
      setIgnoreWidth in interface JRCrosstab
      Parameters:
      ignoreWidth - whether the element width is to be ignored by the crosstab, or null if the default setting is to be used
      See Also:
    • getDefaultLineColor

      public Color getDefaultLineColor()
      Specified by:
      getDefaultLineColor in interface JRBoxContainer
    • getLineBox

      public JRLineBox getLineBox()
      Specified by:
      getLineBox in interface JRBoxContainer