2
* Copyright (c) 2005-2010 Flamingo 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 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.flamingo.internal.ui.ribbon.appmenu;
33
import java.beans.PropertyChangeEvent;
35
import javax.swing.UIManager;
37
import org.pushingpixels.flamingo.api.common.*;
38
import org.pushingpixels.flamingo.api.common.icon.EmptyResizableIcon;
39
import org.pushingpixels.flamingo.api.common.icon.ResizableIcon;
40
import org.pushingpixels.flamingo.api.ribbon.JRibbon;
41
import org.pushingpixels.flamingo.api.ribbon.JRibbonFrame;
42
import org.pushingpixels.flamingo.internal.ui.common.BasicCommandButtonUI;
45
* The main application menu button for {@link JRibbon} component placed in a
46
* {@link JRibbonFrame}. This class is for internal use only and is intended for
47
* look-and-feel layer customization.
49
* @author Kirill Grouchnikov
51
@SuppressWarnings("serial")
52
public class JRibbonApplicationMenuButton extends JCommandButton {
54
/** The application ribbon this menu button is for */
55
private JRibbon ribbon;
56
/** The UI class ID string. */
57
public static final String uiClassID = "RibbonApplicationMenuButtonUI";
58
static final int APP_BUTTON_SIZE = Integer.getInteger(
59
"peacock.appButtonSize", 24);
61
private final static CommandButtonDisplayState APP_MENU_BUTTON_STATE = new CommandButtonDisplayState(
62
"Ribbon Application Menu Button", APP_BUTTON_SIZE) {
64
public org.pushingpixels.flamingo.api.common.CommandButtonLayoutManager createLayoutManager(
65
org.pushingpixels.flamingo.api.common.AbstractCommandButton commandButton) {
66
return new CommandButtonLayoutManager() {
68
public int getPreferredIconSize() {
69
return APP_BUTTON_SIZE;
73
public CommandButtonLayoutInfo getLayoutInfo(
74
AbstractCommandButton commandButton, Graphics g) {
75
CommandButtonLayoutInfo result = new CommandButtonLayoutInfo();
76
result.actionClickArea = new Rectangle(0, 0, 0, 0);
77
result.popupClickArea = new Rectangle(0, 0, commandButton
78
.getWidth(), commandButton.getHeight());
79
result.popupActionRect = new Rectangle(0, 0, 0, 0);
80
ResizableIcon icon = commandButton.getIcon();
82
result.iconRect = new Rectangle((commandButton
83
.getWidth() - icon.getIconWidth()) / 2,
84
(commandButton.getHeight() - icon
85
.getIconHeight()) / 2, icon
86
.getIconWidth(), icon.getIconHeight());
88
result.isTextInActionArea = false;
93
public Dimension getPreferredSize(
94
AbstractCommandButton commandButton) {
95
return new Dimension(40, 40);
99
public void propertyChange(PropertyChangeEvent evt) {
103
public Point getKeyTipAnchorCenterPoint(
104
AbstractCommandButton commandButton) {
106
return new Point(commandButton.getWidth() / 2,
107
commandButton.getHeight() / 2);
114
* Constructs a <code>JRibbonApplicationMenuButton</code> specifying the
115
* ribbon component it belongs to. If the <code>ribbon</code>'s application
116
* icon is <code>null</code> an {@link EmptyResizableIcon} is used for this
119
* A <code>JRibbonApplicationMenuButton</code> is a
120
* {@link org.pushingpixels.flamingo.api.common.JCommandButton.CommandButtonKind#POPUP_ONLY} button and uses a custom button
121
* display state (see {@link #APP_MENU_BUTTON_STATE}).
124
* the ribbon component
126
public JRibbonApplicationMenuButton(JRibbon ribbon) {
127
super("", (ribbon != null && ribbon.getApplicationIcon() != null) ? ribbon
128
.getApplicationIcon() : new EmptyResizableIcon(16));
129
this.setCommandButtonKind(CommandButtonKind.POPUP_ONLY);
130
this.setDisplayState(APP_MENU_BUTTON_STATE);
132
// update the UI now that the ribbon has been set
139
* @see javax.swing.JButton#updateUI()
142
public void updateUI() {
143
if (UIManager.get(getUIClassID()) != null) {
144
setUI((BasicCommandButtonUI) UIManager.getUI(this));
146
setUI(BasicRibbonApplicationMenuButtonUI.createUI(this));
153
* @see javax.swing.JButton#getUIClassID()
156
public String getUIClassID() {
161
* Returns a reference to the application ribbon this application menu
164
* @return the application ribbon
166
public synchronized JRibbon getRibbon() {
171
* Sets the ribbon this application menu button is created for.
174
* the application ribbon
176
public synchronized void setRibbon(JRibbon ribbon) {
177
this.ribbon = ribbon;