jdk/src/share/classes/javax/swing/plaf/synth/SynthDesktopPaneUI.java
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 5506 202f599c92aa
child 20168 137788883a22
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 5506
diff changeset
     2
 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
2
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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4848
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4848
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4848
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4848
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4848
diff changeset
    23
 * questions.
2
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.plaf.basic.BasicDesktopPaneUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
    37
 * Provides the Synth L&F UI delegate for
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
    38
 * {@link javax.swing.JDesktopPane}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @author Joshua Outwater
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @author Steve Wilson
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
    42
 * @since 1.7
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
    44
public class SynthDesktopPaneUI extends BasicDesktopPaneUI implements
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
                  PropertyChangeListener, SynthUI {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private SynthStyle style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private TaskBar taskBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private DesktopManager oldDesktopManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
    50
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
    51
     * Creates a new UI object for the given component.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
    52
     *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
    53
     * @param c component to create UI object for
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
    54
     * @return the UI object
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
    55
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    public static ComponentUI createUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        return new SynthDesktopPaneUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
    60
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
    61
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
    62
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
    63
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    protected void installListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        super.installListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        desktop.addPropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        if (taskBar != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            // Listen for desktop being resized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            desktop.addComponentListener(taskBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            // Listen for frames being added to desktop
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            desktop.addContainerListener(taskBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
    75
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
    76
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
    77
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
    78
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    protected void installDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        updateStyle(desktop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        if (UIManager.getBoolean("InternalFrame.useTaskBar")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            taskBar = new TaskBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            for (Component comp : desktop.getComponents()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                JInternalFrame.JDesktopIcon desktopIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                if (comp instanceof JInternalFrame.JDesktopIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                    desktopIcon = (JInternalFrame.JDesktopIcon)comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                } else if (comp instanceof JInternalFrame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                    desktopIcon = ((JInternalFrame)comp).getDesktopIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                // Move desktopIcon from desktop to taskBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                if (desktopIcon.getParent() == desktop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                    desktop.remove(desktopIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                if (desktopIcon.getParent() != taskBar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                    taskBar.add(desktopIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                    desktopIcon.getInternalFrame().addComponentListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                        taskBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            taskBar.setBackground(desktop.getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            desktop.add(taskBar,
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   107
                Integer.valueOf(JLayeredPane.PALETTE_LAYER.intValue() + 1));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            if (desktop.isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                taskBar.adjustSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    private void updateStyle(JDesktopPane c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        SynthStyle oldStyle = style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        SynthContext context = getContext(c, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        style = SynthLookAndFeel.updateStyle(context, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        if (oldStyle != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            uninstallKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            installKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   125
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   126
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   127
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   128
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    protected void uninstallListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        if (taskBar != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            desktop.removeComponentListener(taskBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            desktop.removeContainerListener(taskBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        desktop.removePropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        super.uninstallListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   138
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   139
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   140
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   141
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    protected void uninstallDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        SynthContext context = getContext(desktop, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        style.uninstallDefaults(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        style = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        if (taskBar != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            for (Component comp : taskBar.getComponents()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                JInternalFrame.JDesktopIcon desktopIcon =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                    (JInternalFrame.JDesktopIcon)comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                taskBar.remove(desktopIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                desktopIcon.setPreferredSize(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                JInternalFrame f = desktopIcon.getInternalFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                if (f.isIcon()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                    desktop.add(desktopIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                f.removeComponentListener(taskBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            desktop.remove(taskBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            taskBar = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   166
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   167
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   168
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   169
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    protected void installDesktopManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        if (UIManager.getBoolean("InternalFrame.useTaskBar")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            desktopManager = oldDesktopManager = desktop.getDesktopManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            if (!(desktopManager instanceof SynthDesktopManager)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                desktopManager = new SynthDesktopManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                desktop.setDesktopManager(desktopManager);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            super.installDesktopManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   182
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   183
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   184
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   185
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    protected void uninstallDesktopManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        if (oldDesktopManager != null && !(oldDesktopManager instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            desktopManager = desktop.getDesktopManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            if (desktopManager == null || desktopManager instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                desktop.setDesktopManager(oldDesktopManager);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        oldDesktopManager = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        super.uninstallDesktopManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    static class TaskBar extends JPanel implements ComponentListener, ContainerListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        TaskBar() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            setOpaque(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                public void layoutContainer(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                    // First shrink buttons to fit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    Component[] comps = target.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                    int n = comps.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                    if (n > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                        // Start with the largest preferred width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                        int prefWidth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                        for (Component c : comps) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                            c.setPreferredSize(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                            Dimension prefSize = c.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                            if (prefSize.width > prefWidth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                                prefWidth = prefSize.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                        // Shrink equally to fit if needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                        Insets insets = target.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                        int tw = target.getWidth() - insets.left - insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                        int w = Math.min(prefWidth, Math.max(10, tw/n));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                        for (Component c : comps) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                            Dimension prefSize = c.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                            c.setPreferredSize(new Dimension(w, prefSize.height));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                    super.layoutContainer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            // PENDING: This should be handled by the painter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            setBorder(new BevelBorder(BevelBorder.RAISED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                protected void paintRaisedBevel(Component c, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                                                int x, int y, int w, int h)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                    Color oldColor = g.getColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                    g.translate(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                    g.setColor(getHighlightOuterColor(c));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                    g.drawLine(0, 0, 0, h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                    g.drawLine(1, 0, w-2, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                    g.setColor(getShadowOuterColor(c));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                    g.drawLine(0, h-1, w-1, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                    g.drawLine(w-1, 0, w-1, h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                    g.translate(-x, -y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                    g.setColor(oldColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        void adjustSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            JDesktopPane desktop = (JDesktopPane)getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            if (desktop != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                int height = getPreferredSize().height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                Insets insets = getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                if (height == insets.top + insets.bottom) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                    if (getHeight() <= height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                        // Initial size, because we have no buttons yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                        height += 21;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                        // We already have a good height
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                        height = getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                setBounds(0, desktop.getHeight() - height, desktop.getWidth(), height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        // ComponentListener interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        public void componentResized(ComponentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            if (e.getSource() instanceof JDesktopPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                adjustSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        public void componentMoved(ComponentEvent e){}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        public void componentShown(ComponentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            if (e.getSource() instanceof JInternalFrame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                adjustSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        public void componentHidden(ComponentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            if (e.getSource() instanceof JInternalFrame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                ((JInternalFrame)e.getSource()).getDesktopIcon().setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        // ContainerListener interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        public void componentAdded(ContainerEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            if (e.getChild() instanceof JInternalFrame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                JDesktopPane desktop = (JDesktopPane)e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                JInternalFrame f = (JInternalFrame)e.getChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                JInternalFrame.JDesktopIcon desktopIcon = f.getDesktopIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                for (Component comp : getComponents()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                    if (comp == desktopIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                        // We have it already
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                add(desktopIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                f.addComponentListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                if (getComponentCount() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                    adjustSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        public void componentRemoved(ContainerEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            if (e.getChild() instanceof JInternalFrame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                JInternalFrame f = (JInternalFrame)e.getChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                if (!f.isIcon()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                    // Frame was removed without using setClosed(true)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                    remove(f.getDesktopIcon());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                    f.removeComponentListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                    revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                    repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    class SynthDesktopManager extends DefaultDesktopManager implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        public void maximizeFrame(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            if (f.isIcon()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                    f.setIcon(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                } catch (PropertyVetoException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                f.setNormalBounds(f.getBounds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                Component desktop = f.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                setBoundsForFrame(f, 0, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                                  desktop.getWidth(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                                  desktop.getHeight() - taskBar.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                f.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            } catch (PropertyVetoException e2) {
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
        public void iconifyFrame(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            JInternalFrame.JDesktopIcon desktopIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            Container c = f.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            JDesktopPane d = f.getDesktopPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            boolean findNext = f.isSelected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            if (c == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            desktopIcon = f.getDesktopIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            if (!f.isMaximum()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                f.setNormalBounds(f.getBounds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            c.remove(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            c.repaint(f.getX(), f.getY(), f.getWidth(), f.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                f.setSelected(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            } catch (PropertyVetoException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            // Get topmost of the remaining frames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            if (findNext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                for (Component comp : c.getComponents()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                    if (comp instanceof JInternalFrame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                            ((JInternalFrame)comp).setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                        } catch (PropertyVetoException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                        ((JInternalFrame)comp).moveToFront();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        public void deiconifyFrame(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            JInternalFrame.JDesktopIcon desktopIcon = f.getDesktopIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            Container c = desktopIcon.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                c = c.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                    c.add(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                    if (f.isMaximum()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                        int w = c.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                        int h = c.getHeight() - taskBar.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                        if (f.getWidth() != w || f.getHeight() != h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                            setBoundsForFrame(f, 0, 0, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                    if (f.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                        f.moveToFront();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                            f.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                        } catch (PropertyVetoException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        protected void removeIconFor(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            super.removeIconFor(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            taskBar.validate();
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 setBoundsForFrame(JComponent f, int newX, int newY, int newWidth, int newHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            super.setBoundsForFrame(f, newX, newY, newWidth, newHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            if (taskBar != null && newY >= taskBar.getY()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                f.setLocation(f.getX(), taskBar.getY()-f.getInsets().top);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   424
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   425
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   426
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   427
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    public SynthContext getContext(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        return getContext(c, getComponentState(c));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    private SynthContext getContext(JComponent c, int state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        return SynthContext.getContext(SynthContext.class, c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                     SynthLookAndFeel.getRegion(c), style, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    private int getComponentState(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        return SynthLookAndFeel.getComponentState(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   441
    /**
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   442
     * 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
   443
     * 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
   444
     * 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
   445
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   446
     * <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
   447
     * 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
   448
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   449
     * @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
   450
     * @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
   451
     * @see #paint(SynthContext,Graphics)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   452
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   453
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    public void update(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        SynthLookAndFeel.update(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        context.getPainter().paintDesktopPaneBackground(context, g, 0, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                                                  c.getWidth(), c.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        paint(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   464
    /**
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   465
     * 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
   466
     * <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
   467
     * 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
   468
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   469
     * @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
   470
     * @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
   471
     * @see #paint(SynthContext,Graphics)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   472
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   473
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    public void paint(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        paint(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   481
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   482
     * Paints the specified component. This implementation does nothing.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   483
     *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   484
     * @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
   485
     * @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
   486
     * @see #update(Graphics,JComponent)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   487
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    protected void paint(SynthContext context, Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   491
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   492
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   493
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   494
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    public void paintBorder(SynthContext context, Graphics g, int x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                            int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        context.getPainter().paintDesktopPaneBorder(context, g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   500
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   501
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   502
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 715
diff changeset
   503
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    public void propertyChange(PropertyChangeEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        if (SynthLookAndFeel.shouldUpdateStyle(evt)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            updateStyle((JDesktopPane)evt.getSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        if (evt.getPropertyName() == "ancestor" && taskBar != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            taskBar.adjustSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
}