use of org.apache.pivot.wtk.CardPane in project pivot by apache.
the class CardPaneSkin method install.
@Override
public void install(Component component) {
super.install(component);
CardPane cardPane = (CardPane) component;
cardPane.getCardPaneListeners().add(this);
}
use of org.apache.pivot.wtk.CardPane 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.CardPane 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);
}
use of org.apache.pivot.wtk.CardPane in project pivot by apache.
the class CardPaneSkin method getBaseline.
@Override
public int getBaseline(int width, int height) {
int baseline = -1;
if (sizeToSelection) {
CardPane cardPane = (CardPane) getComponent();
Component selectedCard = cardPane.getSelectedCard();
if (selectedCard != null) {
int cardWidth = Math.max(width - padding.getWidth(), 0);
int cardHeight = Math.max(height - padding.getHeight(), 0);
baseline = selectedCard.getBaseline(cardWidth, cardHeight);
if (baseline != -1) {
baseline += padding.top;
}
}
}
return baseline;
}
use of org.apache.pivot.wtk.CardPane in project pivot by apache.
the class CardPaneTest method startup.
@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
frame = new Frame(new BoxPane());
frame.getStyles().put(Style.padding, 0);
frame.setTitle("Component Pane Test");
frame.setPreferredSize(800, 600);
frame.setLocation(20, 20);
BXMLSerializer bxmlSerializer = new BXMLSerializer();
sheet = (Sheet) bxmlSerializer.readObject(CardPaneTest.class, "card_pane_test.bxml");
cardPane = (CardPane) bxmlSerializer.getNamespace().get("cardPane");
sizeGroup = (ButtonGroup) bxmlSerializer.getNamespace().get("sizeGroup");
sizeGroup.getButtonGroupListeners().add(new ButtonGroupListener() {
@Override
public void selectionChanged(ButtonGroup buttonGroup, Button previousSelection) {
final Button selection = buttonGroup.getSelection();
int selectedIndex = selection == null ? -1 : selection.getParent().indexOf(selection);
cardPane.getCardPaneListeners().add(new CardPaneListener() {
@Override
public Vote previewSelectedIndexChange(CardPane cardPaneArgument, int selectedIndexArgument) {
if (selection != null) {
selection.getParent().setEnabled(false);
}
return Vote.APPROVE;
}
@Override
public void selectedIndexChangeVetoed(CardPane cardPaneArgument, Vote reason) {
if (selection != null && reason == Vote.DENY) {
selection.getParent().setEnabled(true);
}
}
@Override
public void selectedIndexChanged(CardPane cardPaneArgument, int previousSelectedIndex) {
if (selection != null) {
selection.getParent().setEnabled(true);
}
}
});
cardPane.setSelectedIndex(selectedIndex);
}
});
frame.open(display);
ApplicationContext.queueCallback(() -> sheet.open(frame));
}
Aggregations