001: /*
002: * SmoothGradientInternalFrameUI.java
003: *
004: * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: */
021:
022: package org.underworldlabs.swing.plaf.smoothgradient;
023:
024: import java.awt.Color;
025: import java.awt.Container;
026: import java.beans.PropertyChangeEvent;
027: import java.beans.PropertyChangeListener;
028:
029: import javax.swing.JComponent;
030: import javax.swing.JInternalFrame;
031: import javax.swing.LookAndFeel;
032: import javax.swing.UIManager;
033: import javax.swing.border.Border;
034: import javax.swing.border.EmptyBorder;
035: import javax.swing.plaf.ComponentUI;
036: import javax.swing.plaf.UIResource;
037: import javax.swing.plaf.basic.BasicInternalFrameUI;
038:
039: /* ----------------------------------------------------------
040: * CVS NOTE: Changes to the CVS repository prior to the
041: * release of version 3.0.0beta1 has meant a
042: * resetting of CVS revision numbers.
043: * ----------------------------------------------------------
044: */
045:
046: /**
047: *
048: * @author Takis Diakoumis
049: * @version $Revision: 1.4 $
050: * @date $Date: 2006/05/14 06:56:07 $
051: */
052: public class SmoothGradientInternalFrameUI extends BasicInternalFrameUI {
053:
054: private static final String FRAME_TYPE = "JInternalFrame.frameType";
055: public static final String IS_PALETTE = "JInternalFrame.isPalette";
056: private static final String PALETTE_FRAME = "palette";
057: private static final String OPTION_DIALOG = "optionDialog";
058: private static final Border EMPTY_BORDER = new EmptyBorder(0, 0, 0,
059: 0);
060:
061: private SmoothGradientInternalFrameTitlePane titlePane;
062: private PropertyChangeListener paletteListener;
063: private PropertyChangeListener contentPaneListener;
064:
065: public SmoothGradientInternalFrameUI(JInternalFrame b) {
066: super (b);
067: }
068:
069: public static ComponentUI createUI(JComponent c) {
070: return new SmoothGradientInternalFrameUI((JInternalFrame) c);
071: }
072:
073: public void installUI(JComponent c) {
074: frame = (JInternalFrame) c;
075:
076: paletteListener = new PaletteListener(this );
077: contentPaneListener = new ContentPaneListener(this );
078: c.addPropertyChangeListener(paletteListener);
079: c.addPropertyChangeListener(contentPaneListener);
080:
081: super .installUI(c);
082:
083: Object paletteProp = c.getClientProperty(IS_PALETTE);
084: if (paletteProp != null) {
085: setPalette(((Boolean) paletteProp).booleanValue());
086: }
087:
088: Container content = frame.getContentPane();
089: stripContentBorder(content);
090: }
091:
092: public void uninstallUI(JComponent c) {
093: frame = (JInternalFrame) c;
094:
095: c.removePropertyChangeListener(paletteListener);
096: c.removePropertyChangeListener(contentPaneListener);
097:
098: Container cont = ((JInternalFrame) (c)).getContentPane();
099: if (cont instanceof JComponent) {
100: JComponent content = (JComponent) cont;
101: if (content.getBorder() == EMPTY_BORDER) {
102: content.setBorder(null);
103: }
104: }
105: super .uninstallUI(c);
106: }
107:
108: protected void installDefaults() {
109: super .installDefaults();
110:
111: /* Enable the content pane to inherit background color
112: * from its parent by setting its background color to null.
113: * Fixes bug#4268949, which has been fixed in 1.4, too. */
114: JComponent contentPane = (JComponent) frame.getContentPane();
115: if (contentPane != null) {
116: Color bg = contentPane.getBackground();
117: if (bg instanceof UIResource)
118: contentPane.setBackground(null);
119: }
120: frame.setBackground(UIManager.getLookAndFeelDefaults()
121: .getColor("control"));
122: }
123:
124: protected void installKeyboardActions() {
125: }
126:
127: protected void uninstallKeyboardActions() {
128: }
129:
130: private void stripContentBorder(Object c) {
131: if (c instanceof JComponent) {
132: JComponent contentComp = (JComponent) c;
133: Border contentBorder = contentComp.getBorder();
134: if (contentBorder == null
135: || contentBorder instanceof UIResource) {
136: contentComp.setBorder(EMPTY_BORDER);
137: }
138: }
139: }
140:
141: protected JComponent createNorthPane(JInternalFrame w) {
142: titlePane = new SmoothGradientInternalFrameTitlePane(w);
143: return titlePane;
144: }
145:
146: public void setPalette(boolean isPalette) {
147: String key = isPalette ? "InternalFrame.paletteBorder"
148: : "InternalFrame.border";
149: LookAndFeel.installBorder(frame, key);
150: titlePane.setPalette(isPalette);
151: }
152:
153: private void setFrameType(String frameType) {
154: String key;
155: boolean hasPalette = frameType.equals(PALETTE_FRAME);
156: if (frameType.equals(OPTION_DIALOG)) {
157: key = "InternalFrame.optionDialogBorder";
158: } else if (hasPalette) {
159: key = "InternalFrame.paletteBorder";
160: } else {
161: key = "InternalFrame.border";
162: }
163: LookAndFeel.installBorder(frame, key);
164: titlePane.setPalette(hasPalette);
165: }
166:
167: private static class PaletteListener implements
168: PropertyChangeListener {
169:
170: private final SmoothGradientInternalFrameUI ui;
171:
172: private PaletteListener(SmoothGradientInternalFrameUI ui) {
173: this .ui = ui;
174: }
175:
176: public void propertyChange(PropertyChangeEvent e) {
177: String name = e.getPropertyName();
178: Object value = e.getNewValue();
179: if (name.equals(FRAME_TYPE)) {
180: if (value instanceof String) {
181: ui.setFrameType((String) value);
182: }
183: } else if (name.equals(IS_PALETTE)) {
184: ui.setPalette(Boolean.TRUE.equals(value));
185: }
186: }
187: }
188:
189: private static class ContentPaneListener implements
190: PropertyChangeListener {
191:
192: private final SmoothGradientInternalFrameUI ui;
193:
194: private ContentPaneListener(SmoothGradientInternalFrameUI ui) {
195: this .ui = ui;
196: }
197:
198: public void propertyChange(PropertyChangeEvent e) {
199: String name = e.getPropertyName();
200: if (name.equals(JInternalFrame.CONTENT_PANE_PROPERTY)) {
201: ui.stripContentBorder(e.getNewValue());
202: }
203: }
204: }
205:
206: }
|