use of org.apache.pivot.wtk.Component 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.Component in project pivot by apache.
the class GridPaneSkin method getPreferredSize.
@Override
public Dimensions getPreferredSize() {
GridPane gridPane = (GridPane) getComponent();
GridPane.RowSequence rows = gridPane.getRows();
int columnCount = gridPane.getColumnCount();
int rowCount = rows.getLength();
Metadata metadata = new Metadata();
// calculate the maximum preferred cellWidth and cellHeight
int preferredCellHeight = 0;
int preferredCellWidth = 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()) {
Dimensions d = component.getPreferredSize();
preferredCellHeight = Math.max(preferredCellHeight, d.height);
preferredCellWidth = Math.max(preferredCellWidth, d.width);
}
}
}
// The preferred width of the grid pane is the sum of the column
// widths, plus padding and spacing
int preferredWidth = (metadata.visibleColumnCount * preferredCellWidth) + padding.getWidth();
if (metadata.visibleColumnCount > 1) {
preferredWidth += (metadata.visibleColumnCount - 1) * horizontalSpacing;
}
// 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 new Dimensions(preferredWidth, preferredHeight);
}
use of org.apache.pivot.wtk.Component in project pivot by apache.
the class GridPaneSkin method layout.
@Override
public void layout() {
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();
cellWidth = getCellWidth(width, metadata);
cellHeight = getCellHeight(height, metadata);
int componentY = padding.top;
for (int i = 0; i < rowCount; i++) {
if (metadata.isRowVisible(i)) {
GridPane.Row row = rows.get(i);
int componentX = padding.left;
for (int j = 0, n = row.getLength(); j < n && j < columnCount; j++) {
Component component = row.get(j);
if (component != null && component.isVisible()) {
component.setLocation(componentX, componentY);
component.setSize(cellWidth, cellHeight);
}
if (metadata.isColumnVisible(j)) {
componentX += (cellWidth + horizontalSpacing);
}
}
componentY += (cellHeight + verticalSpacing);
}
}
}
use of org.apache.pivot.wtk.Component in project pivot by apache.
the class FillPaneSkin method getPreferredSize.
@Override
public Dimensions getPreferredSize() {
FillPane fillPane = (FillPane) getComponent();
int preferredWidth = 0;
int preferredHeight = 0;
switch(fillPane.getOrientation()) {
case HORIZONTAL:
{
// Preferred width is the sum of the preferred widths of all
// components
int j = 0;
for (int i = 0, n = fillPane.getLength(); i < n; i++) {
Component component = fillPane.get(i);
if (component.isVisible()) {
Dimensions preferredSize = component.getPreferredSize();
preferredWidth += preferredSize.width;
preferredHeight = Math.max(preferredSize.height, preferredHeight);
j++;
}
}
// Include spacing
if (j > 1) {
preferredWidth += spacing * (j - 1);
}
break;
}
case VERTICAL:
{
// Preferred height is the sum of the preferred heights of all
// components
int j = 0;
for (int i = 0, n = fillPane.getLength(); i < n; i++) {
Component component = fillPane.get(i);
if (component.isVisible()) {
Dimensions preferredSize = component.getPreferredSize();
preferredWidth = Math.max(preferredSize.width, preferredWidth);
preferredHeight += preferredSize.height;
j++;
}
}
// Include spacing
if (j > 1) {
preferredHeight += spacing * (j - 1);
}
break;
}
default:
{
break;
}
}
// Include padding
preferredWidth += padding.getWidth();
preferredHeight += padding.getHeight();
return new Dimensions(preferredWidth, preferredHeight);
}
use of org.apache.pivot.wtk.Component in project pivot by apache.
the class FillPaneSkin method getPreferredWidth.
@Override
public int getPreferredWidth(int height) {
FillPane fillPane = (FillPane) getComponent();
int preferredWidth = 0;
Orientation orientation = fillPane.getOrientation();
if (orientation == Orientation.HORIZONTAL) {
int heightUpdated = height;
// Include padding in constraint
if (heightUpdated != -1) {
heightUpdated = Math.max(heightUpdated - padding.getHeight(), 0);
}
// Preferred width is the sum of the preferred widths of all
// components
int j = 0;
for (int i = 0, n = fillPane.getLength(); i < n; i++) {
Component component = fillPane.get(i);
if (component.isVisible()) {
preferredWidth += component.getPreferredWidth(heightUpdated);
j++;
}
}
// Include spacing
if (j > 1) {
preferredWidth += spacing * (j - 1);
}
} else {
// Preferred width is the maximum preferred width of all components
for (int i = 0, n = fillPane.getLength(); i < n; i++) {
Component component = fillPane.get(i);
if (component.isVisible()) {
preferredWidth = Math.max(preferredWidth, component.getPreferredWidth());
}
}
}
// Include left and right padding values
preferredWidth += padding.getWidth();
return preferredWidth;
}
Aggregations