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.event.*; 14 import javax.swing.border.*; 15 import javax.swing.plaf.basic.*; 16 import java.util.EventListener ; 17 import java.beans.PropertyChangeListener ; 18 import java.beans.PropertyChangeEvent ; 19 import java.beans.PropertyVetoException ; 20 import javax.swing.plaf.*; 21 22 29 public class MetalInternalFrameUI extends BasicInternalFrameUI { 30 31 private MetalInternalFrameTitlePane titlePane; 32 33 private static final PropertyChangeListener metalPropertyChangeListener = 34 new MetalPropertyChangeHandler(); 35 36 private static final Border handyEmptyBorder = new EmptyBorder(0,0,0,0); 37 38 protected static String IS_PALETTE = "JInternalFrame.isPalette"; 39 40 private static String FRAME_TYPE = "JInternalFrame.frameType"; 41 private static String NORMAL_FRAME = "normal"; 42 private static String PALETTE_FRAME = "palette"; 43 private static String OPTION_DIALOG = "optionDialog"; 44 45 public MetalInternalFrameUI(JInternalFrame b) { 46 super(b); 47 } 48 49 public static ComponentUI createUI(JComponent c) { 50 return new MetalInternalFrameUI ( (JInternalFrame) c); 51 } 52 53 public void installUI(JComponent c) { 54 super.installUI(c); 55 56 Object paletteProp = c.getClientProperty( IS_PALETTE ); 57 if ( paletteProp != null ) { 58 setPalette( ((Boolean )paletteProp).booleanValue() ); 59 } 60 61 Container content = frame.getContentPane(); 62 stripContentBorder(content); 63 } 65 66 public void uninstallUI(JComponent c) { 67 frame = (JInternalFrame)c; 68 69 Container cont = ((JInternalFrame)(c)).getContentPane(); 70 if (cont instanceof JComponent) { 71 JComponent content = (JComponent)cont; 72 if ( content.getBorder() == handyEmptyBorder) { 73 content.setBorder(null); 74 } 75 } 76 super.uninstallUI(c); 77 } 78 79 protected void installListeners() { 80 super.installListeners(); 81 frame.addPropertyChangeListener(metalPropertyChangeListener); 82 } 83 84 protected void uninstallListeners() { 85 frame.removePropertyChangeListener(metalPropertyChangeListener); 86 super.uninstallListeners(); 87 } 88 89 protected void installKeyboardActions(){ 90 super.installKeyboardActions(); 91 ActionMap map = SwingUtilities.getUIActionMap(frame); 92 if (map != null) { 93 map.remove("showSystemMenu"); 96 } 97 } 98 99 protected void uninstallKeyboardActions(){ 100 super.uninstallKeyboardActions(); 101 } 102 103 protected void uninstallComponents() { 104 titlePane = null; 105 super.uninstallComponents(); 106 } 107 108 private void stripContentBorder(Object c) { 109 if ( c instanceof JComponent ) { 110 JComponent contentComp = (JComponent)c; 111 Border contentBorder = contentComp.getBorder(); 112 if (contentBorder == null || contentBorder instanceof UIResource) { 113 contentComp.setBorder( handyEmptyBorder ); 114 } 115 } 116 } 117 118 119 protected JComponent createNorthPane(JInternalFrame w) { 120 titlePane = new MetalInternalFrameTitlePane (w); 121 return titlePane; 122 } 123 124 125 private void setFrameType( String frameType ) 126 { 127 if ( frameType.equals( OPTION_DIALOG ) ) 128 { 129 LookAndFeel.installBorder(frame, "InternalFrame.optionDialogBorder"); 130 titlePane.setPalette( false ); 131 } 132 else if ( frameType.equals( PALETTE_FRAME ) ) 133 { 134 LookAndFeel.installBorder(frame, "InternalFrame.paletteBorder"); 135 titlePane.setPalette( true ); 136 } 137 else 138 { 139 LookAndFeel.installBorder(frame, "InternalFrame.border"); 140 titlePane.setPalette( false ); 141 } 142 } 143 144 public void setPalette(boolean isPalette) { 146 if (isPalette) { 147 LookAndFeel.installBorder(frame, "InternalFrame.paletteBorder"); 148 } else { 149 LookAndFeel.installBorder(frame, "InternalFrame.border"); 150 } 151 titlePane.setPalette(isPalette); 152 153 } 154 155 private static class MetalPropertyChangeHandler implements 156 PropertyChangeListener 157 { 158 public void propertyChange(PropertyChangeEvent e) 159 { 160 String name = e.getPropertyName(); 161 JInternalFrame jif = (JInternalFrame)e.getSource(); 162 163 if (!(jif.getUI() instanceof MetalInternalFrameUI )) { 164 return; 165 } 166 167 MetalInternalFrameUI ui = (MetalInternalFrameUI )jif.getUI(); 168 169 if ( name.equals( FRAME_TYPE ) ) 170 { 171 if ( e.getNewValue() instanceof String ) 172 { 173 ui.setFrameType( (String ) e.getNewValue() ); 174 } 175 } 176 else if ( name.equals( IS_PALETTE ) ) 177 { 178 if ( e.getNewValue() != null ) 179 { 180 ui.setPalette( ((Boolean )e.getNewValue()).booleanValue() ); 181 } 182 else 183 { 184 ui.setPalette( false ); 185 } 186 } else if ( name.equals( JInternalFrame.CONTENT_PANE_PROPERTY ) ) { 187 ui.stripContentBorder(e.getNewValue()); 188 } 189 } 190 } } 192 193 | Popular Tags |