use of org.apache.pivot.wtk.ListButton in project pivot by apache.
the class TerraListButtonSkin method getPreferredWidth.
@Override
public int getPreferredWidth(int height) {
ListButton listButton = (ListButton) getComponent();
Button.DataRenderer dataRenderer = listButton.getDataRenderer();
// Determine the preferred width of the current button data
dataRenderer.render(listButton.getButtonData(), listButton, false);
int preferredWidth = dataRenderer.getPreferredWidth(-1);
// The preferred width of the button is the max. width of the rendered
// content plus padding and the trigger width
List<?> listData = listButton.getListData();
for (Object item : listData) {
dataRenderer.render(item, listButton, false);
preferredWidth = Math.max(preferredWidth, dataRenderer.getPreferredWidth(-1));
}
preferredWidth += TRIGGER_WIDTH + padding.getWidth() + 2;
return preferredWidth;
}
use of org.apache.pivot.wtk.ListButton in project pivot by apache.
the class ComponentInspectorSkin method addEnumControl.
private Component addEnumControl(final Dictionary<String, Object> dictionary, final String key, Class<? extends Enum<?>> type, Form.Section section) {
Enum<?> value = (Enum<?>) dictionary.get(key);
ArrayList<Object> listData = new ArrayList<>();
listData.add(null);
Enum<?>[] enumConstants = type.getEnumConstants();
for (int i = 0; i < enumConstants.length; i++) {
listData.add(enumConstants[i]);
}
ListButton listButton = new ListButton();
listButton.setListData(listData);
listButton.setSelectedItem(value);
section.add(listButton);
Form.setLabel(listButton, key);
listButton.getListButtonSelectionListeners().add(new ListButtonSelectionListener() {
private boolean updating = false;
@Override
public void selectedIndexChanged(ListButton listButtonArgument, int previousSelectedIndex) {
if (!updating) {
updating = true;
try {
dictionary.put(key, listButtonArgument.getSelectedItem());
} catch (Exception exception) {
displayErrorMessage(exception, listButtonArgument.getWindow());
listButtonArgument.setSelectedIndex(previousSelectedIndex);
} finally {
updating = false;
}
}
}
});
return listButton;
}
use of org.apache.pivot.wtk.ListButton in project pivot by apache.
the class ExpenseSheet method initialize.
@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resource) {
this.resources = resource;
dateSpinner = (Spinner) namespace.get("dateSpinner");
typeListButton = (ListButton) namespace.get("typeListButton");
amountTextInput = (TextInput) namespace.get("amountTextInput");
cancelButton = (PushButton) namespace.get("cancelButton");
okButton = (PushButton) namespace.get("okButton");
cancelButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
close(false);
}
});
okButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
close(true);
}
});
}
use of org.apache.pivot.wtk.ListButton in project pivot by apache.
the class ListButtons method initialize.
@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
listButton = (ListButton) namespace.get("listButton");
imageView = (ImageView) namespace.get("imageView");
listButton.getListButtonSelectionListeners().add(new ListButtonSelectionListener() {
@Override
public void selectedItemChanged(ListButton listButtonArgument, Object previousSelectedItem) {
Object selectedItem = listButtonArgument.getSelectedItem();
if (selectedItem != null) {
// Get the image URL for the selected item
Image image = Image.loadFromCache(ImageUtils.findByName("/org/apache/pivot/tutorials/" + selectedItem, "image"));
// Update the image
imageView.setImage(image);
}
}
});
listButton.setSelectedIndex(0);
}
use of org.apache.pivot.wtk.ListButton in project pivot by apache.
the class RepeatableListButtons method initialize.
@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
colorListButton = (ListButton) namespace.get("colorListButton");
checkboxBoxPane = (BoxPane) namespace.get("checkboxBoxPane");
ButtonStateListener buttonStateListener = new ButtonStateListener() {
@Override
public void stateChanged(Button button, State previousState) {
if (button.isSelected()) {
selectedCount++;
} else {
selectedCount--;
}
applyColorAction.setEnabled(selectedCount > 0);
}
};
ArrayList<String> numbers = new ArrayList<>("One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten");
for (String number : numbers) {
Checkbox checkbox = new Checkbox(number);
checkbox.getButtonStateListeners().add(buttonStateListener);
checkboxBoxPane.add(checkbox);
}
}
Aggregations