| 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.common.ui; |
| 31 |
|
| 32 |
import java.awt.*; |
| 33 |
import java.util.EnumSet; |
| 34 |
import java.util.Set; |
| 35 |
|
| 36 |
import javax.swing.JComponent; |
| 37 |
import javax.swing.plaf.ComponentUI; |
| 38 |
|
| 39 |
import org.pushingpixels.flamingo.api.common.JCommandButtonPanel; |
| 40 |
import org.pushingpixels.flamingo.internal.ui.common.BasicCommandButtonPanelUI; |
| 41 |
import org.pushingpixels.substance.api.*; |
| 42 |
import org.pushingpixels.substance.api.SubstanceConstants.Side; |
| 43 |
import org.pushingpixels.substance.internal.painter.BackgroundPaintingUtils; |
| 44 |
import org.pushingpixels.substance.internal.painter.HighlightPainterUtils; |
| 45 |
import org.pushingpixels.substance.internal.utils.*; |
| 46 |
|
| 47 |
/** |
| 48 |
* UI for {@link JCommandButtonPanel} components in <b>Substance</b> look and |
| 49 |
* feel. |
| 50 |
* |
| 51 |
* @author Kirill Grouchnikov |
| 52 |
*/ |
| 53 |
public class SubstanceCommandButtonPanelUI extends BasicCommandButtonPanelUI { |
| 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 SubstanceCommandButtonPanelUI(); |
| 62 |
} |
| 63 |
|
| 64 |
/* |
| 65 |
* (non-Javadoc) |
| 66 |
* |
| 67 |
* @see |
| 68 |
* org.jvnet.flamingo.common.ui.BasicCommandButtonPanelUI#getGroupInsets() |
| 69 |
*/ |
| 70 |
@Override |
| 71 |
protected Insets getGroupInsets() { |
| 72 |
int extraPadding = SubstanceSizeUtils |
| 73 |
.getExtraPadding(SubstanceSizeUtils |
| 74 |
.getComponentFontSize(this.buttonPanel)); |
| 75 |
Insets result = super.getGroupInsets(); |
| 76 |
return new Insets(result.top + extraPadding, |
| 77 |
result.left + extraPadding, result.bottom + extraPadding, |
| 78 |
result.right + extraPadding); |
| 79 |
} |
| 80 |
|
| 81 |
/* |
| 82 |
* (non-Javadoc) |
| 83 |
* |
| 84 |
* @see |
| 85 |
* org.jvnet.flamingo.common.ui.BasicCommandButtonPanelUI#getGroupTitleHeight |
| 86 |
* (int) |
| 87 |
*/ |
| 88 |
@Override |
| 89 |
protected int getGroupTitleHeight(int groupIndex) { |
| 90 |
int extraPadding = SubstanceSizeUtils |
| 91 |
.getExtraPadding(SubstanceSizeUtils |
| 92 |
.getComponentFontSize(this.buttonPanel)); |
| 93 |
return super.getGroupTitleHeight(groupIndex) + 2 * extraPadding; |
| 94 |
} |
| 95 |
|
| 96 |
/* |
| 97 |
* (non-Javadoc) |
| 98 |
* |
| 99 |
* @see |
| 100 |
* org.jvnet.flamingo.common.ui.BasicCommandButtonPanelUI#paintGroupBackground |
| 101 |
* (java.awt.Graphics, int, int, int, int, int) |
| 102 |
*/ |
| 103 |
@Override |
| 104 |
protected void paintGroupBackground(Graphics g, int groupIndex, int x, |
| 105 |
int y, int width, int height) { |
| 106 |
SubstanceColorScheme scheme = SubstanceColorSchemeUtilities |
| 107 |
.getColorScheme(buttonPanel, ComponentState.ENABLED); |
| 108 |
Color background = scheme.getBackgroundFillColor(); |
| 109 |
if (groupIndex % 2 == 1) |
| 110 |
background = SubstanceColorUtilities.getDarkerColor(background, |
| 111 |
0.06); |
| 112 |
|
| 113 |
BackgroundPaintingUtils.fillAndWatermark(g, this.buttonPanel, |
| 114 |
background, new Rectangle(x, y, width, height)); |
| 115 |
} |
| 116 |
|
| 117 |
@Override |
| 118 |
protected void paintGroupTitleBackground(Graphics g, int groupIndex, int x, |
| 119 |
int y, int width, int height) { |
| 120 |
Set<SubstanceConstants.Side> openSides = EnumSet.of(Side.LEFT, |
| 121 |
Side.RIGHT); |
| 122 |
if (groupIndex == 0) |
| 123 |
openSides.add(Side.TOP); |
| 124 |
SubstanceColorScheme bgFillScheme = SubstanceColorSchemeUtilities |
| 125 |
.getColorScheme(this.buttonPanel, |
| 126 |
ColorSchemeAssociationKind.HIGHLIGHT, |
| 127 |
ComponentState.ENABLED); |
| 128 |
SubstanceColorScheme bgBorderScheme = SubstanceColorSchemeUtilities |
| 129 |
.getColorScheme(this.buttonPanel, |
| 130 |
ColorSchemeAssociationKind.HIGHLIGHT_BORDER, |
| 131 |
ComponentState.ENABLED); |
| 132 |
HighlightPainterUtils.paintHighlight(g, null, this.buttonPanel, |
| 133 |
new Rectangle(x, y, width, height), 1.0f, openSides, |
| 134 |
bgFillScheme, bgBorderScheme); |
| 135 |
} |
| 136 |
|
| 137 |
/* |
| 138 |
* (non-Javadoc) |
| 139 |
* |
| 140 |
* @see javax.swing.plaf.ComponentUI#update(java.awt.Graphics, |
| 141 |
* javax.swing.JComponent) |
| 142 |
*/ |
| 143 |
@Override |
| 144 |
public void update(Graphics g, JComponent c) { |
| 145 |
BackgroundPaintingUtils.updateIfOpaque(g, c); |
| 146 |
this.paint(g, c); |
| 147 |
} |
| 148 |
} |