Debian Codegraph @

substance-flamingo/src/main/java/org/pushingpixels/substance/flamingo/ribbon/ui/SubstanceRibbonApplicationMenuPopupPanelUI.java

raw symbols SCIP
1 /*
2 * Copyright (c) 2005-2010 Substance 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 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.
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.ribbon.ui;
31
32 import java.awt.*;
33
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;
39
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;
46
47 /**
48 * UI for {@link JRibbonApplicationMenuPopupPanel} components in
49 * <b>Substance</b> look and feel.
50 *
51 * @author Kirill Grouchnikov
52 */
53 public class SubstanceRibbonApplicationMenuPopupPanelUI extends
54 BasicRibbonApplicationMenuPopupPanelUI {
55 public static ComponentUI createUI(JComponent c) {
56 return new SubstanceRibbonApplicationMenuPopupPanelUI();
57 }
58
59 @Override
60 protected void installComponents() {
61 super.installComponents();
62 Border newBorder = new CompoundBorder(new SubstanceBorder(new Insets(2,
63 2, 2, 2)), new Border() {
64 @Override
65 public boolean isBorderOpaque() {
66 return true;
67 }
68
69 @Override
70 public Insets getBorderInsets(Component c) {
71 return new Insets(18, 0, 0, 0);
72 }
73
74 @Override
75 public void paintBorder(Component c, Graphics g, int x, int y,
76 int width, int height) {
77 SubstanceColorScheme bgFillScheme = SubstanceColorSchemeUtilities
78 .getColorScheme(c,
79 ColorSchemeAssociationKind.HIGHLIGHT,
80 ComponentState.ENABLED);
81 SubstanceColorScheme bgBorderScheme = SubstanceColorSchemeUtilities
82 .getColorScheme(c,
83 ColorSchemeAssociationKind.HIGHLIGHT_BORDER,
84 ComponentState.ENABLED);
85 HighlightPainterUtils.paintHighlight(g, null, c, new Rectangle(
86 x, y, width, height), 0.0f, null, bgFillScheme,
87 bgBorderScheme);
88
89 // draw the application menu button
90 JRibbonApplicationMenuButton rendererButton = new JRibbonApplicationMenuButton(
91 applicationMenuPopupPanel.getAppMenuButton()
92 .getRibbon());
93
94 JRibbonApplicationMenuButton appMenuButton = applicationMenuPopupPanel
95 .getAppMenuButton();
96 rendererButton.applyComponentOrientation(appMenuButton
97 .getComponentOrientation());
98
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);
105
106 CellRendererPane buttonRendererPane = new CellRendererPane();
107 Point buttonLoc = appMenuButton.getLocationOnScreen();
108 Point panelLoc = c.getLocationOnScreen();
109
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);
117 }
118
119 });
120 this.applicationMenuPopupPanel.setBorder(newBorder);
121
122 this.panelLevel2.setBorder(new Border() {
123 @Override
124 public Insets getBorderInsets(Component c) {
125 boolean ltr = c.getComponentOrientation().isLeftToRight();
126 return new Insets(0, ltr ? 1 : 0, 0, ltr ? 0 : 1);
127 }
128
129 @Override
130 public boolean isBorderOpaque() {
131 return true;
132 }
133
134 @Override
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);
143
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,
157 joinKind));
158
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
163 * borderDelta);
164
165 g2d.dispose();
166 }
167 });
168 this.mainPanel.setBorder(new SubstanceBorder());
169 }
170 }