001: /*
002: * Copyright (c) 2001-2007 JGoodies Karsten Lentzsch. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of JGoodies Karsten Lentzsch nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030:
031: package com.jgoodies.looks.plastic;
032:
033: import java.awt.Color;
034: import java.awt.Container;
035: import java.beans.PropertyChangeEvent;
036: import java.beans.PropertyChangeListener;
037:
038: import javax.swing.JComponent;
039: import javax.swing.JInternalFrame;
040: import javax.swing.LookAndFeel;
041: import javax.swing.UIManager;
042: import javax.swing.border.Border;
043: import javax.swing.border.EmptyBorder;
044: import javax.swing.plaf.ComponentUI;
045: import javax.swing.plaf.UIResource;
046: import javax.swing.plaf.basic.BasicInternalFrameUI;
047:
048: /**
049: * The JGoodies Plastic Look and Feel implementation of <code>InternalFrameUI</code>.<p>
050: *
051: * Uses a <code>PlasticInternalFrameTitlePane</code>
052: * that in turn uses <code>PlasticTheme</code> colors.<p>
053: *
054: * Although this class is not intended for subclassing, there's no final marker.
055: * If you extend this class, carefully obey all explicit and implicit
056: * constraints made in this class and its superclasses.
057: *
058: * @author Karsten Lentzsch
059: * @version $Revision: 1.4 $
060: */
061: public class PlasticInternalFrameUI extends BasicInternalFrameUI {
062:
063: private static final String FRAME_TYPE = "JInternalFrame.frameType";
064: public static final String IS_PALETTE = "JInternalFrame.isPalette";
065: private static final String PALETTE_FRAME = "palette";
066: private static final String OPTION_DIALOG = "optionDialog";
067: private static final Border EMPTY_BORDER = new EmptyBorder(0, 0, 0,
068: 0);
069:
070: private PlasticInternalFrameTitlePane titlePane;
071: private PropertyChangeListener paletteListener;
072: private PropertyChangeListener contentPaneListener;
073:
074: public PlasticInternalFrameUI(JInternalFrame b) {
075: super (b);
076: }
077:
078: public static ComponentUI createUI(JComponent c) {
079: return new PlasticInternalFrameUI((JInternalFrame) c);
080: }
081:
082: public void installUI(JComponent c) {
083: frame = (JInternalFrame) c;
084:
085: paletteListener = new PaletteListener(this );
086: contentPaneListener = new ContentPaneListener(this );
087: c.addPropertyChangeListener(paletteListener);
088: c.addPropertyChangeListener(contentPaneListener);
089:
090: super .installUI(c);
091:
092: Object paletteProp = c.getClientProperty(IS_PALETTE);
093: if (paletteProp != null) {
094: setPalette(((Boolean) paletteProp).booleanValue());
095: }
096:
097: Container content = frame.getContentPane();
098: stripContentBorder(content);
099: }
100:
101: public void uninstallUI(JComponent c) {
102: frame = (JInternalFrame) c;
103:
104: c.removePropertyChangeListener(paletteListener);
105: c.removePropertyChangeListener(contentPaneListener);
106:
107: Container cont = ((JInternalFrame) (c)).getContentPane();
108: if (cont instanceof JComponent) {
109: JComponent content = (JComponent) cont;
110: if (content.getBorder() == EMPTY_BORDER) {
111: content.setBorder(null);
112: }
113: }
114: super .uninstallUI(c);
115: }
116:
117: protected void installDefaults() {
118: super .installDefaults();
119:
120: /* Enable the content pane to inherit background color
121: * from its parent by setting its background color to null.
122: * Fixes bug#4268949, which has been fixed in 1.4, too. */
123: JComponent contentPane = (JComponent) frame.getContentPane();
124: if (contentPane != null) {
125: Color bg = contentPane.getBackground();
126: if (bg instanceof UIResource)
127: contentPane.setBackground(null);
128: }
129: frame.setBackground(UIManager.getLookAndFeelDefaults()
130: .getColor("control"));
131: }
132:
133: protected void installKeyboardActions() {
134: }
135:
136: protected void uninstallKeyboardActions() {
137: }
138:
139: private void stripContentBorder(Object c) {
140: if (c instanceof JComponent) {
141: JComponent contentComp = (JComponent) c;
142: Border contentBorder = contentComp.getBorder();
143: if (contentBorder == null
144: || contentBorder instanceof UIResource) {
145: contentComp.setBorder(EMPTY_BORDER);
146: }
147: }
148: }
149:
150: protected JComponent createNorthPane(JInternalFrame w) {
151: titlePane = new PlasticInternalFrameTitlePane(w);
152: return titlePane;
153: }
154:
155: public void setPalette(boolean isPalette) {
156: String key = isPalette ? "InternalFrame.paletteBorder"
157: : "InternalFrame.border";
158: LookAndFeel.installBorder(frame, key);
159: titlePane.setPalette(isPalette);
160: }
161:
162: private void setFrameType(String frameType) {
163: String key;
164: boolean hasPalette = frameType.equals(PALETTE_FRAME);
165: if (frameType.equals(OPTION_DIALOG)) {
166: key = "InternalFrame.optionDialogBorder";
167: } else if (hasPalette) {
168: key = "InternalFrame.paletteBorder";
169: } else {
170: key = "InternalFrame.border";
171: }
172: LookAndFeel.installBorder(frame, key);
173: titlePane.setPalette(hasPalette);
174: }
175:
176: private static final class PaletteListener implements
177: PropertyChangeListener {
178:
179: private final PlasticInternalFrameUI ui;
180:
181: private PaletteListener(PlasticInternalFrameUI ui) {
182: this .ui = ui;
183: }
184:
185: public void propertyChange(PropertyChangeEvent e) {
186: String name = e.getPropertyName();
187: Object value = e.getNewValue();
188: if (name.equals(FRAME_TYPE)) {
189: if (value instanceof String) {
190: ui.setFrameType((String) value);
191: }
192: } else if (name.equals(IS_PALETTE)) {
193: ui.setPalette(Boolean.TRUE.equals(value));
194: }
195: }
196: }
197:
198: private static final class ContentPaneListener implements
199: PropertyChangeListener {
200:
201: private final PlasticInternalFrameUI ui;
202:
203: private ContentPaneListener(PlasticInternalFrameUI ui) {
204: this .ui = ui;
205: }
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: }
|