| 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 |
import java.awt.event.HierarchyEvent; |
| 34 |
import java.awt.event.HierarchyListener; |
| 35 |
|
| 36 |
import javax.swing.*; |
| 37 |
import javax.swing.plaf.ComponentUI; |
| 38 |
|
| 39 |
import org.pushingpixels.flamingo.api.ribbon.JRibbon; |
| 40 |
import org.pushingpixels.flamingo.api.ribbon.JRibbonFrame; |
| 41 |
import org.pushingpixels.flamingo.internal.ui.ribbon.JRibbonRootPane; |
| 42 |
import org.pushingpixels.flamingo.internal.ui.ribbon.appmenu.JRibbonApplicationMenuButton; |
| 43 |
import org.pushingpixels.flamingo.internal.utils.FlamingoUtilities; |
| 44 |
import org.pushingpixels.substance.internal.ui.SubstanceRootPaneUI; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
public class SubstanceRibbonRootPaneUI extends SubstanceRootPaneUI { |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
protected JRibbonApplicationMenuButton applicationMenuButton; |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
protected HierarchyListener substanceRibbonHierarchyListener; |
| 62 |
|
| 63 |
public static ComponentUI createUI(JComponent c) { |
| 64 |
return new SubstanceRibbonRootPaneUI(); |
| 65 |
} |
| 66 |
|
| 67 |
@Override |
| 68 |
protected void installComponents(JRootPane root) { |
| 69 |
super.installComponents(root); |
| 70 |
|
| 71 |
this.createAppMenuButton(root); |
| 72 |
} |
| 73 |
|
| 74 |
@Override |
| 75 |
protected void installListeners(final JRootPane root) { |
| 76 |
super.installListeners(root); |
| 77 |
|
| 78 |
this.substanceRibbonHierarchyListener = new HierarchyListener() { |
| 79 |
@Override |
| 80 |
public void hierarchyChanged(HierarchyEvent e) { |
| 81 |
SwingUtilities.invokeLater(new Runnable() { |
| 82 |
@Override |
| 83 |
public void run() { |
| 84 |
createAppMenuButton(root); |
| 85 |
} |
| 86 |
}); |
| 87 |
} |
| 88 |
}; |
| 89 |
|
| 90 |
root.addHierarchyListener(this.substanceRibbonHierarchyListener); |
| 91 |
} |
| 92 |
|
| 93 |
@Override |
| 94 |
protected void uninstallListeners(JRootPane root) { |
| 95 |
root.removeHierarchyListener(this.substanceRibbonHierarchyListener); |
| 96 |
this.substanceRibbonHierarchyListener = null; |
| 97 |
|
| 98 |
super.uninstallListeners(root); |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
@Override |
| 109 |
protected void uninstallComponents(JRootPane root) { |
| 110 |
root.getLayeredPane().remove(this.applicationMenuButton); |
| 111 |
this.applicationMenuButton = null; |
| 112 |
|
| 113 |
super.uninstallComponents(root); |
| 114 |
} |
| 115 |
|
| 116 |
@Override |
| 117 |
protected LayoutManager createLayoutManager() { |
| 118 |
return new SubstanceRibbonRootLayout(); |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
@Override |
| 129 |
protected JComponent createTitlePane(JRootPane root) { |
| 130 |
return new SubstanceRibbonFrameTitlePane(root, this); |
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
protected class SubstanceRibbonRootLayout extends SubstanceRootLayout { |
| 139 |
@Override |
| 140 |
public void layoutContainer(Container parent) { |
| 141 |
super.layoutContainer(parent); |
| 142 |
|
| 143 |
if (applicationMenuButton == null) |
| 144 |
return; |
| 145 |
|
| 146 |
JRibbonRootPane ribbonRootPane = (JRibbonRootPane) root; |
| 147 |
JRibbonFrame ribbonFrame = (JRibbonFrame) ribbonRootPane |
| 148 |
.getParent(); |
| 149 |
boolean ltr = ribbonFrame.getRibbon().getComponentOrientation() |
| 150 |
.isLeftToRight(); |
| 151 |
SubstanceRibbonUI ribbonUI = (SubstanceRibbonUI) ribbonFrame |
| 152 |
.getRibbon().getUI(); |
| 153 |
int appMenuButtonSize = getTitlePane().getHeight() |
| 154 |
+ ribbonUI.getTaskToggleButtonHeight(); |
| 155 |
applicationMenuButton.setVisible(ribbonFrame.getRibbon() |
| 156 |
.getApplicationMenu() != null); |
| 157 |
if (ltr) { |
| 158 |
applicationMenuButton.setBounds(3, 3, appMenuButtonSize - 6, |
| 159 |
appMenuButtonSize - 6); |
| 160 |
} else { |
| 161 |
applicationMenuButton.setBounds(parent.getWidth() - 3 |
| 162 |
- appMenuButtonSize, 3, appMenuButtonSize - 6, |
| 163 |
appMenuButtonSize - 6); |
| 164 |
} |
| 165 |
syncApplicationMenuTips(); |
| 166 |
getTitlePane().doLayout(); |
| 167 |
ribbonFrame.getRibbon().doLayout(); |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
public void syncApplicationMenuTips() { |
| 176 |
if ((this.applicationMenuButton == null) |
| 177 |
|| !this.applicationMenuButton.isVisible()) |
| 178 |
return; |
| 179 |
|
| 180 |
JRibbonRootPane ribbonRootPane = (JRibbonRootPane) root; |
| 181 |
if (ribbonRootPane == null) |
| 182 |
return; |
| 183 |
JRibbonFrame ribbonFrame = (JRibbonFrame) ribbonRootPane.getParent(); |
| 184 |
JRibbon ribbon = ribbonFrame.getRibbon(); |
| 185 |
if (ribbon != null) { |
| 186 |
this.applicationMenuButton.setPopupRichTooltip(ribbon |
| 187 |
.getApplicationMenuRichTooltip()); |
| 188 |
this.applicationMenuButton.setPopupKeyTip(ribbon |
| 189 |
.getApplicationMenuKeyTip()); |
| 190 |
} |
| 191 |
} |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
private void createAppMenuButton(JRootPane root) { |
| 200 |
Window windowAncestor = SwingUtilities.getWindowAncestor(root); |
| 201 |
if ((applicationMenuButton == null) |
| 202 |
&& (windowAncestor instanceof JRibbonFrame)) { |
| 203 |
JRibbonFrame ribbonFrame = (JRibbonFrame) windowAncestor; |
| 204 |
applicationMenuButton = new JRibbonApplicationMenuButton( |
| 205 |
ribbonFrame.getRibbon()); |
| 206 |
applicationMenuButton.applyComponentOrientation(ribbonFrame |
| 207 |
.getRibbon().getComponentOrientation()); |
| 208 |
root.getLayeredPane().add(applicationMenuButton); |
| 209 |
root.getLayeredPane().setLayer(applicationMenuButton, |
| 210 |
JRibbonRootPane.RIBBON_SPECIAL_LAYER); |
| 211 |
FlamingoUtilities.updateRibbonFrameIconImages(ribbonFrame); |
| 212 |
JComponent titlePane = getTitlePane(); |
| 213 |
if (titlePane != null) { |
| 214 |
getTitlePane().doLayout(); |
| 215 |
} |
| 216 |
} |
| 217 |
} |
| 218 |
} |