1 30 31 package com.jgoodies.looks.plastic; 32 33 import java.awt.Color ; 34 import java.awt.Container ; 35 import java.beans.PropertyChangeEvent ; 36 import java.beans.PropertyChangeListener ; 37 38 import javax.swing.JComponent ; 39 import javax.swing.JInternalFrame ; 40 import javax.swing.LookAndFeel ; 41 import javax.swing.UIManager ; 42 import javax.swing.border.Border ; 43 import javax.swing.border.EmptyBorder ; 44 import javax.swing.plaf.ComponentUI ; 45 import javax.swing.plaf.UIResource ; 46 import javax.swing.plaf.basic.BasicInternalFrameUI ; 47 48 49 58 public final class PlasticInternalFrameUI extends BasicInternalFrameUI { 59 60 61 private static final String FRAME_TYPE = "JInternalFrame.frameType"; 62 public static final String IS_PALETTE = "JInternalFrame.isPalette"; 63 private static final String PALETTE_FRAME = "palette"; 64 private static final String OPTION_DIALOG = "optionDialog"; 65 private static final Border EMPTY_BORDER = new EmptyBorder (0, 0, 0, 0); 66 67 68 private PlasticInternalFrameTitlePane titlePane; 69 private PropertyChangeListener paletteListener; 70 private PropertyChangeListener contentPaneListener; 71 72 73 public PlasticInternalFrameUI(JInternalFrame b) { 74 super(b); 75 } 76 77 78 public static ComponentUI createUI(JComponent c) { 79 return new PlasticInternalFrameUI((JInternalFrame ) c); 80 } 81 82 83 public void installUI(JComponent c) { 84 frame = (JInternalFrame ) c; 85 86 paletteListener = new PaletteListener (this); 87 contentPaneListener = new ContentPaneListener(this); 88 c.addPropertyChangeListener(paletteListener); 89 c.addPropertyChangeListener(contentPaneListener); 90 91 super.installUI(c); 92 93 Object paletteProp = c.getClientProperty(IS_PALETTE); 94 if (paletteProp != null) { 95 setPalette(((Boolean ) paletteProp).booleanValue()); 96 } 97 98 Container content = frame.getContentPane(); 99 stripContentBorder(content); 100 } 101 102 103 public void uninstallUI(JComponent c) { 104 frame = (JInternalFrame ) c; 105 106 c.removePropertyChangeListener(paletteListener); 107 c.removePropertyChangeListener(contentPaneListener); 108 109 Container cont = ((JInternalFrame ) (c)).getContentPane(); 110 if (cont instanceof JComponent ) { 111 JComponent content = (JComponent ) cont; 112 if (content.getBorder() == EMPTY_BORDER) { 113 content.setBorder(null); 114 } 115 } 116 super.uninstallUI(c); 117 } 118 119 120 protected void installDefaults() { 121 super.installDefaults(); 122 123 126 JComponent contentPane = (JComponent ) frame.getContentPane(); 127 if (contentPane != null) { 128 Color bg = contentPane.getBackground(); 129 if (bg instanceof UIResource ) 130 contentPane.setBackground(null); 131 } 132 frame.setBackground(UIManager.getLookAndFeelDefaults().getColor("control")); 133 } 134 135 136 protected void installKeyboardActions() { 137 } 138 139 protected void uninstallKeyboardActions() { 140 } 141 142 143 private void stripContentBorder(Object c) { 144 if (c instanceof JComponent ) { 145 JComponent contentComp = (JComponent ) c; 146 Border contentBorder = contentComp.getBorder(); 147 if (contentBorder == null || contentBorder instanceof UIResource ) { 148 contentComp.setBorder(EMPTY_BORDER); 149 } 150 } 151 } 152 153 154 protected JComponent createNorthPane(JInternalFrame w) { 155 titlePane = new PlasticInternalFrameTitlePane(w); 156 return titlePane; 157 } 158 159 160 public void setPalette(boolean isPalette) { 161 String key = isPalette ? "InternalFrame.paletteBorder" : "InternalFrame.border"; 162 LookAndFeel.installBorder(frame, key); 163 titlePane.setPalette(isPalette); 164 } 165 166 167 private void setFrameType(String frameType) { 168 String key; 169 boolean hasPalette = frameType.equals(PALETTE_FRAME); 170 if (frameType.equals(OPTION_DIALOG)) { 171 key = "InternalFrame.optionDialogBorder"; 172 } else if (hasPalette) { 173 key = "InternalFrame.paletteBorder"; 174 } else { 175 key = "InternalFrame.border"; 176 } 177 LookAndFeel.installBorder(frame, key); 178 titlePane.setPalette(hasPalette); 179 } 180 181 182 private static class PaletteListener implements PropertyChangeListener { 183 184 private final PlasticInternalFrameUI ui; 185 186 private PaletteListener(PlasticInternalFrameUI ui) { this.ui = ui; } 187 188 public void propertyChange(PropertyChangeEvent e) { 189 String name = e.getPropertyName(); 190 Object value = e.getNewValue(); 191 if (name.equals(FRAME_TYPE)) { 192 if (value instanceof String ) { 193 ui.setFrameType((String ) value); 194 } 195 } else if (name.equals(IS_PALETTE)) { 196 ui.setPalette(Boolean.TRUE.equals(value)); 197 } 198 } 199 } 200 201 private static class ContentPaneListener implements PropertyChangeListener { 202 203 private final PlasticInternalFrameUI ui; 204 205 private ContentPaneListener(PlasticInternalFrameUI ui) { this.ui = ui; } 206 207 public void propertyChange(PropertyChangeEvent e) { 208 String name = e.getPropertyName(); 209 if (name.equals(JInternalFrame.CONTENT_PANE_PROPERTY)) { 210 ui.stripContentBorder(e.getNewValue()); 211 } 212 } 213 } 214 215 } 216 | Popular Tags |