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.painter.decoration;
031:
032: import java.awt.*;
033: import java.awt.image.BufferedImage;
034: import java.util.Map;
035:
036: import org.jvnet.lafwidget.layout.TransitionLayout;
037: import org.jvnet.substance.SubstanceImageCreator;
038: import org.jvnet.substance.SubstanceLookAndFeel;
039: import org.jvnet.substance.painter.ClassicGradientPainter;
040: import org.jvnet.substance.theme.SubstanceTheme;
041: import org.jvnet.substance.utils.SoftHashMap;
042: import org.jvnet.substance.utils.SubstanceCoreUtilities;
043:
044: /**
045: * Decoration painter that paints a classic gradient. This class is part of
046: * officially supported API.
047: *
048: * @author Kirill Grouchnikov
049: * @since version 4.3
050: */
051: public class ClassicDecorationPainter implements
052: SubstanceDecorationPainter {
053: /**
054: * The display name for the decoraion painters of this class.
055: */
056: public static final String DISPLAY_NAME = "Classic";
057:
058: /**
059: * Cache for small objects.
060: */
061: protected static Map<String, BufferedImage> smallImageCache = new SoftHashMap<String, BufferedImage>();
062:
063: /**
064: * Single gradient painter instance.
065: */
066: protected ClassicGradientPainter painter;
067:
068: /**
069: * Creates new classic title painter.
070: */
071: public ClassicDecorationPainter() {
072: this .painter = new ClassicGradientPainter();
073: }
074:
075: /*
076: * (non-Javadoc)
077: *
078: * @see org.jvnet.substance.utils.SubstanceTrait#getDisplayName()
079: */
080: public String getDisplayName() {
081: return DISPLAY_NAME;
082: }
083:
084: /*
085: * (non-Javadoc)
086: *
087: * @see org.jvnet.substance.painter.decoration.SubstanceDecorationPainter#paintDecorationArea(java.awt.Graphics2D,
088: * java.awt.Component,
089: * org.jvnet.substance.painter.decoration.DecorationAreaType, int, int,
090: * org.jvnet.substance.theme.SubstanceTheme)
091: */
092: public void paintDecorationArea(Graphics2D graphics,
093: Component comp, DecorationAreaType decorationAreaType,
094: int width, int height, SubstanceTheme theme) {
095: int size = Math.max(width, height);
096: if (size < 150) {
097: synchronized (this ) {
098: String key = width + "*" + height + "*"
099: + theme.getDisplayName();
100: BufferedImage result = smallImageCache.get(key);
101: if (result == null) {
102: result = SubstanceCoreUtilities.getBlankImage(
103: width, height);
104: this .internalPaint((Graphics2D) result
105: .getGraphics(), width, height, theme);
106: smallImageCache.put(key, result);
107: }
108: graphics.drawImage(result, 0, 0, null);
109: return;
110: }
111: }
112:
113: this .internalPaint(graphics, width, height, theme);
114: }
115:
116: /**
117: * Paints the title background.
118: *
119: * @param graphics
120: * Graphics context.
121: * @param width
122: * Width.
123: * @param height
124: * Height.
125: * @param leftTitleX
126: * Title start poisition.
127: * @param rightTitleX
128: * Title end position.
129: * @param theme
130: * Substance theme for painting the title packground.
131: */
132: protected void internalPaint(Graphics2D graphics, int width,
133: int height, SubstanceTheme theme) {
134: graphics.setColor(theme.getActiveTitlePaneTheme()
135: .getColorScheme().getMidColor());
136: graphics.drawImage(this .painter.getContourBackground(width + 6,
137: height + 6, new Rectangle(width + 6, height + 6),
138: false,
139: theme.getActiveTitlePaneTheme().getColorScheme(), theme
140: .getActiveTitlePaneTheme().getColorScheme(), 0,
141: false, false), -3, -3, null);
142: }
143:
144: /**
145: * Resets image maps (used when setting new theme).
146: *
147: * @see SubstanceLookAndFeel#setCurrentTheme(String)
148: * @see SubstanceLookAndFeel#setCurrentTheme(SubstanceTheme)
149: */
150: public static synchronized void reset() {
151: smallImageCache.clear();
152: }
153: }
|