use of org.apache.pivot.wtk.Component in project pivot by apache.
the class BoxPaneSkin method getPreferredWidth.
@Override
public int getPreferredWidth(int height) {
BoxPane boxPane = (BoxPane) getComponent();
int preferredWidth = 0;
Orientation orientation = boxPane.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 = boxPane.getLength(); i < n; i++) {
Component component = boxPane.get(i);
if (component.isVisible()) {
preferredWidth += component.getPreferredWidth(fill ? heightUpdated : -1);
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 = boxPane.getLength(); i < n; i++) {
Component component = boxPane.get(i);
if (component.isVisible()) {
preferredWidth = Math.max(preferredWidth, component.getPreferredWidth());
}
}
}
// Include left and right padding values
preferredWidth += padding.getWidth();
return preferredWidth;
}
use of org.apache.pivot.wtk.Component in project pivot by apache.
the class BoxPaneSkin method getPreferredSize.
@Override
public Dimensions getPreferredSize() {
BoxPane boxPane = (BoxPane) getComponent();
int preferredWidth = 0;
int preferredHeight = 0;
switch(boxPane.getOrientation()) {
case HORIZONTAL:
{
// Preferred width is the sum of the preferred widths of all
// components
int j = 0;
for (int i = 0, n = boxPane.getLength(); i < n; i++) {
Component component = boxPane.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 = boxPane.getLength(); i < n; i++) {
Component component = boxPane.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 BoxPaneSkin method getBaseline.
@Override
public int getBaseline(int width, int height) {
BoxPane boxPane = (BoxPane) getComponent();
int baseline = -1;
int contentHeight = 0;
switch(boxPane.getOrientation()) {
case HORIZONTAL:
{
if (fill) {
int clientHeight = Math.max(height - padding.getHeight(), 0);
for (Component component : boxPane) {
if (component.isVisible()) {
int componentWidth = component.getPreferredWidth(clientHeight);
baseline = Math.max(baseline, component.getBaseline(componentWidth, clientHeight));
}
}
} else {
contentHeight = 0;
for (Component component : boxPane) {
if (component.isVisible()) {
contentHeight = Math.max(contentHeight, component.getPreferredHeight());
}
}
for (Component component : boxPane) {
if (component.isVisible()) {
Dimensions size = component.getPreferredSize();
int componentBaseline = component.getBaseline(size.width, size.height);
if (componentBaseline != -1) {
switch(verticalAlignment) {
case CENTER:
{
componentBaseline += (contentHeight - size.height) / 2;
break;
}
case BOTTOM:
{
componentBaseline += contentHeight - size.height;
break;
}
case TOP:
{
break;
}
default:
{
break;
}
}
}
baseline = Math.max(baseline, componentBaseline);
}
}
}
break;
}
case VERTICAL:
{
int clientWidth = Math.max(width - padding.getWidth(), 0);
for (Component component : boxPane) {
if (component.isVisible()) {
Dimensions size;
if (fill) {
size = new Dimensions(clientWidth, component.getPreferredHeight(clientWidth));
} else {
size = component.getPreferredSize();
}
if (baseline == -1) {
baseline = component.getBaseline(size.width, size.height);
if (baseline != -1) {
baseline += contentHeight;
}
}
contentHeight += size.height + spacing;
}
}
contentHeight -= spacing;
break;
}
default:
{
break;
}
}
if (baseline != -1) {
if (fill) {
baseline += padding.top;
} else {
switch(verticalAlignment) {
case TOP:
{
baseline += padding.top;
break;
}
case CENTER:
{
baseline += (height - contentHeight) / 2;
break;
}
case BOTTOM:
{
baseline += height - (contentHeight + padding.bottom);
break;
}
default:
{
break;
}
}
}
}
return baseline;
}
use of org.apache.pivot.wtk.Component in project pivot by apache.
the class CardPaneSkin method getPreferredHeight.
@Override
public int getPreferredHeight(int width) {
int preferredHeight = 0;
CardPane cardPane = (CardPane) getComponent();
if (sizeToSelection) {
if (selectionChangeTransition == null) {
Component selectedCard = cardPane.getSelectedCard();
if (selectedCard != null) {
preferredHeight = selectedCard.getPreferredHeight(width);
}
} else {
float percentComplete = selectionChangeTransition.getPercentComplete();
int previousHeight;
if (selectionChangeTransition.fromCard == null) {
previousHeight = 0;
} else {
previousHeight = selectionChangeTransition.fromCard.getPreferredHeight(width);
}
int height;
if (selectionChangeTransition.toCard == null) {
height = 0;
} else {
height = selectionChangeTransition.toCard.getPreferredHeight(width);
}
preferredHeight = previousHeight + (int) ((height - previousHeight) * percentComplete);
}
} else {
for (Component card : cardPane) {
preferredHeight = Math.max(preferredHeight, card.getPreferredHeight(width));
}
preferredHeight += padding.getHeight();
}
return preferredHeight;
}
use of org.apache.pivot.wtk.Component in project pivot by apache.
the class CardPaneSkin method getPreferredSize.
@Override
public Dimensions getPreferredSize() {
int preferredWidth = 0;
int preferredHeight = 0;
CardPane cardPane = (CardPane) getComponent();
if (sizeToSelection) {
if (selectionChangeTransition == null) {
Component selectedCard = cardPane.getSelectedCard();
if (selectedCard != null) {
Dimensions cardSize = selectedCard.getPreferredSize();
preferredWidth = cardSize.width;
preferredHeight = cardSize.height;
}
} else {
float percentComplete = selectionChangeTransition.getPercentComplete();
int previousWidth;
int previousHeight;
if (selectionChangeTransition.fromCard == null) {
previousWidth = 0;
previousHeight = 0;
} else {
Dimensions fromSize = selectionChangeTransition.fromCard.getPreferredSize();
previousWidth = fromSize.width;
previousHeight = fromSize.height;
}
int width;
int height;
if (selectionChangeTransition.toCard == null) {
width = 0;
height = 0;
} else {
Dimensions toSize = selectionChangeTransition.toCard.getPreferredSize();
width = toSize.width;
height = toSize.height;
}
preferredWidth = previousWidth + (int) ((width - previousWidth) * percentComplete);
preferredHeight = previousHeight + (int) ((height - previousHeight) * percentComplete);
}
} else {
for (Component card : cardPane) {
Dimensions cardSize = card.getPreferredSize();
preferredWidth = Math.max(cardSize.width, preferredWidth);
preferredHeight = Math.max(cardSize.height, preferredHeight);
}
}
preferredWidth += padding.getWidth();
preferredHeight += padding.getHeight();
return new Dimensions(preferredWidth, preferredHeight);
}
Aggregations