2
* Copyright (c) 2005-2010 Substance Flamingo / Substance Kirill Grouchnikov. All Rights Reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are met:
7
* o Redistributions of source code must retain the above copyright notice,
8
* this list of conditions and the following disclaimer.
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.
14
* o Neither the name of Substance 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.
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.
30
package org.pushingpixels.substance.flamingo.ribbon.ui;
34
import javax.swing.CellRendererPane;
35
import javax.swing.JComponent;
36
import javax.swing.border.Border;
37
import javax.swing.border.CompoundBorder;
38
import javax.swing.plaf.ComponentUI;
40
import org.pushingpixels.flamingo.internal.ui.ribbon.appmenu.*;
41
import org.pushingpixels.substance.api.*;
42
import org.pushingpixels.substance.internal.painter.HighlightPainterUtils;
43
import org.pushingpixels.substance.internal.utils.SubstanceColorSchemeUtilities;
44
import org.pushingpixels.substance.internal.utils.SubstanceSizeUtils;
45
import org.pushingpixels.substance.internal.utils.border.SubstanceBorder;
48
* UI for {@link JRibbonApplicationMenuPopupPanel} components in
49
* <b>Substance</b> look and feel.
51
* @author Kirill Grouchnikov
53
public class SubstanceRibbonApplicationMenuPopupPanelUI extends
54
BasicRibbonApplicationMenuPopupPanelUI {
55
public static ComponentUI createUI(JComponent c) {
56
return new SubstanceRibbonApplicationMenuPopupPanelUI();
60
protected void installComponents() {
61
super.installComponents();
62
Border newBorder = new CompoundBorder(new SubstanceBorder(new Insets(2,
63
2, 2, 2)), new Border() {
65
public boolean isBorderOpaque() {
70
public Insets getBorderInsets(Component c) {
71
return new Insets(18, 0, 0, 0);
75
public void paintBorder(Component c, Graphics g, int x, int y,
76
int width, int height) {
77
SubstanceColorScheme bgFillScheme = SubstanceColorSchemeUtilities
79
ColorSchemeAssociationKind.HIGHLIGHT,
80
ComponentState.ENABLED);
81
SubstanceColorScheme bgBorderScheme = SubstanceColorSchemeUtilities
83
ColorSchemeAssociationKind.HIGHLIGHT_BORDER,
84
ComponentState.ENABLED);
85
HighlightPainterUtils.paintHighlight(g, null, c, new Rectangle(
86
x, y, width, height), 0.0f, null, bgFillScheme,
89
// draw the application menu button
90
JRibbonApplicationMenuButton rendererButton = new JRibbonApplicationMenuButton(
91
applicationMenuPopupPanel.getAppMenuButton()
94
JRibbonApplicationMenuButton appMenuButton = applicationMenuPopupPanel
96
rendererButton.applyComponentOrientation(appMenuButton
97
.getComponentOrientation());
99
rendererButton.setPopupKeyTip(appMenuButton.getPopupKeyTip());
100
rendererButton.setIcon(appMenuButton.getIcon());
101
rendererButton.getPopupModel().setRollover(false);
102
rendererButton.getPopupModel().setPressed(true);
103
rendererButton.getPopupModel().setArmed(true);
104
rendererButton.getPopupModel().setPopupShowing(true);
106
CellRendererPane buttonRendererPane = new CellRendererPane();
107
Point buttonLoc = appMenuButton.getLocationOnScreen();
108
Point panelLoc = c.getLocationOnScreen();
110
buttonRendererPane.setBounds(panelLoc.x - buttonLoc.x,
111
panelLoc.y - buttonLoc.y, appMenuButton.getWidth(),
112
appMenuButton.getHeight());
113
buttonRendererPane.paintComponent(g, rendererButton,
114
(Container) c, -panelLoc.x + buttonLoc.x, -panelLoc.y
115
+ buttonLoc.y, appMenuButton.getWidth(),
116
appMenuButton.getHeight(), true);
120
this.applicationMenuPopupPanel.setBorder(newBorder);
122
this.panelLevel2.setBorder(new Border() {
124
public Insets getBorderInsets(Component c) {
125
boolean ltr = c.getComponentOrientation().isLeftToRight();
126
return new Insets(0, ltr ? 1 : 0, 0, ltr ? 0 : 1);
130
public boolean isBorderOpaque() {
135
public void paintBorder(Component c, Graphics g, int x, int y,
136
int width, int height) {
137
int componentFontSize = SubstanceSizeUtils
138
.getComponentFontSize(null);
139
int borderDelta = (int) Math.floor(SubstanceSizeUtils
140
.getBorderStrokeWidth(componentFontSize) / 2.0);
141
float borderThickness = SubstanceSizeUtils
142
.getBorderStrokeWidth(componentFontSize);
144
Graphics2D g2d = (Graphics2D) g.create();
145
SubstanceColorScheme scheme = SubstanceColorSchemeUtilities
146
.getColorScheme(applicationMenuPopupPanel,
147
ColorSchemeAssociationKind.BORDER,
148
ComponentState.ENABLED);
149
g2d.setColor(scheme.getMidColor());
150
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
151
RenderingHints.VALUE_ANTIALIAS_ON);
152
g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
153
RenderingHints.VALUE_STROKE_NORMALIZE);
154
int joinKind = BasicStroke.JOIN_ROUND;
155
int capKind = BasicStroke.CAP_BUTT;
156
g2d.setStroke(new BasicStroke(borderThickness, capKind,
159
boolean ltr = applicationMenuPopupPanel
160
.getComponentOrientation().isLeftToRight();
161
int lineX = ltr ? borderDelta : c.getWidth() - borderDelta - 1;
162
g2d.drawLine(lineX, borderDelta, lineX, height - 1 - 2
168
this.mainPanel.setBorder(new SubstanceBorder());