1 /*
   2  * Copyright (c) 1997, 2004, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.java.swing.plaf.windows;
  27 
  28 import java.awt.*;
  29 import javax.swing.plaf.*;
  30 import javax.swing.plaf.basic.*;
  31 import javax.swing.*;
  32 import javax.swing.border.*;
  33 
  34 
  35 
  36 /**
  37  * Windows icon for a minimized window on the desktop.
  38  * <p>
  39  * <strong>Warning:</strong>
  40  * Serialized objects of this class will not be compatible with
  41  * future Swing releases.  The current serialization support is appropriate
  42  * for short term storage or RMI between applications running the same
  43  * version of Swing.  A future release of Swing will provide support for
  44  * long term persistence.
  45  */
  46 public class WindowsDesktopIconUI extends BasicDesktopIconUI {
  47     private int width;
  48 
  49     public static ComponentUI createUI(JComponent c) {
  50         return new WindowsDesktopIconUI();
  51     }
  52 
  53     public void installDefaults() {
  54         super.installDefaults();
  55         width = UIManager.getInt("DesktopIcon.width");
  56     }
  57 
  58     public void installUI(JComponent c)   {
  59         super.installUI(c);
  60 
  61         c.setOpaque(XPStyle.getXP() == null);
  62     }
  63 
  64     // Uninstall the listeners added by the WindowsInternalFrameTitlePane
  65     public void uninstallUI(JComponent c) {
  66         WindowsInternalFrameTitlePane thePane =
  67                                         (WindowsInternalFrameTitlePane)iconPane;
  68         super.uninstallUI(c);
  69         thePane.uninstallListeners();
  70     }
  71 
  72     protected void installComponents() {
  73         iconPane = new WindowsInternalFrameTitlePane(frame);
  74         desktopIcon.setLayout(new BorderLayout());
  75         desktopIcon.add(iconPane, BorderLayout.CENTER);
  76 
  77         if (XPStyle.getXP() != null) {
  78             desktopIcon.setBorder(null);
  79         }
  80     }
  81 
  82     public Dimension getPreferredSize(JComponent c) {
  83         // Windows desktop icons can not be resized.  Therefore, we should
  84         // always return the minimum size of the desktop icon. See
  85         // getMinimumSize(JComponent c).
  86         return getMinimumSize(c);
  87     }
  88 
  89     /**
  90      * Windows desktop icons are restricted to a width of 160 pixels by
  91      * default.  This value is retrieved by the DesktopIcon.width property.
  92      */
  93     public Dimension getMinimumSize(JComponent c) {
  94         Dimension dim = super.getMinimumSize(c);
  95         dim.width = width;
  96         return dim;
  97     }
  98 }