use of org.apache.pivot.wtk.Component in project pivot by apache.
the class ScrollPaneSkin method getPreferredSize.
@Override
public Dimensions getPreferredSize() {
ScrollPane scrollPane = (ScrollPane) getComponent();
int preferredWidth = 0;
int preferredHeight = 0;
Component view = scrollPane.getView();
if (view != null) {
Dimensions preferredViewSize = view.getPreferredSize();
preferredWidth += preferredViewSize.width;
preferredHeight += preferredViewSize.height;
Component rowHeader = scrollPane.getRowHeader();
if (rowHeader != null) {
preferredWidth += rowHeader.getPreferredWidth(-1);
}
Component columnHeader = scrollPane.getColumnHeader();
if (columnHeader != null) {
preferredHeight += columnHeader.getPreferredHeight(-1);
}
if (scrollPane.getHorizontalScrollBarPolicy() == ScrollBarPolicy.ALWAYS) {
preferredHeight += horizontalScrollBar.getPreferredHeight(-1);
}
if (scrollPane.getVerticalScrollBarPolicy() == ScrollBarPolicy.ALWAYS) {
preferredWidth += verticalScrollBar.getPreferredWidth(-1);
}
}
return new Dimensions(preferredWidth, preferredHeight);
}
use of org.apache.pivot.wtk.Component in project pivot by apache.
the class ScrollPaneSkin method getViewportBounds.
// Viewport.Skin methods
@Override
public Bounds getViewportBounds() {
int x = 0;
int y = 0;
int width = getWidth();
int height = getHeight();
ScrollPane scrollPane = (ScrollPane) getComponent();
Component rowHeader = scrollPane.getRowHeader();
if (rowHeader != null) {
int rowHeaderWidth = rowHeader.getWidth();
x += rowHeaderWidth;
width -= rowHeaderWidth;
}
Component columnHeader = scrollPane.getColumnHeader();
if (columnHeader != null) {
int columnHeaderHeight = columnHeader.getHeight();
y += columnHeaderHeight;
height -= columnHeaderHeight;
}
if (horizontalScrollBar.isVisible()) {
height -= horizontalScrollBar.getHeight();
}
if (verticalScrollBar.isVisible()) {
width -= verticalScrollBar.getWidth();
}
return new Bounds(x, y, width, height);
}
use of org.apache.pivot.wtk.Component in project pivot by apache.
the class ScrollPaneSkin method getBaseline.
@Override
public int getBaseline(int width, int height) {
ScrollPane scrollPane = (ScrollPane) getComponent();
Component view = scrollPane.getView();
Component rowHeader = scrollPane.getRowHeader();
Component columnHeader = scrollPane.getColumnHeader();
int baseline = -1;
int clientWidth = width;
int clientHeight = height;
int rowHeaderWidth = 0;
if (rowHeader != null) {
rowHeaderWidth = rowHeader.getPreferredWidth(-1);
clientWidth -= rowHeaderWidth;
}
int columnHeaderHeight = 0;
if (columnHeader != null) {
columnHeaderHeight = columnHeader.getPreferredHeight(-1);
clientHeight -= columnHeaderHeight;
baseline = columnHeader.getBaseline(clientWidth, columnHeaderHeight);
}
if (baseline == -1 && rowHeader != null) {
baseline = rowHeader.getBaseline(rowHeaderWidth, clientHeight);
if (baseline != -1) {
baseline += columnHeaderHeight;
}
}
if (baseline == -1 && view != null) {
baseline = view.getBaseline(clientWidth, clientHeight);
if (baseline != -1) {
baseline += columnHeaderHeight;
}
}
return baseline;
}
use of org.apache.pivot.wtk.Component in project pivot by apache.
the class TablePaneSkin method getPreferredRowHeight.
/**
* Gets the preferred height of a table pane row, which is defined as the
* maximum preferred height of the row's visible components. The preferred
* height of each constituent component will be constrained by the width of
* the column that the component occupies (as specified in the array of
* column widths). <p> Because their preferred height relates to the
* preferred heights of other rows, components that span multiple rows will
* not be considered in this calculation (even if they live in the column
* directly). It is up to the caller to factor such components into the row
* heights calculation.
*
* @param rowIndex The index of the row whose preferred height we're
* calculating
* @param columnWidthsArgument An array of column width values corresponding
* to the columns of the table pane
*/
private int getPreferredRowHeight(int rowIndex, int[] columnWidthsArgument) {
Utils.checkNull(columnWidthsArgument, "columnWidths");
TablePane tablePane = (TablePane) getComponent();
TablePane.ColumnSequence columns = tablePane.getColumns();
TablePane.Row row = tablePane.getRows().get(rowIndex);
int preferredHeight = 0;
for (int j = 0, n = row.getLength(), m = columns.getLength(); j < n && j < m; j++) {
Component component = row.get(j);
if (component != null && component.isVisible() && TablePane.getRowSpan(component) == 1) {
preferredHeight = Math.max(preferredHeight, component.getPreferredHeight(columnWidthsArgument[j]));
}
}
return preferredHeight;
}
use of org.apache.pivot.wtk.Component in project pivot by apache.
the class TablePaneSkin method paint.
@Override
public void paint(Graphics2D graphics) {
super.paint(graphics);
TablePane tablePane = (TablePane) getComponent();
TablePane.RowSequence rows = tablePane.getRows();
TablePane.ColumnSequence columns = tablePane.getColumns();
int rowCount = rows.getLength();
int columnCount = columns.getLength();
int width = getWidth();
int height = getHeight();
graphics.setPaint(highlightBackgroundColor);
// Paint the highlighted rows
for (int i = 0, rowY = padding.top; i < rowCount; i++) {
TablePane.Row row = rows.get(i);
if (row.isHighlighted()) {
graphics.fillRect(0, rowY, width, rowHeights[i]);
}
rowY += rowHeights[i] + verticalSpacing;
}
// Paint the highlighted columns
for (int j = 0, columnX = padding.left; j < columnCount; j++) {
TablePane.Column column = columns.get(j);
if (column.isHighlighted()) {
graphics.fillRect(columnX, 0, columnWidths[j], height);
}
columnX += columnWidths[j] + horizontalSpacing;
}
// Paint the grid lines
if ((showHorizontalGridLines && verticalSpacing > 0) || (showVerticalGridLines && horizontalSpacing > 0)) {
Graphics2D gridGraphics = (Graphics2D) graphics.create();
gridGraphics.setStroke(new BasicStroke());
GraphicsUtilities.setAntialiasingOn(graphics);
// Find any components that span multiple rows or columns, and
// ensure that the grid lines don't get painted through their
// cells. We'll only instantiate gridClip if we find such cells
Area gridClip = null;
for (int i = 0, componentY = padding.top; i < rowCount; i++) {
for (int j = 0, componentX = padding.left; j < columnCount; j++) {
Component component = tablePane.getCellComponent(i, j);
if (component != null) {
int rowSpan = TablePane.getRowSpan(component);
int columnSpan = TablePane.getColumnSpan(component);
if (rowSpan > 1 || columnSpan > 1) {
int rowY = componentY;
int columnX = componentX;
int rowHeight = rowHeights[i];
int columnWidth = columnWidths[j];
for (int k = i + 1; k < i + rowSpan && k < rowCount; k++) {
rowHeight += rowHeights[k] + verticalSpacing;
}
for (int k = j + 1; k < j + columnSpan && k < columnCount; k++) {
columnWidth += columnWidths[k] + horizontalSpacing;
}
if (gridClip == null) {
gridClip = new Area(graphics.getClip());
}
if (horizontalSpacing > 1) {
columnWidth += horizontalSpacing - 1;
columnX -= (int) ((horizontalSpacing * 0.5f) - 0.5f);
}
if (verticalSpacing > 1) {
rowHeight += verticalSpacing - 1;
rowY -= (int) ((verticalSpacing * 0.5f) - 0.5f);
}
Rectangle2D.Float bounds = new Rectangle2D.Float(columnX, rowY, columnWidth, rowHeight);
gridClip.subtract(new Area(bounds));
}
}
componentX += columnWidths[j] + horizontalSpacing;
}
componentY += rowHeights[i] + verticalSpacing;
}
if (gridClip != null) {
gridGraphics.clip(gridClip);
}
boolean[][] occupiedCells = getOccupiedCells();
if (showHorizontalGridLines && verticalSpacing > 0 && rowCount > 1) {
gridGraphics.setPaint(horizontalGridColor);
int rowY = padding.top;
int visibleRowCount = 0;
for (int i = 0; i < rowCount; i++) {
boolean rowVisible = false;
for (int j = 0; j < columnCount; j++) {
if (occupiedCells[i][j]) {
rowVisible = true;
break;
}
}
if (rowVisible) {
if (visibleRowCount++ > 0) {
int gridY = Math.max(rowY - (int) Math.ceil(verticalSpacing * 0.5f), 0);
GraphicsUtilities.drawLine(gridGraphics, 0, gridY, width, Orientation.HORIZONTAL);
}
rowY += (rowHeights[i] + verticalSpacing);
}
}
}
if (showVerticalGridLines && horizontalSpacing > 0 && columnCount > 1) {
gridGraphics.setPaint(verticalGridColor);
int columnX = padding.left;
int visibleColumnCount = 0;
for (int j = 0; j < columnCount; j++) {
boolean columnVisible = false;
for (int i = 0; i < rowCount; i++) {
if (occupiedCells[i][j]) {
columnVisible = true;
break;
}
}
if (columnVisible) {
if (visibleColumnCount++ > 0) {
int gridX = Math.max(columnX - (int) Math.ceil(horizontalSpacing * 0.5), 0);
GraphicsUtilities.drawLine(gridGraphics, gridX, 0, height, Orientation.VERTICAL);
}
columnX += (columnWidths[j] + horizontalSpacing);
}
}
}
gridGraphics.dispose();
}
}
Aggregations