001: /*
002: * Copyright (c) 2005-2008 Substance Kirill Grouchnikov. 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 Substance Kirill Grouchnikov 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: package org.jvnet.substance;
031:
032: import java.awt.Color;
033: import java.beans.PropertyChangeEvent;
034: import java.beans.PropertyChangeListener;
035:
036: import javax.swing.JComponent;
037: import javax.swing.JInternalFrame;
038: import javax.swing.JInternalFrame.JDesktopIcon;
039: import javax.swing.plaf.ComponentUI;
040: import javax.swing.plaf.UIResource;
041: import javax.swing.plaf.basic.BasicInternalFrameUI;
042:
043: import org.jvnet.substance.utils.SubstanceInternalFrameTitlePane;
044:
045: /**
046: * UI for internal frames in <b>Substance</b> look and feel.
047: *
048: * @author Kirill Grouchnikov
049: */
050: public class SubstanceInternalFrameUI extends BasicInternalFrameUI {
051: /**
052: * Title pane
053: */
054: private SubstanceInternalFrameTitlePane titlePane;
055:
056: /**
057: * Property listener on the associated internal frame.
058: */
059: protected PropertyChangeListener substancePropertyListener;
060:
061: /**
062: * Simple constructor.
063: *
064: * @param b
065: * Associated internal frame.
066: */
067: public SubstanceInternalFrameUI(JInternalFrame b) {
068: super (b);
069: }
070:
071: /*
072: * (non-Javadoc)
073: *
074: * @see javax.swing.plaf.ComponentUI#createUI(javax.swing.JComponent)
075: */
076: public static ComponentUI createUI(JComponent c) {
077: return new SubstanceInternalFrameUI((JInternalFrame) c);
078: }
079:
080: /*
081: * (non-Javadoc)
082: *
083: * @see javax.swing.plaf.basic.BasicInternalFrameUI#createNorthPane(javax.swing.JInternalFrame)
084: */
085: @Override
086: protected JComponent createNorthPane(JInternalFrame w) {
087: this .titlePane = new SubstanceInternalFrameTitlePane(w);
088:
089: // f.putClientProperty(INTERNAL_FRAME_PINNED, Boolean.TRUE);
090:
091: return this .titlePane;
092: }
093:
094: /*
095: * (non-Javadoc)
096: *
097: * @see javax.swing.plaf.basic.BasicInternalFrameUI#uninstallComponents()
098: */
099: @Override
100: protected void uninstallComponents() {
101: this .titlePane.uninstall();
102: super .uninstallComponents();
103: }
104:
105: /*
106: * (non-Javadoc)
107: *
108: * @see javax.swing.plaf.basic.BasicInternalFrameUI#installListeners()
109: */
110: @Override
111: protected void installListeners() {
112: super .installListeners();
113: this .substancePropertyListener = new PropertyChangeListener() {
114: public void propertyChange(PropertyChangeEvent evt) {
115: if (JInternalFrame.IS_CLOSED_PROPERTY.equals(evt
116: .getPropertyName())) {
117: titlePane.uninstall();
118: JDesktopIcon jdi = frame.getDesktopIcon();
119: SubstanceDesktopIconUI ui = (SubstanceDesktopIconUI) jdi
120: .getUI();
121: ui.uninstallUI(jdi);
122: }
123:
124: if ("background".equals(evt.getPropertyName())) {
125: Color newBackgr = (Color) evt.getNewValue();
126: if (!(newBackgr instanceof UIResource)) {
127: getTitlePane().setBackground(newBackgr);
128: frame.getDesktopIcon().setBackground(newBackgr);
129: }
130: }
131: }
132: };
133: this .frame
134: .addPropertyChangeListener(this .substancePropertyListener);
135: }
136:
137: /*
138: * (non-Javadoc)
139: *
140: * @see javax.swing.plaf.basic.BasicInternalFrameUI#uninstallListeners()
141: */
142: @Override
143: protected void uninstallListeners() {
144: this .frame
145: .removePropertyChangeListener(this .substancePropertyListener);
146: this .substancePropertyListener = null;
147: super .uninstallListeners();
148: }
149:
150: // private class BorderListener1 extends BorderListener implements
151: // SwingConstants {
152: //
153: // Rectangle getIconBounds() {
154: // int xOffset = 5;
155: // Rectangle rect = null;
156: //
157: // Icon icon = SubstanceInternalFrameUI.this.frame.getFrameIcon();
158: // if (icon != null) {
159: // int iconY = ((SubstanceInternalFrameUI.this.titlePane.getHeight() / 2) -
160: // (icon
161: // .getIconHeight() / 2));
162: // rect = new Rectangle(xOffset, iconY, icon.getIconWidth(), icon
163: // .getIconHeight());
164: // }
165: // return rect;
166: // }
167: //
168: // @Override
169: // public void mouseClicked(MouseEvent e) {
170: // if ((e.getClickCount() == 2) && (e.getSource() ==
171: // SubstanceInternalFrameUI.this.getNorthPane())
172: // && SubstanceInternalFrameUI.this.frame.isClosable() &&
173: // !SubstanceInternalFrameUI.this.frame.isIcon()) {
174: // Rectangle rect = this.getIconBounds();
175: // if ((rect != null) && rect.contains(e.getX(), e.getY())) {
176: // SubstanceInternalFrameUI.this.frame.doDefaultCloseAction();
177: // } else {
178: // super.mouseClicked(e);
179: // }
180: // } else {
181: // super.mouseClicked(e);
182: // }
183: // }
184: // } // / End BorderListener Class
185: //
186: // /**
187: // * Returns the <code>MouseInputAdapter<code> that will be installed
188: // * on the TitlePane.
189: // *
190: // * @param w the <code>JInternalFrame</code>
191: // * @return the <code>MouseInputAdapter</code> that will be installed
192: // * on the TitlePane.
193: // * @since 1.6
194: // */
195: // @Override
196: // protected MouseInputAdapter createBorderListener(JInternalFrame w) {
197: // return new BorderListener1();
198: // }
199: //
200: /**
201: * Returns the title pane of the associated internal frame. This method is
202: * <b>for internal use only</b>.
203: *
204: * @return Title pane of the associated internal frame.
205: */
206: public SubstanceInternalFrameTitlePane getTitlePane() {
207: return titlePane;
208: }
209:
210: // @Override
211: // public void update(Graphics g, JComponent c) {
212: // super.update(g, c);
213: // }
214: }
|