jdk/src/share/classes/javax/swing/plaf/synth/SynthToolBarUI.java
author peterz
Thu, 28 Jan 2010 17:06:54 +0300
changeset 4848 ffcc849b9351
parent 4394 92a8ec883f5d
child 4962 8e27c99de375
permissions -rw-r--r--
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods Reviewed-by: rupashka
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2002-2006 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing.plaf.synth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    28
import java.awt.Component;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    29
import java.awt.Container;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    30
import java.awt.Dimension;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    31
import java.awt.Graphics;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    32
import java.awt.Insets;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    33
import java.awt.LayoutManager;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    34
import java.awt.Rectangle;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    35
import java.beans.PropertyChangeEvent;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    36
import java.beans.PropertyChangeListener;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    37
import javax.swing.Box;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    38
import javax.swing.Icon;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    39
import javax.swing.JComponent;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    40
import javax.swing.JSeparator;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    41
import javax.swing.JToolBar;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    42
import javax.swing.plaf.ComponentUI;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.swing.plaf.basic.BasicToolBarUI;
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    44
import sun.swing.plaf.synth.SynthIcon;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
/**
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    47
 * Provides the Synth L&F UI delegate for
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    48
 * {@link javax.swing.JToolBar}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    50
 * @since 1.7
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    52
public class SynthToolBarUI extends BasicToolBarUI
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    53
                            implements PropertyChangeListener, SynthUI {
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    54
    private Icon handleIcon = null;
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    55
    private Rectangle contentRect = new Rectangle();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private SynthStyle style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private SynthStyle contentStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private SynthStyle dragWindowStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    61
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    62
     * Creates a new UI object for the given component.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    63
     *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    64
     * @param c component to create UI object for
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    65
     * @return the UI object
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    66
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public static ComponentUI createUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        return new SynthToolBarUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    71
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    72
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    73
     */
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    74
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    protected void installDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        toolBar.setLayout(createLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        updateStyle(toolBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    80
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    81
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    82
     */
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    83
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    protected void installListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        super.installListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        toolBar.addPropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    89
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    90
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    91
     */
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    92
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    protected void uninstallListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        super.uninstallListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        toolBar.removePropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private void updateStyle(JToolBar c) {
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    99
        SynthContext context = getContext(
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   100
                c, Region.TOOL_BAR_CONTENT, null, ENABLED);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   101
        contentStyle = SynthLookAndFeel.updateStyle(context, this);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   102
        context.dispose();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   103
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   104
        context = getContext(c, Region.TOOL_BAR_DRAG_WINDOW, null, ENABLED);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   105
        dragWindowStyle = SynthLookAndFeel.updateStyle(context, this);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   106
        context.dispose();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   107
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   108
        context = getContext(c, ENABLED);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        SynthStyle oldStyle = style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        style = SynthLookAndFeel.updateStyle(context, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        if (oldStyle != style) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            handleIcon =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                style.getIcon(context, "ToolBar.handleIcon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            if (oldStyle != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                uninstallKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                installKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   123
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   124
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   125
     */
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   126
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    protected void uninstallDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        SynthContext context = getContext(toolBar, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        style.uninstallDefaults(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        style = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        handleIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   136
        context = getContext(toolBar, Region.TOOL_BAR_CONTENT,
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   137
                             contentStyle, ENABLED);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        contentStyle.uninstallDefaults(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        contentStyle = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   142
        context = getContext(toolBar, Region.TOOL_BAR_DRAG_WINDOW,
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   143
                             dragWindowStyle, ENABLED);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        dragWindowStyle.uninstallDefaults(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        dragWindowStyle = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        toolBar.setLayout(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   151
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   152
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   153
     */
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   154
    @Override
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   155
    protected void installComponents() {}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   157
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   158
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   159
     */
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   160
    @Override
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   161
    protected void uninstallComponents() {}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   163
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   164
     * Creates a {@code LayoutManager} to use with the toolbar.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   165
     *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   166
     * @return a {@code LayoutManager} instance
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   167
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    protected LayoutManager createLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        return new SynthToolBarLayoutManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   172
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   173
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   174
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   175
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public SynthContext getContext(JComponent c) {
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   177
        return getContext(c, SynthLookAndFeel.getComponentState(c));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    private SynthContext getContext(JComponent c, int state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        return SynthContext.getContext(SynthContext.class, c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                    SynthLookAndFeel.getRegion(c), style, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   185
    private SynthContext getContext(JComponent c, Region region, SynthStyle style) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   186
        return SynthContext.getContext(SynthContext.class, c, region,
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   187
                                       style, getComponentState(c, region));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   190
    private SynthContext getContext(JComponent c, Region region,
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   191
                                    SynthStyle style, int state) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        return SynthContext.getContext(SynthContext.class, c, region,
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   193
                                       style, state);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    private int getComponentState(JComponent c, Region region) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        return SynthLookAndFeel.getComponentState(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   200
    /**
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   201
     * Notifies this UI delegate to repaint the specified component.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   202
     * This method paints the component background, then calls
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   203
     * the {@link #paint(SynthContext,Graphics)} method.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   204
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   205
     * <p>In general, this method does not need to be overridden by subclasses.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   206
     * All Look and Feel rendering code should reside in the {@code paint} method.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   207
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   208
     * @param g the {@code Graphics} object used for painting
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   209
     * @param c the component being painted
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   210
     * @see #paint(SynthContext,Graphics)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   211
     */
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   212
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    public void update(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        SynthLookAndFeel.update(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        context.getPainter().paintToolBarBackground(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                          g, 0, 0, c.getWidth(), c.getHeight(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                          toolBar.getOrientation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        paint(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   224
    /**
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   225
     * Paints the specified component according to the Look and Feel.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   226
     * <p>This method is not used by Synth Look and Feel.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   227
     * Painting is handled by the {@link #paint(SynthContext,Graphics)} method.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   228
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   229
     * @param g the {@code Graphics} object used for painting
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   230
     * @param c the component being painted
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   231
     * @see #paint(SynthContext,Graphics)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   232
     */
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   233
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    public void paint(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        paint(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   241
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   242
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   243
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   244
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    public void paintBorder(SynthContext context, Graphics g, int x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                            int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        context.getPainter().paintToolBarBorder(context, g, x, y, w, h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                                                toolBar.getOrientation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    // Overloaded to do nothing so we can share listeners.
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   252
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   253
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   254
     */
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   255
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    protected void setBorderToNonRollover(Component c) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    // Overloaded to do nothing so we can share listeners.
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   259
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   260
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   261
     */
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   262
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    protected void setBorderToRollover(Component c) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    // Overloaded to do nothing so we can share listeners.
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   266
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   267
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   268
     */
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   269
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    protected void setBorderToNormal(Component c) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   272
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   273
     * Paints the toolbar.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   274
     *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   275
     * @param context context for the component being painted
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   276
     * @param g the {@code Graphics} object used for painting
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   277
     * @see #update(Graphics,JComponent)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   278
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    protected void paint(SynthContext context, Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        if (handleIcon != null && toolBar.isFloatable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            int startX = toolBar.getComponentOrientation().isLeftToRight() ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                0 : toolBar.getWidth() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                    SynthIcon.getIconWidth(handleIcon, context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            SynthIcon.paintIcon(handleIcon, context, g, startX, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                    SynthIcon.getIconWidth(handleIcon, context),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                    SynthIcon.getIconHeight(handleIcon, context));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   289
        SynthContext subcontext = getContext(
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   290
                toolBar, Region.TOOL_BAR_CONTENT, contentStyle);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        paintContent(subcontext, g, contentRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        subcontext.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   295
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   296
     * Paints the toolbar content.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   297
     *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   298
     * @param context context for the component being painted
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   299
     * @param g {@code Graphics} object used for painting
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   300
     * @param bounds bounding box for the toolbar
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   301
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   302
    protected void paintContent(SynthContext context, Graphics g,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            Rectangle bounds) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        SynthLookAndFeel.updateSubregion(context, g, bounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        context.getPainter().paintToolBarContentBackground(context, g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                             bounds.x, bounds.y, bounds.width, bounds.height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                             toolBar.getOrientation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        context.getPainter().paintToolBarContentBorder(context, g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                             bounds.x, bounds.y, bounds.width, bounds.height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                             toolBar.getOrientation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   313
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   314
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   315
     */
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   316
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    protected void paintDragWindow(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        int w = dragWindow.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        int h = dragWindow.getHeight();
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   320
        SynthContext context = getContext(
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   321
                toolBar, Region.TOOL_BAR_DRAG_WINDOW, dragWindowStyle);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   322
        SynthLookAndFeel.updateSubregion(
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   323
                context, g, new Rectangle(0, 0, w, h));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        context.getPainter().paintToolBarDragWindowBackground(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                                                           g, 0, 0, w, h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                                                           dragWindow.getOrientation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        context.getPainter().paintToolBarDragWindowBorder(context, g, 0, 0, w, h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                                                          dragWindow.getOrientation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    // PropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   336
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   337
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   338
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   339
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        if (SynthLookAndFeel.shouldUpdateStyle(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            updateStyle((JToolBar)e.getSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    class SynthToolBarLayoutManager implements LayoutManager {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        public void addLayoutComponent(String name, Component comp) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        public void removeLayoutComponent(Component comp) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        public Dimension minimumLayoutSize(Container parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            JToolBar tb = (JToolBar)parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            Insets insets = tb.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            Dimension dim = new Dimension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            SynthContext context = getContext(tb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            if (tb.getOrientation() == JToolBar.HORIZONTAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                dim.width = tb.isFloatable() ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                    SynthIcon.getIconWidth(handleIcon, context) : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                Dimension compDim;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                for (int i = 0; i < tb.getComponentCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                    compDim = tb.getComponent(i).getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                    dim.width += compDim.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                    dim.height = Math.max(dim.height, compDim.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                dim.height = tb.isFloatable() ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                    SynthIcon.getIconHeight(handleIcon, context) : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                Dimension compDim;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                for (int i = 0; i < tb.getComponentCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                    compDim = tb.getComponent(i).getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                    dim.width = Math.max(dim.width, compDim.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                    dim.height += compDim.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            dim.width += insets.left + insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            dim.height += insets.top + insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            return dim;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        public Dimension preferredLayoutSize(Container parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            JToolBar tb = (JToolBar)parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            Insets insets = tb.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            Dimension dim = new Dimension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            SynthContext context = getContext(tb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            if (tb.getOrientation() == JToolBar.HORIZONTAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                dim.width = tb.isFloatable() ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                    SynthIcon.getIconWidth(handleIcon, context) : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                Dimension compDim;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                for (int i = 0; i < tb.getComponentCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                    compDim = tb.getComponent(i).getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                    dim.width += compDim.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                    dim.height = Math.max(dim.height, compDim.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                dim.height = tb.isFloatable() ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                    SynthIcon.getIconHeight(handleIcon, context) : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                Dimension compDim;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                for (int i = 0; i < tb.getComponentCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                    compDim = tb.getComponent(i).getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                    dim.width = Math.max(dim.width, compDim.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                    dim.height += compDim.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            dim.width += insets.left + insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            dim.height += insets.top + insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            return dim;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        public void layoutContainer(Container parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            JToolBar tb = (JToolBar)parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            Insets insets = tb.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            boolean ltr = tb.getComponentOrientation().isLeftToRight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            SynthContext context = getContext(tb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            Component c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            Dimension d;
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   424
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   425
            // JToolBar by default uses a somewhat modified BoxLayout as
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   426
            // its layout manager. For compatibility reasons, we want to
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   427
            // support Box "glue" as a way to move things around on the
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   428
            // toolbar. "glue" is represented in BoxLayout as a Box.Filler
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   429
            // with a minimum and preferred size of (0,0).
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   430
            // So what we do here is find the number of such glue fillers
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   431
            // and figure out how much space should be allocated to them.
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   432
            int glueCount = 0;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   433
            for (int i=0; i<tb.getComponentCount(); i++) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   434
                if (isGlue(tb.getComponent(i))) glueCount++;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   435
            }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   436
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            if (tb.getOrientation() == JToolBar.HORIZONTAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                int handleWidth = tb.isFloatable() ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                    SynthIcon.getIconWidth(handleIcon, context) : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                // Note: contentRect does not take insets into account
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                // since it is used for determining the bounds that are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                // passed to paintToolBarContentBackground().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                contentRect.x = ltr ? handleWidth : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                contentRect.y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                contentRect.width = tb.getWidth() - handleWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                contentRect.height = tb.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                // However, we do take the insets into account here for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                // the purposes of laying out the toolbar child components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                int x = ltr ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                    handleWidth + insets.left :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                    tb.getWidth() - handleWidth - insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                int baseY = insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                int baseH = tb.getHeight() - insets.top - insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   457
                // we need to get the minimum width for laying things out
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   458
                // so that we can calculate how much empty space needs to
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   459
                // be distributed among the "glue", if any
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   460
                int extraSpacePerGlue = 0;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   461
                if (glueCount > 0) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   462
                    int minWidth = minimumLayoutSize(parent).width;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   463
                    extraSpacePerGlue = (tb.getWidth() - minWidth) / glueCount;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   464
                    if (extraSpacePerGlue < 0) extraSpacePerGlue = 0;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   465
                }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   466
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                for (int i = 0; i < tb.getComponentCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                    c = tb.getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                    d = c.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                    int y, h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                    if (d.height >= baseH || c instanceof JSeparator) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                        // Fill available height
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                        y = baseY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                        h = baseH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                        // Center component vertically in the available space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                        y = baseY + (baseH / 2) - (d.height / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                        h = d.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                    }
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   480
                    //if the component is a "glue" component then add to its
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   481
                    //width the extraSpacePerGlue it is due
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   482
                    if (isGlue(c)) d.width += extraSpacePerGlue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                    c.setBounds(ltr ? x : x - d.width, y, d.width, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                    x = ltr ? x + d.width : x - d.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                int handleHeight = tb.isFloatable() ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                    SynthIcon.getIconHeight(handleIcon, context) : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                // See notes above regarding the use of insets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                contentRect.x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                contentRect.y = handleHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                contentRect.width = tb.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                contentRect.height = tb.getHeight() - handleHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                int baseX = insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                int baseW = tb.getWidth() - insets.left - insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                int y = handleHeight + insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   500
                // we need to get the minimum height for laying things out
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   501
                // so that we can calculate how much empty space needs to
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   502
                // be distributed among the "glue", if any
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   503
                int extraSpacePerGlue = 0;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   504
                if (glueCount > 0) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   505
                    int minHeight = minimumLayoutSize(parent).height;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   506
                    extraSpacePerGlue = (tb.getHeight() - minHeight) / glueCount;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   507
                    if (extraSpacePerGlue < 0) extraSpacePerGlue = 0;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   508
                }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   509
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                for (int i = 0; i < tb.getComponentCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                    c = tb.getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                    d = c.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                    int x, w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                    if (d.width >= baseW || c instanceof JSeparator) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                        // Fill available width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                        x = baseX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                        w = baseW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                        // Center component horizontally in the available space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                        x = baseX + (baseW / 2) - (d.width / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                        w = d.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                    }
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   523
                    //if the component is a "glue" component then add to its
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   524
                    //height the extraSpacePerGlue it is due
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   525
                    if (isGlue(c)) d.height += extraSpacePerGlue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                    c.setBounds(x, y, w, d.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                    y += d.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        }
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   532
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   533
        private boolean isGlue(Component c) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   534
            if (c instanceof Box.Filler) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   535
                Box.Filler f = (Box.Filler)c;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   536
                Dimension min = f.getMinimumSize();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   537
                Dimension pref = f.getPreferredSize();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   538
                return min.width == 0 &&  min.height == 0 &&
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   539
                        pref.width == 0 && pref.height == 0;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   540
            }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   541
            return false;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   542
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
}