Debian Codegraph @

substance-flamingo/src/main/java/org/pushingpixels/substance/flamingo/ribbon/ui/SubstanceRibbonRootPaneUI.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 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 * UI delegate for root panes of {@link JRibbonFrame} under Substance
48 * look-and-feel.
49 *
50 * @author Kirill Grouchnikov
51 */
52 public class SubstanceRibbonRootPaneUI extends SubstanceRootPaneUI {
53 /**
54 * Application menu button of this root pane.
55 */
56 protected JRibbonApplicationMenuButton applicationMenuButton;
57
58 /**
59 * Hierarchy listener to track the creation of application menu button.
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 * (non-Javadoc)
103 *
104 * @see
105 * javax.swing.plaf.basic.BasicRootPaneUI#uninstallComponents(javax.swing
106 * .JRootPane)
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 * (non-Javadoc)
123 *
124 * @see
125 * org.jvnet.substance.SubstanceRootPaneUI#createTitlePane(javax.swing.JRootPane
126 * )
127 */
128 @Override
129 protected JComponent createTitlePane(JRootPane root) {
130 return new SubstanceRibbonFrameTitlePane(root, this);
131 }
132
133 /**
134 * Custom layout manager for the {@link JRibbonRootPane} under Substance.
135 *
136 * @author Kirill Grouchnikov
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 * Synchronizes the rich tooltip and popup keytip of the application menu
173 * button.
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 * Creates the application menu button.
195 *
196 * @param root
197 * Root pane.
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 }