This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 216175
Collapse All | Expand All

(-)a/core.io.ui/src/org/netbeans/core/io/ui/IOWindow.java (-2 / +3 lines)
Lines 74-79 Link Here
74
import org.openide.util.Utilities;
74
import org.openide.util.Utilities;
75
import org.openide.awt.MouseUtils;
75
import org.openide.awt.MouseUtils;
76
import org.openide.awt.TabbedPaneFactory;
76
import org.openide.awt.TabbedPaneFactory;
77
import org.openide.awt.ToolbarWithOverflow;
77
import org.openide.util.HelpCtx;
78
import org.openide.util.HelpCtx;
78
import org.openide.util.ImageUtilities;
79
import org.openide.util.ImageUtilities;
79
import org.openide.util.NbBundle;
80
import org.openide.util.NbBundle;
Lines 210-216 Link Here
210
            pane.addPropertyChangeListener(TabbedPaneFactory.PROP_CLOSE, this);
211
            pane.addPropertyChangeListener(TabbedPaneFactory.PROP_CLOSE, this);
211
            setFocusable(true);
212
            setFocusable(true);
212
213
213
            toolbar = new JToolBar();
214
            toolbar = new ToolbarWithOverflow();
214
            toolbar.setOrientation(JToolBar.VERTICAL);
215
            toolbar.setOrientation(JToolBar.VERTICAL);
215
            toolbar.setLayout(new BoxLayout(toolbar, BoxLayout.Y_AXIS));
216
            toolbar.setLayout(new BoxLayout(toolbar, BoxLayout.Y_AXIS));
216
            toolbar.setFloatable(false);
217
            toolbar.setFloatable(false);
Lines 507-513 Link Here
507
                    toolbar.add(buttons[i]);
508
                    toolbar.add(buttons[i]);
508
                }
509
                }
509
            }
510
            }
510
            toolbar.revalidate();
511
            toolbar.validate();
511
            toolbar.repaint();
512
            toolbar.repaint();
512
        }
513
        }
513
514
(-)a/core.windows/src/org/netbeans/core/windows/view/ui/toolbars/ToolbarConfiguration.java (+2 lines)
Lines 280-287 Link Here
280
                if (comps[j] instanceof JComponent) {
280
                if (comps[j] instanceof JComponent) {
281
                    if (smallToolbarIcons) {
281
                    if (smallToolbarIcons) {
282
                        ((JComponent) comps[j]).putClientProperty("PreferredIconSize",null); //NOI18N
282
                        ((JComponent) comps[j]).putClientProperty("PreferredIconSize",null); //NOI18N
283
                        tb.putClientProperty("PreferredIconSize",null); //NOI18N
283
                    } else {
284
                    } else {
284
                        ((JComponent) comps[j]).putClientProperty("PreferredIconSize",Integer.valueOf(24)); //NOI18N
285
                        ((JComponent) comps[j]).putClientProperty("PreferredIconSize",Integer.valueOf(24)); //NOI18N
286
                        tb.putClientProperty("PreferredIconSize",Integer.valueOf(24)); //NOI18N
285
                    }
287
                    }
286
                }
288
                }
287
                //TODO add icon shadow for mac l&f?
289
                //TODO add icon shadow for mac l&f?
(-)a/editor/src/org/netbeans/modules/editor/NbEditorToolBar.java (-1 / +2 lines)
Lines 97-102 Link Here
97
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
97
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
98
import org.netbeans.modules.editor.impl.ToolbarActionsProvider;
98
import org.netbeans.modules.editor.impl.ToolbarActionsProvider;
99
import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
99
import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
100
import org.openide.awt.ToolbarWithOverflow;
100
import org.openide.filesystems.FileChangeAdapter;
101
import org.openide.filesystems.FileChangeAdapter;
101
import org.openide.filesystems.FileChangeListener;
102
import org.openide.filesystems.FileChangeListener;
102
import org.openide.filesystems.FileEvent;
103
import org.openide.filesystems.FileEvent;
Lines 124-130 Link Here
124
 * @version 1.00
125
 * @version 1.00
125
 */
126
 */
126
127
127
/* package */ final class NbEditorToolBar extends JToolBar {
128
/* package */ final class NbEditorToolBar extends ToolbarWithOverflow {
128
129
129
    // -J-Dorg.netbeans.modules.editor.NbEditorToolBar.level=FINE
130
    // -J-Dorg.netbeans.modules.editor.NbEditorToolBar.level=FINE
130
    private static final Logger LOG = Logger.getLogger(NbEditorToolBar.class.getName());
131
    private static final Logger LOG = Logger.getLogger(NbEditorToolBar.class.getName());
(-)a/openide.awt/apichanges.xml (+14 lines)
Lines 50-55 Link Here
50
<apidef name="awt">AWT API</apidef>
50
<apidef name="awt">AWT API</apidef>
51
</apidefs>
51
</apidefs>
52
<changes>
52
<changes>
53
    <change id="ToolbarWithOverflow">
54
      <api name="awt"/>
55
      <summary>ToolbarWithOverflow class that adds an overflow button when the toolbar becomes too small to show all the available actions.</summary>
56
      <version major="7" minor="50"/>
57
      <date day="7" month="8" year="2012"/>
58
      <author login="theofanis"/>
59
      <compatibility addition="yes" binary="compatible" source="compatible" deprecation="no" semantic="compatible" modification="no" deletion="no"/>
60
      <description>
61
          ToolbarWithOverflow class is added. It can be used to add an overflow button 
62
          when the toolbar becomes too small to show all the available actions.
63
      </description>
64
      <class package="org.openide.awt" name="ToolbarWithOverflow"/>
65
      <issue number="216175"/>
66
    </change>
53
    <change id="CheckForUpdatesProvider">
67
    <change id="CheckForUpdatesProvider">
54
        <api name="awt"/>
68
        <api name="awt"/>
55
        <summary>Support for Check for Updates feature</summary>
69
        <summary>Support for Check for Updates feature</summary>
(-)a/openide.awt/manifest.mf (-1 / +1 lines)
Lines 2-6 Link Here
2
OpenIDE-Module: org.openide.awt
2
OpenIDE-Module: org.openide.awt
3
OpenIDE-Module-Localizing-Bundle: org/openide/awt/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/openide/awt/Bundle.properties
4
AutoUpdate-Essential-Module: true
4
AutoUpdate-Essential-Module: true
5
OpenIDE-Module-Specification-Version: 7.47
5
OpenIDE-Module-Specification-Version: 7.50
6
6
(-)a/openide.awt/src/org/openide/awt/ToolbarWithOverflow.java (+287 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.openide.awt;
43
44
import java.awt.Component;
45
import java.awt.Dimension;
46
import java.awt.event.ComponentAdapter;
47
import java.awt.event.ComponentEvent;
48
import java.awt.event.MouseAdapter;
49
import java.awt.event.MouseEvent;
50
import javax.swing.JButton;
51
import javax.swing.JComponent;
52
import javax.swing.JPopupMenu;
53
import javax.swing.JToolBar;
54
import org.openide.util.ImageUtilities;
55
56
/**
57
 * ToolbarWithOverflow provides a component which is useful for displaying commonly used
58
 * actions.  It adds an overflow button when the toolbar becomes too small to show all the
59
 * available actions.
60
 *
61
 * @author Th. Oikonomou
62
 * @since 7.50
63
 */
64
public class ToolbarWithOverflow extends JToolBar {
65
66
    private JButton overflowButton;
67
    private JPopupMenu popup;
68
    private JToolBar overflowToolbar;
69
    private int visibleButtons;
70
    private final String toolbarArrowHorizontal = "org/openide/awt/resources/toolbar_arrow_horizontal.png"; //NOI18N
71
    private final String toolbarArrowVertical = "org/openide/awt/resources/toolbar_arrow_vertical.png"; //NOI18N
72
    private final String PROP_PREF_ICON_SIZE = "PreferredIconSize"; //NOI18N
73
    private final String PROP_DRAGGER = "_toolbar_dragger_"; //NOI18N
74
75
    /**
76
     * Creates a new tool bar; orientation defaults to
77
     * <code>HORIZONTAL</code>.
78
     */
79
    public ToolbarWithOverflow() {
80
        this(HORIZONTAL);
81
    }
82
83
    /**
84
     * Creates a new tool bar with the specified
85
     * <code>orientation</code>. The
86
     * <code>orientation</code> must be either
87
     * <code>HORIZONTAL</code> or
88
     * <code>VERTICAL</code>.
89
     *
90
     * @param orientation the orientation desired
91
     */
92
    public ToolbarWithOverflow(int orientation) {
93
        this(null, orientation);
94
    }
95
96
    /**
97
     * Creates a new tool bar with the specified
98
     * <code>name</code>. The name is used as the title of the undocked tool
99
     * bar. The default orientation is
100
     * <code>HORIZONTAL</code>.
101
     *
102
     * @param name the name of the tool bar
103
     */
104
    public ToolbarWithOverflow(String name) {
105
        this(name, HORIZONTAL);
106
    }
107
108
    /**
109
     * Creates a new tool bar with a specified
110
     * <code>name</code> and
111
     * <code>orientation</code>. All other constructors call this constructor.
112
     * If
113
     * <code>orientation</code> is an invalid value, an exception will be
114
     * thrown.
115
     *
116
     * @param name the name of the tool bar
117
     * @param orientation the initial orientation -- it must be     *		either <code>HORIZONTAL</code> or <code>VERTICAL</code>
118
     * @exception IllegalArgumentException if orientation is neither
119
     * <code>HORIZONTAL</code> nor <code>VERTICAL</code>
120
     */
121
    public ToolbarWithOverflow(String name, int orientation) {
122
        super(name, orientation);
123
        setupOverflowButton();
124
        popup = new JPopupMenu();
125
        overflowToolbar = new JToolBar("overflowToolbar", orientation == HORIZONTAL ? VERTICAL : HORIZONTAL);
126
        overflowToolbar.setFloatable(false);
127
        addComponentListener(new ComponentAdapter() {
128
            @Override
129
            public void componentResized(ComponentEvent e) {
130
                maybeAddOverflow();
131
            }
132
        });
133
    }
134
    
135
    @Override
136
    public final Dimension getPreferredSize() {
137
        Component[] comps = getAllComponents();
138
        int width = 0;
139
        int height = 0;
140
        for (int i = 0; i < comps.length; i++) {
141
            Component comp = comps[i];
142
            width += getOrientation() == HORIZONTAL ? comp.getPreferredSize().width : comp.getPreferredSize().height;
143
            height = getOrientation() == HORIZONTAL ? comp.getPreferredSize().height : comp.getPreferredSize().width;
144
        }
145
        if(overflowToolbar.getComponentCount() > 0) {
146
            width += getOrientation() == HORIZONTAL ? overflowButton.getPreferredSize().width : overflowButton.getPreferredSize().height;
147
        }
148
        Dimension dim = getOrientation() == HORIZONTAL ? new Dimension(width, height) : new Dimension(height, width);
149
        return dim;        
150
    }
151
152
    @Override
153
    public void setOrientation(int o) {
154
        super.setOrientation(o);
155
        setupOverflowButton();
156
    }
157
    
158
    @Override
159
    public void removeAll() {
160
        super.removeAll();
161
        overflowToolbar.removeAll();
162
    }
163
164
    @Override
165
    public void validate() {
166
        computeVisibleButtons();
167
        if (visibleButtons == -1) {
168
            handleOverflowRemoval();
169
        } else {
170
            handleOverflowAddittion();
171
        }
172
        super.validate();
173
    }
174
    
175
    private void setupOverflowButton() {        
176
        overflowButton = new JButton(ImageUtilities.loadImageIcon(getOrientation() == HORIZONTAL ? toolbarArrowVertical : toolbarArrowHorizontal, false));
177
        overflowButton.addMouseListener(new MouseAdapter() {
178
            @Override
179
            public void mouseClicked(MouseEvent e) {
180
                int x = getOrientation() == HORIZONTAL ? 0 : overflowButton.getWidth();
181
                int y = getOrientation() == HORIZONTAL ? overflowButton.getHeight() : 0;
182
                popup.show(overflowButton, x, y);
183
            }
184
        });
185
    }
186
187
    /**
188
     * Determines if an overflow button should be added to or removed from the toolbar.
189
     */
190
    private void maybeAddOverflow() {
191
        validate();
192
        repaint();
193
    }
194
195
    private void computeVisibleButtons() {
196
        handleIconResize();
197
        Component[] comps = getAllComponents();
198
        int sizeSoFar = 0;
199
        int maxSize = getOrientation() == HORIZONTAL ? getWidth() : getHeight();
200
        int overflowButtonSize = getOrientation() == HORIZONTAL ? overflowButton.getPreferredSize().width : overflowButton.getPreferredSize().height;
201
        for (int i = 0; i < comps.length; i++) {
202
            Component comp = comps[i];
203
            sizeSoFar += getOrientation() == HORIZONTAL ? comp.getPreferredSize().width : comp.getPreferredSize().height;
204
            if (sizeSoFar > maxSize) {
205
                visibleButtons = i;
206
                break;
207
            } else {
208
                if (sizeSoFar + overflowButtonSize > maxSize && i + 1 != comps.length) {
209
                    visibleButtons = i;
210
                    break;
211
                } else {
212
                    visibleButtons = i + 1;
213
                }
214
            }
215
        }
216
        if(visibleButtons == 0 && comps.length > 0) {            
217
            if (comps[0] instanceof JComponent) {
218
                if (Boolean.TRUE.equals(((JComponent) comps[0]).getClientProperty(PROP_DRAGGER))) {
219
                    visibleButtons = 1;
220
                }
221
            }
222
        }
223
        if (visibleButtons == comps.length) {
224
            visibleButtons = -1;
225
        }
226
    }
227
228
    private void handleOverflowAddittion() {
229
        Component[] comps = getAllComponents();
230
        if (visibleButtons <= comps.length) {
231
            removeAll();
232
            overflowToolbar.setOrientation(getOrientation() == HORIZONTAL ? VERTICAL : HORIZONTAL);
233
            popup.removeAll();
234
235
            for (int i = 0; i < visibleButtons; i++) {
236
                add(comps[i]);
237
            }
238
            for (int i = visibleButtons; i < comps.length; i++) {
239
                overflowToolbar.add(comps[i]);
240
            }
241
            popup.add(overflowToolbar);
242
            add(overflowButton);
243
        }
244
    }
245
246
    private void handleOverflowRemoval() {
247
        if (overflowToolbar.getComponents().length > 0) {
248
            remove(overflowButton);
249
            handleIconResize();
250
            for (Component comp : overflowToolbar.getComponents()) {
251
                add(comp);
252
            }
253
            overflowToolbar.removeAll();
254
            popup.removeAll();
255
        }
256
    }
257
258
    private void handleIconResize() {
259
        for (Component comp : overflowToolbar.getComponents()) {
260
            boolean smallToolbarIcons = getClientProperty(PROP_PREF_ICON_SIZE) == null;
261
            if (smallToolbarIcons) {
262
                ((JComponent) comp).putClientProperty(PROP_PREF_ICON_SIZE, null);
263
            } else {
264
                ((JComponent) comp).putClientProperty(PROP_PREF_ICON_SIZE, Integer.valueOf(24));
265
            }
266
        }
267
    }
268
269
    private Component[] getAllComponents() {
270
        Component[] toolbarComps;
271
        Component[] overflowComps = overflowToolbar.getComponents();
272
        if (overflowComps.length == 0) {
273
            toolbarComps = getComponents();
274
        } else {
275
            if (getComponentCount() > 0) {
276
                toolbarComps = new Component[getComponents().length - 1];
277
                System.arraycopy(getComponents(), 0, toolbarComps, 0, toolbarComps.length);
278
            } else {
279
                toolbarComps = new Component[0];
280
            }
281
        }
282
        Component[] comps = new Component[toolbarComps.length + overflowComps.length];
283
        System.arraycopy(toolbarComps, 0, comps, 0, toolbarComps.length);
284
        System.arraycopy(overflowComps, 0, comps, toolbarComps.length, overflowComps.length);
285
        return comps;
286
    }
287
}
(-)a/openide.loaders/src/org/openide/awt/Toolbar.java (-1 / +1 lines)
Lines 79-85 Link Here
79
 *
79
 *
80
 * @author  David Peroutka, Libor Kramolis
80
 * @author  David Peroutka, Libor Kramolis
81
 */
81
 */
82
public class Toolbar extends JToolBar /*implemented by patchsuperclass MouseInputListener*/ {
82
public class Toolbar extends ToolbarWithOverflow /*implemented by patchsuperclass MouseInputListener*/ {
83
    /** Basic toolbar height.
83
    /** Basic toolbar height.
84
     @deprecated Use getBasicHeight instead. */
84
     @deprecated Use getBasicHeight instead. */
85
    @Deprecated
85
    @Deprecated

Return to bug 216175