use of org.apache.pivot.wtk.BoxPane 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.BoxPane 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.BoxPane 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.BoxPane in project pivot by apache.
the class ColorSchemeBuilderWindow method createColorPaletteCell.
private static Component createColorPaletteCell(int index) {
Border border = new Border();
border.getStyles().put(Style.backgroundColor, index);
Theme theme = Theme.getTheme();
Label label = new Label();
label.setText(Integer.toString(index));
label.getStyles().put(Style.font, "{size:'80%'}");
label.getStyles().put(Style.backgroundColor, 4);
label.getStyles().put(Style.padding, 1);
BoxPane boxPane = new BoxPane();
boxPane.getStyles().put(Style.padding, 2);
boxPane.getStyles().put(Style.horizontalAlignment, HorizontalAlignment.CENTER);
boxPane.getStyles().put(Style.verticalAlignment, VerticalAlignment.CENTER);
boxPane.add(new Border(label));
border.setContent(boxPane);
return border;
}
use of org.apache.pivot.wtk.BoxPane in project pivot by apache.
the class ColorListButtonTest method startup.
@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
BXMLSerializer bxmlSerializer = new BXMLSerializer();
BoxPane boxPane = (BoxPane) bxmlSerializer.readObject(ColorListButtonTest.class, "color_list_button_test.bxml");
listButton = (ListButton) bxmlSerializer.getNamespace().get("listButton");
// test the getListPopup() method
listButton.getListPopup().getDecorators().add(new ReflectionDecorator());
frame = new Frame(boxPane);
frame.setTitle("Color List Button Test");
frame.setPreferredSize(480, 360);
frame.open(display);
}
Aggregations