use of org.apache.pivot.collections.ArrayList in project pivot by apache.
the class TerraListViewSkin method mouseDown.
@Override
public boolean mouseDown(Component component, Mouse.Button button, int x, int y) {
boolean consumed = super.mouseDown(component, button, x, y);
ListView listView = (ListView) getComponent();
int itemIndex = getItemAt(y);
if (itemIndex != -1 && !listView.isItemDisabled(itemIndex)) {
if (!listView.getCheckmarksEnabled() || listView.isCheckmarkDisabled(itemIndex) || !getCheckboxBounds(itemIndex).contains(x, y)) {
ListView.SelectMode selectMode = listView.getSelectMode();
if (button == Mouse.Button.LEFT) {
Keyboard.Modifier commandModifier = Platform.getCommandModifier();
if (Keyboard.isPressed(Keyboard.Modifier.SHIFT) && selectMode == ListView.SelectMode.MULTI) {
Filter<?> disabledItemFilter = listView.getDisabledItemFilter();
if (disabledItemFilter == null) {
// Select the range
ArrayList<Span> selectedRanges = new ArrayList<>();
int startIndex = listView.getFirstSelectedIndex();
int endIndex = listView.getLastSelectedIndex();
Span selectedRange = (itemIndex > startIndex) ? new Span(startIndex, itemIndex) : new Span(itemIndex, endIndex);
selectedRanges.add(selectedRange);
listView.setSelectedRanges(selectedRanges);
}
} else if (Keyboard.isPressed(commandModifier) && selectMode == ListView.SelectMode.MULTI) {
// Toggle the item's selection state
if (listView.isItemSelected(itemIndex)) {
listView.removeSelectedIndex(itemIndex);
} else {
listView.addSelectedIndex(itemIndex);
}
} else if (Keyboard.isPressed(commandModifier) && selectMode == ListView.SelectMode.SINGLE) {
// Toggle the item's selection state
if (listView.isItemSelected(itemIndex)) {
listView.setSelectedIndex(-1);
} else {
listView.setSelectedIndex(itemIndex);
}
} else {
if (selectMode != ListView.SelectMode.NONE) {
if (listView.isItemSelected(itemIndex)) {
selectIndex = itemIndex;
} else {
listView.setSelectedIndex(itemIndex);
}
}
}
}
}
}
listView.requestFocus();
return consumed;
}
use of org.apache.pivot.collections.ArrayList in project pivot by apache.
the class TerraListViewSkin method layout.
@Override
public void layout() {
ListView listView = (ListView) getComponent();
@SuppressWarnings("unchecked") List<Object> listData = (List<Object>) listView.getListData();
ListView.ItemRenderer itemRenderer = listView.getItemRenderer();
if (variableItemHeight) {
int width = getWidth();
int checkboxHeight = 0;
if (listView.getCheckmarksEnabled()) {
checkboxHeight = CHECKBOX.getHeight() + checkboxPadding.getHeight();
}
int n = listData.getLength();
itemBoundaries = new ArrayList<>(n);
int itemY = 0;
for (int i = 0; i < n; i++) {
Object item = listData.get(i);
int itemWidth = width;
int itemX = 0;
Button.State state = Button.State.UNSELECTED;
if (listView.getCheckmarksEnabled()) {
if (listView.getAllowTriStateCheckmarks()) {
state = listView.getItemCheckmarkState(i);
} else {
state = listView.isItemChecked(i) ? Button.State.SELECTED : Button.State.UNSELECTED;
}
itemX = CHECKBOX.getWidth() + checkboxPadding.getWidth();
itemWidth -= itemX;
}
itemRenderer.render(item, i, listView, false, state, false, false);
int itemHeight = itemRenderer.getPreferredHeight(itemWidth);
if (listView.getCheckmarksEnabled()) {
itemHeight = Math.max(itemHeight, checkboxHeight);
}
itemY += itemHeight;
itemBoundaries.add(itemY);
}
} else {
itemRenderer.render(null, -1, listView, false, Button.State.UNSELECTED, false, false);
fixedItemHeight = itemRenderer.getPreferredHeight(-1);
if (listView.getCheckmarksEnabled()) {
fixedItemHeight = Math.max(CHECKBOX.getHeight() + checkboxPadding.getHeight(), fixedItemHeight);
}
}
if (validateSelection) {
// Ensure that the selection is visible
Sequence<Span> selectedRanges = listView.getSelectedRanges();
if (selectedRanges.getLength() > 0) {
int rangeStart = selectedRanges.get(0).start;
int rangeEnd = selectedRanges.get(selectedRanges.getLength() - 1).end;
Bounds selectionBounds = getItemBounds(rangeStart);
selectionBounds = selectionBounds.union(getItemBounds(rangeEnd));
Bounds visibleSelectionBounds = listView.getVisibleArea(selectionBounds);
if (visibleSelectionBounds != null && visibleSelectionBounds.height < selectionBounds.height) {
listView.scrollAreaToVisible(selectionBounds);
}
}
}
validateSelection = false;
}
use of org.apache.pivot.collections.ArrayList 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.collections.ArrayList in project pivot by apache.
the class ComponentPropertyInspectorSkin method sourceChanged.
@Override
public void sourceChanged(ComponentInspector componentInspector, Component previousSource) {
Component source = componentInspector.getSource();
clearControls();
Form.SectionSequence sections = form.getSections();
sections.remove(0, sections.getLength());
if (previousSource != null) {
beanMonitor.getPropertyChangeListeners().remove(propertyChangeListener);
}
if (source == null) {
beanMonitor = null;
} else {
beanMonitor = new BeanMonitor(source);
beanMonitor.getPropertyChangeListeners().add(propertyChangeListener);
Class<?> sourceType = source.getClass();
HashMap<Class<?>, List<String>> declaringClassPartitions = new HashMap<>(classComparator);
// Partition the properties by their declaring class
BeanAdapter beanAdapter = new BeanAdapter(source);
for (String propertyName : beanAdapter) {
if (beanMonitor.isNotifying(propertyName) && !beanAdapter.isReadOnly(propertyName)) {
Method method = BeanAdapter.getGetterMethod(sourceType, propertyName);
Class<?> declaringClass = method.getDeclaringClass();
List<String> propertyNames = declaringClassPartitions.get(declaringClass);
if (propertyNames == null) {
propertyNames = new ArrayList<>(nameComparator);
declaringClassPartitions.put(declaringClass, propertyNames);
}
propertyNames.add(propertyName);
}
}
// Add the controls
for (Class<?> declaringClass : declaringClassPartitions) {
Form.Section section = new Form.Section();
section.setHeading(declaringClass.getSimpleName());
sections.add(section);
List<String> propertyNames = declaringClassPartitions.get(declaringClass);
for (String propertyName : propertyNames) {
Class<?> type = beanAdapter.getType(propertyName);
addControl(beanAdapter, propertyName, type, section);
}
}
}
}
use of org.apache.pivot.collections.ArrayList in project pivot by apache.
the class EventLoggerSkin method sourceChanged.
// EventLoggerListener methods
@Override
public void sourceChanged(EventLogger eventLogger, Component previousSource) {
// Component source = eventLogger.getSource();
HashMap<Class<?>, ArrayList<Method>> buckets = new HashMap<>();
for (Method event : eventLogger.getDeclaredEvents()) {
Class<?> listenerInterface = event.getDeclaringClass();
ArrayList<Method> bucket = buckets.get(listenerInterface);
if (bucket == null) {
bucket = new ArrayList<>();
buckets.put(listenerInterface, bucket);
}
bucket.add(event);
}
ArrayList<TreeNode> treeData = new ArrayList<>(treeNodeComparator);
declaredEventsTreeView.setTreeData(treeData);
updating = true;
try {
for (Class<?> listenerInterface : buckets) {
TreeBranch treeBranch = new TreeBranch(listenerInterface.getSimpleName());
treeBranch.setComparator(treeNodeComparator);
treeData.add(treeBranch);
for (Method event : buckets.get(listenerInterface)) {
treeBranch.add(new EventNode(event));
eventLogger.getIncludeEvents().add(event);
}
}
Sequence.Tree.ItemIterator<TreeNode> iter = Sequence.Tree.depthFirstIterator(treeData);
while (iter.hasNext()) {
iter.next();
declaredEventsTreeView.setNodeChecked(iter.getPath(), true);
}
} finally {
updating = false;
}
}
Aggregations