~ubuntu-branches/debian/stretch/insubstantial/stretch

« back to all changes in this revision

Viewing changes to flamingo/src/main/java/org/pushingpixels/flamingo/internal/ui/bcb/BreadcrumbItemChoices.java

  • Committer: Package Import Robot
  • Author(s): Felix Natter
  • Date: 2016-01-18 20:58:45 UTC
  • Revision ID: package-import@ubuntu.com-20160118205845-crbmrkda61qsi5qa
Tags: upstream-7.3+dfsg2
ImportĀ upstreamĀ versionĀ 7.3+dfsg2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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> 
 
5
 * in January 2006. 
 
6
 *
 
7
 * Redistribution and use in source and binary forms, with or without 
 
8
 * modification, are permitted provided that the following conditions are met:
 
9
 * 
 
10
 *  o Redistributions of source code must retain the above copyright notice, 
 
11
 *    this list of conditions and the following disclaimer. 
 
12
 *     
 
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. 
 
16
 *     
 
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. 
 
20
 *     
 
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.
 
32
 */
 
33
package org.pushingpixels.flamingo.internal.ui.bcb;
 
34
 
 
35
import java.util.List;
 
36
 
 
37
import javax.swing.Icon;
 
38
 
 
39
import org.pushingpixels.flamingo.api.bcb.BreadcrumbItem;
 
40
import org.pushingpixels.flamingo.api.common.StringValuePair;
 
41
 
 
42
/**
 
43
 * This is the model for the popup that is shown by clicking on the path
 
44
 * selector.
 
45
 */
 
46
final class BreadcrumbItemChoices<T> {
 
47
        /**
 
48
         * Contains all possible choices.
 
49
         */
 
50
        private BreadcrumbItem<T>[] choices;
 
51
 
 
52
        /**
 
53
         * The ancestor item. This can be <code>null</code> only for the root
 
54
         * choices element.
 
55
         */
 
56
        private BreadcrumbItem ancestor;
 
57
 
 
58
        /**
 
59
         * The index of <code>this</code> element.
 
60
         */
 
61
        private int selectedIndex = 0;
 
62
 
 
63
        public BreadcrumbItemChoices(BreadcrumbItem ancestor,
 
64
                        List<StringValuePair<T>> entries) {
 
65
                this.ancestor = ancestor;
 
66
                this.choices = new BreadcrumbItem[entries.size()];
 
67
                int index = 0;
 
68
                for (StringValuePair<T> pair : entries) {
 
69
                        this.choices[index] = new BreadcrumbItem<T>(pair.getKey(), pair
 
70
                                        .getValue());
 
71
                        this.choices[index].setIcon((Icon) pair.get("icon"));
 
72
                        index++;
 
73
                }
 
74
                this.selectedIndex = -1;
 
75
        }
 
76
 
 
77
        /**
 
78
         * Returns the 0-based index of the first {@link BreadcrumbItem} whose
 
79
         * display name matches the specified string.
 
80
         * 
 
81
         * @param s
 
82
         *            String.
 
83
         * @return The 0-based index of the first {@link BreadcrumbItem} whose
 
84
         *         display name matches the specified string.
 
85
         */
 
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()))
 
91
                                return i;
 
92
                }
 
93
                return -1;
 
94
        }
 
95
 
 
96
        public void setSelectedIndex(int index) {
 
97
                this.selectedIndex = index;
 
98
        }
 
99
 
 
100
        public int getSelectedIndex() {
 
101
                return this.selectedIndex;
 
102
        }
 
103
 
 
104
        /**
 
105
         * Returns the item array of <code>true</code>his element.
 
106
         * 
 
107
         * @return The item array of <code>true</code>his element.
 
108
         */
 
109
        public BreadcrumbItem[] getChoices() {
 
110
                return choices;
 
111
        }
 
112
 
 
113
        public BreadcrumbItem getAncestor() {
 
114
                return ancestor;
 
115
        }
 
116
}