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.Graphics2D;
022: import java.awt.Window;
023: import java.awt.image.BufferedImage;
024:
025: import javax.swing.*;
026: import javax.swing.plaf.ComponentUI;
027:
028: import org.jdesktop.swingx.JXStatusBar;
029: import org.jdesktop.swingx.plaf.basic.BasicStatusBarUI;
030: import org.jvnet.substance.SubstanceImageCreator;
031: import org.jvnet.substance.color.ColorScheme;
032: import org.jvnet.substance.painter.decoration.DecorationAreaType;
033: import org.jvnet.substance.painter.decoration.SubstanceDecorationUtilities;
034: import org.jvnet.substance.theme.SubstanceTheme;
035: import org.jvnet.substance.utils.SubstanceCoreUtilities;
036: import org.jvnet.substance.utils.SubstanceThemeUtilities;
037:
038: /**
039: * Substance-consistent UI delegate for {@link JXStatusBar}.
040: *
041: * @author Kirill Grouchnikov
042: */
043: public class SubstanceStatusBarUI extends BasicStatusBarUI {
044: /**
045: * Background delegate.
046: */
047: private SubstanceSwingxFillBackgroundDelegate bgDelegate;
048:
049: public static ComponentUI createUI(JComponent c) {
050: return new SubstanceStatusBarUI();
051: }
052:
053: /**
054: * Creates a new UI delegate.
055: */
056: public SubstanceStatusBarUI() {
057: super ();
058: this .bgDelegate = new SubstanceSwingxFillBackgroundDelegate();
059: }
060:
061: /*
062: * (non-Javadoc)
063: *
064: * @see org.jdesktop.swingx.plaf.basic.BasicStatusBarUI#installDefaults(org.jdesktop.swingx.JXStatusBar)
065: */
066: @Override
067: protected void installDefaults(JXStatusBar sb) {
068: super .installDefaults(sb);
069: sb.putClientProperty(
070: SubstanceCoreUtilities.HAS_CUSTOM_BACKGROUND_FILL,
071: Boolean.TRUE);
072: SubstanceDecorationUtilities.setDecorationType(sb,
073: DecorationAreaType.GENERAL);
074: }
075:
076: /*
077: * (non-Javadoc)
078: *
079: * @see org.jdesktop.swingx.plaf.basic.BasicStatusBarUI#uninstallDefaults(org.jdesktop.swingx.JXStatusBar)
080: */
081: @Override
082: protected void uninstallDefaults(JXStatusBar sb) {
083: SubstanceDecorationUtilities.clearDecorationType(sb);
084: sb
085: .putClientProperty(
086: SubstanceCoreUtilities.HAS_CUSTOM_BACKGROUND_FILL,
087: null);
088: super .uninstallDefaults(sb);
089: }
090:
091: @Override
092: protected void paintBackground(Graphics2D g, JXStatusBar bar) {
093: this .bgDelegate.paint(bar, g, true);
094: // SubstanceTitlePainter titlePainter = SubstanceLookAndFeel
095: // .getCurrentTitlePainter();
096: // boolean useHeaderPainter = (titlePainter instanceof
097: // SubstanceHeaderPainter);
098: // SubstanceTheme headerTheme = SubstanceLookAndFeel.getTheme()
099: // .getActiveTitlePaneTheme();
100: // if (useHeaderPainter) {
101: // if (SubstanceCoreUtilities.isThemeDark(headerTheme) !=
102: // SubstanceCoreUtilities
103: // .isThemeDark(SubstanceLookAndFeel.getTheme())) {
104: // headerTheme = SubstanceLookAndFeel.getTheme();
105: // }
106: // }
107: //
108: JRootPane rootPane = SwingUtilities.getRootPane(bar);
109: Window window = SwingUtilities.getWindowAncestor(bar);
110: boolean isResizable = false;
111: if (window instanceof JFrame) {
112: JFrame frame = (JFrame) window;
113: isResizable = frame.isResizable()
114: && (frame.getExtendedState() != JFrame.MAXIMIZED_BOTH);
115: }
116: if (window instanceof JDialog) {
117: isResizable = ((JDialog) window).isResizable();
118: }
119: boolean hasResizeGrip = SubstanceCoreUtilities
120: .toShowExtraElements(rootPane)
121: && isResizable;
122: if (hasResizeGrip) {
123: int dim = bar.getHeight() * 2 / 3;
124: SubstanceTheme componentTheme = SubstanceThemeUtilities
125: .getTheme(bar);
126: BufferedImage resizeImage = SubstanceImageCreator
127: .getResizeGripImage(bar, componentTheme, dim, false);
128: g.drawImage(resizeImage, bar.getWidth() - dim, bar
129: .getHeight()
130: - dim, null);
131: }
132: }
133:
134: /*
135: * (non-Javadoc)
136: *
137: * @see org.jdesktop.swingx.plaf.basic.BasicStatusBarUI#paintSeparator(java.awt.Graphics2D,
138: * org.jdesktop.swingx.JXStatusBar, int, int, int, int)
139: */
140: @Override
141: protected void paintSeparator(Graphics2D g, JXStatusBar bar, int x,
142: int y, int w, int h) {
143: g.translate(x, y);
144:
145: SubstanceTheme componentTheme = SubstanceThemeUtilities
146: .getTheme(bar);
147: // SubstanceTitlePainter titlePainter = SubstanceCoreUtilities
148: // .getTitlePainter(SwingUtilities.getRootPane(bar));
149: // boolean shouldUseHeaderPainter = titlePainter instanceof
150: // SubstanceHeaderPainter;
151: // SubstanceTheme theme = SubstanceLookAndFeel.getTheme();
152: // if (shouldUseHeaderPainter) {
153: // theme = SubstanceLookAndFeel.getTheme().getActiveTitlePaneTheme();
154: //
155: // // special case for skins such as BusinessBlackSteel, which use
156: // // dark theme for header (title pane + menus) - using such a dark
157: // // theme on a status bar is not good, since all the status bar
158: // // controls are assuming a non-dark theme (they use black foreground
159: // // color).
160: // if (SubstanceCoreUtilities.isThemeDark(theme) !=
161: // SubstanceCoreUtilities
162: // .isThemeDark(SubstanceLookAndFeel.getTheme())) {
163: // theme = SubstanceLookAndFeel.getTheme();
164: // }
165: // }
166: // boolean isDark = SubstanceCoreUtilities.isThemeDark(theme
167: // .getActiveTheme());
168: ColorScheme colorScheme = componentTheme.getColorScheme();
169:
170: SubstanceCoreUtilities.paintSeparator(bar, g, colorScheme,
171: SubstanceCoreUtilities.isThemeDark(componentTheme), w,
172: h, JSlider.VERTICAL, true, 4);
173: g.translate(-x, -y);
174: }
175: //
176: // /*
177: // * (non-Javadoc)
178: // *
179: // * @see javax.swing.plaf.ComponentUI#update(java.awt.Graphics,
180: // * javax.swing.JComponent)
181: // */
182: // @Override
183: // public void update(Graphics g, JComponent c) {
184: // super.update(g, c);
185: // GhostPaintingUtils.paintGhostImages(c, g);
186: // }
187: }
|