~ubuntu-branches/debian/stretch/insubstantial/stretch

« back to all changes in this revision

Viewing changes to flamingo/src/main/java/org/pushingpixels/flamingo/internal/ui/ribbon/appmenu/JRibbonApplicationMenuButton.java

  • Committer: Package Import Robot
  • Author(s): Felix Natter
  • Date: 2016-01-18 20:58:45 UTC
  • Revision ID: package-import@ubuntu.com-20160118205845-crbmrkda61qsi5qa
Tags: upstream-7.3+dfsg2
ImportĀ upstreamĀ versionĀ 7.3+dfsg2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2005-2010 Flamingo 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 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.flamingo.internal.ui.ribbon.appmenu;
 
31
 
 
32
import java.awt.*;
 
33
import java.beans.PropertyChangeEvent;
 
34
 
 
35
import javax.swing.UIManager;
 
36
 
 
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;
 
43
 
 
44
/**
 
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.
 
48
 * 
 
49
 * @author Kirill Grouchnikov
 
50
 */
 
51
@SuppressWarnings("serial")
 
52
public class JRibbonApplicationMenuButton extends JCommandButton {
 
53
 
 
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);
 
60
 
 
61
        private final static CommandButtonDisplayState APP_MENU_BUTTON_STATE = new CommandButtonDisplayState(
 
62
                        "Ribbon Application Menu Button", APP_BUTTON_SIZE) {
 
63
                @Override
 
64
                public org.pushingpixels.flamingo.api.common.CommandButtonLayoutManager createLayoutManager(
 
65
                                org.pushingpixels.flamingo.api.common.AbstractCommandButton commandButton) {
 
66
                        return new CommandButtonLayoutManager() {
 
67
                                @Override
 
68
                                public int getPreferredIconSize() {
 
69
                                        return APP_BUTTON_SIZE;
 
70
                                }
 
71
 
 
72
                                @Override
 
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();
 
81
                                        if (icon != null) {
 
82
                                                result.iconRect = new Rectangle((commandButton
 
83
                                                                .getWidth() - icon.getIconWidth()) / 2,
 
84
                                                                (commandButton.getHeight() - icon
 
85
                                                                                .getIconHeight()) / 2, icon
 
86
                                                                                .getIconWidth(), icon.getIconHeight());
 
87
                                        }
 
88
                                        result.isTextInActionArea = false;
 
89
                                        return result;
 
90
                                }
 
91
 
 
92
                                @Override
 
93
                                public Dimension getPreferredSize(
 
94
                                                AbstractCommandButton commandButton) {
 
95
                                        return new Dimension(40, 40);
 
96
                                }
 
97
 
 
98
                                @Override
 
99
                                public void propertyChange(PropertyChangeEvent evt) {
 
100
                                }
 
101
 
 
102
                                @Override
 
103
                                public Point getKeyTipAnchorCenterPoint(
 
104
                                                AbstractCommandButton commandButton) {
 
105
                                        // dead center
 
106
                                        return new Point(commandButton.getWidth() / 2,
 
107
                                                        commandButton.getHeight() / 2);
 
108
                                }
 
109
                        };
 
110
                }
 
111
        };
 
112
 
 
113
        /**
 
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
 
117
         * button.
 
118
         * <p>
 
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}).
 
122
         * 
 
123
         * @param ribbon
 
124
         *            the ribbon component
 
125
         */
 
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);
 
131
                setRibbon(ribbon);
 
132
                // update the UI now that the ribbon has been set
 
133
                updateUI();
 
134
        }
 
135
 
 
136
        /*
 
137
         * (non-Javadoc)
 
138
         * 
 
139
         * @see javax.swing.JButton#updateUI()
 
140
         */
 
141
        @Override
 
142
        public void updateUI() {
 
143
                if (UIManager.get(getUIClassID()) != null) {
 
144
                        setUI((BasicCommandButtonUI) UIManager.getUI(this));
 
145
                } else {
 
146
                        setUI(BasicRibbonApplicationMenuButtonUI.createUI(this));
 
147
                }
 
148
        }
 
149
 
 
150
        /*
 
151
         * (non-Javadoc)
 
152
         * 
 
153
         * @see javax.swing.JButton#getUIClassID()
 
154
         */
 
155
        @Override
 
156
        public String getUIClassID() {
 
157
                return uiClassID;
 
158
        }
 
159
 
 
160
        /**
 
161
         * Returns a reference to the application ribbon this application menu
 
162
         * button is for.
 
163
         * 
 
164
         * @return the application ribbon
 
165
         */
 
166
        public synchronized JRibbon getRibbon() {
 
167
                return this.ribbon;
 
168
        }
 
169
 
 
170
        /**
 
171
         * Sets the ribbon this application menu button is created for.
 
172
         * 
 
173
         * @param ribbon
 
174
         *            the application ribbon
 
175
         */
 
176
        public synchronized void setRibbon(JRibbon ribbon) {
 
177
                this.ribbon = ribbon;
 
178
        }
 
179
 
 
180
}