2
* Copyright (c) 2003-2010 Flamingo Kirill Grouchnikov
3
* and <a href="http://www.topologi.com">Topologi</a>.
4
* Contributed by <b>Rick Jelliffe</b> of <b>Topologi</b>
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions are met:
10
* o Redistributions of source code must retain the above copyright notice,
11
* this list of conditions and the following disclaimer.
13
* o Redistributions in binary form must reproduce the above copyright notice,
14
* this list of conditions and the following disclaimer in the documentation
15
* and/or other materials provided with the distribution.
17
* o Neither the name of Flamingo Kirill Grouchnikov Topologi nor the names of
18
* its contributors may be used to endorse or promote products derived
19
* from this software without specific prior written permission.
21
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
30
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
package org.pushingpixels.flamingo.internal.ui.bcb;
35
import java.util.List;
37
import javax.swing.Icon;
39
import org.pushingpixels.flamingo.api.bcb.BreadcrumbItem;
40
import org.pushingpixels.flamingo.api.common.StringValuePair;
43
* This is the model for the popup that is shown by clicking on the path
46
final class BreadcrumbItemChoices<T> {
48
* Contains all possible choices.
50
private BreadcrumbItem<T>[] choices;
53
* The ancestor item. This can be <code>null</code> only for the root
56
private BreadcrumbItem ancestor;
59
* The index of <code>this</code> element.
61
private int selectedIndex = 0;
63
public BreadcrumbItemChoices(BreadcrumbItem ancestor,
64
List<StringValuePair<T>> entries) {
65
this.ancestor = ancestor;
66
this.choices = new BreadcrumbItem[entries.size()];
68
for (StringValuePair<T> pair : entries) {
69
this.choices[index] = new BreadcrumbItem<T>(pair.getKey(), pair
71
this.choices[index].setIcon((Icon) pair.get("icon"));
74
this.selectedIndex = -1;
78
* Returns the 0-based index of the first {@link BreadcrumbItem} whose
79
* display name matches the specified string.
83
* @return The 0-based index of the first {@link BreadcrumbItem} whose
84
* display name matches the specified string.
86
public int getPosition(String s) {
87
assert (s != null && s.length() > 0);
88
for (int i = 0; i < choices.length; i++) {
89
BreadcrumbItem it = choices[i];
90
if (s.equals(it.getKey()))
96
public void setSelectedIndex(int index) {
97
this.selectedIndex = index;
100
public int getSelectedIndex() {
101
return this.selectedIndex;
105
* Returns the item array of <code>true</code>his element.
107
* @return The item array of <code>true</code>his element.
109
public BreadcrumbItem[] getChoices() {
113
public BreadcrumbItem getAncestor() {