Debian Codegraph @

substance-flamingo/src/main/java/org/pushingpixels/substance/flamingo/ribbon/ui/SubstanceRibbonGalleryUI.java

raw symbols SCIP
1 /*
2 * Copyright (c) 2005-2010 Flamingo / Substance 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.substance.flamingo.ribbon.ui;
31
32 import java.awt.*;
33
34 import javax.swing.*;
35 import javax.swing.plaf.ComponentUI;
36
37 import org.pushingpixels.flamingo.api.common.JCommandButton;
38 import org.pushingpixels.flamingo.api.common.icon.ResizableIcon;
39 import org.pushingpixels.flamingo.internal.ui.ribbon.BasicRibbonGalleryUI;
40 import org.pushingpixels.flamingo.internal.ui.ribbon.JRibbonGallery;
41 import org.pushingpixels.substance.api.*;
42 import org.pushingpixels.substance.flamingo.common.TransitionAwareResizableIcon;
43 import org.pushingpixels.substance.flamingo.common.ui.ActionPopupTransitionAwareUI;
44 import org.pushingpixels.substance.internal.animation.StateTransitionTracker;
45 import org.pushingpixels.substance.internal.utils.*;
46
47 /**
48 * UI delegate for {@link JRibbonGallery} component under Substance
49 * look-and-feel.
50 *
51 * @author Kirill Grouchnikov
52 */
53 public class SubstanceRibbonGalleryUI extends BasicRibbonGalleryUI {
54 /*
55 * (non-Javadoc)
56 *
57 * @see javax.swing.plaf.ComponentUI#createUI(javax.swing.JComponent)
58 */
59 public static ComponentUI createUI(JComponent comp) {
60 SubstanceCoreUtilities.testComponentCreationThreadingViolation(comp);
61 return new SubstanceRibbonGalleryUI();
62 }
63
64 /**
65 * Creates new UI delegate.
66 */
67 private SubstanceRibbonGalleryUI() {
68 }
69
70 /*
71 * (non-Javadoc)
72 *
73 * @see
74 * org.jvnet.flamingo.ribbon.ui.BasicRibbonGalleryUI#paintRibbonGalleryBorder
75 * (java.awt.Graphics)
76 */
77 @Override
78 protected void paintRibbonGalleryBorder(Graphics graphics) {
79 Graphics2D g2d = (Graphics2D) graphics;
80 SubstanceColorScheme borderColorScheme = SubstanceColorSchemeUtilities
81 .getColorScheme(this.ribbonGallery,
82 ColorSchemeAssociationKind.BORDER,
83 ComponentState.ENABLED);
84 SubstanceImageCreator.paintBorder(this.ribbonGallery, g2d,
85 this.margin.left, this.margin.top, this.ribbonGallery
86 .getWidth()
87 - this.margin.left - this.margin.right,
88 this.ribbonGallery.getHeight() - this.margin.top
89 - this.margin.bottom, SubstanceSizeUtils
90 .getClassicButtonCornerRadius(SubstanceSizeUtils
91 .getComponentFontSize(this.ribbonGallery)),
92 borderColorScheme);
93 g2d.dispose();
94 }
95
96 /*
97 * (non-Javadoc)
98 *
99 * @see
100 * org.jvnet.flamingo.ribbon.ui.BasicRibbonGalleryUI#createExpandButton()
101 */
102 @Override
103 protected ExpandCommandButton createExpandButton() {
104 final ExpandCommandButton button = super.createExpandButton();
105 final int fontSize = SubstanceSizeUtils.getComponentFontSize(button);
106 int arrowIconHeight = (int) SubstanceSizeUtils
107 .getSmallArrowIconHeight(fontSize) + 3;
108 int arrowIconWidth = (int) SubstanceSizeUtils
109 .getSmallArrowIconWidth(fontSize);
110 final ResizableIcon arrowIcon = new TransitionAwareResizableIcon(
111 button,
112 new TransitionAwareResizableIcon.StateTransitionTrackerDelegate() {
113 @Override
114 public StateTransitionTracker getStateTransitionTracker() {
115 return ((ActionPopupTransitionAwareUI) button.getUI())
116 .getActionTransitionTracker();
117 }
118 }, new TransitionAwareResizableIcon.Delegate() {
119 @Override
120 public Icon getColorSchemeIcon(SubstanceColorScheme scheme,
121 int width, int height) {
122 return SubstanceImageCreator
123 .getDoubleArrowIcon(
124 SubstanceSizeUtils
125 .getComponentFontSize(button),
126 width,
127 height,
128 SubstanceSizeUtils
129 .getDoubleArrowStrokeWidth(fontSize),
130 SwingConstants.SOUTH, scheme);
131 }
132 }, new Dimension(arrowIconWidth, arrowIconHeight));
133 button.setIcon(arrowIcon);
134 return button;
135 }
136
137 /*
138 * (non-Javadoc)
139 *
140 * @see
141 * org.jvnet.flamingo.ribbon.ui.BasicRibbonGalleryUI#createScrollDownButton
142 * ()
143 */
144 @Override
145 protected JCommandButton createScrollDownButton() {
146 final JCommandButton button = super.createScrollDownButton();
147 final int fontSize = SubstanceSizeUtils.getComponentFontSize(button);
148 int arrowIconHeight = (int) SubstanceSizeUtils
149 .getSmallArrowIconHeight(fontSize);
150 int arrowIconWidth = (int) SubstanceSizeUtils
151 .getSmallArrowIconWidth(fontSize);
152 final ResizableIcon arrowIcon = new TransitionAwareResizableIcon(
153 button,
154 new TransitionAwareResizableIcon.StateTransitionTrackerDelegate() {
155 @Override
156 public StateTransitionTracker getStateTransitionTracker() {
157 return ((ActionPopupTransitionAwareUI) button.getUI())
158 .getActionTransitionTracker();
159 }
160 }, new TransitionAwareResizableIcon.Delegate() {
161 @Override
162 public Icon getColorSchemeIcon(SubstanceColorScheme scheme,
163 int width, int height) {
164 return SubstanceImageCreator.getArrowIcon(width,
165 height, SubstanceSizeUtils
166 .getDoubleArrowStrokeWidth(fontSize),
167 SwingConstants.SOUTH, scheme);
168 }
169 }, new Dimension(arrowIconWidth, arrowIconHeight));
170 button.setIcon(arrowIcon);
171 return button;
172 }
173
174 /*
175 * (non-Javadoc)
176 *
177 * @see
178 * org.jvnet.flamingo.ribbon.ui.BasicRibbonGalleryUI#createScrollUpButton()
179 */
180 @Override
181 protected JCommandButton createScrollUpButton() {
182 final JCommandButton button = super.createScrollUpButton();
183 final int fontSize = SubstanceSizeUtils.getComponentFontSize(button);
184 int arrowIconHeight = (int) SubstanceSizeUtils
185 .getSmallArrowIconHeight(fontSize);
186 int arrowIconWidth = (int) SubstanceSizeUtils
187 .getSmallArrowIconWidth(fontSize);
188 ResizableIcon arrowIcon = new TransitionAwareResizableIcon(
189 button,
190 new TransitionAwareResizableIcon.StateTransitionTrackerDelegate() {
191 @Override
192 public StateTransitionTracker getStateTransitionTracker() {
193 return ((ActionPopupTransitionAwareUI) button.getUI())
194 .getActionTransitionTracker();
195 }
196 }, new TransitionAwareResizableIcon.Delegate() {
197 @Override
198 public Icon getColorSchemeIcon(SubstanceColorScheme scheme,
199 int width, int height) {
200 return SubstanceImageCreator.getArrowIcon(width,
201 height, SubstanceSizeUtils
202 .getDoubleArrowStrokeWidth(fontSize),
203 SwingConstants.NORTH, scheme);
204 }
205 }, new Dimension(arrowIconWidth, arrowIconHeight));
206 button.setIcon(arrowIcon);
207 return button;
208 }
209 }