use of org.apache.pivot.wtk.GridPane in project pivot by apache.
the class GridPaneSkin method install.
@Override
public void install(Component component) {
super.install(component);
GridPane gridPane = (GridPane) component;
gridPane.getGridPaneListeners().add(this);
}
use of org.apache.pivot.wtk.GridPane in project pivot by apache.
the class GridPaneSkin method paint.
@Override
public void paint(Graphics2D graphics) {
super.paint(graphics);
GridPane gridPane = (GridPane) getComponent();
GridPane.RowSequence rows = gridPane.getRows();
int columnCount = gridPane.getColumnCount();
int rowCount = rows.getLength();
int width = getWidth();
int height = getHeight();
Metadata metadata = new Metadata();
if (showHorizontalGridLines && verticalSpacing > 0 && rowCount > 1) {
graphics.setPaint(horizontalGridColor);
int rowY = padding.top + (cellHeight + verticalSpacing);
for (int i = 1; i < rowCount; i++) {
if (metadata.isRowVisible(i - 1)) {
int gridY = Math.max(rowY - (int) Math.ceil(verticalSpacing * 0.5f), 0);
GraphicsUtilities.drawLine(graphics, 0, gridY, width, Orientation.HORIZONTAL);
rowY += (cellHeight + verticalSpacing);
}
}
}
if (showVerticalGridLines && horizontalSpacing > 0 && columnCount > 1) {
graphics.setPaint(verticalGridColor);
int columnX = padding.left + (cellWidth + horizontalSpacing);
for (int j = 1; j < columnCount; j++) {
if (metadata.isColumnVisible(j - 1)) {
int gridX = Math.max(columnX - (int) Math.ceil(horizontalSpacing * 0.5f), 0);
GraphicsUtilities.drawLine(graphics, gridX, 0, height, Orientation.VERTICAL);
columnX += (cellWidth + horizontalSpacing);
}
}
}
}
use of org.apache.pivot.wtk.GridPane in project pivot by apache.
the class GridPaneSkin method getPreferredHeight.
@Override
public int getPreferredHeight(int width) {
GridPane gridPane = (GridPane) getComponent();
GridPane.RowSequence rows = gridPane.getRows();
int columnCount = gridPane.getColumnCount();
int rowCount = rows.getLength();
Metadata metadata = new Metadata();
int cellWidthLocal = getCellWidth(width, metadata);
int preferredCellHeight = 0;
for (int i = 0; i < rowCount; i++) {
GridPane.Row row = rows.get(i);
for (int j = 0, n = row.getLength(); j < n && j < columnCount; j++) {
Component component = row.get(j);
if (component != null && component.isVisible()) {
preferredCellHeight = Math.max(preferredCellHeight, component.getPreferredHeight(cellWidthLocal));
}
}
}
// The preferred height of the grid pane is the sum of the row
// heights, plus padding and spacing
int preferredHeight = (metadata.visibleRowCount * preferredCellHeight) + padding.getHeight();
if (metadata.visibleRowCount > 1) {
preferredHeight += (metadata.visibleRowCount - 1) * verticalSpacing;
}
return preferredHeight;
}
use of org.apache.pivot.wtk.GridPane in project pivot by apache.
the class GridPaneSkin method getBaseline.
@Override
public int getBaseline(int width, int height) {
GridPane gridPane = (GridPane) getComponent();
GridPane.RowSequence rows = gridPane.getRows();
int columnCount = gridPane.getColumnCount();
int rowCount = rows.getLength();
Metadata metadata = new Metadata();
int cellWidthLocal = getCellWidth(width, metadata);
int cellHeightLocal = getCellHeight(height, metadata);
// Return the first available baseline by traversing cells top left to
// bottom right
int baseline = -1;
int rowY = padding.top;
for (int i = 0; i < rowCount && baseline == -1; i++) {
if (metadata.isRowVisible(i)) {
GridPane.Row row = rows.get(i);
for (int j = 0, n = row.getLength(); j < n && j < columnCount && baseline == -1; j++) {
Component component = row.get(j);
if (component != null && component.isVisible()) {
baseline = component.getBaseline(cellWidthLocal, cellHeightLocal);
if (baseline != -1) {
baseline += rowY;
}
}
}
rowY += (cellHeightLocal + verticalSpacing);
}
}
return baseline;
}
use of org.apache.pivot.wtk.GridPane in project pivot by apache.
the class GridPaneSkin method getRowAt.
// GridPane.Skin methods
@Override
public int getRowAt(int y) {
GridPane gridPane = (GridPane) getComponent();
GridPane.RowSequence rows = gridPane.getRows();
int rowCount = rows.getLength();
int rowIndex = -1;
int rowY = padding.top;
for (int i = 0; rowY <= y && i < rowCount; i++) {
if (y < rowY + cellHeight) {
rowIndex = i;
break;
}
rowY += cellHeight + verticalSpacing;
}
return rowIndex;
}
Aggregations