2
* Copyright (c) 2005-2010 Flamingo Kirill Grouchnikov. All Rights Reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are met:
7
* o Redistributions of source code must retain the above copyright notice,
8
* this list of conditions and the following disclaimer.
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.
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.
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.
30
package org.pushingpixels.flamingo.api.ribbon;
32
import java.awt.Color;
33
import java.util.ArrayList;
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
47
* @author Kirill Grouchnikov
49
public class RibbonContextualTaskGroup {
51
* The ribbon that contains this task group.
53
private JRibbon ribbon;
58
* @see #RibbonContextualTaskGroup(String, Color, RibbonTask...)
59
* @see #getTaskCount()
62
private ArrayList<RibbonTask> tasks;
67
* @see #RibbonContextualTaskGroup(String, Color, RibbonTask...)
69
* @see #setTitle(String)
74
* Hue color for this group.
76
* @see #RibbonContextualTaskGroup(String, Color, RibbonTask...)
79
private Color hueColor;
82
* Alpha factor for colorizing the toggle tab buttons of tasks in contextual
85
public static final double HUE_ALPHA = 0.25;
88
* Creates a task contextual group that contains the specified tasks.
93
* Hue color for this group. Should be a saturated non-dark color
96
* Tasks to add to the group.
98
public RibbonContextualTaskGroup(String title, Color hueColor,
99
RibbonTask... tasks) {
101
this.hueColor = hueColor;
102
this.tasks = new ArrayList<RibbonTask>();
103
for (RibbonTask ribbonTask : tasks) {
104
ribbonTask.setContextualGroup(this);
105
this.tasks.add(ribbonTask);
110
* Returns the number of tasks in <code>this</code> group.
112
* @return Number of tasks in <code>this</code> group.
115
public int getTaskCount() {
116
return this.tasks.size();
120
* Returns task at the specified index from <code>this</code> group.
124
* @return Task at the specified index.
125
* @see #getTaskCount()
127
public RibbonTask getTask(int index) {
128
return this.tasks.get(index);
132
* Returns the name of this group.
134
* @return The name of this group.
135
* @see #setTitle(String)
137
public String getTitle() {
142
* Returns the hue color for this group.
144
* @return The hue color for this group.
146
public Color getHueColor() {
147
return this.hueColor;
151
* Changes the title of this ribbon contextual task group.
154
* The new title for this ribbon contextual task group.
157
public void setTitle(String title) {
159
if (this.ribbon != null)
160
this.ribbon.fireStateChanged();
166
* @see java.lang.Object#toString()
169
public String toString() {
170
return getTitle() + " (" + getTaskCount() + " tasks)";
174
* Associates this ribbon contextual task group with the specified ribbon.
175
* This method is package protected and is for internal use only.
178
* The associated ribbon.
180
void setRibbon(JRibbon ribbon) {
181
if (this.ribbon != null) {
182
throw new IllegalStateException(
183
"The contextual task group already belongs to another ribbon");
185
this.ribbon = ribbon;