use of org.apache.pivot.wtk.Dimensions in project pivot by apache.
the class FillPaneSkin method getBaseline.
@Override
public int getBaseline(int width, int height) {
FillPane fillPane = (FillPane) getComponent();
int baseline = -1;
int contentHeight = 0;
switch(fillPane.getOrientation()) {
case HORIZONTAL:
{
int clientHeight = Math.max(height - padding.getHeight(), 0);
for (Component component : fillPane) {
if (component.isVisible()) {
int componentWidth = component.getPreferredWidth(clientHeight);
baseline = Math.max(baseline, component.getBaseline(componentWidth, clientHeight));
}
}
break;
}
case VERTICAL:
{
int clientWidth = Math.max(width - padding.getWidth(), 0);
for (Component component : fillPane) {
if (component.isVisible()) {
Dimensions size;
size = new Dimensions(clientWidth, component.getPreferredHeight(clientWidth));
if (baseline == -1) {
baseline = component.getBaseline(size.width, size.height);
if (baseline != -1) {
baseline += contentHeight;
}
}
contentHeight += size.height + spacing;
}
}
break;
}
default:
{
break;
}
}
if (baseline != -1) {
baseline += padding.top;
}
return baseline;
}
use of org.apache.pivot.wtk.Dimensions in project pivot by apache.
the class ImageViewSkin method getBaseline.
@Override
public int getBaseline(int width, int height) {
ImageView imageView = (ImageView) getComponent();
Image image = imageView.getImage();
int baseline = -1;
if (image != null) {
baseline = image.getBaseline();
if (baseline != -1) {
Dimensions imageSize = image.getSize();
if (fill) {
// Scale to fit
if (preserveAspectRatio) {
float aspectRatio = (float) width / (float) height;
float imageAspectRatio = (float) imageSize.width / (float) imageSize.height;
if (aspectRatio > imageAspectRatio) {
baseline *= (float) height / (float) imageSize.height;
} else {
float scaleYLocal = (float) width / (float) imageSize.width;
baseline *= scaleYLocal;
baseline += (int) (height - imageSize.height * scaleYLocal) / 2;
}
} else {
baseline *= (float) height / (float) imageSize.height;
}
} else {
if (verticalAlignment == VerticalAlignment.CENTER) {
baseline += (height - imageSize.height) / 2;
} else if (verticalAlignment == VerticalAlignment.BOTTOM) {
baseline += height - imageSize.height;
}
}
}
}
return baseline;
}
use of org.apache.pivot.wtk.Dimensions in project pivot by apache.
the class ImageViewSkin method getPreferredSize.
@Override
public Dimensions getPreferredSize() {
ImageView imageView = (ImageView) getComponent();
Image image = imageView.getImage();
return (image == null) ? Dimensions.ZERO : new Dimensions(image.getWidth(), image.getHeight());
}
use of org.apache.pivot.wtk.Dimensions in project pivot by apache.
the class ImageViewSkin method layout.
@Override
public void layout() {
ImageView imageView = (ImageView) getComponent();
Image image = imageView.getImage();
if (image != null) {
int width = getWidth();
int height = getHeight();
Dimensions imageSize = image.getSize();
if (fill) {
// Scale to fit
if (preserveAspectRatio) {
float aspectRatio = (float) width / (float) height;
float imageAspectRatio = (float) imageSize.width / (float) imageSize.height;
if (aspectRatio > imageAspectRatio) {
imageY = 0;
scaleY = (float) height / (float) imageSize.height;
imageX = (int) (width - imageSize.width * scaleY) / 2;
scaleX = scaleY;
} else {
imageX = 0;
scaleX = (float) width / (float) imageSize.width;
imageY = (int) (height - imageSize.height * scaleX) / 2;
scaleY = scaleX;
}
} else {
imageX = 0;
scaleX = (float) width / (float) imageSize.width;
imageY = 0;
scaleY = (float) height / (float) imageSize.height;
}
} else {
if (horizontalAlignment == HorizontalAlignment.CENTER) {
imageX = (width - imageSize.width) / 2;
} else if (horizontalAlignment == HorizontalAlignment.RIGHT) {
imageX = width - imageSize.width;
} else {
imageX = 0;
}
scaleX = 1.0f;
if (verticalAlignment == VerticalAlignment.CENTER) {
imageY = (height - imageSize.height) / 2;
} else if (verticalAlignment == VerticalAlignment.BOTTOM) {
imageY = height - imageSize.height;
} else {
imageY = 0;
}
scaleY = 1.0f;
}
}
}
use of org.apache.pivot.wtk.Dimensions in project pivot by apache.
the class LabelSkin method getPreferredSize.
@Override
public Dimensions getPreferredSize() {
Label label = (Label) getComponent();
String text = label.getText();
FontRenderContext fontRenderContext = Platform.getFontRenderContext();
LineMetrics lm = font.getLineMetrics("", fontRenderContext);
int lineHeight = (int) Math.ceil(lm.getHeight());
int preferredHeight = 0;
int preferredWidth = 0;
if (text != null && text.length() > 0) {
String[] str;
if (wrapText) {
str = text.split("\n");
} else {
str = new String[] { text };
}
for (String line : str) {
Rectangle2D stringBounds = font.getStringBounds(line, fontRenderContext);
int w = (int) Math.ceil(stringBounds.getWidth());
if (w > preferredWidth) {
preferredWidth = w;
}
preferredHeight += lineHeight;
}
} else {
preferredHeight += lineHeight;
}
preferredHeight += (padding.top + padding.bottom);
preferredWidth += (padding.left + padding.right);
return new Dimensions(preferredWidth, preferredHeight);
}
Aggregations