1 7 8 package javax.swing.plaf.metal; 9 10 import java.awt.*; 11 import java.awt.event.*; 12 import javax.swing.*; 13 import javax.swing.border.*; 14 import javax.swing.plaf.*; 15 import java.beans.*; 16 import java.util.EventListener ; 17 import java.io.Serializable ; 18 import javax.swing.plaf.basic.BasicDesktopIconUI ; 19 20 26 public class MetalDesktopIconUI extends BasicDesktopIconUI 27 { 28 29 JButton button; 30 JLabel label; 31 TitleListener titleListener; 32 private int width; 33 34 public static ComponentUI createUI(JComponent c) { 35 return new MetalDesktopIconUI (); 36 } 37 38 public MetalDesktopIconUI() { 39 } 40 41 protected void installDefaults() { 42 super.installDefaults(); 43 LookAndFeel.installColorsAndFont(desktopIcon, "DesktopIcon.background", "DesktopIcon.foreground", "DesktopIcon.font"); 44 width = UIManager.getInt("DesktopIcon.width"); 45 } 46 47 protected void installComponents() { 48 frame = desktopIcon.getInternalFrame(); 49 Icon icon = frame.getFrameIcon(); 50 String title = frame.getTitle(); 51 52 button = new JButton (title, icon); 53 button.addActionListener( new ActionListener() { 54 public void actionPerformed(ActionEvent e) { 55 deiconize(); }} ); 56 button.setFont(desktopIcon.getFont()); 57 button.setBackground(desktopIcon.getBackground()); 58 button.setForeground(desktopIcon.getForeground()); 59 60 int buttonH = button.getPreferredSize().height; 61 62 Icon drag = new MetalBumps ((buttonH/3), buttonH, 63 MetalLookAndFeel.getControlHighlight(), 64 MetalLookAndFeel.getControlDarkShadow(), 65 MetalLookAndFeel.getControl()); 66 label = new JLabel(drag); 67 68 label.setBorder( new MatteBorder( 0, 2, 0, 1, desktopIcon.getBackground()) ); 69 desktopIcon.setLayout(new BorderLayout(2, 0)); 70 desktopIcon.add(button, BorderLayout.CENTER); 71 desktopIcon.add(label, BorderLayout.WEST); 72 } 73 74 protected void uninstallComponents() { 75 desktopIcon.setLayout(null); 76 desktopIcon.remove(label); 77 desktopIcon.remove(button); 78 button = null; 79 frame = null; 80 } 81 82 protected void installListeners() { 83 super.installListeners(); 84 desktopIcon.getInternalFrame().addPropertyChangeListener( 85 titleListener = new TitleListener()); 86 } 87 88 protected void uninstallListeners() { 89 desktopIcon.getInternalFrame().removePropertyChangeListener( 90 titleListener); 91 titleListener = null; 92 super.uninstallListeners(); 93 } 94 95 96 public Dimension getPreferredSize(JComponent c) { 97 return getMinimumSize(c); 100 } 101 102 public Dimension getMinimumSize(JComponent c) { 103 return new Dimension(width, 107 desktopIcon.getLayout().minimumLayoutSize(desktopIcon).height); 108 } 109 110 public Dimension getMaximumSize(JComponent c) { 111 return getMinimumSize(c); 114 } 115 116 class TitleListener implements PropertyChangeListener { 117 public void propertyChange (PropertyChangeEvent e) { 118 if (e.getPropertyName().equals("title")) { 119 button.setText((String )e.getNewValue()); 120 } 121 122 if (e.getPropertyName().equals("frameIcon")) { 123 button.setIcon((Icon)e.getNewValue()); 124 } 125 } 126 } 127 } 128 | Popular Tags |