use of org.apache.pivot.wtk.CardPane in project pivot by apache.
the class Pivot894 method startup.
@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
System.out.println("public startup(...)");
System.out.println("\n" + "Attention: now the application will go in an infinite loop, to be able to see the memory leak.\n" + "Note that probably you'll have to kill the application from outside (kill the Java process).\n" + "\n");
// add some sleep to let users see the warning messages in console ...
Thread.sleep(2000);
final CardPane cardPane = new CardPane();
cardPane.getStyles().put(Style.selectionChangeEffect, CardPaneSkin.SelectionChangeEffect.HORIZONTAL_SLIDE);
final Window window = new Window(cardPane);
window.open(display);
ApplicationContext.scheduleRecurringCallback(new Runnable() {
@Override
public void run() {
Thread.currentThread().setName("switcher-thread");
// temp
System.out.println("Run num " + num++);
//
try {
// Before the fixes for PIVOT-861 (part two) it was causing
// out of memory ...
//
// Note that this has been moved to another issue, but the
// problem is due to the usage
// of dataRenderer tags (and then instancing
// ButtonDataRenderer) in the loaded bxml,
// so probably even this test will be updated ...
//
final GridPane grid = (GridPane) new BXMLSerializer().readObject(Pivot894.class, "btn_grid.bxml");
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
Iterator<Component> iterator = cardPane.iterator();
List<Component> componentList = new ArrayList<>();
while (iterator.hasNext()) {
Component card = iterator.next();
if (!card.isShowing()) {
componentList.add(card);
}
}
for (Component card : componentList) {
cardPane.remove(card);
}
cardPane.setSelectedIndex(cardPane.add(grid));
System.out.println(cardPane.getSelectedIndex());
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
@SuppressWarnings("unused")
private Row createGridRow() {
Row row = new Row();
try {
// note that this method doesn't use ApplicationContext
// cache for images ...
row.add(new PushButton(new ButtonData(Image.load(new File("clock_icon.png").toURI().toURL()), "Clock")));
row.add(new PushButton(new ButtonData(Image.load(new File("clock_icon.png").toURI().toURL()), "Clock")));
row.add(new PushButton(new ButtonData(Image.load(new File("clock_icon.png").toURI().toURL()), "Clock")));
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (TaskExecutionException e) {
e.printStackTrace();
}
return row;
}
}, 100);
}
use of org.apache.pivot.wtk.CardPane in project pivot by apache.
the class CardPaneSkin method componentInserted.
@Override
public void componentInserted(Container container, int index) {
if (selectionChangeTransition != null) {
selectionChangeTransition.end();
}
super.componentInserted(container, index);
CardPane cardPane = (CardPane) container;
Component card = cardPane.get(index);
card.setVisible(false);
if (cardPane.getLength() == 1) {
cardPane.setSelectedIndex(0);
}
invalidateComponent();
}
use of org.apache.pivot.wtk.CardPane in project pivot by apache.
the class CardPaneSkin method getPreferredWidth.
@Override
public int getPreferredWidth(int height) {
int preferredWidth = 0;
CardPane cardPane = (CardPane) getComponent();
if (sizeToSelection) {
if (selectionChangeTransition == null) {
Component selectedCard = cardPane.getSelectedCard();
if (selectedCard != null) {
preferredWidth = selectedCard.getPreferredWidth(height);
}
} else {
float percentComplete = selectionChangeTransition.getPercentComplete();
int previousWidth;
if (selectionChangeTransition.fromCard == null) {
previousWidth = 0;
} else {
previousWidth = selectionChangeTransition.fromCard.getPreferredWidth(height);
}
int width;
if (selectionChangeTransition.toCard == null) {
width = 0;
} else {
width = selectionChangeTransition.toCard.getPreferredWidth(height);
}
preferredWidth = previousWidth + (int) ((width - previousWidth) * percentComplete);
}
} else {
for (Component card : cardPane) {
preferredWidth = Math.max(preferredWidth, card.getPreferredWidth(height));
}
preferredWidth += padding.getWidth();
}
return preferredWidth;
}
use of org.apache.pivot.wtk.CardPane in project pivot by apache.
the class CardPaneSkin method layout.
@Override
public void layout() {
// Set the size of all components to match the size of the card pane,
// minus padding
CardPane cardPane = (CardPane) getComponent();
int width = Math.max(getWidth() - padding.getWidth(), 0);
int height = Math.max(getHeight() - padding.getHeight(), 0);
for (Component card : cardPane) {
card.setLocation(padding.left, padding.top);
card.setSize(width, height);
}
}
use of org.apache.pivot.wtk.CardPane in project pivot by apache.
the class CardPanes method initialize.
@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
cardPane = (CardPane) namespace.get("cardPane");
previousButton = (LinkButton) namespace.get("previousButton");
nextButton = (LinkButton) namespace.get("nextButton");
sizeToSelectionCheckbox = (Checkbox) namespace.get("sizeToSelectionCheckbox");
crossfadeRadioButton = (RadioButton) namespace.get("crossfadeRadioButton");
horizontalSlideRadioButton = (RadioButton) namespace.get("horizontalSlideRadioButton");
verticalSlideRadioButton = (RadioButton) namespace.get("verticalSlideRadioButton");
horizontalFlipRadioButton = (RadioButton) namespace.get("horizontalFlipRadioButton");
verticalFlipRadioButton = (RadioButton) namespace.get("verticalFlipRadioButton");
zoomRadioButton = (RadioButton) namespace.get("zoomRadioButton");
noneRadioButton = (RadioButton) namespace.get("noneRadioButton");
cardPane.getCardPaneListeners().add(new CardPaneListener() {
@Override
public void selectedIndexChanged(CardPane cardPaneArgument, int previousSelectedIndex) {
updateLinkButtonState();
}
});
previousButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
cardPane.setSelectedIndex(cardPane.getSelectedIndex() - 1);
}
});
nextButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
cardPane.setSelectedIndex(cardPane.getSelectedIndex() + 1);
}
});
ButtonStateListener checkboxStateListener = new ButtonStateListener() {
@Override
public void stateChanged(Button button, Button.State previousState) {
updateCardPane();
}
};
sizeToSelectionCheckbox.getButtonStateListeners().add(checkboxStateListener);
ButtonStateListener radioButtonStateListener = new ButtonStateListener() {
@Override
public void stateChanged(Button button, Button.State previousState) {
if (button.isSelected()) {
updateCardPane();
}
}
};
crossfadeRadioButton.getButtonStateListeners().add(radioButtonStateListener);
horizontalSlideRadioButton.getButtonStateListeners().add(radioButtonStateListener);
verticalSlideRadioButton.getButtonStateListeners().add(radioButtonStateListener);
horizontalFlipRadioButton.getButtonStateListeners().add(radioButtonStateListener);
verticalFlipRadioButton.getButtonStateListeners().add(radioButtonStateListener);
zoomRadioButton.getButtonStateListeners().add(radioButtonStateListener);
noneRadioButton.getButtonStateListeners().add(radioButtonStateListener);
updateCardPane();
updateLinkButtonState();
}
Aggregations