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.common.ui;
031:
032: import java.awt.*;
033:
034: import javax.swing.JComponent;
035: import javax.swing.plaf.ComponentUI;
036:
037: import org.jvnet.flamingo.common.JCommandButtonPanel;
038: import org.jvnet.flamingo.common.ui.BasicCommandButtonPanelUI;
039: import org.jvnet.substance.SubstanceFillBackgroundDelegate;
040: import org.jvnet.substance.SubstanceLookAndFeel;
041: import org.jvnet.substance.painter.text.SubstanceTextPainter;
042: import org.jvnet.substance.theme.SubstanceTheme;
043: import org.jvnet.substance.utils.*;
044:
045: /**
046: * UI for {@link JIconPanel} component in <b>Substance</b> look and feel.
047: *
048: * @author Kirill Grouchnikov
049: */
050: public class SubstanceCommandButtonPanelUI extends
051: BasicCommandButtonPanelUI {
052: protected SubstanceFillBackgroundDelegate fillDelegate;
053:
054: /*
055: * (non-Javadoc)
056: *
057: * @see javax.swing.plaf.ComponentUI#createUI(javax.swing.JComponent)
058: */
059: public static ComponentUI createUI(JComponent c) {
060: return new SubstanceCommandButtonPanelUI(
061: (JCommandButtonPanel) c);
062: }
063:
064: /**
065: * Simple constructor.
066: */
067: public SubstanceCommandButtonPanelUI(JCommandButtonPanel panel) {
068: super (panel);
069: this .fillDelegate = new SubstanceFillBackgroundDelegate();
070: }
071:
072: /*
073: * (non-Javadoc)
074: *
075: * @see org.jvnet.flamingo.common.ui.BasicCommandButtonPanelUI#installDefaults()
076: */
077: @Override
078: protected void installDefaults() {
079: super .installDefaults();
080: this .buttonPanel.putClientProperty(
081: SubstanceCoreUtilities.HAS_CUSTOM_BACKGROUND_FILL,
082: Boolean.TRUE);
083: }
084:
085: /*
086: * (non-Javadoc)
087: *
088: * @see org.jvnet.flamingo.common.ui.BasicCommandButtonPanelUI#uninstallComponents()
089: */
090: @Override
091: protected void uninstallComponents() {
092: this .buttonPanel
093: .putClientProperty(
094: SubstanceCoreUtilities.HAS_CUSTOM_BACKGROUND_FILL,
095: null);
096: super .uninstallComponents();
097: }
098:
099: /*
100: * (non-Javadoc)
101: *
102: * @see org.jvnet.flamingo.common.ui.BasicCommandButtonPanelUI#getGroupInsets()
103: */
104: @Override
105: protected Insets getGroupInsets() {
106: int extraPadding = SubstanceSizeUtils
107: .getExtraPadding(SubstanceSizeUtils
108: .getComponentFontSize(this .buttonPanel));
109: Insets result = super .getGroupInsets();
110: return new Insets(result.top + extraPadding, result.left
111: + extraPadding, result.bottom + extraPadding,
112: result.right + extraPadding);
113: }
114:
115: /*
116: * (non-Javadoc)
117: *
118: * @see org.jvnet.flamingo.common.ui.BasicCommandButtonPanelUI#getGroupTitleHeight()
119: */
120: @Override
121: protected int getGroupTitleHeight() {
122: int extraPadding = SubstanceSizeUtils
123: .getExtraPadding(SubstanceSizeUtils
124: .getComponentFontSize(this .buttonPanel));
125: return super .getGroupTitleHeight() + 2 * extraPadding;
126: }
127:
128: /*
129: * (non-Javadoc)
130: *
131: * @see org.jvnet.flamingo.common.ui.BasicCommandButtonPanelUI#paintGroupBackground(java.awt.Graphics,
132: * int, int, int, int, int)
133: */
134: @Override
135: protected void paintGroupBackground(Graphics g, int groupIndex,
136: int x, int y, int width, int height) {
137: SubstanceTheme theme = SubstanceThemeUtilities.getTheme(
138: buttonPanel, ComponentState.DEFAULT);
139: Color background = theme.getBackgroundColor();
140: if (groupIndex % 2 == 1)
141: background = SubstanceColorUtilities.getDarkerColor(
142: background, 0.1);
143:
144: Graphics2D g2d = (Graphics2D) g.create();
145: g2d.setColor(background);
146: g2d.fillRect(x, y, width, height);
147: g2d.dispose();
148: }
149:
150: /*
151: * (non-Javadoc)
152: *
153: * @see org.jvnet.flamingo.common.ui.BasicCommandButtonPanelUI#paintGroupTitle(java.awt.Graphics,
154: * java.lang.String, int, int, int, int, int)
155: */
156: @Override
157: protected void paintGroupTitle(Graphics g, String groupTitle,
158: int groupIndex, int x, int y, int width, int height) {
159: SubstanceTheme theme = SubstanceThemeUtilities.getTheme(
160: buttonPanel, ComponentState.DEFAULT);
161: Color foreground = theme.getForegroundColor();
162:
163: int titleRectHeight = this .getGroupTitleHeight();
164: Graphics2D g2d = (Graphics2D) g.create();
165: g2d.translate(x, y);
166:
167: SubstanceTextPainter textPainter = SubstanceLookAndFeel
168: .getCurrentTextPainter();
169: textPainter.init(this .buttonPanel, null, false);
170: Color background = theme.getBackgroundColor();
171: if (groupIndex % 2 == 1)
172: background = SubstanceColorUtilities.getDarkerColor(
173: background, 0.1);
174: textPainter.setBackgroundFill(this .buttonPanel, background,
175: true, 0, 0);
176: SubstanceCoreUtilities
177: .paintTextWithDropShadow(buttonPanel, g2d, foreground,
178: groupTitle, width, 2 * titleRectHeight,
179: 2 * getGroupInsets().left,
180: (titleRectHeight + g2d.getFontMetrics()
181: .getHeight()) / 2);
182: textPainter.renderSurface(g2d);
183: g2d.dispose();
184: }
185: }
|