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.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.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.ListenerList;
import org.apache.pivot.wtk.content.SpinnerItemRenderer;
/**
* Component that presents a means of cycling through a list of items.
*/
@DefaultProperty("spinnerData")
public class Spinner extends Container {
/**
* {@link Renderer} interface to customize the appearance of the data in a Spinner.
*/
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 spinner
* The host component.
*/
public void render(Object item, Spinner spinner);
/**
* Converts a spinner 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);
}
/**
* Translates between spinner and bind context data during data binding.
*/
public interface SpinnerDataBindMapping {
/**
* Converts a context value to spinner data during a
* {@link Component#load(Object)} operation.
*
* @param value
*/
public List> toSpinnerData(Object value);
/**
* Converts spinner data to a context value during a
* {@link Component#store(Object)} operation.
*
* @param spinnerData
*/
public Object valueOf(List> spinnerData);
}
/**
* Spinner skin interface. Spinner skins must implement this interface to
* facilitate additional communication between the component and the skin.
*/
public interface Skin {
public Bounds getContentBounds();
}
/**
* Translates between spinner 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 spinnerData
* The source spinner 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> spinnerData, Object value);
/**
* Retrieves the item at the given index during a
* {@link Component#store(Object)} operation.
*
* @param spinnerData
* The source spinner data.
*
* @param index
* The index of the value to retrieve.
*/
public Object get(List> spinnerData, int index);
}
private static class SpinnerListenerList extends WTKListenerList
implements SpinnerListener {
@Override
public void spinnerDataChanged(Spinner spinner, List> previousSpinnerData) {
for (SpinnerListener listener : this) {
listener.spinnerDataChanged(spinner, previousSpinnerData);
}
}
@Override
public void itemRendererChanged(Spinner spinner,
Spinner.ItemRenderer previousItemRenderer) {
for (SpinnerListener listener : this) {
listener.itemRendererChanged(spinner, previousItemRenderer);
}
}
@Override
public void circularChanged(Spinner spinner) {
for (SpinnerListener listener : this) {
listener.circularChanged(spinner);
}
}
}
private static class SpinnerItemListenerList extends WTKListenerList
implements SpinnerItemListener {
@Override
public void itemInserted(Spinner spinner, int index) {
for (SpinnerItemListener listener : this) {
listener.itemInserted(spinner, index);
}
}
@Override
public void itemsRemoved(Spinner spinner, int index, int count) {
for (SpinnerItemListener listener : this) {
listener.itemsRemoved(spinner, index, count);
}
}
@Override
public void itemUpdated(Spinner spinner, int index) {
for (SpinnerItemListener listener : this) {
listener.itemUpdated(spinner, index);
}
}
@Override
public void itemsCleared(Spinner spinner) {
for (SpinnerItemListener listener : this) {
listener.itemsCleared(spinner);
}
}
@Override
public void itemsSorted(Spinner spinner) {
for (SpinnerItemListener listener : this) {
listener.itemsSorted(spinner);
}
}
}
private static class SpinnerSelectionListenerList
extends WTKListenerList
implements SpinnerSelectionListener {
@Override
public void selectedIndexChanged(Spinner spinner, int previousSelectedIndex) {
for (SpinnerSelectionListener listener : this) {
listener.selectedIndexChanged(spinner, previousSelectedIndex);
}
}
@Override
public void selectedItemChanged(Spinner spinner, Object previousSelectedItem) {
for (SpinnerSelectionListener listener : this) {
listener.selectedItemChanged(spinner, previousSelectedItem);
}
}
}
private static class SpinnerBindingListenerList extends WTKListenerList
implements SpinnerBindingListener {
@Override
public void spinnerDataKeyChanged(Spinner spinner, String previousSpinnerDataKey) {
for (SpinnerBindingListener listener : this) {
listener.spinnerDataKeyChanged(spinner, previousSpinnerDataKey);
}
}
@Override
public void spinnerDataBindTypeChanged(Spinner spinner, BindType previousSpinnerDataBindType) {
for (SpinnerBindingListener listener : this) {
listener.spinnerDataBindTypeChanged(spinner, previousSpinnerDataBindType);
}
}
@Override
public void spinnerDataBindMappingChanged(Spinner spinner,
Spinner.SpinnerDataBindMapping previousSpinnerDataBindMapping) {
for (SpinnerBindingListener listener : this) {
listener.spinnerDataBindMappingChanged(spinner, previousSpinnerDataBindMapping);
}
}
@Override
public void selectedItemKeyChanged(Spinner spinner, String previousSelectedItemKey) {
for (SpinnerBindingListener listener : this) {
listener.selectedItemKeyChanged(spinner, previousSelectedItemKey);
}
}
@Override
public void selectedItemBindTypeChanged(Spinner spinner, BindType previousSelectedItemBindType) {
for (SpinnerBindingListener listener : this) {
listener.selectedItemBindTypeChanged(spinner, previousSelectedItemBindType);
}
}
@Override
public void selectedItemBindMappingChanged(Spinner spinner, ItemBindMapping previousSelectedItemBindMapping) {
for (SpinnerBindingListener listener : this) {
listener.selectedItemBindMappingChanged(spinner, previousSelectedItemBindMapping);
}
}
}
private List> spinnerData = null;
private ItemRenderer itemRenderer = null;
private boolean circular = false;
private int selectedIndex = -1;
private String spinnerDataKey = null;
private BindType spinnerDataBindType = BindType.BOTH;
private SpinnerDataBindMapping spinnerDataBindMapping = null;
private String selectedItemKey = null;
private BindType selectedItemBindType = BindType.BOTH;
private ItemBindMapping selectedItemBindMapping = null;
private ListListener