jdk/src/share/classes/javax/swing/plaf/synth/SynthDesktopPaneUI.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 438 2ae294e4518c
child 4394 92a8ec883f5d
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 438
diff changeset
     2
 * Copyright 2002-2008 Sun Microsystems, Inc.  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
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
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.Dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.Insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.Graphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.KeyboardFocusManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import sun.swing.plaf.synth.SynthUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * Synth L&F for a desktop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * @author Joshua Outwater
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @author Steve Wilson
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
class SynthDesktopPaneUI extends BasicDesktopPaneUI implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
                  PropertyChangeListener, SynthUI {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private SynthStyle style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private TaskBar taskBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private DesktopManager oldDesktopManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    protected void installListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        super.installListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        desktop.addPropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        if (taskBar != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            // Listen for desktop being resized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            desktop.addComponentListener(taskBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            // Listen for frames being added to desktop
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            desktop.addContainerListener(taskBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    protected void installDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        updateStyle(desktop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        if (UIManager.getBoolean("InternalFrame.useTaskBar")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            taskBar = new TaskBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            for (Component comp : desktop.getComponents()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                JInternalFrame.JDesktopIcon desktopIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                if (comp instanceof JInternalFrame.JDesktopIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                    desktopIcon = (JInternalFrame.JDesktopIcon)comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                } else if (comp instanceof JInternalFrame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                    desktopIcon = ((JInternalFrame)comp).getDesktopIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                // Move desktopIcon from desktop to taskBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                if (desktopIcon.getParent() == desktop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                    desktop.remove(desktopIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                if (desktopIcon.getParent() != taskBar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                    taskBar.add(desktopIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                    desktopIcon.getInternalFrame().addComponentListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                        taskBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            taskBar.setBackground(desktop.getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            desktop.add(taskBar,
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
    99
                Integer.valueOf(JLayeredPane.PALETTE_LAYER.intValue() + 1));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            if (desktop.isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                taskBar.adjustSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private void updateStyle(JDesktopPane c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        SynthStyle oldStyle = style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        SynthContext context = getContext(c, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        style = SynthLookAndFeel.updateStyle(context, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        if (oldStyle != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            uninstallKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            installKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    protected void uninstallListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        if (taskBar != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            desktop.removeComponentListener(taskBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            desktop.removeContainerListener(taskBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        desktop.removePropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        super.uninstallListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    protected void uninstallDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        SynthContext context = getContext(desktop, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        style.uninstallDefaults(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        style = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        if (taskBar != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            for (Component comp : taskBar.getComponents()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                JInternalFrame.JDesktopIcon desktopIcon =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                    (JInternalFrame.JDesktopIcon)comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                taskBar.remove(desktopIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                desktopIcon.setPreferredSize(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                JInternalFrame f = desktopIcon.getInternalFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                if (f.isIcon()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                    desktop.add(desktopIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                f.removeComponentListener(taskBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            desktop.remove(taskBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            taskBar = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    protected void installDesktopManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        if (UIManager.getBoolean("InternalFrame.useTaskBar")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            desktopManager = oldDesktopManager = desktop.getDesktopManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            if (!(desktopManager instanceof SynthDesktopManager)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                desktopManager = new SynthDesktopManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                desktop.setDesktopManager(desktopManager);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            super.installDesktopManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    protected void uninstallDesktopManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        if (oldDesktopManager != null && !(oldDesktopManager instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            desktopManager = desktop.getDesktopManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            if (desktopManager == null || desktopManager instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                desktop.setDesktopManager(oldDesktopManager);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        oldDesktopManager = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        super.uninstallDesktopManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    static class TaskBar extends JPanel implements ComponentListener, ContainerListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        TaskBar() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            setOpaque(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                public void layoutContainer(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                    // First shrink buttons to fit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                    Component[] comps = target.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                    int n = comps.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                    if (n > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                        // Start with the largest preferred width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                        int prefWidth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                        for (Component c : comps) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                            c.setPreferredSize(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                            Dimension prefSize = c.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                            if (prefSize.width > prefWidth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                                prefWidth = prefSize.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                        // Shrink equally to fit if needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                        Insets insets = target.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                        int tw = target.getWidth() - insets.left - insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                        int w = Math.min(prefWidth, Math.max(10, tw/n));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                        for (Component c : comps) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                            Dimension prefSize = c.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                            c.setPreferredSize(new Dimension(w, prefSize.height));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                    super.layoutContainer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            // PENDING: This should be handled by the painter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            setBorder(new BevelBorder(BevelBorder.RAISED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                protected void paintRaisedBevel(Component c, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                                                int x, int y, int w, int h)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                    Color oldColor = g.getColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                    g.translate(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                    g.setColor(getHighlightOuterColor(c));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                    g.drawLine(0, 0, 0, h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                    g.drawLine(1, 0, w-2, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                    g.setColor(getShadowOuterColor(c));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                    g.drawLine(0, h-1, w-1, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                    g.drawLine(w-1, 0, w-1, h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                    g.translate(-x, -y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                    g.setColor(oldColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        void adjustSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            JDesktopPane desktop = (JDesktopPane)getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            if (desktop != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                int height = getPreferredSize().height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                Insets insets = getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                if (height == insets.top + insets.bottom) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                    if (getHeight() <= height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                        // Initial size, because we have no buttons yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                        height += 21;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                        // We already have a good height
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                        height = getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                setBounds(0, desktop.getHeight() - height, desktop.getWidth(), height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        // ComponentListener interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        public void componentResized(ComponentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            if (e.getSource() instanceof JDesktopPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                adjustSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        public void componentMoved(ComponentEvent e){}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        public void componentShown(ComponentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            if (e.getSource() instanceof JInternalFrame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                adjustSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        public void componentHidden(ComponentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            if (e.getSource() instanceof JInternalFrame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                ((JInternalFrame)e.getSource()).getDesktopIcon().setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        // ContainerListener interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        public void componentAdded(ContainerEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            if (e.getChild() instanceof JInternalFrame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                JDesktopPane desktop = (JDesktopPane)e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                JInternalFrame f = (JInternalFrame)e.getChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                JInternalFrame.JDesktopIcon desktopIcon = f.getDesktopIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                for (Component comp : getComponents()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                    if (comp == desktopIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                        // We have it already
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                add(desktopIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                f.addComponentListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                if (getComponentCount() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                    adjustSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        public void componentRemoved(ContainerEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            if (e.getChild() instanceof JInternalFrame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                JInternalFrame f = (JInternalFrame)e.getChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                if (!f.isIcon()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                    // Frame was removed without using setClosed(true)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                    remove(f.getDesktopIcon());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                    f.removeComponentListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                    revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                    repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    class SynthDesktopManager extends DefaultDesktopManager implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        public void maximizeFrame(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            if (f.isIcon()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                    f.setIcon(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                } catch (PropertyVetoException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                f.setNormalBounds(f.getBounds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                Component desktop = f.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                setBoundsForFrame(f, 0, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                                  desktop.getWidth(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                                  desktop.getHeight() - taskBar.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                f.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            } catch (PropertyVetoException e2) {
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
        public void iconifyFrame(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            JInternalFrame.JDesktopIcon desktopIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            Container c = f.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            JDesktopPane d = f.getDesktopPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            boolean findNext = f.isSelected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            if (c == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            desktopIcon = f.getDesktopIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            if (!f.isMaximum()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                f.setNormalBounds(f.getBounds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            c.remove(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            c.repaint(f.getX(), f.getY(), f.getWidth(), f.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                f.setSelected(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            } catch (PropertyVetoException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            // Get topmost of the remaining frames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            if (findNext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                for (Component comp : c.getComponents()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                    if (comp instanceof JInternalFrame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                            ((JInternalFrame)comp).setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                        } catch (PropertyVetoException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                        ((JInternalFrame)comp).moveToFront();
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
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        public void deiconifyFrame(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            JInternalFrame.JDesktopIcon desktopIcon = f.getDesktopIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            Container c = desktopIcon.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                c = c.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                    c.add(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                    if (f.isMaximum()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                        int w = c.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                        int h = c.getHeight() - taskBar.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                        if (f.getWidth() != w || f.getHeight() != h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                            setBoundsForFrame(f, 0, 0, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                    if (f.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                        f.moveToFront();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                            f.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                        } catch (PropertyVetoException e2) {
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
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        protected void removeIconFor(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            super.removeIconFor(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            taskBar.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        public void setBoundsForFrame(JComponent f, int newX, int newY, int newWidth, int newHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            super.setBoundsForFrame(f, newX, newY, newWidth, newHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            if (taskBar != null && newY >= taskBar.getY()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                f.setLocation(f.getX(), taskBar.getY()-f.getInsets().top);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    public SynthContext getContext(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        return getContext(c, getComponentState(c));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    private SynthContext getContext(JComponent c, int state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        return SynthContext.getContext(SynthContext.class, c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                     SynthLookAndFeel.getRegion(c), style, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    private Region getRegion(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        return SynthLookAndFeel.getRegion(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    private int getComponentState(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        return SynthLookAndFeel.getComponentState(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    public void update(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        SynthLookAndFeel.update(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        context.getPainter().paintDesktopPaneBackground(context, g, 0, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                                                  c.getWidth(), c.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        paint(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    public void paint(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        paint(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    protected void paint(SynthContext context, Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    public void paintBorder(SynthContext context, Graphics g, int x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                            int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        context.getPainter().paintDesktopPaneBorder(context, g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    public void propertyChange(PropertyChangeEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        if (SynthLookAndFeel.shouldUpdateStyle(evt)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            updateStyle((JDesktopPane)evt.getSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        if (evt.getPropertyName() == "ancestor" && taskBar != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            taskBar.adjustSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
}