org.eclipse.nebula.widgets.nattable.layer
Class SizeConfig

java.lang.Object
  extended by org.eclipse.nebula.widgets.nattable.layer.SizeConfig
All Implemented Interfaces:
IPersistable

public class SizeConfig
extends Object
implements IPersistable

This class stores the size configuration of rows/columns within the NatTable. Mixed mode (fixed/percentage sizing):
The mixed mode is only working if percentage sizing is enabled globally, and the fixed sized positions are marked separately.


Field Summary
protected  Map<Integer,Integer> aggregatedSizeCacheMap
          Map that contains the cached aggregated sizes.
protected  int availableSpace
          The available space needed for percentage calculation on resizing.
protected  int defaultSize
          The global default size of this SizeConfig.
protected  Map<Integer,Integer> defaultSizeMap
          Map that contains default sizes per column.
protected  IDpiConverter dpiConverter
          The IDpiConverter that is used for scaling DPI conversion.
protected  boolean isAggregatedSizeCacheValid
          Flag that indicates if the aggregated size cache is valid or if it needs to get recalculated.
protected  boolean percentageSizing
          Flag to tell whether the sizing is done for pixel or percentage values.
protected  Map<Integer,Boolean> percentageSizingMap
          Map that contains the percentage sizing information per row/column.
static String PERSISTENCE_KEY_DEFAULT_SIZE
           
static String PERSISTENCE_KEY_DEFAULT_SIZES
           
static String PERSISTENCE_KEY_PERCENTAGE_SIZING
           
static String PERSISTENCE_KEY_PERCENTAGE_SIZING_INDEXES
           
static String PERSISTENCE_KEY_RESIZABLE_BY_DEFAULT
           
static String PERSISTENCE_KEY_RESIZABLE_INDEXES
           
static String PERSISTENCE_KEY_SIZES
           
protected  Map<Integer,Integer> realSizeMap
          Map that contains the real pixel size.
protected  boolean resizableByDefault
          The global resizable information of this SizeConfig.
protected  Map<Integer,Boolean> resizablesMap
          Map that contains the resizable information per row/column.
protected  Map<Integer,Integer> sizeMap
          Map that contains sizes per column.
 
Fields inherited from interface org.eclipse.nebula.widgets.nattable.persistence.IPersistable
DOT, VALUE_SEPARATOR
 
Constructor Summary
SizeConfig(int defaultSize)
          Create a new SizeConfig with the given default size.
 
Method Summary
protected  int calculateAvailableSpace(int space)
          Calculates the available space for percentage size calculation.
 void calculatePercentages(int space, int positionCount)
          Will calculate the real pixel values for the positions if percentage sizing is enabled.
protected  int[] correctPercentageValues(int sum, int positionCount)
          This method is used to correct the calculated percentage values in case a user configured more than 100 percent.
protected  int downScale(int value)
          Calculates the size value dependent on a possible configured scaling from DPI to pixel value.
 int getAggregateSize(int position)
           
 int getDefaultSize()
           
 int getSize(int position)
           
 boolean isAllPositionsSameSize()
           
 boolean isPercentageSizing()
           
 boolean isPercentageSizing(int position)
          Checks if there is a special percentage sizing configuration for the given position.
 boolean isPositionResizable(int position)
          Checks if there is a special resizable configuration for the given position.
 boolean isResizableByDefault()
           
 void loadState(String prefix, Properties properties)
          Restore the state out of the given Properties identified by the specified prefix.
 void saveState(String prefix, Properties properties)
          Saves the state to the given Properties using the specified prefix.
 void setDefaultSize(int size)
          Set the default size that should be used in case there is no position based size configured.
 void setDefaultSize(int position, int size)
           
 void setDpiConverter(IDpiConverter dpiConverter)
           
 void setPercentage(int position, int percentage)
          Will set the given percentage size information for the given position and will set the given position to be sized via percentage value.
 void setPercentageSizing(boolean percentageSizing)
           
 void setPercentageSizing(int position, boolean percentageSizing)
          Sets the percentage sizing configuration for the given row/column position.
 void setPositionResizable(int position, boolean resizable)
          Sets the resizable configuration for the given row/column position.
 void setResizableByDefault(boolean resizableByDefault)
          Sets the global resizable configuration.
 void setSize(int position, int size)
          Sets the given size for the given position.
 void updatePercentageValues(int positionCount)
          Recalculate the percentage values for the given amount of columns.
protected  int upScale(int value)
          Calculates the size value dependent on a possible configured scaling from pixel to DPI value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PERSISTENCE_KEY_DEFAULT_SIZE

public static final String PERSISTENCE_KEY_DEFAULT_SIZE
See Also:
Constant Field Values

PERSISTENCE_KEY_DEFAULT_SIZES

public static final String PERSISTENCE_KEY_DEFAULT_SIZES
See Also:
Constant Field Values

PERSISTENCE_KEY_SIZES

public static final String PERSISTENCE_KEY_SIZES
See Also:
Constant Field Values

PERSISTENCE_KEY_RESIZABLE_BY_DEFAULT

public static final String PERSISTENCE_KEY_RESIZABLE_BY_DEFAULT
See Also:
Constant Field Values

PERSISTENCE_KEY_RESIZABLE_INDEXES

public static final String PERSISTENCE_KEY_RESIZABLE_INDEXES
See Also:
Constant Field Values

PERSISTENCE_KEY_PERCENTAGE_SIZING

public static final String PERSISTENCE_KEY_PERCENTAGE_SIZING
See Also:
Constant Field Values

PERSISTENCE_KEY_PERCENTAGE_SIZING_INDEXES

public static final String PERSISTENCE_KEY_PERCENTAGE_SIZING_INDEXES
See Also:
Constant Field Values

defaultSize

protected int defaultSize
The global default size of this SizeConfig.


defaultSizeMap

protected final Map<Integer,Integer> defaultSizeMap
Map that contains default sizes per column.


sizeMap

protected final Map<Integer,Integer> sizeMap
Map that contains sizes per column.


resizablesMap

protected final Map<Integer,Boolean> resizablesMap
Map that contains the resizable information per row/column.


resizableByDefault

protected boolean resizableByDefault
The global resizable information of this SizeConfig.


percentageSizingMap

protected final Map<Integer,Boolean> percentageSizingMap
Map that contains the percentage sizing information per row/column.


percentageSizing

protected boolean percentageSizing
Flag to tell whether the sizing is done for pixel or percentage values.


availableSpace

protected int availableSpace
The available space needed for percentage calculation on resizing.


realSizeMap

protected final Map<Integer,Integer> realSizeMap
Map that contains the real pixel size. Will only be used on percentage sizing. This map is not persisted as it will be calculated on resize.


aggregatedSizeCacheMap

protected final Map<Integer,Integer> aggregatedSizeCacheMap
Map that contains the cached aggregated sizes.


isAggregatedSizeCacheValid

protected boolean isAggregatedSizeCacheValid
Flag that indicates if the aggregated size cache is valid or if it needs to get recalculated.


dpiConverter

protected IDpiConverter dpiConverter
The IDpiConverter that is used for scaling DPI conversion.

Constructor Detail

SizeConfig

public SizeConfig(int defaultSize)
Create a new SizeConfig with the given default size.

Parameters:
defaultSize - The default size to use.
Method Detail

saveState

public void saveState(String prefix,
                      Properties properties)
Description copied from interface: IPersistable
Saves the state to the given Properties using the specified prefix. Note: The prefix must be prepended to the property key to support multiple states within one Properties instance.

Specified by:
saveState in interface IPersistable
Parameters:
prefix - The prefix to use for the state keys. Is also used as the state configuration name.
properties - The Properties instance to save the state to.

loadState

public void loadState(String prefix,
                      Properties properties)
Description copied from interface: IPersistable
Restore the state out of the given Properties identified by the specified prefix. Note: The prefix must be prepended to the property key to support multiple states within one Properties instance.

Specified by:
loadState in interface IPersistable
Parameters:
prefix - The prefix to use for the state keys. Is also used as the state configuration name.
properties - The Properties instance to load the state from.

setDefaultSize

public void setDefaultSize(int size)
Set the default size that should be used in case there is no position based size configured.

Parameters:
size - The default size to set.

getDefaultSize

public int getDefaultSize()
Returns:
The default size that is used in case there is no position based size configured.

setDefaultSize

public void setDefaultSize(int position,
                           int size)

getAggregateSize

public int getAggregateSize(int position)

getSize

public int getSize(int position)

setSize

public void setSize(int position,
                    int size)
Sets the given size for the given position. This method can be called manually for configuration via DataLayer and will be called on resizing within the rendered UI. This is why there is a check for percentage configuration. If this SizeConfig is configured to not use percentage sizing, the size is taken as is. If percentage sizing is enabled, the given size will be calculated to percentage value based on the already known pixel values.

If you want to use percentage sizing you should use setPercentage(int, int) for manual size configuration to avoid unnecessary calculations.

Parameters:
position - The position for which the size should be set.
size - The size in pixels to set for the given position.

setPercentage

public void setPercentage(int position,
                          int percentage)
Will set the given percentage size information for the given position and will set the given position to be sized via percentage value.

Parameters:
position - The positions whose percentage sizing information should be set.
percentage - The percentage value to set, always dependent on the available space for percentage sizing, which can be less than the real available space in case there are also positions that are configured for fixed size.

isResizableByDefault

public boolean isResizableByDefault()
Returns:
The global resizable information of this SizeConfig.

isPositionResizable

public boolean isPositionResizable(int position)
Checks if there is a special resizable configuration for the given position. If not the global resizable information is returned.

Parameters:
position - The position of the row/column for which the resizable information is requested.
Returns:
true if the given row/column position is resizable, false if not.

setPositionResizable

public void setPositionResizable(int position,
                                 boolean resizable)
Sets the resizable configuration for the given row/column position.

Parameters:
position - The position of the row/column for which the resizable configuration should be set.
resizable - true if the given row/column position should be resizable, false if not.

setResizableByDefault

public void setResizableByDefault(boolean resizableByDefault)
Sets the global resizable configuration. Will reset all special resizable configurations.

Parameters:
resizableByDefault - true if all rows/columns should be resizable, false if no row/column should be resizable.

isAllPositionsSameSize

public boolean isAllPositionsSameSize()

isPercentageSizing

public boolean isPercentageSizing()
Returns:
true if the size of at least one position is interpreted in percentage, false if the size of all positions is interpreted by pixel.

setPercentageSizing

public void setPercentageSizing(boolean percentageSizing)
Parameters:
percentageSizing - true if the size of the positions should be interpreted percentaged, false if the size of the positions should be interpreted by pixel.

isPercentageSizing

public boolean isPercentageSizing(int position)
Checks if there is a special percentage sizing configuration for the given position. If not the global percentage sizing information is returned.

Parameters:
position - The position of the row/column for which the percentage sizing information is requested.
Returns:
true if the given row/column position is sized by percentage value, false if not.

setPercentageSizing

public void setPercentageSizing(int position,
                                boolean percentageSizing)
Sets the percentage sizing configuration for the given row/column position.

Parameters:
position - The position of the row/column for which the percentage sizing configuration should be set.
percentageSizing - true if the given row/column position should be interpreted in percentage, false if not.

calculatePercentages

public void calculatePercentages(int space,
                                 int positionCount)
Will calculate the real pixel values for the positions if percentage sizing is enabled.

Parameters:
space - The space that is available for rendering.
positionCount - The number of positions that should be handled by this SizeConfig

calculateAvailableSpace

protected int calculateAvailableSpace(int space)
Calculates the available space for percentage size calculation. This is necessary to support mixed mode of sizing, e.g. if two columns are configured to have fixed size of 50 pixels and one column that should take the rest of the available space of 500 pixels, the available space for percentage sizing is 400 pixels.

Parameters:
space - The whole available space for rendering.
Returns:
The available space for percentage sizing. Might be negative if the width of all fixed sized positions is greater than the available space.

correctPercentageValues

protected int[] correctPercentageValues(int sum,
                                        int positionCount)
This method is used to correct the calculated percentage values in case a user configured more than 100 percent. In that case the set percentage values are scaled down to not exceed 100 percent.

Parameters:
sum - The sum of all configured percentage sized positions.
positionCount - The number of positions to check.
Returns:
Integer array with the sum value at first position and the new calculated real pixel sum at second position in case a corrections took place. Will return null in case no correction happened.

updatePercentageValues

public void updatePercentageValues(int positionCount)
Recalculate the percentage values for the given amount of columns. Needed for structural changes that aren't caused by a client are resize, e.g. adding a column.

Parameters:
positionCount - The number of columns that should be used to calculate the percentage values.

upScale

protected int upScale(int value)
Calculates the size value dependent on a possible configured scaling from pixel to DPI value.

Parameters:
value - The value that should be up scaled.
Returns:
The scaled value if a IDpiConverter is configured, the value itself if no IDpiConverter is set.
See Also:
IDpiConverter.convertPixelToDpi(int)

downScale

protected int downScale(int value)
Calculates the size value dependent on a possible configured scaling from DPI to pixel value.

This method is used for percentage sizing calculations.

Parameters:
value - The value that should be down scaled.
Returns:
The scaled value if a IDpiConverter is configured, the value itself if no IDpiConverter is set.

setDpiConverter

public void setDpiConverter(IDpiConverter dpiConverter)
Parameters:
dpiConverter - The IDpiConverter to use for size scaling.


Copyright © 2015. All rights reserved.