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:
034: import javax.swing.JComponent;
035: import javax.swing.plaf.ComponentUI;
036:
037: import org.jvnet.flamingo.ribbon.JToggleTabButton;
038: import org.jvnet.flamingo.ribbon.ui.BasicRibbonUI;
039: import org.jvnet.substance.border.SubstanceBorderPainter;
040: import org.jvnet.substance.color.ColorScheme;
041: import org.jvnet.substance.painter.decoration.DecorationAreaType;
042: import org.jvnet.substance.painter.decoration.SubstanceDecorationUtilities;
043: import org.jvnet.substance.utils.*;
044:
045: /**
046: * UI for ribbon in <b>Substance</b> look and feel.
047: *
048: * @author Kirill Grouchnikov
049: */
050: public class SubstanceRibbonUI extends BasicRibbonUI {
051: /*
052: * (non-Javadoc)
053: *
054: * @see javax.swing.plaf.ComponentUI#createUI(javax.swing.JComponent)
055: */
056: public static ComponentUI createUI(JComponent c) {
057: return new SubstanceRibbonUI();
058: }
059:
060: /*
061: * (non-Javadoc)
062: *
063: * @see org.jvnet.flamingo.ribbon.ui.BasicRibbonUI#installDefaults()
064: */
065: @Override
066: protected void installDefaults() {
067: super .installDefaults();
068: SubstanceDecorationUtilities.setDecorationType(this .ribbon,
069: DecorationAreaType.HEADER);
070: }
071:
072: /*
073: * (non-Javadoc)
074: *
075: * @see org.jvnet.flamingo.ribbon.ui.BasicRibbonUI#uninstallDefaults()
076: */
077: @Override
078: protected void uninstallDefaults() {
079: SubstanceDecorationUtilities.clearDecorationType(this .ribbon);
080: super .uninstallDefaults();
081: }
082:
083: /*
084: * (non-Javadoc)
085: *
086: * @see org.jvnet.flamingo.ribbon.ui.BasicRibbonUI#paintTaskBorder(java.awt.Graphics,
087: * int, int, int, int)
088: */
089: @Override
090: protected void paintTaskBorder(Graphics g, int x, int y, int width,
091: int height) {
092: Graphics2D g2d = (Graphics2D) g.create();
093:
094: int selectedTaskIndex = this .ribbon.getSelectedTaskIndex();
095: JToggleTabButton selectedTaskButton = this .ribbon
096: .getTaskToggleButtons().get(selectedTaskIndex);
097: Rectangle selectedTaskButtonBounds = selectedTaskButton
098: .getBounds();
099: float radius = SubstanceSizeUtils
100: .getClassicButtonCornerRadius(SubstanceSizeUtils
101: .getComponentFontSize(this .ribbon));
102:
103: int borderDelta = (int) Math.floor(SubstanceSizeUtils
104: .getBorderStrokeWidth(SubstanceSizeUtils
105: .getComponentFontSize(this .ribbon)) / 2.0);
106:
107: SubstanceBorderPainter borderPainter = SubstanceCoreUtilities
108: .getBorderPainter(this .ribbon);
109: int borderThickness = (int) SubstanceSizeUtils
110: .getBorderStrokeWidth(SubstanceSizeUtils
111: .getComponentFontSize(this .ribbon));
112: // GeneralPath contourInner = BaseButtonShaper.getBaseOutline(width,
113: // height, radius, null, borderThickness + borderDelta);
114: ColorScheme borderScheme = SubstanceThemeUtilities.getTheme(
115: this .ribbon, ComponentState.DEFAULT).getBorderTheme()
116: .getColorScheme();
117:
118: Shape outerContour = RibbonBorderShaper.getRibbonBorderOutline(
119: x + borderDelta, x + width - 2 * borderDelta - 1,
120: selectedTaskButtonBounds.x + borderDelta,
121: selectedTaskButtonBounds.x
122: + selectedTaskButtonBounds.width - 2
123: * borderDelta, selectedTaskButtonBounds.y
124: + borderDelta, y + borderDelta, y + height - 2
125: * borderDelta, radius);
126:
127: Shape innerContour = RibbonBorderShaper.getRibbonBorderOutline(
128: x + borderDelta + borderThickness, x + width - 2
129: * (borderDelta + borderThickness) - 1,
130: selectedTaskButtonBounds.x + borderDelta
131: + borderThickness, selectedTaskButtonBounds.x
132: + selectedTaskButtonBounds.width - 2
133: * (borderDelta + borderThickness),
134: selectedTaskButtonBounds.y + borderDelta
135: + borderThickness, y + borderDelta
136: + borderThickness, y + height - 2
137: * (borderDelta + borderThickness) + 1, radius);
138:
139: borderPainter.paintBorder(g2d, this .ribbon, width, height
140: + selectedTaskButtonBounds.height + 1, outerContour,
141: innerContour, borderScheme, borderScheme, 0, false);
142:
143: //
144: // SubstanceImageCreator.paintBorder(this.ribbon, g2d, x, y, width,
145: // height, SubstanceSizeUtils
146: // .getClassicButtonCornerRadius(SubstanceSizeUtils
147: // .getComponentFontSize(this.ribbon)),
148: // SubstanceCoreUtilities.getDefaultScheme(this.ribbon));
149: g2d.dispose();
150: }
151: }
|