use of org.apache.pivot.wtk.TableView in project pivot by apache.
the class TerraTableViewHeaderSkin method getHeaderBounds.
@Override
public Bounds getHeaderBounds(int headerIndex) {
Bounds headerBounds = null;
TableViewHeader tableViewHeader = (TableViewHeader) getComponent();
TableView tableView = tableViewHeader.getTableView();
if (tableView != null) {
Utils.checkZeroBasedIndex(headerIndex, headerWidths.getLength());
int cellX = 0;
for (int i = 0; i < headerIndex; i++) {
cellX += (headerWidths.get(i).intValue() + 1);
}
headerBounds = new Bounds(cellX, 0, headerWidths.get(headerIndex).intValue(), getHeight() - 1);
}
return headerBounds;
}
use of org.apache.pivot.wtk.TableView in project pivot by apache.
the class TerraTableViewHeaderSkin method getHeaderAt.
@Override
public int getHeaderAt(int x) {
Utils.checkNonNegative(x, "x");
int headerIndex = -1;
TableViewHeader tableViewHeader = (TableViewHeader) getComponent();
TableView tableView = tableViewHeader.getTableView();
if (tableView != null) {
int i = 0;
int n = tableView.getColumns().getLength();
int headerX = 0;
while (i < n && x > headerX) {
headerX += (headerWidths.get(i).intValue() + 1);
i++;
}
if (x <= headerX) {
headerIndex = i - 1;
}
}
return headerIndex;
}
use of org.apache.pivot.wtk.TableView in project pivot by apache.
the class TerraTableViewHeaderSkin method mouseMove.
@Override
public boolean mouseMove(Component component, int x, int y) {
boolean consumed = super.mouseMove(component, x, y);
TableViewHeader tableViewHeader = (TableViewHeader) getComponent();
TableView tableView = tableViewHeader.getTableView();
if (tableView != null) {
if (resizeHeaderIndex != -1 && Mouse.getCapturer() != tableViewHeader) {
Mouse.capture(tableViewHeader);
}
if (Mouse.getCapturer() == tableViewHeader) {
TableView.Column column = tableView.getColumns().get(resizeHeaderIndex);
Bounds headerBounds = getHeaderBounds(resizeHeaderIndex);
int columnWidth = Math.max(x - headerBounds.x, MINIMUM_COLUMN_WIDTH);
column.setWidth(columnWidth, false);
} else {
int headerIndex = getHeaderAt(x);
if (headerIndex != -1 && columnsResizable) {
Bounds headerBounds = getHeaderBounds(headerIndex);
TableView.Column column = tableView.getColumns().get(headerIndex);
if (!column.isRelative() && column.getWidth() != -1 && x > headerBounds.x + headerBounds.width - RESIZE_HANDLE_SIZE) {
tableViewHeader.setCursor(Cursor.RESIZE_EAST);
} else {
tableViewHeader.setCursor((Cursor) null);
}
} else {
tableViewHeader.setCursor((Cursor) null);
}
}
}
return consumed;
}
use of org.apache.pivot.wtk.TableView in project pivot by apache.
the class TerraTableViewHeaderSkin method paint.
@Override
public void paint(Graphics2D graphics) {
int width = getWidth();
int height = getHeight();
TableViewHeader tableViewHeader = (TableViewHeader) getComponent();
Color backgroundColorLocal = null;
Color bevelColorLocal = null;
Color borderColorLocal = null;
if (tableViewHeader.isEnabled()) {
backgroundColorLocal = this.backgroundColor;
bevelColorLocal = this.bevelColor;
borderColorLocal = this.borderColor;
} else {
backgroundColorLocal = disabledBackgroundColor;
bevelColorLocal = disabledBevelColor;
borderColorLocal = disabledBorderColor;
}
// Paint the background
if (!themeIsFlat()) {
graphics.setPaint(new GradientPaint(width / 2f, 0, bevelColorLocal, width / 2f, height, backgroundColorLocal));
} else {
graphics.setPaint(backgroundColorLocal);
}
graphics.fillRect(0, 0, width, height);
// Paint the border
if (!themeIsFlat()) {
graphics.setPaint(borderColorLocal);
graphics.setStroke(new BasicStroke(1));
graphics.draw(new Line2D.Double(0.5, height - 0.5, width - 0.5, height - 0.5));
}
// Paint the content
TableView tableView = tableViewHeader.getTableView();
if (tableView != null) {
TableView.ColumnSequence columns = tableView.getColumns();
int headerX = 0;
for (int columnIndex = 0, columnCount = columns.getLength(); columnIndex < columnCount; columnIndex++) {
TableView.Column column = columns.get(columnIndex);
int headerWidth = headerWidths.get(columnIndex).intValue();
// Paint the pressed bevel
if (columnIndex == pressedHeaderIndex) {
graphics.setPaint(new GradientPaint(width / 2f, 0, pressedBevelColor, width / 2f, height, backgroundColorLocal));
graphics.fillRect(headerX, 0, headerWidth, height - 1);
}
// Paint the header data
Object headerData = column.getHeaderData();
TableView.HeaderDataRenderer headerDataRenderer = column.getHeaderDataRenderer();
headerDataRenderer.render(headerData, columnIndex, tableViewHeader, column.getName(), false);
headerDataRenderer.setSize(headerWidth, height - 1);
Graphics2D rendererGraphics = (Graphics2D) graphics.create(headerX, 0, headerWidth, height - 1);
headerDataRenderer.paint(rendererGraphics);
rendererGraphics.dispose();
// Draw the sort image
Image sortImage = null;
String columnName = column.getName();
SortDirection sortDirection = tableView.getSort().get(columnName);
if (sortDirection != null) {
switch(sortDirection) {
case ASCENDING:
{
sortImage = sortAscendingImage;
break;
}
case DESCENDING:
{
sortImage = sortDescendingImage;
break;
}
default:
{
break;
}
}
}
if (sortImage != null) {
int sortImageMargin = sortImage.getWidth() + SORT_INDICATOR_PADDING * 2;
if (headerWidth >= headerDataRenderer.getPreferredWidth(-1) + sortImageMargin) {
Graphics2D sortImageGraphics = (Graphics2D) graphics.create();
sortImageGraphics.translate(headerX + headerWidth - sortImageMargin, (height - sortImage.getHeight()) / 2);
sortImage.paint(sortImageGraphics);
sortImageGraphics.dispose();
}
}
// Draw the divider
headerX += headerWidth;
if (columnIndex < columnCount - 1 || includeTrailingVerticalGridLine) {
if (!themeIsFlat()) {
graphics.setPaint(borderColorLocal);
graphics.draw(new Line2D.Double(headerX + 0.5, 0.5, headerX + 0.5, height - 0.5));
}
}
headerX++;
}
}
}
use of org.apache.pivot.wtk.TableView in project pivot by apache.
the class TerraTableViewSkin method getCellBounds.
@Override
public Bounds getCellBounds(int rowIndex, int columnIndex) {
TableView tableView = (TableView) getComponent();
@SuppressWarnings("unchecked") List<Object> tableData = (List<Object>) tableView.getTableData();
Utils.checkZeroBasedIndex(rowIndex, tableData.getLength());
int cellX = 0;
for (int i = 0; i < columnIndex; i++) {
cellX += (columnWidths.get(i).intValue() + 1);
}
int rowHeight = getRowHeight(rowIndex);
return new Bounds(cellX, rowIndex * (rowHeight + 1), columnWidths.get(columnIndex).intValue(), rowHeight);
}
Aggregations