001: /*
002: * Copyright (c) 2005-2008 Flamingo / Substance Kirill Grouchnikov. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of Flamingo Kirill Grouchnikov nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030: package org.jvnet.substance.flamingo.ribbon.ui;
031:
032: import java.awt.*;
033: import java.beans.PropertyChangeEvent;
034: import java.beans.PropertyChangeListener;
035:
036: import javax.swing.*;
037: import javax.swing.plaf.ComponentUI;
038:
039: import org.jvnet.flamingo.ribbon.ui.BasicRibbonGalleryUI;
040: import org.jvnet.substance.SubstanceFillBackgroundDelegate;
041: import org.jvnet.substance.SubstanceImageCreator;
042: import org.jvnet.substance.scroll.SubstanceScrollButton;
043: import org.jvnet.substance.utils.*;
044:
045: public class SubstanceRibbonGalleryUI extends BasicRibbonGalleryUI {
046: /**
047: * Background delegate.
048: */
049: private SubstanceFillBackgroundDelegate bgDelegate;
050:
051: /**
052: * Property change listener on the buttons.
053: */
054: protected PropertyChangeListener substanceButtonsPropertyChangeListener;
055:
056: /*
057: * (non-Javadoc)
058: *
059: * @see javax.swing.plaf.ComponentUI#createUI(javax.swing.JComponent)
060: */
061: public static ComponentUI createUI(JComponent c) {
062: return new SubstanceRibbonGalleryUI();
063: }
064:
065: /**
066: * Creates new UI delegate.
067: */
068: private SubstanceRibbonGalleryUI() {
069: this .bgDelegate = new SubstanceFillBackgroundDelegate(0.6f);
070: }
071:
072: /*
073: * (non-Javadoc)
074: *
075: * @see org.jvnet.flamingo.ribbon.ui.BasicRibbonGalleryUI#installListeners()
076: */
077: @Override
078: protected void installListeners() {
079: super .installListeners();
080:
081: this .substanceButtonsPropertyChangeListener = new PropertyChangeListener() {
082: public void propertyChange(PropertyChangeEvent evt) {
083: if ("enabled".equals(evt.getPropertyName())) {
084: // update button icons
085: }
086: }
087: };
088: this .expandActionButton
089: .addPropertyChangeListener(this .substanceButtonsPropertyChangeListener);
090: this .scrollDownButton
091: .addPropertyChangeListener(this .substanceButtonsPropertyChangeListener);
092: this .scrollUpButton
093: .addPropertyChangeListener(this .substanceButtonsPropertyChangeListener);
094: }
095:
096: /*
097: * (non-Javadoc)
098: *
099: * @see org.jvnet.flamingo.ribbon.ui.BasicRibbonGalleryUI#uninstallListeners()
100: */
101: @Override
102: protected void uninstallListeners() {
103: this .expandActionButton
104: .removePropertyChangeListener(this .substanceButtonsPropertyChangeListener);
105: this .scrollDownButton
106: .removePropertyChangeListener(this .substanceButtonsPropertyChangeListener);
107: this .scrollUpButton
108: .removePropertyChangeListener(this .substanceButtonsPropertyChangeListener);
109: this .substanceButtonsPropertyChangeListener = null;
110: super .uninstallListeners();
111: }
112:
113: /*
114: * (non-Javadoc)
115: *
116: * @see org.jvnet.flamingo.ribbon.ui.BasicRibbonGalleryUI#paintRibbonGalleryBackground(java.awt.Graphics)
117: */
118: @Override
119: protected void paintRibbonGalleryBackground(Graphics graphics) {
120: this .bgDelegate.fillAndWatermark(graphics, this .ribbonGallery,
121: this .ribbonGallery.getBackground(), new Rectangle(0, 0,
122: this .ribbonGallery.getWidth(),
123: this .ribbonGallery.getHeight()));
124: }
125:
126: /*
127: * (non-Javadoc)
128: *
129: * @see org.jvnet.flamingo.ribbon.ui.BasicRibbonGalleryUI#paintRibbonGalleryBorder(java.awt.Graphics)
130: */
131: @Override
132: protected void paintRibbonGalleryBorder(Graphics graphics) {
133: Graphics2D g2d = (Graphics2D) graphics;
134: SubstanceImageCreator
135: .paintBorder(
136: this .ribbonGallery,
137: g2d,
138: this .margin.left,
139: this .margin.top,
140: this .ribbonGallery.getWidth()
141: - this .margin.left - this .margin.right,
142: this .ribbonGallery.getHeight()
143: - this .margin.top - this .margin.bottom,
144: SubstanceSizeUtils
145: .getClassicButtonCornerRadius(SubstanceSizeUtils
146: .getComponentFontSize(this .ribbonGallery)),
147: SubstanceThemeUtilities.getTheme(
148: this .ribbonGallery,
149: ComponentState.DEFAULT)
150: .getBorderTheme().getColorScheme());
151: g2d.dispose();
152: }
153:
154: /*
155: * (non-Javadoc)
156: *
157: * @see org.jvnet.flamingo.ribbon.ui.BasicRibbonGalleryUI#createExpandButton()
158: */
159: @Override
160: protected AbstractButton createExpandButton() {
161: AbstractButton button = new SubstanceScrollButton(
162: SwingConstants.SOUTH);
163: Icon arrowIcon = SubstanceCoreUtilities.getDoubleArrowIcon(
164: this .ribbonGallery, button, SwingConstants.SOUTH);
165: button.setIcon(arrowIcon);
166: button.setDisabledIcon(SubstanceImageCreator.makeTransparent(
167: button, arrowIcon, 0.4));
168: return button;
169: }
170:
171: /*
172: * (non-Javadoc)
173: *
174: * @see org.jvnet.flamingo.ribbon.ui.BasicRibbonGalleryUI#createScrollDownButton()
175: */
176: @Override
177: protected AbstractButton createScrollDownButton() {
178: AbstractButton button = new SubstanceScrollButton(
179: SwingConstants.SOUTH);
180: Icon arrowIcon = SubstanceCoreUtilities.getArrowIcon(
181: this .ribbonGallery, button, SwingConstants.SOUTH);
182: button.setIcon(arrowIcon);
183: button.setDisabledIcon(SubstanceImageCreator.makeTransparent(
184: button, arrowIcon, 0.4));
185: return button;
186: }
187:
188: /*
189: * (non-Javadoc)
190: *
191: * @see org.jvnet.flamingo.ribbon.ui.BasicRibbonGalleryUI#createScrollUpButton()
192: */
193: @Override
194: protected AbstractButton createScrollUpButton() {
195: AbstractButton button = new SubstanceScrollButton(
196: SwingConstants.NORTH);
197: Icon arrowIcon = SubstanceCoreUtilities.getArrowIcon(
198: this .ribbonGallery, button, SwingConstants.NORTH);
199: button.setIcon(arrowIcon);
200: button.setDisabledIcon(SubstanceImageCreator.makeTransparent(
201: button, arrowIcon, 0.4));
202: return button;
203: }
204: }
|