1. /*
  2. * @(#)MetalDesktopIconUI.java 1.19 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.swing.plaf.metal;
  8. import java.awt.*;
  9. import java.awt.event.*;
  10. import javax.swing.*;
  11. import javax.swing.border.*;
  12. import javax.swing.plaf.*;
  13. import java.beans.*;
  14. import java.util.EventListener;
  15. import java.io.Serializable;
  16. import javax.swing.plaf.basic.BasicDesktopIconUI;
  17. /**
  18. * Metal desktop icon.
  19. *
  20. * @version 1.19 01/23/03
  21. * @author Steve Wilson
  22. */
  23. public class MetalDesktopIconUI extends BasicDesktopIconUI
  24. {
  25. JButton button;
  26. JLabel label;
  27. TitleListener titleListener;
  28. private int width;
  29. public static ComponentUI createUI(JComponent c) {
  30. return new MetalDesktopIconUI();
  31. }
  32. public MetalDesktopIconUI() {
  33. }
  34. protected void installDefaults() {
  35. super.installDefaults();
  36. LookAndFeel.installColorsAndFont(desktopIcon, "DesktopIcon.background", "DesktopIcon.foreground", "DesktopIcon.font");
  37. desktopIcon.setOpaque(true);
  38. width = UIManager.getInt("DesktopIcon.width");
  39. }
  40. protected void installComponents() {
  41. frame = desktopIcon.getInternalFrame();
  42. Icon icon = frame.getFrameIcon();
  43. String title = frame.getTitle();
  44. button = new JButton (title, icon);
  45. button.addActionListener( new ActionListener() {
  46. public void actionPerformed(ActionEvent e) {
  47. deiconize(); }} );
  48. button.setFont(desktopIcon.getFont());
  49. button.setBackground(desktopIcon.getBackground());
  50. button.setForeground(desktopIcon.getForeground());
  51. int buttonH = button.getPreferredSize().height;
  52. Icon drag = new MetalBumps((buttonH3), buttonH,
  53. MetalLookAndFeel.getControlHighlight(),
  54. MetalLookAndFeel.getControlDarkShadow(),
  55. MetalLookAndFeel.getControl());
  56. label = new JLabel(drag);
  57. label.setBorder( new MatteBorder( 0, 2, 0, 1, desktopIcon.getBackground()) );
  58. desktopIcon.setLayout(new BorderLayout(2, 0));
  59. desktopIcon.add(button, BorderLayout.CENTER);
  60. desktopIcon.add(label, BorderLayout.WEST);
  61. }
  62. protected void uninstallComponents() {
  63. desktopIcon.setLayout(null);
  64. desktopIcon.remove(label);
  65. desktopIcon.remove(button);
  66. button = null;
  67. frame = null;
  68. }
  69. protected void installListeners() {
  70. super.installListeners();
  71. desktopIcon.getInternalFrame().addPropertyChangeListener(
  72. titleListener = new TitleListener());
  73. }
  74. protected void uninstallListeners() {
  75. desktopIcon.getInternalFrame().removePropertyChangeListener(
  76. titleListener);
  77. titleListener = null;
  78. super.uninstallListeners();
  79. }
  80. public Dimension getPreferredSize(JComponent c) {
  81. // Metal desktop icons can not be resized. Their dimensions should
  82. // always be the minimum size. See getMinimumSize(JComponent c).
  83. return getMinimumSize(c);
  84. }
  85. public Dimension getMinimumSize(JComponent c) {
  86. // For the metal desktop icon we will use the layout maanger to
  87. // determine the correct height of the component, but we want to keep
  88. // the width consistent according to the jlf spec.
  89. return new Dimension(width,
  90. desktopIcon.getLayout().minimumLayoutSize(desktopIcon).height);
  91. }
  92. public Dimension getMaximumSize(JComponent c) {
  93. // Metal desktop icons can not be resized. Their dimensions should
  94. // always be the minimum size. See getMinimumSize(JComponent c).
  95. return getMinimumSize(c);
  96. }
  97. class TitleListener implements PropertyChangeListener {
  98. public void propertyChange (PropertyChangeEvent e) {
  99. if (e.getPropertyName().equals("title")) {
  100. button.setText((String)e.getNewValue());
  101. }
  102. if (e.getPropertyName().equals("frameIcon")) {
  103. button.setIcon((Icon)e.getNewValue());
  104. }
  105. }
  106. }
  107. }