001: /*
002: * Copyright 2005-2008 Kirill Grouchnikov, based on work by
003: * Sun Microsystems, Inc. All rights reserved.
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
018: */
019: package org.jvnet.substance.swingx;
020:
021: import java.awt.*;
022: import java.awt.event.HierarchyEvent;
023: import java.awt.event.HierarchyListener;
024: import java.awt.image.BufferedImage;
025:
026: import javax.swing.*;
027: import javax.swing.plaf.ComponentUI;
028:
029: import org.jdesktop.swingx.JXLoginPane;
030: import org.jdesktop.swingx.plaf.basic.BasicLoginPaneUI;
031: import org.jvnet.lafwidget.utils.RenderingUtils;
032: import org.jvnet.substance.*;
033: import org.jvnet.substance.painter.decoration.DecorationAreaType;
034: import org.jvnet.substance.painter.decoration.SubstanceDecorationUtilities;
035: import org.jvnet.substance.utils.SubstanceCoreUtilities;
036:
037: /**
038: * Substance-consistent UI delegate for {@link JXLoginPane}.
039: *
040: * @author Kirill Grouchnikov
041: */
042: public class SubstanceLoginPaneUI extends BasicLoginPaneUI {
043: protected JXLoginPane loginPanel;
044:
045: protected HierarchyListener substanceHierarchyListener;
046:
047: // protected ComponentListener substanceComponentListener;
048:
049: public static ComponentUI createUI(JComponent c) {
050: return new SubstanceLoginPaneUI((JXLoginPane) c);
051: }
052:
053: /**
054: * Creates a new UI component.
055: *
056: * @param dlg
057: * Login panel component.
058: */
059: public SubstanceLoginPaneUI(JXLoginPane dlg) {
060: super (dlg);
061: this .loginPanel = dlg;
062: }
063:
064: /*
065: * (non-Javadoc)
066: *
067: * @see javax.swing.plaf.ComponentUI#installUI(javax.swing.JComponent)
068: */
069: @Override
070: public void installUI(JComponent c) {
071: super .installUI(c);
072: this .substanceHierarchyListener = new HierarchyListener() {
073: public void hierarchyChanged(HierarchyEvent e) {
074: SwingUtilities.invokeLater(new Runnable() {
075: public void run() {
076: Window window = SwingUtilities
077: .getWindowAncestor(loginPanel);
078: if (window != null) {
079: JComponent titlePane = SubstanceLookAndFeel
080: .getTitlePaneComponent(window);
081: if (titlePane != null) {
082: titlePane
083: .putClientProperty(
084: SubstanceLookAndFeel.WATERMARK_IGNORE,
085: Boolean.TRUE);
086: }
087: }
088:
089: loginPanel.setBanner(getBanner());
090: }
091: });
092: }
093: };
094: this .loginPanel
095: .addHierarchyListener(this .substanceHierarchyListener);
096: // this.substanceComponentListener = new ComponentAdapter() {
097: // @Override
098: // public void componentShown(ComponentEvent e) {
099: // SwingUtilities.invokeLater(new Runnable() {
100: // public void run() {
101: // System.out.println("Recomputed");
102: // loginPanel.setImage(getBanner());
103: // }
104: // });
105: // }
106: // };
107: // this.loginPanel.addComponentListener(this.substanceComponentListener);
108: }
109:
110: /*
111: * (non-Javadoc)
112: *
113: * @see javax.swing.plaf.ComponentUI#uninstallUI(javax.swing.JComponent)
114: */
115: @Override
116: public void uninstallUI(JComponent c) {
117: this .loginPanel
118: .removeHierarchyListener(this .substanceHierarchyListener);
119: this .substanceHierarchyListener = null;
120: // this.loginPanel.removeComponentListener(this.substanceComponentListener);
121: // this.substanceComponentListener = null;
122: super .uninstallUI(c);
123: }
124:
125: /*
126: * (non-Javadoc)
127: *
128: * @see org.jdesktop.swingx.plaf.basic.BasicLoginPanelUI#getBanner()
129: */
130: @Override
131: public Image getBanner() {
132: Image super Result = super .getBanner();
133: if (this .loginPanel.getParent() == null)
134: return super Result;
135:
136: int width = super Result.getWidth(null);
137: int height = super Result.getHeight(null);
138: BufferedImage result = SubstanceCoreUtilities.getBlankImage(
139: width, height);
140: Graphics2D graphics = (Graphics2D) result.getGraphics();
141:
142: Icon origIcon = SubstanceCoreUtilities
143: .getIcon("resource/32/login-new32.png");
144: // if (!SubstanceLookAndFeel.isToUseConstantThemesOnDialogs()) {
145: origIcon = new ImageIcon(SubstanceImageCreator.getThemeImage(
146: this .loginPanel, origIcon, SubstanceLookAndFeel
147: .getTheme().getActiveTheme(), false));
148: // }
149:
150: // SubstanceDecorationUtilities.bd =
151:
152: // SubstanceFillBackgroundDelegate sfbd = new
153: // SubstanceFillBackgroundDelegate();
154: SubstanceDecorationUtilities.setDecorationType(this .loginPanel,
155: DecorationAreaType.HEADER);
156: SubstanceFillBackgroundDelegate.GLOBAL_INSTANCE.update(
157: graphics, this .loginPanel, true);
158: SubstanceDecorationUtilities
159: .clearDecorationType(this .loginPanel);
160: //
161: // SubstanceTitlePainter titlePainter = SubstanceLookAndFeel
162: // .getCurrentTitlePainter();
163: // if (titlePainter instanceof SubstanceHeaderPainter) {
164: // SubstanceHeaderPainter headerPainter = (SubstanceHeaderPainter)
165: // titlePainter;
166: // headerPainter.paintExtraBackground(graphics, this.loginPanel
167: // .getParent(), this.loginPanel, width, height,
168: // SubstanceLookAndFeel.getTheme().getActiveTitlePaneTheme(),
169: // false);
170: // } else {
171: // SubstanceTitlePainter painter = SubstanceLookAndFeel
172: // .getCurrentTitlePainter();
173: // if (painter instanceof Glass3DTitlePainter)
174: // painter = new ClassicTitlePainter();
175: // SubstanceTheme theme =
176: // SubstanceThemeUtilities.getTheme(loginPanel).getActiveTitlePaneTheme();
177: // painter.paintTitleBackground(graphics, loginPanel, width, height,
178: // 0, width, theme, 0.0f);
179: // }
180: // SubstanceLookAndFeel.getCurrentWatermark().drawWatermarkImage(
181: // graphics, this.loginPanel, 0, 0, width, height);
182: // Composite oldComp = graphics.getComposite();
183: // graphics.setComposite(TransitionLayout.getAlphaComposite(
184: // this.loginPanel, 0.5f));
185: // headerPainter.paintExtraBackground(graphics, this.loginPanel
186: // .getParent(), this.loginPanel, width, height,
187: // SubstanceLookAndFeel.getTheme(), false);
188: // graphics.setComposite(oldComp);
189:
190: float loginStringX = origIcon.getIconWidth() + 8 + width * .05f;
191: float loginStringY = height * .75f;
192:
193: Font font = UIManager.getFont("JXLoginPane.bannerFont");
194: graphics.setFont(font);
195: Graphics2D originalGraphics = graphics;
196: if (!loginPanel.getComponentOrientation().isLeftToRight()) {
197: originalGraphics = (Graphics2D) graphics.create();
198: graphics.scale(-1, 1);
199: graphics.translate(-width, 0);
200: loginStringX = width
201: - origIcon.getIconWidth()
202: - 8
203: - (((float) font.getStringBounds(
204: loginPanel.getBannerText(),
205: originalGraphics.getFontRenderContext())
206: .getWidth()) + width * .05f);
207: }
208:
209: RenderingUtils.installDesktopHints(graphics);
210: // graphics.setRenderingHint(RenderingHints.KEY_RENDERING,
211: // RenderingHints.VALUE_RENDER_QUALITY);
212: // graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
213: // RenderingHints.VALUE_ANTIALIAS_ON);
214: // graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
215: // RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
216: // graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
217: // RenderingHints.VALUE_FRACTIONALMETRICS_ON);
218:
219: graphics.setColor(SubstanceLookAndFeel.getTheme()
220: .getActiveTitlePaneTheme().getForegroundColor());
221: originalGraphics.drawString(loginPanel.getBannerText(),
222: loginStringX, loginStringY);
223:
224: int iconY = (height - origIcon.getIconHeight()) / 2;
225: if (!loginPanel.getComponentOrientation().isLeftToRight()) {
226: origIcon.paintIcon(loginPanel, graphics, width
227: - origIcon.getIconWidth() - 8, iconY);
228: } else {
229: origIcon.paintIcon(loginPanel, graphics, 8, iconY);
230: }
231: return result;
232: }
233: }
|