KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jgoodies > looks > plastic > PlasticInternalFrameUI


1 /*
2  * Copyright (c) 2001-2005 JGoodies Karsten Lentzsch. All Rights Reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * o Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  *
10  * o Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * o Neither the name of JGoodies Karsten Lentzsch nor the names of
15  * its contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */

30
31 package com.jgoodies.looks.plastic;
32
33 import java.awt.Color JavaDoc;
34 import java.awt.Container JavaDoc;
35 import java.beans.PropertyChangeEvent JavaDoc;
36 import java.beans.PropertyChangeListener JavaDoc;
37
38 import javax.swing.JComponent JavaDoc;
39 import javax.swing.JInternalFrame JavaDoc;
40 import javax.swing.LookAndFeel JavaDoc;
41 import javax.swing.UIManager JavaDoc;
42 import javax.swing.border.Border JavaDoc;
43 import javax.swing.border.EmptyBorder JavaDoc;
44 import javax.swing.plaf.ComponentUI JavaDoc;
45 import javax.swing.plaf.UIResource JavaDoc;
46 import javax.swing.plaf.basic.BasicInternalFrameUI JavaDoc;
47
48
49 /**
50  * The JGoodies Plastic Look and Feel implementation of <code>InternalFrameUI</code>.<p>
51  *
52  * Uses a <code>PlasticInternalFrameTitlePane</code>
53  * that in turn uses <code>PlasticTheme</code> colors.
54  *
55  * @author Karsten Lentzsch
56  * @version $Revision: 1.2 $
57  */

58 public final class PlasticInternalFrameUI extends BasicInternalFrameUI JavaDoc {
59
60
61     private static final String JavaDoc FRAME_TYPE = "JInternalFrame.frameType";
62     public static final String JavaDoc IS_PALETTE = "JInternalFrame.isPalette";
63     private static final String JavaDoc PALETTE_FRAME = "palette";
64     private static final String JavaDoc OPTION_DIALOG = "optionDialog";
65     private static final Border JavaDoc EMPTY_BORDER = new EmptyBorder JavaDoc(0, 0, 0, 0);
66     
67
68     private PlasticInternalFrameTitlePane titlePane;
69     private PropertyChangeListener JavaDoc paletteListener;
70     private PropertyChangeListener JavaDoc contentPaneListener;
71
72     
73     public PlasticInternalFrameUI(JInternalFrame JavaDoc b) {
74         super(b);
75     }
76
77
78     public static ComponentUI JavaDoc createUI(JComponent JavaDoc c) {
79         return new PlasticInternalFrameUI((JInternalFrame JavaDoc) c);
80     }
81
82
83     public void installUI(JComponent JavaDoc c) {
84         frame = (JInternalFrame JavaDoc) 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 JavaDoc paletteProp = c.getClientProperty(IS_PALETTE);
94         if (paletteProp != null) {
95             setPalette(((Boolean JavaDoc) paletteProp).booleanValue());
96         }
97     
98         Container JavaDoc content = frame.getContentPane();
99         stripContentBorder(content);
100     }
101     
102     
103     public void uninstallUI(JComponent JavaDoc c) {
104         frame = (JInternalFrame JavaDoc) c;
105     
106         c.removePropertyChangeListener(paletteListener);
107         c.removePropertyChangeListener(contentPaneListener);
108     
109         Container JavaDoc cont = ((JInternalFrame JavaDoc) (c)).getContentPane();
110         if (cont instanceof JComponent JavaDoc) {
111             JComponent JavaDoc content = (JComponent JavaDoc) 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         /* Enable the content pane to inherit background color
124          * from its parent by setting its background color to null.
125          * Fixes bug#4268949, which has been fixed in 1.4, too. */

126         JComponent JavaDoc contentPane = (JComponent JavaDoc) frame.getContentPane();
127         if (contentPane != null) {
128               Color JavaDoc bg = contentPane.getBackground();
129           if (bg instanceof UIResource JavaDoc)
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 JavaDoc c) {
144         if (c instanceof JComponent JavaDoc) {
145             JComponent JavaDoc contentComp = (JComponent JavaDoc) c;
146             Border JavaDoc contentBorder = contentComp.getBorder();
147             if (contentBorder == null || contentBorder instanceof UIResource JavaDoc) {
148                 contentComp.setBorder(EMPTY_BORDER);
149             }
150         }
151     }
152     
153     
154     protected JComponent JavaDoc createNorthPane(JInternalFrame JavaDoc w) {
155         titlePane = new PlasticInternalFrameTitlePane(w);
156         return titlePane;
157     }
158
159
160     public void setPalette(boolean isPalette) {
161         String JavaDoc key = isPalette ? "InternalFrame.paletteBorder" : "InternalFrame.border";
162         LookAndFeel.installBorder(frame, key);
163         titlePane.setPalette(isPalette);
164     }
165
166
167     private void setFrameType(String JavaDoc frameType) {
168         String JavaDoc 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 JavaDoc {
183
184         private final PlasticInternalFrameUI ui;
185         
186         private PaletteListener(PlasticInternalFrameUI ui) { this.ui = ui; }
187         
188         public void propertyChange(PropertyChangeEvent JavaDoc e) {
189             String JavaDoc name = e.getPropertyName();
190             Object JavaDoc value = e.getNewValue();
191             if (name.equals(FRAME_TYPE)) {
192                 if (value instanceof String JavaDoc) {
193                     ui.setFrameType((String JavaDoc) 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 JavaDoc {
202         
203         private final PlasticInternalFrameUI ui;
204         
205         private ContentPaneListener(PlasticInternalFrameUI ui) { this.ui = ui; }
206         
207         public void propertyChange(PropertyChangeEvent JavaDoc e) {
208             String JavaDoc name = e.getPropertyName();
209             if (name.equals(JInternalFrame.CONTENT_PANE_PROPERTY)) {
210                 ui.stripContentBorder(e.getNewValue());
211             }
212         }
213     }
214
215 }
216
Popular Tags