Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.pivot.wtk;
import java.io.IOException;
import java.net.URL;
import java.util.Comparator;
import org.apache.pivot.beans.DefaultProperty;
import org.apache.pivot.collections.ArrayList;
import org.apache.pivot.collections.List;
import org.apache.pivot.collections.ListListener;
import org.apache.pivot.collections.Map;
import org.apache.pivot.collections.Sequence;
import org.apache.pivot.collections.immutable.ImmutableList;
import org.apache.pivot.json.JSON;
import org.apache.pivot.json.JSONSerializer;
import org.apache.pivot.serialization.SerializationException;
import org.apache.pivot.util.Filter;
import org.apache.pivot.util.ListenerList;
import org.apache.pivot.wtk.content.ListViewItemRenderer;
/**
* Component that displays a sequence of items, optionally allowing a user
* to select or check one or more items.
*/
@DefaultProperty("listData")
public class ListView extends Component {
/**
* Enumeration defining supported selection modes.
*/
public enum SelectMode {
/**
* Selection is disabled.
*/
NONE,
/**
* A single index may be selected at a time.
*/
SINGLE,
/**
* Multiple indexes may be concurrently selected.
*/
MULTI
}
/**
* {@link Renderer} interface to customize the appearance of items in a ListView.
*/
public interface ItemRenderer extends Renderer {
/**
* Prepares the renderer for layout or paint.
*
* @param item
* The item to render, or null if called to calculate preferred
* height for skins that assume a fixed renderer height.
*
* @param index
* The index of the item being rendered, or -1 if item
* is null.
*
* @param listView
* The host component.
*
* @param selected
* If true, the item is selected.
* the item.
*
* @param checked
* If true, the item is checked.
*
* @param highlighted
* If true, the item is highlighted.
*
* @param disabled
* If true, the item is disabled.
*/
public void render(Object item, int index, ListView listView, boolean selected,
boolean checked, boolean highlighted, boolean disabled);
/**
* Converts a list item to a string representation.
*
* @param item
*
* @return
* The item's string representation, or null if the item does not
* have a string representation.
*
* Note that this method may be called often during keyboard navigation, so
* implementations should avoid unnecessary string allocations.
*/
public String toString(Object item);
}
/**
* List view item editor interface.
*/
public interface ItemEditor {
/**
* Called to begin editing a list item.
*
* @param listView
* @param itemIndex
*/
public void beginEdit(ListView listView, int itemIndex);
/**
* Terminates an edit operation.
*
* @param result
* true to perform the edit; false to cancel it.
*/
public void endEdit(boolean result);
/**
* Tests whether an edit is currently in progress.
*/
public boolean isEditing();
}
/**
* List view skin interface. List view skins are required to implement
* this.
*/
public interface Skin {
public int getItemAt(int y);
public Bounds getItemBounds(int index);
public int getItemIndent();
}
/**
* Translates between list and bind context data during data binding.
*/
public interface ListDataBindMapping {
/**
* Converts a context value to list data during a
* {@link Component#load(Object)} operation.
*
* @param value
*/
public List> toListData(Object value);
/**
* Converts list data to a context value during a
* {@link Component#store(Object)} operation.
*
* @param listData
*/
public Object valueOf(List> listData);
}
/**
* Translates between item position and bind context data during data binding.
*/
public interface ItemBindMapping {
/**
* Returns the index of the item in the source list during a
* {@link Component#load(Object)} operation.
*
* @param listData
* The source list data.
*
* @param value
* The value to locate.
*
* @return
* The index of first occurrence of the value if it exists in the list;
* -1, otherwise.
*/
public int indexOf(List> listData, Object value);
/**
* Retrieves the value at the given index during a
* {@link Component#store(Object)} operation.
*
* @param listData
* The source list data.
*
* @param index
* The index of the value to retrieve.
*/
public Object get(List> listData, int index);
}
private static class ListViewListenerList extends WTKListenerList
implements ListViewListener {
@Override
public void listDataChanged(ListView listView, List> previousListData) {
for (ListViewListener listener : this) {
listener.listDataChanged(listView, previousListData);
}
}
@Override
public void itemRendererChanged(ListView listView,
ListView.ItemRenderer previousItemRenderer) {
for (ListViewListener listener : this) {
listener.itemRendererChanged(listView, previousItemRenderer);
}
}
@Override
public void itemEditorChanged(ListView listView,
ListView.ItemEditor previousItemEditor) {
for (ListViewListener listener : this) {
listener.itemEditorChanged(listView, previousItemEditor);
}
}
@Override
public void selectModeChanged(ListView listView,
ListView.SelectMode previousSelectMode) {
for (ListViewListener listener : this) {
listener.selectModeChanged(listView, previousSelectMode);
}
}
@Override
public void checkmarksEnabledChanged(ListView listView) {
for (ListViewListener listener : this) {
listener.checkmarksEnabledChanged(listView);
}
}
@Override
public void disabledItemFilterChanged(ListView listView,
Filter> previousDisabledItemFilter) {
for (ListViewListener listener : this) {
listener.disabledItemFilterChanged(listView, previousDisabledItemFilter);
}
}
@Override
public void disabledCheckmarkFilterChanged(ListView listView,
Filter> previousDisabledCheckmarkFilter) {
for (ListViewListener listener : this) {
listener.disabledCheckmarkFilterChanged(listView, previousDisabledCheckmarkFilter);
}
}
}
private static class ListViewItemListenerList extends WTKListenerList
implements ListViewItemListener {
@Override
public void itemInserted(ListView listView, int index) {
for (ListViewItemListener listener : this) {
listener.itemInserted(listView, index);
}
}
@Override
public void itemsRemoved(ListView listView, int index, int count) {
for (ListViewItemListener listener : this) {
listener.itemsRemoved(listView, index, count);
}
}
@Override
public void itemUpdated(ListView listView, int index) {
for (ListViewItemListener listener : this) {
listener.itemUpdated(listView, index);
}
}
@Override
public void itemsCleared(ListView listView) {
for (ListViewItemListener listener : this) {
listener.itemsCleared(listView);
}
}
@Override
public void itemsSorted(ListView listView) {
for (ListViewItemListener listener : this) {
listener.itemsSorted(listView);
}
}
}
private static class ListViewItemStateListenerList extends WTKListenerList
implements ListViewItemStateListener {
@Override
public void itemCheckedChanged(ListView listView, int index) {
for (ListViewItemStateListener listener : this) {
listener.itemCheckedChanged(listView, index);
}
}
}
private static class ListViewSelectionListenerList extends WTKListenerList
implements ListViewSelectionListener {
@Override
public void selectedRangeAdded(ListView listView, int rangeStart, int rangeEnd) {
for (ListViewSelectionListener listener : this) {
listener.selectedRangeAdded(listView, rangeStart, rangeEnd);
}
}
@Override
public void selectedRangeRemoved(ListView listView, int rangeStart, int rangeEnd) {
for (ListViewSelectionListener listener : this) {
listener.selectedRangeRemoved(listView, rangeStart, rangeEnd);
}
}
@Override
public void selectedRangesChanged(ListView listView, Sequence previousSelection) {
for (ListViewSelectionListener listener : this) {
listener.selectedRangesChanged(listView, previousSelection);
}
}
@Override
public void selectedItemChanged(ListView listView, Object previousSelectedItem) {
for (ListViewSelectionListener listener : this) {
listener.selectedItemChanged(listView, previousSelectedItem);
}
}
}
private static class ListViewBindingListenerList extends WTKListenerList
implements ListViewBindingListener {
@Override
public void listDataKeyChanged(ListView listView, String previousListDataKey) {
for (ListViewBindingListener listener : this) {
listener.listDataKeyChanged(listView, previousListDataKey);
}
}
@Override
public void listDataBindTypeChanged(ListView listView, BindType previousListDataBindType) {
for (ListViewBindingListener listener : this) {
listener.listDataBindTypeChanged(listView, previousListDataBindType);
}
}
@Override
public void listDataBindMappingChanged(ListView listView,
ListView.ListDataBindMapping previousListDataBindMapping) {
for (ListViewBindingListener listener : this) {
listener.listDataBindMappingChanged(listView, previousListDataBindMapping);
}
}
@Override
public void selectedItemKeyChanged(ListView listView, String previousSelectedItemKey) {
for (ListViewBindingListener listener : this) {
listener.selectedItemKeyChanged(listView, previousSelectedItemKey);
}
}
@Override
public void selectedItemBindTypeChanged(ListView listView, BindType previousSelectedItemBindType) {
for (ListViewBindingListener listener : this) {
listener.selectedItemBindTypeChanged(listView, previousSelectedItemBindType);
}
}
@Override
public void selectedItemBindMappingChanged(ListView listView,
ItemBindMapping previousSelectedItemBindMapping) {
for (ListViewBindingListener listener : this) {
listener.selectedItemBindMappingChanged(listView, previousSelectedItemBindMapping);
}
}
@Override
public void selectedItemsKeyChanged(ListView listView, String previousSelectedItemsKey) {
for (ListViewBindingListener listener : this) {
listener.selectedItemsKeyChanged(listView, previousSelectedItemsKey);
}
}
@Override
public void selectedItemsBindTypeChanged(ListView listView, BindType previousSelectedItemsBindType) {
for (ListViewBindingListener listener : this) {
listener.selectedItemsBindTypeChanged(listView, previousSelectedItemsBindType);
}
}
@Override
public void selectedItemsBindMappingChanged(ListView listView,
ItemBindMapping previousSelectedItemsBindMapping) {
for (ListViewBindingListener listener : this) {
listener.selectedItemsBindMappingChanged(listView, previousSelectedItemsBindMapping);
}
}
@Override
public void checkedItemsKeyChanged(ListView listView, String previousCheckedItemsKey) {
for (ListViewBindingListener listener : this) {
listener.checkedItemsKeyChanged(listView, previousCheckedItemsKey);
}
}
@Override
public void checkedItemsBindTypeChanged(ListView listView, BindType previousCheckedItemsBindType) {
for (ListViewBindingListener listener : this) {
listener.checkedItemsBindTypeChanged(listView, previousCheckedItemsBindType);
}
}
@Override
public void checkedItemsBindMappingChanged(ListView listView,
ListView.ItemBindMapping previousCheckedItemsBindMapping) {
for (ListViewBindingListener listener : this) {
listener.checkedItemsBindMappingChanged(listView, previousCheckedItemsBindMapping);
}
}
}
private List> listData = null;
private ItemRenderer itemRenderer = null;
private ItemEditor itemEditor = null;
private RangeSelection rangeSelection = new RangeSelection();
private SelectMode selectMode = SelectMode.SINGLE;
private boolean checkmarksEnabled = false;
private ArrayList checkedIndexes = new ArrayList();
private Filter> disabledItemFilter = null;
private Filter> disabledCheckmarkFilter = null;
private String listDataKey = null;
private BindType listDataBindType = BindType.BOTH;
private ListDataBindMapping listDataBindMapping = null;
private String selectedItemKey = null;
private BindType selectedItemBindType = BindType.BOTH;
private ItemBindMapping selectedItemBindMapping = null;
private String selectedItemsKey = null;
private BindType selectedItemsBindType = BindType.BOTH;
private ItemBindMapping selectedItemsBindMapping = null;
private String checkedItemsKey = null;
private BindType checkedItemsBindType = BindType.BOTH;
private ItemBindMapping checkedItemsBindMapping = null;
private ListListener