*
* @author Markus Kr�ger
*/
public void setWidth(short width) throws TextException {
// get text table properties
ITextTableProperties textTableProperties = textTable.getProperties();
// get column separators
TextTableColumnsSeparator[] textTableColumnsSeparators = textTableProperties
.getTableColumnSeparators();
int columnsSeparatorsLength = textTableColumnsSeparators.length;
long textTableWidth = textTableProperties.getWidth();
// only if there is more than one column
if (columnsSeparatorsLength > 0 && index <= columnsSeparatorsLength) {
// sets separator if index is 0
if (index == 0) {
// for a table with only two columns
if (columnsSeparatorsLength == 1) {
// set new position only if the width does not exceed table
// width
if (width < textTableWidth - MIN_COLUMN_WIDTH) {
// set new position of separator
textTableColumnsSeparators[index].setPosition(width);
} else {
// set new position of separator to table width
textTableColumnsSeparators[index]
.setPosition((short) (textTableWidth - MIN_COLUMN_WIDTH));
}
}
// for a table with at least three columns
else {
// set new position only if the width does not exceed the
// position of the next column separator
if (width < textTableColumnsSeparators[index + 1]
.getPosition()
- MIN_COLUMN_WIDTH) {
// set new position of separator
textTableColumnsSeparators[index].setPosition(width);
} else {
// set new position of separator right next to the
// position of the next column separator
textTableColumnsSeparators[index]
.setPosition((short) (textTableColumnsSeparators[index + 1]
.getPosition() - MIN_COLUMN_WIDTH));
}
}
}
// sets separator the column is not the first one or the last one
else if (index < columnsSeparatorsLength) {
// if the column is the last but one
if (index == columnsSeparatorsLength - 1) {
// set new position only if the width does not exceed table
// width
if (textTableColumnsSeparators[index - 1].getPosition()
+ width < textTableWidth - MIN_COLUMN_WIDTH) {
// set new position of separator
textTableColumnsSeparators[index]
.setPosition((short) (textTableColumnsSeparators[index - 1]
.getPosition() + width));
} else {
// set new position of separator to table width
textTableColumnsSeparators[index]
.setPosition((short) (textTableWidth - MIN_COLUMN_WIDTH));
}
}
// if the column is not the last but one
else {
// set new position only if the width does not exceed the
// position of the next column separator
if (textTableColumnsSeparators[index - 1].getPosition()
+ width < textTableColumnsSeparators[index + 1]
.getPosition()
- MIN_COLUMN_WIDTH) {
// set new position of separator
textTableColumnsSeparators[index]
.setPosition((short) (textTableColumnsSeparators[index - 1]
.getPosition() + width));
} else {
// set new position of separator right next to the
// position of the next column separator
textTableColumnsSeparators[index]
.setPosition((short) (textTableColumnsSeparators[index + 1]
.getPosition() - MIN_COLUMN_WIDTH));
}
}
}
// sets the last column width
else {
// if there are only two columns
if (columnsSeparatorsLength == 1) {
// new position is not smaller than 0
if (textTableWidth - width > MIN_COLUMN_WIDTH) {
// set new position of the only separator
textTableColumnsSeparators[index - 1]
.setPosition((short) (textTableWidth - width));
}
// new position is smaller than MIN_COLUMN_WIDTH, then set
// it to MIN_COLUMN_WIDTH
else {
// set new position of the only separator
textTableColumnsSeparators[index - 1]
.setPosition((short) MIN_COLUMN_WIDTH);
}
}
// if there are more than two columns
else {
// new position is not smaller than the position of the last
// separator
if (textTableWidth - width > textTableColumnsSeparators[index - 2]
.getPosition()
+ MIN_COLUMN_WIDTH) {
// set new position of the separator
textTableColumnsSeparators[index - 1]
.setPosition((short) (textTableWidth - width));
}
// new position is smaller than the position of the last
// separator, then set it right next to it
else {
// set new position of the separator
textTableColumnsSeparators[index - 1]
.setPosition((short) (textTableColumnsSeparators[index - 2]
.getPosition() + MIN_COLUMN_WIDTH));
}
}
}
}
// sets new separators
textTableProperties
.setTableColumnSeparators(textTableColumnsSeparators);
}