| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 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 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 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 |
|
| 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 |
} |