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

« back to all changes in this revision

Viewing changes to flamingo/src/main/java/org/pushingpixels/flamingo/api/ribbon/RibbonContextualTaskGroup.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) 2005-2010 Flamingo Kirill Grouchnikov. All Rights Reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without 
 
5
 * modification, are permitted provided that the following conditions are met:
 
6
 * 
 
7
 *  o Redistributions of source code must retain the above copyright notice, 
 
8
 *    this list of conditions and the following disclaimer. 
 
9
 *     
 
10
 *  o Redistributions in binary form must reproduce the above copyright notice, 
 
11
 *    this list of conditions and the following disclaimer in the documentation 
 
12
 *    and/or other materials provided with the distribution. 
 
13
 *     
 
14
 *  o Neither the name of Flamingo Kirill Grouchnikov nor the names of 
 
15
 *    its contributors may be used to endorse or promote products derived 
 
16
 *    from this software without specific prior written permission. 
 
17
 *     
 
18
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 
19
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
 
20
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
 
21
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
 
22
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
 
23
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
 
24
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
 
25
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
 
26
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
 
27
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
 
28
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 
29
 */
 
30
package org.pushingpixels.flamingo.api.ribbon;
 
31
 
 
32
import java.awt.Color;
 
33
import java.util.ArrayList;
 
34
 
 
35
/**
 
36
 * A contextual group of {@link RibbonTask}s. The contextual ribbon task groups
 
37
 * allow showing and hiding ribbon tasks based on the current selection in the
 
38
 * application. For example, Word only shows the table tasks when a table is
 
39
 * selected in the document. By default, tasks belonging to the groups added by
 
40
 * {@link JRibbon#addContextualTaskGroup(RibbonContextualTaskGroup)} are not
 
41
 * visible. To show the tasks belonging to the specific group, call
 
42
 * {@link JRibbon#setVisible(RibbonContextualTaskGroup, boolean)} API. Note that
 
43
 * you can have multiple task groups visible at the same time. This class is a
 
44
 * logical entity that groups ribbon tasks belonging to the same contextual
 
45
 * group.
 
46
 * 
 
47
 * @author Kirill Grouchnikov
 
48
 */
 
49
public class RibbonContextualTaskGroup {
 
50
        /**
 
51
         * The ribbon that contains this task group.
 
52
         */
 
53
        private JRibbon ribbon;
 
54
 
 
55
        /**
 
56
         * List of all tasks.
 
57
         * 
 
58
         * @see #RibbonContextualTaskGroup(String, Color, RibbonTask...)
 
59
         * @see #getTaskCount()
 
60
         * @see #getTask(int)
 
61
         */
 
62
        private ArrayList<RibbonTask> tasks;
 
63
 
 
64
        /**
 
65
         * Group title.
 
66
         * 
 
67
         * @see #RibbonContextualTaskGroup(String, Color, RibbonTask...)
 
68
         * @see #getTitle()
 
69
         * @see #setTitle(String)
 
70
         */
 
71
        private String title;
 
72
 
 
73
        /**
 
74
         * Hue color for this group.
 
75
         * 
 
76
         * @see #RibbonContextualTaskGroup(String, Color, RibbonTask...)
 
77
         * @see #getHueColor()
 
78
         */
 
79
        private Color hueColor;
 
80
 
 
81
        /**
 
82
         * Alpha factor for colorizing the toggle tab buttons of tasks in contextual
 
83
         * groups.
 
84
         */
 
85
        public static final double HUE_ALPHA = 0.25;
 
86
 
 
87
        /**
 
88
         * Creates a task contextual group that contains the specified tasks.
 
89
         * 
 
90
         * @param title
 
91
         *            Group title.
 
92
         * @param hueColor
 
93
         *            Hue color for this group. Should be a saturated non-dark color
 
94
         *            for good visuals.
 
95
         * @param tasks
 
96
         *            Tasks to add to the group.
 
97
         */
 
98
        public RibbonContextualTaskGroup(String title, Color hueColor,
 
99
                        RibbonTask... tasks) {
 
100
                this.title = title;
 
101
                this.hueColor = hueColor;
 
102
                this.tasks = new ArrayList<RibbonTask>();
 
103
                for (RibbonTask ribbonTask : tasks) {
 
104
                        ribbonTask.setContextualGroup(this);
 
105
                        this.tasks.add(ribbonTask);
 
106
                }
 
107
        }
 
108
 
 
109
        /**
 
110
         * Returns the number of tasks in <code>this</code> group.
 
111
         * 
 
112
         * @return Number of tasks in <code>this</code> group.
 
113
         * @see #getTask(int)
 
114
         */
 
115
        public int getTaskCount() {
 
116
                return this.tasks.size();
 
117
        }
 
118
 
 
119
        /**
 
120
         * Returns task at the specified index from <code>this</code> group.
 
121
         * 
 
122
         * @param index
 
123
         *            Task index.
 
124
         * @return Task at the specified index.
 
125
         * @see #getTaskCount()
 
126
         */
 
127
        public RibbonTask getTask(int index) {
 
128
                return this.tasks.get(index);
 
129
        }
 
130
 
 
131
        /**
 
132
         * Returns the name of this group.
 
133
         * 
 
134
         * @return The name of this group.
 
135
         * @see #setTitle(String)
 
136
         */
 
137
        public String getTitle() {
 
138
                return this.title;
 
139
        }
 
140
 
 
141
        /**
 
142
         * Returns the hue color for this group.
 
143
         * 
 
144
         * @return The hue color for this group.
 
145
         */
 
146
        public Color getHueColor() {
 
147
                return this.hueColor;
 
148
        }
 
149
 
 
150
        /**
 
151
         * Changes the title of this ribbon contextual task group.
 
152
         * 
 
153
         * @param title
 
154
         *            The new title for this ribbon contextual task group.
 
155
         * @see #getTitle()
 
156
         */
 
157
        public void setTitle(String title) {
 
158
                this.title = title;
 
159
                if (this.ribbon != null)
 
160
                        this.ribbon.fireStateChanged();
 
161
        }
 
162
 
 
163
        /*
 
164
         * (non-Javadoc)
 
165
         * 
 
166
         * @see java.lang.Object#toString()
 
167
         */
 
168
        @Override
 
169
        public String toString() {
 
170
                return getTitle() + " (" + getTaskCount() + " tasks)";
 
171
        }
 
172
 
 
173
        /**
 
174
         * Associates this ribbon contextual task group with the specified ribbon.
 
175
         * This method is package protected and is for internal use only.
 
176
         * 
 
177
         * @param ribbon
 
178
         *            The associated ribbon.
 
179
         */
 
180
        void setRibbon(JRibbon ribbon) {
 
181
                if (this.ribbon != null) {
 
182
                        throw new IllegalStateException(
 
183
                                        "The contextual task group already belongs to another ribbon");
 
184
                }
 
185
                this.ribbon = ribbon;
 
186
        }
 
187
 
 
188
}