001 /* MetalInternalFrameUI.java 002 Copyright (C) 2005 Free Software Foundation, Inc. 003 004 This file is part of GNU Classpath. 005 006 GNU Classpath is free software; you can redistribute it and/or modify 007 it under the terms of the GNU General Public License as published by 008 the Free Software Foundation; either version 2, or (at your option) 009 any later version. 010 011 GNU Classpath is distributed in the hope that it will be useful, but 012 WITHOUT ANY WARRANTY; without even the implied warranty of 013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 General Public License for more details. 015 016 You should have received a copy of the GNU General Public License 017 along with GNU Classpath; see the file COPYING. If not, write to the 018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 019 02110-1301 USA. 020 021 Linking this library statically or dynamically with other modules is 022 making a combined work based on this library. Thus, the terms and 023 conditions of the GNU General Public License cover the whole 024 combination. 025 026 As a special exception, the copyright holders of this library give you 027 permission to link this library with independent modules to produce an 028 executable, regardless of the license terms of these independent 029 modules, and to copy and distribute the resulting executable under 030 terms of your choice, provided that you also meet, for each linked 031 independent module, the terms and conditions of the license of that 032 module. An independent module is a module which is not derived from 033 or based on this library. If you modify this library, you may extend 034 this exception to your version of the library, but you are not 035 obligated to do so. If you do not wish to do so, delete this 036 exception statement from your version. */ 037 038 039 package javax.swing.plaf.metal; 040 041 import java.beans.PropertyChangeEvent; 042 import java.beans.PropertyChangeListener; 043 044 import javax.swing.ActionMap; 045 import javax.swing.JComponent; 046 import javax.swing.JInternalFrame; 047 import javax.swing.SwingUtilities; 048 import javax.swing.plaf.ComponentUI; 049 import javax.swing.plaf.basic.BasicInternalFrameUI; 050 051 /** 052 * A UI delegate for the {@link JInternalFrame} component. 053 */ 054 public class MetalInternalFrameUI 055 extends BasicInternalFrameUI 056 { 057 /** 058 * The key (<code>JInternalFrame.isPalette</code>) for the client property 059 * that controls whether the internal frame is displayed using the palette 060 * style. 061 */ 062 protected static String IS_PALETTE = "JInternalFrame.isPalette"; 063 064 /** 065 * Constructs a new instance of <code>MetalInternalFrameUI</code>. 066 * 067 * @param frame the frame. 068 */ 069 public MetalInternalFrameUI(JInternalFrame frame) 070 { 071 super(frame); 072 } 073 074 /** 075 * Returns an instance of <code>MetalInternalFrameUI</code>. 076 * 077 * @param component the internal frame. 078 * 079 * @return an instance of <code>MetalInternalFrameUI</code>. 080 */ 081 public static ComponentUI createUI(JComponent component) 082 { 083 return new MetalInternalFrameUI((JInternalFrame) component); 084 } 085 086 /** 087 * Sets the fields and properties for the component. 088 * 089 * @param c the component. 090 */ 091 public void installUI(JComponent c) 092 { 093 super.installUI(c); 094 JInternalFrame f = (JInternalFrame) c; 095 boolean isPalette = false; 096 Boolean p = (Boolean) f.getClientProperty(IS_PALETTE); 097 if (p != null) 098 isPalette = p.booleanValue(); 099 setPalette(isPalette); 100 } 101 102 /** 103 * Creates and returns the component that will be used for the north pane 104 * of the {@link JInternalFrame}. 105 * 106 * @param w the internal frame. 107 * 108 * @return A new instance of {@link MetalInternalFrameTitlePane}. 109 */ 110 protected JComponent createNorthPane(JInternalFrame w) 111 { 112 titlePane = new MetalInternalFrameTitlePane(w); 113 return titlePane; 114 } 115 116 /** 117 * Sets the state of the {@link JInternalFrame} to reflect whether or not 118 * it is using the palette style. When a frame is displayed as a palette, 119 * it uses a different border and the title pane is drawn differently. 120 * 121 * @param isPalette use the palette style? 122 */ 123 public void setPalette(boolean isPalette) 124 { 125 MetalInternalFrameTitlePane title = (MetalInternalFrameTitlePane) northPane; 126 title.setPalette(isPalette); 127 if (isPalette) 128 frame.setBorder(new MetalBorders.PaletteBorder()); 129 else 130 frame.setBorder(new MetalBorders.InternalFrameBorder()); 131 } 132 133 /** A listener that is used to handle IS_PALETTE property changes. */ 134 private PropertyChangeListener paletteListener; 135 136 /** 137 * Adds the required listeners. 138 */ 139 protected void installListeners() 140 { 141 super.installListeners(); 142 paletteListener = new PropertyChangeListener() 143 { 144 public void propertyChange(PropertyChangeEvent e) 145 { 146 if (e.getPropertyName().equals(IS_PALETTE)) 147 { 148 if (Boolean.TRUE.equals(e.getNewValue())) 149 setPalette(true); 150 else 151 setPalette(false); 152 } 153 } 154 }; 155 frame.addPropertyChangeListener(paletteListener); 156 } 157 158 /** 159 * Removes the listeners used. 160 */ 161 protected void uninstallListeners() 162 { 163 super.uninstallListeners(); 164 frame.removePropertyChangeListener(IS_PALETTE, paletteListener); 165 paletteListener = null; 166 } 167 168 /** 169 * Installs keyboard actions. This is overridden to remove the 170 * <code>showSystemMenu</code> Action that is installed by the 171 * <code>BasicInternalFrameUI</code>, since Metal JInternalFrames don't have 172 * a system menu. 173 */ 174 protected void installKeyboardActions() 175 { 176 super.installKeyboardActions(); 177 ActionMap am = SwingUtilities.getUIActionMap(frame); 178 if (am != null) 179 { 180 am.remove("showSystemMenu"); 181 } 182 } 183 }