GNU Classpath (0.20) | |
Frames | No Frames |
1: /* MetalInternalFrameUI.java 2: Copyright (C) 2005 Free Software Foundation, Inc. 3: 4: This file is part of GNU Classpath. 5: 6: GNU Classpath is free software; you can redistribute it and/or modify 7: it under the terms of the GNU General Public License as published by 8: the Free Software Foundation; either version 2, or (at your option) 9: any later version. 10: 11: GNU Classpath is distributed in the hope that it will be useful, but 12: WITHOUT ANY WARRANTY; without even the implied warranty of 13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14: General Public License for more details. 15: 16: You should have received a copy of the GNU General Public License 17: along with GNU Classpath; see the file COPYING. If not, write to the 18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19: 02110-1301 USA. 20: 21: Linking this library statically or dynamically with other modules is 22: making a combined work based on this library. Thus, the terms and 23: conditions of the GNU General Public License cover the whole 24: combination. 25: 26: As a special exception, the copyright holders of this library give you 27: permission to link this library with independent modules to produce an 28: executable, regardless of the license terms of these independent 29: modules, and to copy and distribute the resulting executable under 30: terms of your choice, provided that you also meet, for each linked 31: independent module, the terms and conditions of the license of that 32: module. An independent module is a module which is not derived from 33: or based on this library. If you modify this library, you may extend 34: this exception to your version of the library, but you are not 35: obligated to do so. If you do not wish to do so, delete this 36: exception statement from your version. */ 37: 38: 39: package javax.swing.plaf.metal; 40: 41: import java.beans.PropertyChangeEvent; 42: import java.beans.PropertyChangeListener; 43: 44: import javax.swing.JComponent; 45: import javax.swing.JInternalFrame; 46: import javax.swing.plaf.ComponentUI; 47: import javax.swing.plaf.basic.BasicInternalFrameUI; 48: 49: /** 50: * A UI delegate for the {@link JInternalFrame} component. 51: */ 52: public class MetalInternalFrameUI 53: extends BasicInternalFrameUI 54: { 55: /** 56: * The key (<code>JInternalFrame.isPalette</code>) for the client property 57: * that controls whether the internal frame is displayed using the palette 58: * style. 59: */ 60: protected static String IS_PALETTE = "JInternalFrame.isPalette"; 61: 62: /** 63: * Constructs a new instance of <code>MetalInternalFrameUI</code>. 64: * 65: * @param frame the frame. 66: */ 67: public MetalInternalFrameUI(JInternalFrame frame) 68: { 69: super(frame); 70: } 71: 72: /** 73: * Returns an instance of <code>MetalInternalFrameUI</code>. 74: * 75: * @param component the internal frame. 76: * 77: * @return an instance of <code>MetalInternalFrameUI</code>. 78: */ 79: public static ComponentUI createUI(JComponent component) 80: { 81: return new MetalInternalFrameUI((JInternalFrame) component); 82: } 83: 84: /** 85: * Sets the fields and properties for the component. 86: * 87: * @param c the component. 88: */ 89: public void installUI(JComponent c) 90: { 91: super.installUI(c); 92: JInternalFrame f = (JInternalFrame) c; 93: boolean isPalette = false; 94: Boolean p = (Boolean) f.getClientProperty(IS_PALETTE); 95: if (p != null) 96: isPalette = p.booleanValue(); 97: setPalette(isPalette); 98: } 99: 100: /** 101: * Creates and returns the component that will be used for the north pane 102: * of the {@link JInternalFrame}. 103: * 104: * @param w the internal frame. 105: * 106: * @return A new instance of {@link MetalInternalFrameTitlePane}. 107: */ 108: protected JComponent createNorthPane(JInternalFrame w) 109: { 110: titlePane = new MetalInternalFrameTitlePane(w); 111: return titlePane; 112: } 113: 114: /** 115: * Sets the state of the {@link JInternalFrame} to reflect whether or not 116: * it is using the palette style. When a frame is displayed as a palette, 117: * it uses a different border and the title pane is drawn differently. 118: * 119: * @param isPalette use the palette style? 120: */ 121: public void setPalette(boolean isPalette) 122: { 123: MetalInternalFrameTitlePane title = (MetalInternalFrameTitlePane) northPane; 124: title.setPalette(isPalette); 125: if (isPalette) 126: frame.setBorder(new MetalBorders.PaletteBorder()); 127: else 128: frame.setBorder(new MetalBorders.InternalFrameBorder()); 129: } 130: 131: /** A listener that is used to handle IS_PALETTE property changes. */ 132: private PropertyChangeListener paletteListener; 133: 134: /** 135: * Adds the required listeners. 136: */ 137: protected void installListeners() 138: { 139: super.installListeners(); 140: paletteListener = new PropertyChangeListener() 141: { 142: public void propertyChange(PropertyChangeEvent e) 143: { 144: if (e.getPropertyName().equals(IS_PALETTE)) 145: { 146: if (Boolean.TRUE.equals(e.getNewValue())) 147: setPalette(true); 148: else 149: setPalette(false); 150: } 151: } 152: }; 153: frame.addPropertyChangeListener(paletteListener); 154: } 155: 156: /** 157: * Removes the listeners used. 158: */ 159: protected void uninstallListeners() 160: { 161: super.uninstallListeners(); 162: frame.removePropertyChangeListener(IS_PALETTE, paletteListener); 163: paletteListener = null; 164: } 165: }
GNU Classpath (0.20) |