Source Code Cross Referenced for SubstanceImageCreator.java in  » Swing-Library » substance-look-feel » org » jvnet » substance » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Swing Library » substance look feel » org.jvnet.substance 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * Copyright (c) 2005-2008 Substance Kirill Grouchnikov. All Rights Reserved.
0003:         *
0004:         * Redistribution and use in source and binary forms, with or without
0005:         * modification, are permitted provided that the following conditions are met:
0006:         *
0007:         *  o Redistributions of source code must retain the above copyright notice,
0008:         *    this list of conditions and the following disclaimer.
0009:         *
0010:         *  o Redistributions in binary form must reproduce the above copyright notice,
0011:         *    this list of conditions and the following disclaimer in the documentation
0012:         *    and/or other materials provided with the distribution.
0013:         *
0014:         *  o Neither the name of Substance Kirill Grouchnikov nor the names of
0015:         *    its contributors may be used to endorse or promote products derived
0016:         *    from this software without specific prior written permission.
0017:         *
0018:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0019:         * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
0020:         * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
0021:         * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
0022:         * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
0023:         * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
0024:         * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
0025:         * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
0026:         * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
0027:         * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
0028:         * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0029:         */
0030:        package org.jvnet.substance;
0031:
0032:        import java.awt.*;
0033:        import java.awt.geom.Ellipse2D;
0034:        import java.awt.geom.GeneralPath;
0035:        import java.awt.image.*;
0036:        import java.util.*;
0037:        import java.util.List;
0038:
0039:        import javax.swing.*;
0040:        import javax.swing.plaf.UIResource;
0041:
0042:        import org.jvnet.lafwidget.animation.FadeKind;
0043:        import org.jvnet.lafwidget.layout.TransitionLayout;
0044:        import org.jvnet.substance.border.FlatBorderPainter;
0045:        import org.jvnet.substance.border.SubstanceBorderPainter;
0046:        import org.jvnet.substance.button.BaseButtonShaper;
0047:        import org.jvnet.substance.color.*;
0048:        import org.jvnet.substance.painter.*;
0049:        import org.jvnet.substance.theme.*;
0050:        import org.jvnet.substance.theme.SubstanceTheme.ThemeKind;
0051:        import org.jvnet.substance.utils.*;
0052:        import org.jvnet.substance.utils.ComponentState.ColorSchemeKind;
0053:        import org.jvnet.substance.utils.SubstanceConstants.Side;
0054:        import org.jvnet.substance.watermark.SubstanceWatermark;
0055:
0056:        /**
0057:         * Provides utility functions for creating various images for <b>Substance </b>
0058:         * look and feel. This class is <b>for internal use only</b>.
0059:         * 
0060:         * @author Kirill Grouchnikov
0061:         */
0062:        public final class SubstanceImageCreator {
0063:            /**
0064:             * Paints border instance of specified dimensions and status.
0065:             * 
0066:             * @param c
0067:             *            Component.
0068:             * @param graphics
0069:             *            Graphics context.
0070:             * @param x
0071:             *            Component left X (in graphics context).
0072:             * @param y
0073:             *            Component top Y (in graphics context).
0074:             * @param width
0075:             *            Border width.
0076:             * @param height
0077:             *            Border height.
0078:             * @param radius
0079:             *            Border radius.
0080:             * @param borderScheme
0081:             *            Border color scheme.
0082:             */
0083:            public static void paintBorder(Component c, Graphics2D graphics,
0084:                    int x, int y, int width, int height, float radius,
0085:                    ColorScheme borderScheme) {
0086:
0087:                SubstanceBorderPainter borderPainter = SubstanceCoreUtilities
0088:                        .getBorderPainter(c);
0089:                graphics.translate(x, y);
0090:                int borderDelta = (int) Math.floor(SubstanceSizeUtils
0091:                        .getBorderStrokeWidth(SubstanceSizeUtils
0092:                                .getComponentFontSize(c)) / 2.0);
0093:                Shape contour = BaseButtonShaper.getBaseOutline(width, height,
0094:                        radius, null, borderDelta);
0095:                int borderThickness = (int) SubstanceSizeUtils
0096:                        .getBorderStrokeWidth(SubstanceSizeUtils
0097:                                .getComponentFontSize(c));
0098:                GeneralPath contourInner = BaseButtonShaper.getBaseOutline(
0099:                        width, height, radius, null, borderThickness
0100:                                + borderDelta);
0101:                borderPainter.paintBorder(graphics, c, width, height, contour,
0102:                        contourInner, borderScheme, borderScheme, 0, false);
0103:                graphics.translate(-x, -y);
0104:            }
0105:
0106:            /**
0107:             * Paints border instance of specified dimensions and status.
0108:             * 
0109:             * @param c
0110:             *            Component.
0111:             * @param graphics
0112:             *            Graphics context.
0113:             * @param x
0114:             *            Component left X (in graphics context).
0115:             * @param y
0116:             *            Component top Y (in graphics context).
0117:             * @param width
0118:             *            Border width.
0119:             * @param height
0120:             *            Border height.
0121:             * @param radius
0122:             *            Border radius.
0123:             * @param theme
0124:             *            Border theme.
0125:             */
0126:            public static void paintBorder(Component c, Graphics2D graphics,
0127:                    int x, int y, int width, int height, float radius,
0128:                    SubstanceTheme theme) {
0129:                SubstanceImageCreator
0130:                        .paintBorder(c, graphics, x, y, width, height, radius,
0131:                                theme.getBorderTheme().getColorScheme());
0132:            }
0133:
0134:            /**
0135:             * Retrieves check mark image.
0136:             * 
0137:             * @param button
0138:             *            Button for the check mark.
0139:             * @param dimension
0140:             *            Check mark dimension.
0141:             * @param isEnabled
0142:             *            Enabled status.
0143:             * @param theme
0144:             *            Theme for the check mark.
0145:             * @param checkMarkVisibility
0146:             *            Checkmark visibility in 0.0-1.0 range.
0147:             * @return Check mark image.
0148:             */
0149:            private static BufferedImage getCheckMark(AbstractButton button,
0150:                    int dimension, boolean isEnabled, SubstanceTheme theme,
0151:                    float checkMarkVisibility) {
0152:                BufferedImage result = SubstanceCoreUtilities.getBlankImage(
0153:                        dimension, dimension);
0154:
0155:                // get graphics and set hints
0156:                Graphics2D graphics = (Graphics2D) result.getGraphics();
0157:                graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
0158:                        RenderingHints.VALUE_ANTIALIAS_ON);
0159:
0160:                // create curved checkbox path
0161:                GeneralPath path = new GeneralPath();
0162:
0163:                path.moveTo(0.25f * dimension, 0.5f * dimension);
0164:                path.quadTo(0.37f * dimension, 0.6f * dimension,
0165:                        0.47f * dimension, 0.8f * dimension);
0166:                path.quadTo(0.55f * dimension, 0.5f * dimension,
0167:                        0.85f * dimension, 0f);
0168:
0169:                // compute the x-based clip for the visibility
0170:                float xClipStart = 0.15f * dimension;
0171:                float xClipEnd = 0.95f * dimension;
0172:
0173:                float xClipRealEnd = xClipStart + (xClipEnd - xClipStart)
0174:                        * checkMarkVisibility;
0175:
0176:                graphics
0177:                        .setClip(0, 0, (int) Math.ceil(xClipRealEnd), dimension);
0178:
0179:                boolean isColorized = SubstanceCoreUtilities
0180:                        .hasColorization(button);
0181:                if (isColorized) {
0182:                    // support for enhancement 256 - colorizing the check mark
0183:                    // with foreground color.
0184:                    double colorization = SubstanceCoreUtilities
0185:                            .getColorizationFactor(button);
0186:                    if (!button.isEnabled())
0187:                        colorization /= 2.0;
0188:                    Color fore = button.getForeground();
0189:                    if (!(fore instanceof  UIResource)) {
0190:                        theme = SubstanceShiftTheme.getShiftedTheme(theme,
0191:                                fore, colorization, fore, colorization);
0192:                    }
0193:                }
0194:
0195:                graphics.setColor(SubstanceCoreUtilities.getMarkColor(theme,
0196:                        isEnabled));
0197:                Stroke stroke = new BasicStroke((float) 0.15 * dimension,
0198:                        BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
0199:                graphics.setStroke(stroke);
0200:                graphics.draw(path);
0201:
0202:                // if (isEnabled) {
0203:                // graphics.setColor(theme.getBorderTheme().getColorScheme()
0204:                // .getDarkColor());
0205:                // Stroke stroke2 = new BasicStroke((float) 0.05 * dimension,
0206:                // BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
0207:                // graphics.setStroke(stroke2);
0208:                // graphics.draw(path);
0209:                // }
0210:
0211:                return result;
0212:            }
0213:
0214:            /**
0215:             * Returns arrow icon for the specified parameters.
0216:             * 
0217:             * @param fontSize
0218:             *            Font size.
0219:             * @param direction
0220:             *            Arrow direction.
0221:             * @param theme
0222:             *            Icon theme.
0223:             * @return Arrow icon.
0224:             */
0225:            public static Icon getArrowIcon(int fontSize, int direction,
0226:                    SubstanceTheme theme) {
0227:                return new ImageIcon(getArrow(SubstanceSizeUtils
0228:                        .getArrowIconWidth(fontSize), SubstanceSizeUtils
0229:                        .getArrowIconHeight(fontSize), SubstanceSizeUtils
0230:                        .getArrowStrokeWidth(fontSize), direction, theme));
0231:            }
0232:
0233:            /**
0234:             * Returns arrow icon for the specified parameters.
0235:             * 
0236:             * @param fontSize
0237:             *            Font size.
0238:             * @param deltaWidth
0239:             *            Arrow width delta.
0240:             * @param deltaHeight
0241:             *            Arrow height delta.
0242:             * @param deltaStrokeWidth
0243:             *            Arrow stroke width delta.
0244:             * @param direction
0245:             *            Arrow direction.
0246:             * @param theme
0247:             *            Icon theme.
0248:             * @return Arrow icon.
0249:             */
0250:            public static Icon getArrowIcon(int fontSize, int deltaWidth,
0251:                    int deltaHeight, float deltaStrokeWidth, int direction,
0252:                    SubstanceTheme theme) {
0253:                int arrowWidth = SubstanceSizeUtils.getArrowIconWidth(fontSize);
0254:                if (deltaWidth != 0) {
0255:                    arrowWidth += SubstanceSizeUtils.getAdjustedSize(fontSize,
0256:                            deltaWidth, 6, -1, true);// - 1;
0257:                }
0258:                if (arrowWidth % 2 == 0)
0259:                    arrowWidth--;
0260:                int arrowHeight = SubstanceSizeUtils
0261:                        .getArrowIconHeight(fontSize);
0262:                if (deltaHeight != 0) {
0263:                    arrowHeight += SubstanceSizeUtils.getAdjustedSize(fontSize,
0264:                            deltaHeight, 4, -1, false);
0265:                }
0266:                float arrowStrokeWidth = SubstanceSizeUtils
0267:                        .getArrowStrokeWidth(fontSize);
0268:                if (deltaStrokeWidth != 0) {
0269:                    arrowStrokeWidth += SubstanceSizeUtils.getAdjustedSize(
0270:                            fontSize, deltaStrokeWidth, 1, 0.04f);
0271:                }
0272:                return new ImageIcon(getArrow(arrowWidth, arrowHeight,
0273:                        arrowStrokeWidth, direction, theme));
0274:            }
0275:
0276:            /**
0277:             * Retrieves arrow icon.
0278:             * 
0279:             * @param width
0280:             *            Arrow width.
0281:             * @param height
0282:             *            Arrow height.
0283:             * @param strokeWidth
0284:             *            Stroke width.
0285:             * @param direction
0286:             *            Arrow direction.
0287:             * @param theme
0288:             *            Theme for the arrow.
0289:             * @return Arrow image.
0290:             * @see SwingConstants#NORTH
0291:             * @see SwingConstants#WEST
0292:             * @see SwingConstants#SOUTH
0293:             * @see SwingConstants#EAST
0294:             */
0295:            public static Icon getArrowIcon(int width, int height,
0296:                    float strokeWidth, int direction, SubstanceTheme theme) {
0297:                return new ImageIcon(getArrow(width, height, strokeWidth,
0298:                        direction, theme));
0299:            }
0300:
0301:            /**
0302:             * Retrieves arrow image.
0303:             * 
0304:             * @param width
0305:             *            Arrow width.
0306:             * @param height
0307:             *            Arrow height.
0308:             * @param strokeWidth
0309:             *            Stroke width.
0310:             * @param direction
0311:             *            Arrow direction.
0312:             * @param theme
0313:             *            Theme for the arrow.
0314:             * @return Arrow image.
0315:             * @see SwingConstants#NORTH
0316:             * @see SwingConstants#WEST
0317:             * @see SwingConstants#SOUTH
0318:             * @see SwingConstants#EAST
0319:             * @see SwingConstants#CENTER
0320:             */
0321:            public static BufferedImage getArrow(int width, int height,
0322:                    float strokeWidth, int direction, SubstanceTheme theme) {
0323:                BufferedImage arrowImage = SubstanceCoreUtilities
0324:                        .getBlankImage(width, height);
0325:
0326:                // System.out.println(width + ":" + height + ":" + strokeWidth);
0327:
0328:                // get graphics and set hints
0329:                Graphics2D graphics = (Graphics2D) arrowImage.getGraphics();
0330:                graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
0331:                        RenderingHints.VALUE_ANTIALIAS_ON);
0332:
0333:                Color arrowColor = SubstanceCoreUtilities.getMarkColor(theme
0334:                        .getActiveTheme(), true);
0335:
0336:                graphics.setColor(arrowColor);
0337:                Stroke stroke = new BasicStroke(strokeWidth,
0338:                        BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
0339:
0340:                graphics.setStroke(stroke);
0341:
0342:                if (direction == SwingConstants.CENTER) {
0343:                    GeneralPath gp = new GeneralPath();
0344:                    float h2 = height / 2.f;
0345:                    float w2 = (float) 0.5 * (width - 1);
0346:                    gp.moveTo(0, h2 - 1f);
0347:                    gp.lineTo(w2, 2);
0348:                    gp.lineTo(width - 1, h2 - 1f);
0349:                    gp.moveTo(width - 1, h2 + 1f);
0350:                    gp.lineTo(w2, height - 2);
0351:                    gp.lineTo(0, h2 + 1f);
0352:                    graphics.draw(gp);
0353:                    return arrowImage;
0354:
0355:                } else {
0356:
0357:                    GeneralPath gp = new GeneralPath();
0358:                    gp.moveTo(0, 0);
0359:                    gp.lineTo((float) 0.5 * (width - 1), height - 2);
0360:                    gp.lineTo(width - 1, 0);
0361:                    graphics.draw(gp);
0362:                    // graphics.drawPolyline(new int[] { 0, width / 2, width - 1 }, new
0363:                    // int[] {
0364:                    // 0, height - 2, 0 }, 3);
0365:
0366:                    int quadrantCounterClockwise = 0;
0367:                    switch (direction) {
0368:                    case SwingConstants.NORTH:
0369:                        quadrantCounterClockwise = 2;
0370:                        break;
0371:                    case SwingConstants.WEST:
0372:                        quadrantCounterClockwise = 1;
0373:                        break;
0374:                    case SwingConstants.SOUTH:
0375:                        quadrantCounterClockwise = 0;
0376:                        break;
0377:                    case SwingConstants.EAST:
0378:                        quadrantCounterClockwise = 3;
0379:                        break;
0380:                    }
0381:                    BufferedImage rotatedImage = SubstanceImageCreator
0382:                            .getRotated(arrowImage, quadrantCounterClockwise);
0383:
0384:                    return rotatedImage;
0385:                }
0386:            }
0387:
0388:            /**
0389:             * Returns double arrow icon for the specified parameters.
0390:             * 
0391:             * @param fontSize
0392:             *            Font size.
0393:             * @param direction
0394:             *            Arrow direction.
0395:             * @param theme
0396:             *            Icon theme.
0397:             * @return Double arrow icon.
0398:             */
0399:            public static Icon getDoubleArrowIcon(int fontSize, int direction,
0400:                    SubstanceTheme theme) {
0401:                return getDoubleArrowIcon(fontSize, 0, 0, 0, direction, theme);
0402:            }
0403:
0404:            /**
0405:             * Returns double arrow icon for the specified parameters.
0406:             * 
0407:             * @param fontSize
0408:             *            Font size.
0409:             * @param deltaWidth
0410:             *            Arrow width delta.
0411:             * @param deltaHeight
0412:             *            Arrow height delta.
0413:             * @param deltaStrokeWidth
0414:             *            Arrow stroke width delta.
0415:             * @param direction
0416:             *            Arrow direction.
0417:             * @param theme
0418:             *            Icon theme.
0419:             * @return Double arrow icon.
0420:             */
0421:            public static Icon getDoubleArrowIcon(int fontSize, int deltaWidth,
0422:                    int deltaHeight, float deltaStrokeWidth, int direction,
0423:                    SubstanceTheme theme) {
0424:                int arrowWidth = SubstanceSizeUtils
0425:                        .getArrowIconWidth(SubstanceSizeUtils
0426:                                .getControlFontSize())
0427:                        + deltaWidth;
0428:                int arrowHeight = SubstanceSizeUtils
0429:                        .getArrowIconHeight(SubstanceSizeUtils
0430:                                .getControlFontSize())
0431:                        + deltaHeight;
0432:                float arrowStrokeWidth = SubstanceSizeUtils
0433:                        .getDoubleArrowStrokeWidth(SubstanceSizeUtils
0434:                                .getControlFontSize())
0435:                        + deltaStrokeWidth;
0436:                return getDoubleArrowIcon(arrowWidth, arrowHeight,
0437:                        arrowStrokeWidth, direction, theme);
0438:            }
0439:
0440:            /**
0441:             * Retrieves arrow icon.
0442:             * 
0443:             * @param width
0444:             *            Arrow width.
0445:             * @param height
0446:             *            Arrow height.
0447:             * @param strokeWidth
0448:             *            Stroke width.
0449:             * @param direction
0450:             *            Arrow direction.
0451:             * @param theme
0452:             *            Theme for the arrow.
0453:             * @return Arrow image.
0454:             * @see SwingConstants#NORTH
0455:             * @see SwingConstants#WEST
0456:             * @see SwingConstants#SOUTH
0457:             * @see SwingConstants#EAST
0458:             */
0459:            public static Icon getDoubleArrowIcon(int width, int height,
0460:                    float strokeWidth, int direction, SubstanceTheme theme) {
0461:                int delta = 3 + SubstanceSizeUtils
0462:                        .getExtraPadding(SubstanceSizeUtils
0463:                                .getControlFontSize());
0464:                BufferedImage downArrowImage = SubstanceCoreUtilities
0465:                        .getBlankImage(width, height + delta - 2);
0466:
0467:                // get graphics and set hints
0468:                Graphics2D graphics = (Graphics2D) downArrowImage.getGraphics();
0469:                graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
0470:                        RenderingHints.VALUE_ANTIALIAS_ON);
0471:
0472:                Color arrowColor = SubstanceCoreUtilities.getMarkColor(theme
0473:                        .getActiveTheme(), true);
0474:                graphics.setColor(arrowColor);
0475:                Stroke stroke = new BasicStroke(strokeWidth,
0476:                        BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
0477:
0478:                graphics.setStroke(stroke);
0479:                GeneralPath gp = new GeneralPath();
0480:                gp.moveTo(0, 0);
0481:                gp.lineTo((float) 0.5 * (width - 1), height - delta - 1);
0482:                gp.lineTo(width - 1, 0);
0483:                graphics.draw(gp);
0484:
0485:                GeneralPath gp2 = new GeneralPath();
0486:                gp2.moveTo(0, delta);
0487:                gp2.lineTo((float) 0.5 * (width - 1), height - 1);
0488:                gp2.lineTo(width - 1, delta);
0489:                graphics.draw(gp2);
0490:
0491:                int quadrantCounterClockwise = 0;
0492:                switch (direction) {
0493:                case SwingConstants.NORTH:
0494:                    quadrantCounterClockwise = 2;
0495:                    break;
0496:                case SwingConstants.WEST:
0497:                    quadrantCounterClockwise = 1;
0498:                    break;
0499:                case SwingConstants.SOUTH:
0500:                    quadrantCounterClockwise = 0;
0501:                    break;
0502:                case SwingConstants.EAST:
0503:                    quadrantCounterClockwise = 3;
0504:                    break;
0505:                }
0506:                BufferedImage arrowImage = SubstanceImageCreator.getRotated(
0507:                        downArrowImage, quadrantCounterClockwise);
0508:
0509:                return new ImageIcon(arrowImage);
0510:            }
0511:
0512:            /**
0513:             * Returns rotated image.
0514:             * 
0515:             * @param bi
0516:             *            Image to rotate.
0517:             * @param quadrantClockwise
0518:             *            Amount of quadrants to rotate in clockwise directio. The
0519:             *            rotation angle is 90 times this value.
0520:             * @return Rotated image.
0521:             */
0522:            public static BufferedImage getRotated(final BufferedImage bi,
0523:                    int quadrantClockwise) {
0524:                quadrantClockwise = quadrantClockwise % 4;
0525:                int width = bi.getWidth();
0526:                int height = bi.getHeight();
0527:                if ((quadrantClockwise == 1) || (quadrantClockwise == 3)) {
0528:                    width = bi.getHeight();
0529:                    height = bi.getWidth();
0530:                }
0531:                BufferedImage biRot = SubstanceCoreUtilities.getBlankImage(
0532:                        width, height);
0533:                switch (quadrantClockwise) {
0534:                case 0:
0535:                    return bi;
0536:                case 1:
0537:                    // 90 deg
0538:                    for (int col = 0; col < width; col++) {
0539:                        for (int row = 0; row < height; row++) {
0540:                            biRot.setRGB(col, row, bi.getRGB(row, width - col
0541:                                    - 1));
0542:                        }
0543:                    }
0544:                    return biRot;
0545:                case 2:
0546:                    // 180 deg
0547:                    for (int col = 0; col < width; col++) {
0548:                        for (int row = 0; row < height; row++) {
0549:                            biRot.setRGB(col, row, bi.getRGB(width - col - 1,
0550:                                    height - row - 1));
0551:                        }
0552:                    }
0553:                    return biRot;
0554:                case 3:
0555:                    // 270 deg
0556:                    for (int col = 0; col < width; col++) {
0557:                        for (int row = 0; row < height; row++) {
0558:                            biRot.setRGB(col, row, bi.getRGB(height - row - 1,
0559:                                    col));
0560:                        }
0561:                    }
0562:                    return biRot;
0563:                }
0564:                return null;
0565:            }
0566:
0567:            /**
0568:             * Translated the specified icon to grey scale.
0569:             * 
0570:             * @param icon
0571:             *            Icon.
0572:             * @return Greyscale version of the specified icon.
0573:             */
0574:            public static Icon toGreyscale(Icon icon) {
0575:                if (icon == null) {
0576:                    return null;
0577:                }
0578:
0579:                int width = icon.getIconWidth();
0580:                int height = icon.getIconHeight();
0581:
0582:                BufferedImage result = new BufferedImage(width, height,
0583:                        BufferedImage.TYPE_INT_ARGB);
0584:
0585:                // set completely transparent
0586:                for (int col = 0; col < width; col++) {
0587:                    for (int row = 0; row < height; row++) {
0588:                        result.setRGB(col, row, 0x0);
0589:                    }
0590:                }
0591:
0592:                icon.paintIcon(null, result.getGraphics(), 0, 0);
0593:                for (int col = 0; col < width; col++) {
0594:                    for (int row = 0; row < height; row++) {
0595:                        int color = result.getRGB(col, row);
0596:                        int transp = (color >>> 24) & 0xFF;
0597:
0598:                        int newComp = SubstanceColorUtilities
0599:                                .getColorBrightness(color);
0600:                        int newColor = (transp << 24) | (newComp << 16)
0601:                                | (newComp << 8) | newComp;
0602:
0603:                        result.setRGB(col, row, newColor);
0604:                    }
0605:                }
0606:
0607:                return new ImageIcon(result);
0608:            }
0609:
0610:            /**
0611:             * Makes the specified icon transparent.
0612:             * 
0613:             * @param c
0614:             *            Component.
0615:             * @param icon
0616:             *            Icon.
0617:             * @param alpha
0618:             *            The opaqueness of the resulting image. The closer this value
0619:             *            is to 0.0, the more transparent resulting image will be.
0620:             * @return Transparent version of the specified icon.
0621:             */
0622:            public static Icon makeTransparent(Component c, Icon icon,
0623:                    double alpha) {
0624:                if (icon == null) {
0625:                    return null;
0626:                }
0627:
0628:                int width = icon.getIconWidth();
0629:                int height = icon.getIconHeight();
0630:
0631:                BufferedImage result = new BufferedImage(width, height,
0632:                        BufferedImage.TYPE_INT_ARGB);
0633:
0634:                // set completely transparent
0635:                for (int col = 0; col < width; col++) {
0636:                    for (int row = 0; row < height; row++) {
0637:                        result.setRGB(col, row, 0x0);
0638:                    }
0639:                }
0640:
0641:                icon.paintIcon(c, result.getGraphics(), 0, 0);
0642:                for (int col = 0; col < width; col++) {
0643:                    for (int row = 0; row < height; row++) {
0644:                        int color = result.getRGB(col, row);
0645:                        int transp = (int) (alpha * ((color >>> 24) & 0xFF));
0646:                        int r = (color >>> 16) & 0xFF;
0647:                        int g = (color >>> 8) & 0xFF;
0648:                        int b = (color >>> 0) & 0xFF;
0649:
0650:                        int newColor = (transp << 24) | (r << 16) | (g << 8)
0651:                                | b;
0652:
0653:                        result.setRGB(col, row, newColor);
0654:                    }
0655:                }
0656:
0657:                return new ImageIcon(result);
0658:            }
0659:
0660:            /**
0661:             * Retrieves radio button of the specified size that matches the specified
0662:             * parameters.
0663:             * 
0664:             * @param component
0665:             *            Component.
0666:             * @param dimension
0667:             *            Radio button dimension.
0668:             * @param componentState
0669:             *            Component state.
0670:             * @param offsetX
0671:             *            Offset on X axis - should be positive in order to see the
0672:             *            entire radio button.
0673:             * @param theme1
0674:             *            Theme 1.
0675:             * @param theme2
0676:             *            Theme 2.
0677:             * @param interpolationCyclePos10
0678:             *            Interpolation cycle.
0679:             * @param checkMarkVisibility
0680:             *            Checkmark visibility in 0.0-1.0 range.
0681:             * @return Radio button of the specified size that matches the specified
0682:             *         parameters.
0683:             */
0684:            public static BufferedImage getRadioButton(Component component,
0685:                    int dimension, ComponentState componentState, int offsetX,
0686:                    SubstanceTheme theme1, SubstanceTheme theme2,
0687:                    float interpolationCyclePos10, float checkMarkVisibility) {
0688:
0689:                // ComponentState.ColorSchemeKind kind = componentState
0690:                // .getColorSchemeKind();
0691:
0692:                float cyclePos = (theme1 != theme2) ? interpolationCyclePos10
0693:                        : componentState.getCycleCount();
0694:
0695:                Shape contour = new Ellipse2D.Float(0, 0, dimension - 1,
0696:                        dimension - 1);
0697:                // GeneralPath contour = BaseButtonShaper.getBaseOutline(dimension,
0698:                // dimension, (dimension - 1) / 2.0f, null);
0699:                SubstanceGradientPainter painter = SubstanceLookAndFeel
0700:                        .getCurrentGradientPainter();
0701:                // if ((componentState == ComponentState.PRESSED_SELECTED)
0702:                // || (componentState == ComponentState.PRESSED_UNSELECTED)) {
0703:                // painter = new FlatGradientPainter();
0704:                // }
0705:                if (componentState.getColorSchemeKind() != ColorSchemeKind.CURRENT) {
0706:                    painter = SubstanceThemeUtilities.getTheme(component)
0707:                            .getNonActivePainter();
0708:                }
0709:                SubstanceBorderPainter borderPainter = SubstanceCoreUtilities
0710:                        .getBorderPainter(component);
0711:                BufferedImage background = painter.getContourBackground(
0712:                        dimension, dimension, contour, false, theme1
0713:                                .getColorScheme(), theme2.getColorScheme(),
0714:                        cyclePos, true, theme1 != theme2);
0715:
0716:                float borderThickness = SubstanceSizeUtils
0717:                        .getBorderStrokeWidth(dimension);
0718:                int delta = (int) (borderThickness - 0.6);
0719:                // System.out.println(dimension + ":" + borderThickness + ":" + delta);
0720:
0721:                Shape contourBorder = new Ellipse2D.Float(delta, delta,
0722:                        dimension - 2 * delta - 1, dimension - 2 * delta - 1);
0723:
0724:                BufferedImage offBackground = SubstanceCoreUtilities
0725:                        .getBlankImage(dimension + offsetX, dimension);
0726:                Graphics2D graphics = (Graphics2D) offBackground.getGraphics();
0727:                float alpha = SubstanceThemeUtilities.getTheme(component)
0728:                        .getThemeAlpha(component, componentState);
0729:                graphics.setComposite(AlphaComposite.getInstance(
0730:                        AlphaComposite.SRC_OVER, alpha));
0731:
0732:                graphics.translate(offsetX, 0);
0733:                graphics.drawImage(background, 0, 0, null);
0734:
0735:                Shape contourInner = new Ellipse2D.Float(delta
0736:                        + borderThickness, delta + borderThickness, dimension
0737:                        - 2 * delta - 2 * borderThickness, dimension - 2
0738:                        * delta - 2 * borderThickness);
0739:
0740:                borderPainter.paintBorder(graphics, component, dimension,
0741:                        dimension, contourBorder, contourInner, theme1
0742:                                .getBorderTheme().getColorScheme(), theme2
0743:                                .getBorderTheme().getColorScheme(), cyclePos,
0744:                        theme1 != theme2);
0745:                graphics.setComposite(AlphaComposite.SrcOver);
0746:                graphics.translate(-offsetX, 0);
0747:
0748:                float rc = dimension / 2.0f;
0749:                float radius = dimension / 4.5f;
0750:                graphics.translate(offsetX, 0);
0751:
0752:                graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
0753:                        RenderingHints.VALUE_ANTIALIAS_ON);
0754:
0755:                boolean isColorized = SubstanceCoreUtilities
0756:                        .hasColorization(component);
0757:                if (isColorized) {
0758:                    // support for enhancement 256 - colorizing the check mark
0759:                    // with foreground color.
0760:                    double colorization = SubstanceCoreUtilities
0761:                            .getColorizationFactor(component);
0762:                    if (!component.isEnabled())
0763:                        colorization /= 2.0;
0764:                    Color fore = component.getForeground();
0765:                    if (!(fore instanceof  UIResource)) {
0766:                        theme1 = SubstanceShiftTheme.getShiftedTheme(theme1,
0767:                                fore, colorization, fore, colorization);
0768:                        theme2 = SubstanceShiftTheme.getShiftedTheme(theme2,
0769:                                fore, colorization, fore, colorization);
0770:                    }
0771:                }
0772:
0773:                if (componentState.isKindActive(FadeKind.SELECTION)
0774:                        || (checkMarkVisibility > 0.0)) {
0775:                    // mark
0776:                    Shape markOval = new Ellipse2D.Double(rc - radius, rc
0777:                            - radius, 2 * radius, 2 * radius);
0778:                    // float innerRadius = dimension / 7.0f;
0779:                    // Shape innerMarkOval = new Ellipse2D.Double(rc - innerRadius, rc
0780:                    // - innerRadius, 2 * innerRadius, 2 * innerRadius);
0781:
0782:                    graphics.setComposite(AlphaComposite.getInstance(
0783:                            AlphaComposite.SRC_OVER, alpha
0784:                                    * checkMarkVisibility));
0785:                    drawRadioMark(
0786:                            graphics,
0787:                            SubstanceCoreUtilities
0788:                                    .getMarkColor(
0789:                                            theme1,
0790:                                            componentState.getColorSchemeKind() != ColorSchemeKind.DISABLED),
0791:                            markOval);
0792:                    // if (componentState.isKindActive(FadeKind.ENABLE))
0793:                    // drawRadioMark(graphics, theme1.getBorderTheme()
0794:                    // .getColorScheme().getDarkColor(), innerMarkOval);
0795:                    graphics.setComposite(AlphaComposite.getInstance(
0796:                            AlphaComposite.SRC_OVER, alpha
0797:                                    * checkMarkVisibility * cyclePos / 10.0f));
0798:                    drawRadioMark(
0799:                            graphics,
0800:                            SubstanceCoreUtilities
0801:                                    .getMarkColor(
0802:                                            theme2,
0803:                                            componentState.getColorSchemeKind() != ColorSchemeKind.DISABLED),
0804:                            markOval);
0805:                    // if (componentState.isKindActive(FadeKind.ENABLE))
0806:                    // drawRadioMark(graphics, theme2.getBorderTheme()
0807:                    // .getColorScheme().getDarkColor(), innerMarkOval);
0808:                } else {
0809:                    // draw ghost mark holder
0810:                    graphics.setPaint(new GradientPaint(rc + radius, rc
0811:                            - radius, theme1.getColorScheme().getDarkColor(),
0812:                            rc - radius, rc + radius, theme1.getColorScheme()
0813:                                    .getLightColor()));
0814:                    Shape markOval = new Ellipse2D.Double(rc - radius, rc
0815:                            - radius, 2 * radius, 2 * radius);
0816:                    graphics.setComposite(AlphaComposite.getInstance(
0817:                            AlphaComposite.SRC_OVER, alpha * 0.3f));
0818:                    graphics.fill(markOval);
0819:                }
0820:                graphics.translate(-offsetX, 0);
0821:
0822:                return offBackground;
0823:            }
0824:
0825:            /**
0826:             * Draws radio mark.
0827:             * 
0828:             * @param graphics
0829:             *            Graphics context.
0830:             * @param color
0831:             *            Radio mark color.
0832:             * @param markOval
0833:             *            Radio mark shape.
0834:             */
0835:            private static void drawRadioMark(Graphics2D graphics, Color color,
0836:                    Shape markOval) {
0837:                graphics.setColor(color);
0838:                graphics.fill(markOval);
0839:            }
0840:
0841:            /**
0842:             * Retrieves check box of the specified size that matches the specified
0843:             * component state.
0844:             * 
0845:             * @param button
0846:             *            Button for the check mark.
0847:             * @param dimension
0848:             *            Check box size.
0849:             * @param componentState
0850:             *            Component state.
0851:             * @return Check box of the specified size that matches the specified
0852:             *         component state.
0853:             * @param theme1
0854:             *            Theme 1.
0855:             * @param theme2
0856:             *            Theme 2.
0857:             * @param interpolationCyclePos10
0858:             *            Interpolation cycle.
0859:             * @param checkMarkVisibility
0860:             *            Checkmark visibility in 0.0-1.0 range.
0861:             */
0862:            public static BufferedImage getCheckBox(AbstractButton button,
0863:                    int dimension, ComponentState componentState,
0864:                    SubstanceTheme theme1, SubstanceTheme theme2,
0865:                    float interpolationCyclePos10, float checkMarkVisibility,
0866:                    boolean isCheckMarkFadingOut) {
0867:
0868:                int offset = SubstanceSizeUtils.getAdjustedSize(
0869:                        SubstanceSizeUtils.getComponentFontSize(button), 3, 9,
0870:                        1, false);
0871:                int delta = offset;
0872:                float cornerRadius = SubstanceSizeUtils
0873:                        .getClassicButtonCornerRadius(SubstanceSizeUtils
0874:                                .getComponentFontSize(button));
0875:                if (dimension <= 10) {
0876:                    offset = 2;
0877:                    cornerRadius = 2;
0878:                }
0879:
0880:                float cyclePos = (theme1 != theme2) ? interpolationCyclePos10
0881:                        : componentState.getCycleCount();
0882:
0883:                int contourDim = dimension - delta;
0884:                int borderDelta = (int) Math.floor(SubstanceSizeUtils
0885:                        .getBorderStrokeWidth(SubstanceSizeUtils
0886:                                .getComponentFontSize(button)) / 2.0);
0887:                GeneralPath contour = BaseButtonShaper
0888:                        .getBaseOutline(contourDim, contourDim, cornerRadius,
0889:                                null, borderDelta);
0890:
0891:                SubstanceGradientPainter painter = SubstanceLookAndFeel
0892:                        .getCurrentGradientPainter();
0893:                if (componentState.getColorSchemeKind() != ColorSchemeKind.CURRENT) {
0894:                    painter = SubstanceThemeUtilities.getTheme(button)
0895:                            .getNonActivePainter();
0896:                }
0897:                SubstanceBorderPainter borderPainter = SubstanceCoreUtilities
0898:                        .getBorderPainter(button);
0899:
0900:                BufferedImage background = painter.getContourBackground(
0901:                        contourDim, contourDim, contour, false, theme1
0902:                                .getColorScheme(), theme2.getColorScheme(),
0903:                        cyclePos, true, theme1 != theme2);
0904:
0905:                BufferedImage offBackground = SubstanceCoreUtilities
0906:                        .getBlankImage(dimension, dimension);
0907:                Graphics2D graphics = (Graphics2D) offBackground.getGraphics();
0908:                float alpha = SubstanceThemeUtilities.getTheme(button)
0909:                        .getThemeAlpha(button, componentState);
0910:                graphics.setComposite(AlphaComposite.getInstance(
0911:                        AlphaComposite.SRC_OVER, alpha));
0912:
0913:                graphics.translate(delta - 1, delta - 1);
0914:                graphics.drawImage(background, 0, 0, null);
0915:                int borderThickness = (int) SubstanceSizeUtils
0916:                        .getBorderStrokeWidth(dimension);
0917:                GeneralPath contourInner = BaseButtonShaper.getBaseOutline(
0918:                        contourDim, contourDim, cornerRadius, null,
0919:                        borderThickness + borderDelta);
0920:                borderPainter.paintBorder(graphics, button, contourDim,
0921:                        contourDim, contour, contourInner, theme1
0922:                                .getBorderTheme().getColorScheme(), theme2
0923:                                .getBorderTheme().getColorScheme(), cyclePos,
0924:                        theme1 != theme2);
0925:                graphics.translate(-delta, 1 - delta);
0926:                if (componentState.isKindActive(FadeKind.SELECTION)
0927:                        || (checkMarkVisibility > 0.0)) {
0928:                    if (isCheckMarkFadingOut) {
0929:                        graphics.setComposite(AlphaComposite.getInstance(
0930:                                AlphaComposite.SRC_OVER, alpha
0931:                                        * checkMarkVisibility));
0932:                        checkMarkVisibility = 1.0f;
0933:                    }
0934:
0935:                    BufferedImage checkMark1 = SubstanceImageCreator
0936:                            .getCheckMark(button, dimension - 2 * offset / 3,
0937:                                    componentState
0938:                                            .isKindActive(FadeKind.ENABLE),
0939:                                    theme1, checkMarkVisibility);
0940:                    graphics.drawImage(checkMark1, 1 + 2 * offset / 3,
0941:                            (dimension < 14) ? 0 : -1, null);
0942:                    BufferedImage checkMark2 = SubstanceImageCreator
0943:                            .getCheckMark(button, dimension - 2 * offset / 3,
0944:                                    componentState
0945:                                            .isKindActive(FadeKind.ENABLE),
0946:                                    theme2, checkMarkVisibility);
0947:                    graphics.setComposite(AlphaComposite.getInstance(
0948:                            AlphaComposite.SRC_OVER, alpha * cyclePos / 10.0f));
0949:                    graphics.drawImage(checkMark2, 1 + 2 * offset / 3,
0950:                            (dimension < 14) ? 0 : -1, null);
0951:                }
0952:
0953:                return offBackground;
0954:            }
0955:
0956:            /**
0957:             * Retrieves composite background for the specified parameters. The
0958:             * composite background consists of three layers:
0959:             * <ol>
0960:             * <li>Layer that matches the <code>increased</code> state.
0961:             * <li>Layer that matches the <code>decreased</code> state.
0962:             * <li>Regular layer with rounded background.
0963:             * </ol>
0964:             * The layers are drawn in the following order:
0965:             * <ol>
0966:             * <li>The left half of the first layer
0967:             * <li>The right half of the second layer
0968:             * <li>The third layer
0969:             * </ol>
0970:             * Combined together, the layers create the image for scrollbar track with
0971:             * continuation of the arrow increase and decrease buttons.
0972:             * 
0973:             * @param component
0974:             *            Component.
0975:             * @param width
0976:             *            Image width.
0977:             * @param height
0978:             *            Image height.
0979:             * @param cornerRadius
0980:             *            Corner radius.
0981:             * @param decrButton
0982:             *            The <code>decrease</code> button.
0983:             * @param incrButton
0984:             *            The <code>increase</code> button.
0985:             * @param flipSides
0986:             *            If <code>true</code>, the drawn halves of the first and the
0987:             *            second layers above will be swapped.
0988:             * @return Composite background for the specified parameters.
0989:             */
0990:            public static BufferedImage getCompositeRoundedBackground(
0991:                    JComponent component, int width, int height,
0992:                    int cornerRadius, AbstractButton decrButton,
0993:                    AbstractButton incrButton, boolean flipSides) {
0994:
0995:                BufferedImage decrLayer = null;
0996:                BufferedImage incrLayer = null;
0997:
0998:                int delta = 3;
0999:                Set<Side> left = new HashSet<Side>();
1000:                left.add(Side.LEFT);
1001:                Set<Side> right = new HashSet<Side>();
1002:                right.add(Side.RIGHT);
1003:                SubstanceGradientPainter painter = new SimplisticSoftBorderReverseGradientPainter();
1004:
1005:                if (decrButton != null) {
1006:                    decrLayer = PairwiseButtonBackgroundDelegate
1007:                            .getPairwiseBackground(decrButton, painter, width
1008:                                    + 2 * delta, height, flipSides ? Side.RIGHT
1009:                                    : Side.LEFT, true);
1010:                }
1011:
1012:                if (incrButton != null) {
1013:                    incrLayer = PairwiseButtonBackgroundDelegate
1014:                            .getPairwiseBackground(incrButton, painter, width
1015:                                    + 2 * delta, height, flipSides ? Side.LEFT
1016:                                    : Side.RIGHT, true);
1017:                }
1018:
1019:                BufferedImage result = SubstanceCoreUtilities.getBlankImage(
1020:                        width, height);
1021:                Graphics2D graphics = (Graphics2D) result.getGraphics();
1022:                if (!flipSides) {
1023:                    if (decrLayer != null) {
1024:                        graphics.drawImage(decrLayer, -delta, 0, width / 2,
1025:                                height, 0, 0, width / 2, height, null);
1026:                    }
1027:                    if (incrLayer != null) {
1028:                        graphics.drawImage(incrLayer, width / 2, 0, width,
1029:                                height, width / 2, 0, width, height, null);
1030:                    }
1031:                } else {
1032:                    if (incrLayer != null) {
1033:                        graphics.drawImage(incrLayer, -delta, 0, width / 2,
1034:                                height, 0, 0, width / 2, height, null);
1035:                    }
1036:                    if (decrLayer != null) {
1037:                        graphics.drawImage(decrLayer, width / 2, 0, width,
1038:                                height, width / 2, 0, width, height, null);
1039:                    }
1040:                }
1041:
1042:                return result;
1043:            }
1044:
1045:            /**
1046:             * Returns a one-pixel high line of the specified width that has gradient
1047:             * based on the parameters.
1048:             * 
1049:             * @param width
1050:             *            The width of the resulting image.
1051:             * @param colorLeft
1052:             *            The color of the leftmost pixel.
1053:             * @param colorRight
1054:             *            The color of the rightmost pixel.
1055:             * @param waypoints
1056:             *            Each entry in this map specifies color for some
1057:             *            <code>waypoint</code>. The pixels between the waypoints
1058:             *            will be colored based on the interpolation of the two closest
1059:             *            waypoints.
1060:             * @return One-pixel high line of the specified width that has gradient
1061:             *         based on the parameters.
1062:             */
1063:            public static BufferedImage getOneLineGradient(int width,
1064:                    Color colorLeft, Color colorRight,
1065:                    Map<Integer, Color> waypoints) {
1066:                BufferedImage image = new BufferedImage(width, 1,
1067:                        BufferedImage.TYPE_INT_ARGB);
1068:
1069:                Graphics2D graphics = (Graphics2D) image.getGraphics();
1070:
1071:                java.util.List<Integer> waypointMarkers = new ArrayList<Integer>();
1072:                if (waypoints != null) {
1073:                    for (Integer marker : waypoints.keySet()) {
1074:                        waypointMarkers.add(marker);
1075:                    }
1076:                }
1077:                Collections.sort(waypointMarkers);
1078:
1079:                int[] markers = new int[waypointMarkers.size() + 2];
1080:                Color[] colors = new Color[waypointMarkers.size() + 2];
1081:                markers[0] = 0;
1082:                colors[0] = colorLeft;
1083:                int index = 1;
1084:                for (Integer marker : waypointMarkers) {
1085:                    markers[index] = marker;
1086:                    colors[index] = waypoints.get(marker);
1087:                    index++;
1088:                }
1089:                markers[index] = width - 1;
1090:                colors[index] = colorRight;
1091:
1092:                for (int i = 0; i < (markers.length - 1); i++) {
1093:                    GradientPaint gradient = new GradientPaint(markers[i], 0,
1094:                            colors[i], markers[i + 1], 0, colors[i + 1]);
1095:                    graphics.setPaint(gradient);
1096:                    graphics.drawLine(markers[i], 0, markers[i + 1], 0);
1097:                }
1098:
1099:                return image;
1100:            }
1101:
1102:            // /**
1103:            // * Paints a one-pixel high line of the specified width that has gradient
1104:            // * based on the parameters.
1105:            // *
1106:            // * @param graphics
1107:            // * Graphics context.
1108:            // * @param x
1109:            // * X start coordinate.
1110:            // * @param y
1111:            // * Y start coordinate.
1112:            // * @param dimension
1113:            // * The dimension of the resulting image. If
1114:            // * <code>isVertical</code> parameter is <code>true</code>,
1115:            // * the resulting painting will be 1 pixel high and
1116:            // * <code>dimension</code> pixels wide, otherwise it will be
1117:            // * <code>dimension</code> pixels high and 1 pixel wide.
1118:            // * @param isVertical
1119:            // * Indication of horizontal / vertical orientation.
1120:            // * @param colorLeft
1121:            // * The color of the leftmost pixel.
1122:            // * @param colorRight
1123:            // * The color of the rightmost pixel.
1124:            // * @param waypoints
1125:            // * Each entry in this map specifies color for some
1126:            // * <code>waypoint</code>. The pixels between the waypoints
1127:            // * will be colored based on the interpolation of the two closest
1128:            // * waypoints.
1129:            // */
1130:            // public static void paintOneLineGradient(Graphics2D graphics, int x, int
1131:            // y,
1132:            // int dimension, boolean isVertical, Color colorLeft,
1133:            // Color colorRight, Map<Integer, Color> waypoints) {
1134:            //
1135:            // graphics.translate(x, y);
1136:            // java.util.List<Integer> waypointMarkers = new ArrayList<Integer>();
1137:            // if (waypoints != null) {
1138:            // for (Integer marker : waypoints.keySet()) {
1139:            // waypointMarkers.add(marker);
1140:            // }
1141:            // }
1142:            // Collections.sort(waypointMarkers);
1143:            //
1144:            // int[] markers = new int[waypointMarkers.size() + 2];
1145:            // Color[] colors = new Color[waypointMarkers.size() + 2];
1146:            // markers[0] = 0;
1147:            // colors[0] = colorLeft;
1148:            // int index = 1;
1149:            // for (Integer marker : waypointMarkers) {
1150:            // markers[index] = marker;
1151:            // colors[index] = waypoints.get(marker);
1152:            // index++;
1153:            // }
1154:            // markers[index] = dimension - 1;
1155:            // colors[index] = colorRight;
1156:            //
1157:            // if (!isVertical) {
1158:            // for (int i = 0; i < (markers.length - 1); i++) {
1159:            // GradientPaint gradient = new GradientPaint(markers[i], 0,
1160:            // colors[i], markers[i + 1], 0, colors[i + 1]);
1161:            // graphics.setPaint(gradient);
1162:            // graphics
1163:            // .fillRect(markers[i], 0, markers[i + 1] - markers[i], 1);
1164:            // }
1165:            // } else {
1166:            // for (int i = 0; i < (markers.length - 1); i++) {
1167:            // GradientPaint gradient = new GradientPaint(0, markers[i],
1168:            // colors[i], 0, markers[i + 1], colors[i + 1]);
1169:            // graphics.setPaint(gradient);
1170:            // graphics
1171:            // .fillRect(0, markers[i], 1, markers[i + 1] - markers[i]);
1172:            // }
1173:            // }
1174:            // graphics.translate(-x, -y);
1175:            // }
1176:            //
1177:            /**
1178:             * Overlays light-colored echo below the specified image.
1179:             * 
1180:             * @param image
1181:             *            The input image.
1182:             * @param echoAlpha
1183:             *            Alpha channel for the echo image.
1184:             * @param offsetX
1185:             *            X offset of the echo.
1186:             * @param offsetY
1187:             *            Y offset of the echo.
1188:             * @return Image with overlayed echo.
1189:             */
1190:            public static BufferedImage overlayEcho(BufferedImage image,
1191:                    float echoAlpha, int offsetX, int offsetY) {
1192:                int width = image.getWidth();
1193:                int height = image.getHeight();
1194:
1195:                // blur the original image
1196:                // ConvolveOp convolve = new ConvolveOp(new Kernel(3, 3, new float[] {
1197:                // .4f, .4f, .4f, .4f, .0f, .4f, .4f, .4f, .4f }),
1198:                // ConvolveOp.EDGE_NO_OP, null);
1199:                offsetX = offsetY = 0;
1200:                BufferedImage negated = getNegated(image);
1201:                BufferedImage result = SubstanceCoreUtilities.getBlankImage(
1202:                        width, height);
1203:                Graphics2D graphics = (Graphics2D) result.getGraphics()
1204:                        .create();
1205:                graphics.setComposite(AlphaComposite.getInstance(
1206:                        AlphaComposite.SRC_OVER, 0.2f * echoAlpha * echoAlpha
1207:                                * echoAlpha));
1208:                graphics.drawImage(negated, offsetX - 1, offsetY - 1, null);
1209:                graphics.drawImage(negated, offsetX + 1, offsetY - 1, null);
1210:                graphics.drawImage(negated, offsetX - 1, offsetY + 1, null);
1211:                graphics.drawImage(negated, offsetX + 1, offsetY + 1, null);
1212:                graphics.setComposite(AlphaComposite.getInstance(
1213:                        AlphaComposite.SRC_OVER, 0.7f * echoAlpha * echoAlpha
1214:                                * echoAlpha));
1215:                graphics.drawImage(negated, offsetX, offsetY - 1, null);
1216:                graphics.drawImage(negated, offsetX, offsetY + 1, null);
1217:                graphics.drawImage(negated, offsetX - 1, offsetY, null);
1218:                graphics.drawImage(negated, offsetX + 1, offsetY, null);
1219:
1220:                graphics.setComposite(AlphaComposite.getInstance(
1221:                        AlphaComposite.SRC_OVER, 1.0f));
1222:                graphics.drawImage(image, 0, 0, null);
1223:
1224:                graphics.dispose();
1225:                return result;
1226:                //
1227:                // BufferedImage blurred = convolve.filter(image, null);
1228:                // BufferedImage negatedBlurred = getNegated(blurred);
1229:                // BufferedImage blurredNegated = convolve.filter(negated, null);
1230:                // // put the original image
1231:                // // blurredNegated.getGraphics().drawImage(image, 0, 0, null);
1232:                // return negated;
1233:            }
1234:
1235:            /**
1236:             * Returns <code>minimize</code> icon.
1237:             * 
1238:             * @param theme
1239:             *            Theme for the icon.
1240:             * @return <code>Minimize</code> icon.
1241:             */
1242:            public static Icon getMinimizeIcon(SubstanceTheme theme) {
1243:                int iSize = SubstanceSizeUtils.getTitlePaneIconSize();
1244:                return getMinimizeIcon(iSize, theme);
1245:            }
1246:
1247:            /**
1248:             * Returns <code>minimize</code> icon.
1249:             * 
1250:             * @param iSize
1251:             *            Icon dimension.
1252:             * @param theme
1253:             *            Theme for the icon.
1254:             * @return <code>Minimize</code> icon.
1255:             */
1256:            public static Icon getMinimizeIcon(int iSize, SubstanceTheme theme) {
1257:                BufferedImage image = SubstanceCoreUtilities.getBlankImage(
1258:                        iSize, iSize);
1259:                Graphics2D graphics = (Graphics2D) image.getGraphics();
1260:                int start = (iSize / 4) - 2;
1261:                int end = (3 * iSize / 4);// - 1;
1262:                int size = end - start - 3;
1263:                Color color = theme.getColorScheme().getForegroundColor();
1264:                graphics.setColor(color);
1265:                graphics.fillRect(start + 2, end - 2, size, 3);
1266:                return new ImageIcon(SubstanceImageCreator.overlayEcho(image,
1267:                        SubstanceColorUtilities.getColorStrength(color), 1, 1));
1268:            }
1269:
1270:            /**
1271:             * Returns <code>restore</code> icon.
1272:             * 
1273:             * @param theme
1274:             *            Theme for the icon.
1275:             * @return <code>Restore</code> icon.
1276:             */
1277:            public static Icon getRestoreIcon(SubstanceTheme theme) {
1278:                int iSize = SubstanceSizeUtils.getTitlePaneIconSize();
1279:                BufferedImage image = SubstanceCoreUtilities.getBlankImage(
1280:                        iSize, iSize);
1281:                Graphics2D graphics = (Graphics2D) image.getGraphics();
1282:                int start = (iSize / 4) - 2;
1283:                int end = (3 * iSize / 4) - 1;
1284:                int size = end - start - 3;
1285:                Color color = theme.getColorScheme().getForegroundColor();
1286:                graphics.setColor(color);
1287:                graphics.drawRect(start, end - size + 1, size, size);
1288:                graphics.drawLine(start, end - size + 2, start + size, end
1289:                        - size + 2);
1290:                graphics.fillRect(end - size, start + 1, size + 1, 2);
1291:                graphics.drawLine(end, start + 1, end, start + size + 1);
1292:                graphics.drawLine(start + size + 2, start + size + 1, end,
1293:                        start + size + 1);
1294:                return new ImageIcon(SubstanceImageCreator.overlayEcho(image,
1295:                        SubstanceColorUtilities.getColorStrength(color), 1, 1));
1296:            }
1297:
1298:            /**
1299:             * Returns <code>maximize</code> icon.
1300:             * 
1301:             * @param theme
1302:             *            Theme for the icon.
1303:             * @return <code>Maximize</code> icon.
1304:             */
1305:            public static Icon getMaximizeIcon(SubstanceTheme theme) {
1306:                int iSize = SubstanceSizeUtils.getTitlePaneIconSize();
1307:                return getMaximizeIcon(iSize, theme);
1308:            }
1309:
1310:            /**
1311:             * Returns <code>maximize</code> icon.
1312:             * 
1313:             * @param iSize
1314:             *            Icon dimension.
1315:             * @param theme
1316:             *            Theme for the icon.
1317:             * @return <code>Maximize</code> icon.
1318:             */
1319:            public static Icon getMaximizeIcon(int iSize, SubstanceTheme theme) {
1320:                BufferedImage image = SubstanceCoreUtilities.getBlankImage(
1321:                        iSize, iSize);
1322:                Graphics2D graphics = (Graphics2D) image.getGraphics();
1323:                int start = (iSize / 4) - 1;
1324:                int end = iSize - start - 1;// (3 * iSize / 4);
1325:                Color color = theme.getColorScheme().getForegroundColor();
1326:                graphics.setColor(color);
1327:                graphics.drawRect(start, start, end - start, end - start);
1328:                graphics.drawLine(start, start + 1, end, start + 1);
1329:                return new ImageIcon(SubstanceImageCreator.overlayEcho(image,
1330:                        SubstanceColorUtilities.getColorStrength(color), 1, 1));
1331:            }
1332:
1333:            /**
1334:             * Returns <code>close</code> icon.
1335:             * 
1336:             * @param theme
1337:             *            Theme for the icon.
1338:             * @return <code>Close</code> icon.
1339:             */
1340:            public static Icon getCloseIcon(SubstanceTheme theme) {
1341:                return SubstanceImageCreator.getCloseIcon(SubstanceSizeUtils
1342:                        .getTitlePaneIconSize(), theme);
1343:            }
1344:
1345:            /**
1346:             * Returns <code>close</code> icon.
1347:             * 
1348:             * @param iSize
1349:             *            Icon dimension.
1350:             * @param theme
1351:             *            Theme for the icon.
1352:             * @return <code>Close</code> icon.
1353:             */
1354:            public static Icon getCloseIcon(int iSize, SubstanceTheme theme) {
1355:                return getCloseIcon(iSize, theme.getColorScheme());
1356:            }
1357:
1358:            /**
1359:             * Returns <code>close</code> icon.
1360:             * 
1361:             * @param iSize
1362:             *            Icon dimension.
1363:             * @param colorScheme
1364:             *            Color scheme for the icon.
1365:             * @return <code>Close</code> icon.
1366:             */
1367:            public static Icon getCloseIcon(int iSize, ColorScheme colorScheme) {
1368:                BufferedImage image = SubstanceCoreUtilities.getBlankImage(
1369:                        iSize, iSize);
1370:                Graphics2D graphics = (Graphics2D) image.getGraphics();
1371:                if (iSize < 15) {
1372:                    graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1373:                            RenderingHints.VALUE_ANTIALIAS_ON);
1374:                } else {
1375:                    graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1376:                            RenderingHints.VALUE_ANTIALIAS_OFF);
1377:                }
1378:                int start = (iSize / 4);// - 1;
1379:                int end = (3 * iSize / 4);
1380:
1381:                // System.out.println(iSize + ":" + start + ":" + end);
1382:
1383:                Stroke stroke = new BasicStroke(SubstanceSizeUtils
1384:                        .getFocusStrokeWidth(iSize), BasicStroke.CAP_ROUND,
1385:                        BasicStroke.JOIN_ROUND);
1386:
1387:                graphics.setStroke(stroke);
1388:                Color color = colorScheme.getForegroundColor();
1389:                graphics.setColor(color);
1390:                graphics.drawLine(start, start, end, end);
1391:                graphics.drawLine(start, end, end, start);
1392:                return new ImageIcon(SubstanceImageCreator.overlayEcho(image,
1393:                        SubstanceColorUtilities.getColorStrength(color), 1, 1));
1394:            }
1395:
1396:            /**
1397:             * Paints rectangular gradient background.
1398:             * 
1399:             * @param g
1400:             *            Graphic context.
1401:             * @param startX
1402:             *            Background starting X coord.
1403:             * @param startY
1404:             *            Background starting Y coord.
1405:             * @param width
1406:             *            Background width.
1407:             * @param height
1408:             *            Background height.
1409:             * @param colorScheme
1410:             *            Color scheme for the background.
1411:             * @param borderAlpha
1412:             *            Border alpha.
1413:             * @param isVertical
1414:             *            if <code>true</code>, the gradient will be vertical, if
1415:             *            <code>false</code>, the gradient will be horizontal.
1416:             */
1417:            public static void paintRectangularBackground(Graphics g,
1418:                    int startX, int startY, int width, int height,
1419:                    ColorScheme colorScheme, float borderAlpha,
1420:                    boolean isVertical) {
1421:                Graphics2D graphics = (Graphics2D) g.create();
1422:                graphics.translate(startX, startY);
1423:
1424:                if (colorScheme instanceof  MixColorScheme) {
1425:                    ColorScheme[] schemes = ((MixColorScheme) colorScheme)
1426:                            .getOrigSchemes();
1427:                    if (!isVertical) {
1428:                        BufferedImage[] components = new BufferedImage[schemes.length];
1429:                        for (int i = 0; i < schemes.length; i++) {
1430:
1431:                            Map<Integer, Color> gradColors = new HashMap<Integer, Color>();
1432:                            gradColors.put((int) (0.4 * height), schemes[i]
1433:                                    .getLightColor());
1434:                            gradColors.put((int) (0.5 * height), schemes[i]
1435:                                    .getMidColor());
1436:
1437:                            BufferedImage horLine = SubstanceImageCreator
1438:                                    .getOneLineGradient(height, schemes[i]
1439:                                            .getUltraLightColor(), schemes[i]
1440:                                            .getUltraLightColor(), gradColors);
1441:                            BufferedImage verLine = SubstanceImageCreator
1442:                                    .getRotated(horLine, 1);
1443:
1444:                            BufferedImage schemeImage = SubstanceCoreUtilities
1445:                                    .getBlankImage(width, height);
1446:                            Graphics2D schemeGraphics = (Graphics2D) schemeImage
1447:                                    .getGraphics();
1448:                            for (int col = 0; col < width; col++) {
1449:                                schemeGraphics.drawImage(verLine, col, 0, null);
1450:                            }
1451:                            components[i] = schemeImage;
1452:                        }
1453:
1454:                        // Let the blending begin
1455:                        BufferedImage current = components[0];
1456:                        for (int i = 1; i < components.length; i++) {
1457:                            double start = (i - 0.3) / components.length;
1458:                            double end = (i + 0.3) / components.length;
1459:                            current = SubstanceCoreUtilities
1460:                                    .blendImagesHorizontal(current,
1461:                                            components[i], start, end);
1462:                        }
1463:
1464:                        // for (int row = 0; row < height; row++) {
1465:                        graphics.drawImage(current, 0, 0, null);
1466:                        // }
1467:                    } else {
1468:                        BufferedImage[] components = new BufferedImage[schemes.length];
1469:                        for (int i = 0; i < schemes.length; i++) {
1470:                            Map<Integer, Color> gradColors = new HashMap<Integer, Color>();
1471:                            gradColors.put((int) (0.4 * height), schemes[i]
1472:                                    .getLightColor());
1473:                            gradColors.put((int) (0.5 * height), schemes[i]
1474:                                    .getMidColor());
1475:                            components[i] = SubstanceImageCreator
1476:                                    .getOneLineGradient(height, schemes[i]
1477:                                            .getUltraLightColor(), schemes[i]
1478:                                            .getUltraLightColor(), gradColors);
1479:                        }
1480:
1481:                        // Let the blending begin
1482:                        BufferedImage current = components[0];
1483:                        for (int i = 1; i < components.length; i++) {
1484:                            double start = (i - 0.3) / components.length;
1485:                            double end = (i + 0.3) / components.length;
1486:                            current = SubstanceCoreUtilities
1487:                                    .blendImagesHorizontal(current,
1488:                                            components[i], start, end);
1489:                        }
1490:
1491:                        current = SubstanceImageCreator.getRotated(current, 1);
1492:
1493:                        for (int column = 0; column < width; column++) {
1494:                            graphics.drawImage(current, column, 0, null);
1495:                        }
1496:                    }
1497:                } else {
1498:                    if (!isVertical) {
1499:                        Map<Integer, Color> gradColors = new HashMap<Integer, Color>();
1500:                        gradColors.put((int) (0.4 * height), colorScheme
1501:                                .getLightColor());
1502:                        gradColors.put((int) (0.5 * height), colorScheme
1503:                                .getMidColor());
1504:
1505:                        BufferedImage horLine = SubstanceImageCreator
1506:                                .getOneLineGradient(height, colorScheme
1507:                                        .getUltraLightColor(), colorScheme
1508:                                        .getUltraLightColor(), gradColors);
1509:                        BufferedImage verLine = SubstanceImageCreator
1510:                                .getRotated(horLine, 1);
1511:                        for (int col = 0; col < width; col++) {
1512:                            graphics.drawImage(verLine, col, 0, null);
1513:                        }
1514:                    } else {
1515:                        Map<Integer, Color> gradColors = new HashMap<Integer, Color>();
1516:                        gradColors.put((int) (0.4 * width), colorScheme
1517:                                .getLightColor());
1518:                        gradColors.put((int) (0.5 * width), colorScheme
1519:                                .getMidColor());
1520:
1521:                        BufferedImage horLine = SubstanceImageCreator
1522:                                .getOneLineGradient(width, colorScheme
1523:                                        .getUltraLightColor(), colorScheme
1524:                                        .getUltraLightColor(), gradColors);
1525:                        for (int row = 1; row < height; row++) {
1526:                            graphics.drawImage(horLine, 0, row, null);
1527:                        }
1528:                    }
1529:                }
1530:
1531:                if (borderAlpha > 0.0f) {
1532:                    Graphics2D g2d = (Graphics2D) graphics.create();
1533:                    g2d.setComposite(TransitionLayout.getAlphaComposite(null,
1534:                            borderAlpha, graphics));
1535:                    SubstanceImageCreator.paintBorder(null, g2d, 0, 0, width,
1536:                            height, 0, colorScheme);
1537:                    g2d.dispose();
1538:                }
1539:                graphics.dispose();
1540:            }
1541:
1542:            /**
1543:             * Paints rectangular gradient background with spots and optional replicated
1544:             * stripe image.
1545:             * 
1546:             * @param g
1547:             *            Graphics context.
1548:             * @param startX
1549:             *            X start coordinate.
1550:             * @param startY
1551:             *            Y start coordinate.
1552:             * @param width
1553:             *            Background width.
1554:             * @param height
1555:             *            Background height.
1556:             * @param colorScheme
1557:             *            Color scheme for the background.
1558:             * @param stripeImage
1559:             *            Stripe image to replicate.
1560:             * @param stripeOffset
1561:             *            Offset of the first stripe replication.
1562:             * @param borderAlpha
1563:             *            Border alpha.
1564:             * @param isVertical
1565:             *            Indication of horizontal / vertical orientation.
1566:             */
1567:            public static void paintRectangularStripedBackground(Graphics g,
1568:                    int startX, int startY, int width, int height,
1569:                    ColorScheme colorScheme, BufferedImage stripeImage,
1570:                    int stripeOffset, float borderAlpha, boolean isVertical) {
1571:                Graphics2D graphics = (Graphics2D) g.create(startX, startY,
1572:                        width, height);
1573:                if (!isVertical) {
1574:                    Map<Integer, Color> gradColors = new HashMap<Integer, Color>();
1575:                    gradColors.put((int) (0.2 * height), colorScheme
1576:                            .getLightColor());
1577:                    gradColors.put((int) (0.5 * height), colorScheme
1578:                            .getMidColor());
1579:                    gradColors.put((int) (0.8 * height), colorScheme
1580:                            .getLightColor());
1581:
1582:                    BufferedImage horLine = SubstanceImageCreator
1583:                            .getOneLineGradient(height, colorScheme
1584:                                    .getDarkColor(),
1585:                                    colorScheme.getDarkColor(), gradColors);
1586:                    BufferedImage verLine = SubstanceImageCreator.getRotated(
1587:                            horLine, 1);
1588:                    for (int col = 0; col < width; col++) {
1589:                        graphics.drawImage(verLine, col, 0, null);
1590:                    }
1591:
1592:                    if (stripeImage != null) {
1593:                        int stripeSize = stripeImage.getHeight();
1594:                        int stripeCount = width / stripeSize;
1595:                        stripeOffset = stripeOffset % (2 * stripeSize);
1596:                        for (int stripe = -2; stripe <= stripeCount; stripe += 2) {
1597:                            int stripePos = stripe * stripeSize + stripeOffset;
1598:
1599:                            graphics.drawImage(stripeImage, stripePos, 0, null);
1600:                        }
1601:                    }
1602:                } else {
1603:                    Map<Integer, Color> gradColors = new HashMap<Integer, Color>();
1604:                    gradColors.put((int) (0.2 * width), colorScheme
1605:                            .getLightColor());
1606:                    gradColors.put((int) (0.5 * width), colorScheme
1607:                            .getMidColor());
1608:                    gradColors.put((int) (0.8 * width), colorScheme
1609:                            .getLightColor());
1610:
1611:                    BufferedImage horLine = SubstanceImageCreator
1612:                            .getOneLineGradient(width, colorScheme
1613:                                    .getDarkColor(),
1614:                                    colorScheme.getDarkColor(), gradColors);
1615:                    for (int row = 0; row < height; row++) {
1616:                        graphics.drawImage(horLine, 0, row, null);
1617:                    }
1618:
1619:                    if (stripeImage != null) {
1620:                        int stripeSize = stripeImage.getWidth();
1621:                        int stripeCount = height / stripeSize;
1622:                        stripeOffset = stripeOffset % (2 * stripeSize);
1623:                        for (int stripe = -2; stripe <= stripeCount; stripe += 2) {
1624:                            int stripePos = stripe * stripeSize + stripeOffset;
1625:
1626:                            graphics.drawImage(stripeImage, 0, stripePos, null);
1627:                        }
1628:                    }
1629:                }
1630:
1631:                if (borderAlpha > 0.0f) {
1632:                    Graphics2D g2d = (Graphics2D) graphics.create();
1633:                    g2d.setComposite(TransitionLayout.getAlphaComposite(null,
1634:                            borderAlpha, graphics));
1635:                    SubstanceImageCreator.paintBorder(null, g2d, 0, 0, width,
1636:                            height, 0, colorScheme);
1637:                    g2d.dispose();
1638:                }
1639:                graphics.dispose();
1640:            }
1641:
1642:            /**
1643:             * Returns diagonal stripe image.
1644:             * 
1645:             * @param baseSize
1646:             *            Stripe base in pixels.
1647:             * @param color
1648:             *            Stripe color.
1649:             * @return Diagonal stripe image.
1650:             */
1651:            public static BufferedImage getStripe(int baseSize, Color color) {
1652:                int width = (int) (1.8 * baseSize);
1653:                int height = baseSize;
1654:                BufferedImage result = SubstanceCoreUtilities.getBlankImage(
1655:                        width, height);
1656:                Graphics2D graphics = (Graphics2D) result.getGraphics();
1657:
1658:                graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1659:                        RenderingHints.VALUE_ANTIALIAS_ON);
1660:
1661:                Polygon polygon = new Polygon();
1662:                polygon.addPoint(0, 0);
1663:                polygon.addPoint(width - 1 - baseSize, 0);
1664:                polygon.addPoint(width - 1, height - 1);
1665:                polygon.addPoint(baseSize, height - 1);
1666:
1667:                graphics.setColor(color);
1668:                graphics.fillPolygon(polygon);
1669:                graphics.drawPolygon(polygon);
1670:
1671:                float[] BLUR = { 0.10f, 0.10f, 0.10f, 0.10f, 0.30f, 0.10f,
1672:                        0.10f, 0.10f, 0.10f };
1673:                ConvolveOp vBlurOp = new ConvolveOp(new Kernel(3, 3, BLUR));
1674:                BufferedImage blurred = vBlurOp.filter(result, null);
1675:
1676:                return blurred;
1677:            }
1678:
1679:            /**
1680:             * Returns drag bumps image.
1681:             * 
1682:             * @param c
1683:             *            Component.
1684:             * @param theme
1685:             *            Theme.
1686:             * @param alwaysUseActive
1687:             *            Indicates whether the active theme should always be used.
1688:             * @param width
1689:             *            Drag bumps width.
1690:             * @param height
1691:             *            Drag bumps height.
1692:             * @param isCrowded
1693:             *            Indicates whether the bumps should be painted closely.
1694:             * @param maxNumberOfStripes
1695:             *            The maximum number of bump stripes (rows or columns).
1696:             * @return Drag bumps image.
1697:             */
1698:            public static BufferedImage getDragImage(Component c,
1699:                    SubstanceTheme theme, int width, int height, boolean isBig,
1700:                    boolean isCrowded, int maxNumberOfStripes) {
1701:                BufferedImage result = SubstanceCoreUtilities.getBlankImage(
1702:                        width, height);
1703:                Graphics2D graphics = (Graphics2D) result.getGraphics();
1704:
1705:                graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1706:                        RenderingHints.VALUE_ANTIALIAS_ON);
1707:
1708:                boolean isDark = SubstanceCoreUtilities.isThemeDark(theme
1709:                        .getActiveTheme());
1710:                // ColorScheme colorScheme = (alwaysUseActive) ? theme.getActiveTheme()
1711:                // .getColorScheme() : theme.getDefaultTheme().getColorScheme();
1712:                ColorScheme colorScheme = theme.getColorScheme();
1713:                Color back1 = isDark ? colorScheme.getLightColor()
1714:                        : SubstanceColorUtilities.getInterpolatedColor(
1715:                                colorScheme.getLightColor(), colorScheme
1716:                                        .getDarkColor(), 0.8);
1717:                Color back2 = isDark ? colorScheme.getExtraLightColor()
1718:                        : SubstanceColorUtilities.getInterpolatedColor(
1719:                                colorScheme.getMidColor(), colorScheme
1720:                                        .getDarkColor(), 0.4);
1721:                Color fore = isDark ? colorScheme.getDarkColor() : colorScheme
1722:                        .getUltraLightColor();
1723:
1724:                int componentFontSize = SubstanceSizeUtils
1725:                        .getComponentFontSize(c);
1726:                int bumpDotDiameter = isBig ? SubstanceSizeUtils
1727:                        .getBigDragBumpDiameter(componentFontSize)
1728:                        : SubstanceSizeUtils
1729:                                .getDragBumpDiameter(componentFontSize);
1730:                int bumpCellSize = (int) (1.5 * bumpDotDiameter + 1);
1731:                if (isCrowded)
1732:                    bumpCellSize--;
1733:                int bumpRows = Math.max(1, height / bumpCellSize - 1);
1734:                int bumpColumns = Math.max(1, (width - 2) / bumpCellSize);
1735:                if (maxNumberOfStripes > 0) {
1736:                    if (height > width)
1737:                        bumpColumns = Math.min(bumpColumns, maxNumberOfStripes);
1738:                    else
1739:                        bumpRows = Math.min(bumpRows, maxNumberOfStripes);
1740:                }
1741:
1742:                int bumpRowOffset = (height - bumpCellSize * bumpRows) / 2;
1743:                int bumpColOffset = 1 + (width - bumpCellSize * bumpColumns) / 2;
1744:
1745:                for (int col = 0; col < bumpColumns; col++) {
1746:                    int cx = bumpColOffset + col * bumpCellSize;
1747:                    boolean isEvenCol = (col % 2 == 0);
1748:                    int offsetY = isEvenCol ? 0 : bumpDotDiameter;
1749:                    for (int row = 0; row < bumpRows; row++) {
1750:                        int cy = offsetY + bumpRowOffset + row * bumpCellSize;
1751:                        graphics.setColor(fore);
1752:                        graphics.fillOval(cx + 1, cy + 1, bumpDotDiameter,
1753:                                bumpDotDiameter);
1754:                        // graphics.setColor(back1);
1755:                        graphics.setPaint(new GradientPaint(cx, cy, back1, cx
1756:                                + bumpDotDiameter - 1,
1757:                                cy + bumpDotDiameter - 1, back2));
1758:                        graphics.fillOval(cx, cy, bumpDotDiameter,
1759:                                bumpDotDiameter);
1760:                    }
1761:                }
1762:                return result;
1763:            }
1764:
1765:            public static BufferedImage getSplitDividerBumpImage(Component c,
1766:                    int width, int height, boolean isHorizontal,
1767:                    ComponentState componentState, SubstanceTheme theme1,
1768:                    SubstanceTheme theme2, float interpolationCyclePos10) {
1769:                BufferedImage result = SubstanceCoreUtilities.getBlankImage(
1770:                        width, height);
1771:                Graphics2D graphics = (Graphics2D) result.getGraphics();
1772:
1773:                graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1774:                        RenderingHints.VALUE_ANTIALIAS_ON);
1775:
1776:                int componentFontSize = SubstanceSizeUtils
1777:                        .getComponentFontSize(c);
1778:                int bumpDotDiameter = SubstanceSizeUtils
1779:                        .getBigDragBumpDiameter(componentFontSize);
1780:                int bumpCellSize = (int) (1.5 * bumpDotDiameter + 1);
1781:                int bumpRows = isHorizontal ? 1 : Math.max(1, height
1782:                        / bumpCellSize - 1);
1783:                int bumpColumns = isHorizontal ? Math.max(1, (width - 2)
1784:                        / bumpCellSize) : 1;
1785:
1786:                int bumpRowOffset = (height - bumpCellSize * bumpRows) / 2;
1787:                int bumpColOffset = 1 + (width - bumpCellSize * bumpColumns) / 2;
1788:
1789:                BufferedImage singleDot = SubstanceCoreUtilities.getBlankImage(
1790:                        bumpDotDiameter, bumpDotDiameter);
1791:                Graphics2D dotGraphics = (Graphics2D) singleDot.getGraphics();
1792:                dotGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1793:                        RenderingHints.VALUE_ANTIALIAS_ON);
1794:
1795:                dotGraphics.setComposite(AlphaComposite.getInstance(
1796:                        AlphaComposite.SRC_OVER,
1797:                        1.0f - interpolationCyclePos10 / 10.0f));
1798:                Color markColor = SubstanceCoreUtilities.getMarkColor(theme1, c
1799:                        .isEnabled());
1800:                dotGraphics.setColor(markColor);
1801:                dotGraphics.fillOval(0, 0, bumpDotDiameter, bumpDotDiameter);
1802:
1803:                dotGraphics.setComposite(AlphaComposite.getInstance(
1804:                        AlphaComposite.SRC_OVER,
1805:                        interpolationCyclePos10 / 10.0f));
1806:                Color markColor2 = SubstanceCoreUtilities.getMarkColor(theme2,
1807:                        c.isEnabled());
1808:                dotGraphics.setColor(markColor2);
1809:                dotGraphics.fillOval(0, 0, bumpDotDiameter, bumpDotDiameter);
1810:
1811:                dotGraphics.setComposite(AlphaComposite.getInstance(
1812:                        AlphaComposite.SRC_OVER, 0.4f));
1813:                SubstanceBorderPainter borderPainter = SubstanceCoreUtilities
1814:                        .getBorderPainter(c);
1815:                borderPainter.paintBorder(dotGraphics, c, width, height,
1816:                        new Ellipse2D.Float(0, 0, bumpDotDiameter - 1,
1817:                                bumpDotDiameter - 1), null, theme1
1818:                                .getColorScheme(), theme2.getColorScheme(),
1819:                        interpolationCyclePos10, theme1 != theme2);
1820:
1821:                // BufferedImage singleDot = getRadioButton(c, bumpDotDiameter,
1822:                // componentState, 0, theme1, theme2, interpolationCyclePos10,
1823:                // 0.0f, 0.5f);
1824:                //
1825:                graphics.setComposite(AlphaComposite.getInstance(
1826:                        AlphaComposite.SRC_OVER, 0.8f));
1827:                for (int col = 0; col < bumpColumns; col++) {
1828:                    int cx = bumpColOffset + col * bumpCellSize;
1829:                    for (int row = 0; row < bumpRows; row++) {
1830:                        int cy = bumpRowOffset + row * bumpCellSize
1831:                                + (bumpCellSize - bumpDotDiameter) / 2;
1832:                        graphics.drawImage(singleDot, cx, cy, null);
1833:                    }
1834:                }
1835:                return result;
1836:            }
1837:
1838:            /**
1839:             * Returns resize grip image.
1840:             * 
1841:             * @param c
1842:             *            Component.
1843:             * @param theme
1844:             *            Theme.
1845:             * @param alwaysUseActive
1846:             *            Indicates whether the active theme should always be used.
1847:             * @param dimension
1848:             *            Resize grip width.
1849:             * @param isCrowded
1850:             *            Indicates whether the grips should be painted closely.
1851:             * @return Resize grip image.
1852:             */
1853:            public static BufferedImage getResizeGripImage(Component c,
1854:                    SubstanceTheme theme, int dimension, boolean isCrowded) {
1855:                BufferedImage result = SubstanceCoreUtilities.getBlankImage(
1856:                        dimension, dimension);
1857:                Graphics2D graphics = (Graphics2D) result.getGraphics();
1858:
1859:                graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1860:                        RenderingHints.VALUE_ANTIALIAS_ON);
1861:
1862:                boolean isDark = SubstanceCoreUtilities.isThemeDark(theme
1863:                        .getActiveTheme());
1864:                ColorScheme colorScheme = theme.getColorScheme();
1865:                // SubstanceCoreUtilities
1866:                // .getActiveScheme(null) : SubstanceCoreUtilities
1867:                // .getDefaultScheme(null);
1868:                Color back1 = isDark ? colorScheme.getLightColor()
1869:                        : SubstanceColorUtilities.getInterpolatedColor(
1870:                                colorScheme.getLightColor(), colorScheme
1871:                                        .getDarkColor(), 0.8);
1872:                Color back2 = isDark ? colorScheme.getExtraLightColor()
1873:                        : SubstanceColorUtilities.getInterpolatedColor(
1874:                                colorScheme.getMidColor(), colorScheme
1875:                                        .getDarkColor(), 0.4);
1876:                Color fore = isDark ? colorScheme.getDarkColor() : colorScheme
1877:                        .getUltraLightColor();
1878:
1879:                int bumpDotDiameter = SubstanceSizeUtils
1880:                        .getDragBumpDiameter(SubstanceSizeUtils
1881:                                .getComponentFontSize(c));
1882:                int bumpCellSize = (int) (1.5 * bumpDotDiameter + 1);
1883:                if (isCrowded)
1884:                    bumpCellSize--;
1885:                int bumpLines = dimension / bumpCellSize;
1886:
1887:                int bumpOffset = (dimension - bumpCellSize * bumpLines) / 2;
1888:
1889:                for (int col = 0; col < bumpLines; col++) {
1890:                    int cx = bumpOffset + col * bumpCellSize;
1891:                    for (int row = (bumpLines - col - 1); row < bumpLines; row++) {
1892:                        int cy = bumpOffset + row * bumpCellSize;
1893:                        graphics.setColor(fore);
1894:                        graphics.fillOval(cx + 1, cy + 1, bumpDotDiameter,
1895:                                bumpDotDiameter);
1896:                        // graphics.setColor(back1);
1897:                        graphics.setPaint(new GradientPaint(cx, cy, back1, cx
1898:                                + bumpDotDiameter - 1,
1899:                                cy + bumpDotDiameter - 1, back2));
1900:                        graphics.fillOval(cx, cy, bumpDotDiameter,
1901:                                bumpDotDiameter);
1902:                    }
1903:                }
1904:                return result;
1905:            }
1906:
1907:            /**
1908:             * Retrieves tree icon.
1909:             * 
1910:             * @param tree
1911:             *            Tree.
1912:             * @param theme
1913:             *            Icon theme.
1914:             * @param isCollapsed
1915:             *            Collapsed state.
1916:             * @return Tree icon.
1917:             */
1918:            public static BufferedImage getTreeIcon(JTree tree,
1919:                    SubstanceTheme theme, boolean isCollapsed) {
1920:                int fontSize = SubstanceSizeUtils.getComponentFontSize(tree);
1921:                int dim = SubstanceSizeUtils.getTreeIconSize(fontSize);
1922:                BufferedImage result = SubstanceCoreUtilities.getBlankImage(
1923:                        dim + 2, dim);
1924:                Graphics2D graphics = (Graphics2D) result.getGraphics();
1925:
1926:                graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1927:                        RenderingHints.VALUE_ANTIALIAS_OFF);
1928:
1929:                Graphics2D g2 = (Graphics2D) graphics.create();
1930:                g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1931:                        RenderingHints.VALUE_ANTIALIAS_OFF);
1932:                SimplisticGradientPainter gradPainter = new SimplisticSoftBorderReverseGradientPainter();
1933:                FlatBorderPainter fbp = new FlatBorderPainter();
1934:
1935:                int borderDelta = (int) Math.floor(SubstanceSizeUtils
1936:                        .getBorderStrokeWidth(fontSize) / 2.0);
1937:                Shape contour = BaseButtonShaper.getBaseOutline(dim - 1,
1938:                        dim - 1, SubstanceSizeUtils
1939:                                .getClassicButtonCornerRadius(dim), null,
1940:                        borderDelta);
1941:
1942:                g2.translate(0, 1);
1943:
1944:                boolean isDark = SubstanceCoreUtilities.isThemeDark(theme);
1945:                ColorScheme colorScheme = theme.getColorScheme();
1946:
1947:                ColorScheme fillScheme = new ShiftColorScheme(colorScheme,
1948:                        colorScheme.getExtraLightColor(), 0.7);
1949:                g2.drawImage(gradPainter
1950:                        .getContourBackground(dim - 1, dim - 1, contour, false,
1951:                                fillScheme, fillScheme, 0, false, false), 0, 0,
1952:                        null);
1953:                ColorScheme borderScheme = new ShiftColorScheme(colorScheme,
1954:                        isDark ? colorScheme.getUltraLightColor() : colorScheme
1955:                                .getLightColor(), 0.95);
1956:                fbp.paintBorder(g2, tree, dim - 1, dim - 1, contour, null,
1957:                        borderScheme, borderScheme, 0, false);
1958:
1959:                g2.translate(-1, -1);
1960:
1961:                Color signColor = isDark ? colorScheme.getUltraLightColor()
1962:                        .brighter().brighter() : colorScheme
1963:                        .getUltraDarkColor();
1964:                if ((tree != null) && !tree.isEnabled())
1965:                    signColor = colorScheme.getForegroundColor();
1966:                g2.setColor(signColor);
1967:                int mid = dim / 2;
1968:                int length = 5 * dim / 12;
1969:                g2.drawLine(mid - length / 2, dim / 2, mid + length / 2,
1970:                        dim / 2);
1971:                if (isCollapsed) {
1972:                    g2.drawLine(dim / 2, mid - length / 2, dim / 2, mid
1973:                            + length / 2);
1974:                }
1975:                g2.dispose();
1976:
1977:                return result;
1978:            }
1979:
1980:            /**
1981:             * Retrieves a single crayon of the specified color and dimensions for the
1982:             * crayon panel in color chooser.
1983:             * 
1984:             * @param mainColor
1985:             *            Crayon main color.
1986:             * @param width
1987:             *            Crayon width.
1988:             * @param height
1989:             *            Crayon height.
1990:             * @return Crayon image.
1991:             */
1992:            public static BufferedImage getSingleCrayon(Color mainColor,
1993:                    int width, int height) {
1994:                BufferedImage image = SubstanceCoreUtilities.getBlankImage(
1995:                        width, height);
1996:
1997:                int baseTop = (int) (0.2 * height);
1998:
1999:                Graphics2D graphics = (Graphics2D) image.getGraphics().create();
2000:                graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
2001:                        RenderingHints.VALUE_ANTIALIAS_ON);
2002:
2003:                int r = mainColor.getRed();
2004:                int g = mainColor.getGreen();
2005:                int b = mainColor.getBlue();
2006:                // light coefficient
2007:                double lc = 0.8;
2008:                int lr = (int) (r + (255 - r) * lc);
2009:                int lg = (int) (g + (255 - g) * lc);
2010:                int lb = (int) (b + (255 - b) * lc);
2011:                // dark coefficient
2012:                double dc = 0.05;
2013:                int dr = (int) ((1.0 - dc) * r);
2014:                int dg = (int) ((1.0 - dc) * g);
2015:                int db = (int) ((1.0 - dc) * b);
2016:
2017:                Color lightColor = new Color(lr, lg, lb);
2018:                Color darkColor = new Color(dr, dg, db);
2019:
2020:                Map<Integer, Color> fillColorsColor = new HashMap<Integer, Color>();
2021:                fillColorsColor.put((int) (0.3 * width), darkColor);
2022:                fillColorsColor.put((int) (0.5 * width), darkColor);
2023:                fillColorsColor.put((int) (0.9 * width), lightColor);
2024:
2025:                Image fillLineColor = SubstanceImageCreator.getOneLineGradient(
2026:                        width, lightColor, lightColor, fillColorsColor);
2027:
2028:                for (int y = baseTop; y < height; y++) {
2029:                    graphics.drawImage(fillLineColor, 0, y, null);
2030:                }
2031:
2032:                int dbwr = lr;
2033:                int dbwg = lg;
2034:                int dbwb = lb;
2035:                int lbwr = 128 + dr / 4;
2036:                int lbwg = 128 + dg / 4;
2037:                int lbwb = 128 + db / 4;
2038:                Map<Integer, Color> fillColorsBW = new HashMap<Integer, Color>();
2039:                fillColorsBW.put((int) (0.3 * width), new Color(dbwr, dbwg,
2040:                        dbwb));
2041:                fillColorsBW.put((int) (0.5 * width), new Color(dbwr, dbwg,
2042:                        dbwb));
2043:                fillColorsBW.put((int) (0.9 * width), new Color(lbwr, lbwg,
2044:                        lbwb));
2045:
2046:                Image fillLineBW = SubstanceImageCreator.getOneLineGradient(
2047:                        width, new Color(lbwr, lbwg, lbwb), new Color(lbwr,
2048:                                lbwg, lbwb), fillColorsBW);
2049:
2050:                int stripeTop = (int) (0.35 * height);
2051:                int stripeHeight = (int) (0.04 * height);
2052:                for (int y = stripeTop; y < (stripeTop + stripeHeight); y++) {
2053:                    graphics.drawImage(fillLineBW, 0, y, null);
2054:                }
2055:                graphics.setColor(new Color(lbwr, lbwg, lbwb));
2056:                graphics.drawRect(0, stripeTop, width - 1, stripeHeight);
2057:
2058:                // create cap path
2059:                GeneralPath capPath = new GeneralPath();
2060:                capPath.moveTo(0.5f * width - 3, 4);
2061:                capPath.quadTo(0.5f * width, 0, 0.5f * width + 3, 4);
2062:                capPath.lineTo(width - 3, baseTop);
2063:                capPath.lineTo(2, baseTop);
2064:                capPath.lineTo(0.5f * width - 3, 4);
2065:
2066:                graphics.setClip(capPath);
2067:
2068:                graphics.setPaint(new GradientPaint(0, baseTop / 2, lightColor,
2069:                        (int) (0.6 * width), baseTop, mainColor));
2070:                graphics.fillRect(0, 0, width / 2, baseTop);
2071:                graphics.setPaint(new GradientPaint(width, baseTop / 2,
2072:                        lightColor, (int) (0.4 * width), baseTop, mainColor));
2073:                graphics.fillRect(width / 2, 0, width / 2, baseTop);
2074:
2075:                graphics.setStroke(new BasicStroke((float) 1.3,
2076:                        BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
2077:
2078:                graphics.setClip(null);
2079:                graphics.setColor(new Color(64 + dr / 2, 64 + dg / 2,
2080:                        64 + db / 2, 200));
2081:                graphics.drawRect(0, baseTop, width - 1, height - baseTop - 1);
2082:                graphics.draw(capPath);
2083:
2084:                graphics.dispose();
2085:
2086:                return image;
2087:            }
2088:
2089:            /**
2090:             * Crayon colors.
2091:             */
2092:            private final static int[] crayonColors = { 0x800000, // Cayenne
2093:                    0x808000, // Asparagus
2094:                    0x008000, // Clover
2095:                    0x008080, // Teal
2096:                    0x000080, // Midnight
2097:                    0x800080, // Plum
2098:                    0x7f7f7f, // Tin
2099:                    0x808080, // Nickel
2100:
2101:                    0x804000, // Mocha
2102:                    0x408000, // Fern
2103:                    0x008040, // Moss
2104:                    0x004080, // Ocean
2105:                    0x400080, // Eggplant
2106:                    0x800040, // Maroon
2107:                    0x666666, // Steel
2108:                    0x999999, // Aluminium
2109:
2110:                    0xff0000, // Maraschino
2111:                    0xffff00, // Lemon
2112:                    0x00ff00, // Spring
2113:                    0x00ffff, // Turquoise
2114:                    0x0000ff, // Blueberry
2115:                    0xff00ff, // Magenta
2116:                    0x4c4c4c, // Iron
2117:                    0xb3b3b3, // Magnesium
2118:
2119:                    0xff8000, // Tangerine
2120:                    0x80ff00, // Lime
2121:                    0x00ff80, // Sea Foam
2122:                    0x0080ff, // Aqua
2123:                    0x8000ff, // Grape
2124:                    0xff0080, // Strawberry
2125:                    0x333333, // Tungsten
2126:                    0xcccccc, // Silver
2127:
2128:                    0xff6666, // Salmon
2129:                    0xffff66, // Banana
2130:                    0x66ff66, // Flora
2131:                    0x66ffff, // Ice
2132:                    0x6666ff, // Orchid
2133:                    0xff66ff, // Bubblegum
2134:                    0x191919, // Lead
2135:                    0xe6e6e6, // Mercury
2136:
2137:                    0xffcc66, // Cantaloupe
2138:                    0xccff66, // Honeydew
2139:                    0x66ffcc, // Spindrift
2140:                    0x66ccff, // Sky
2141:                    0xcc66ff, // Lavender
2142:                    0xff6fcf, // Carnation
2143:                    0x000000, // Licorice
2144:                    0xffffff, // Snow
2145:            };
2146:
2147:            /**
2148:             * Retrieves crayon X offset.
2149:             * 
2150:             * @param i
2151:             *            Crayon index.
2152:             * @return Crayon X offset.
2153:             */
2154:            private static int crayonX(int i) {
2155:                return (i % 8) * 22 + 4 + ((i / 8) % 2) * 11;
2156:            }
2157:
2158:            /**
2159:             * Retrieves crayon Y offset.
2160:             * 
2161:             * @param i
2162:             *            Crayon index.
2163:             * @return Crayon Y offset.
2164:             */
2165:            private static int crayonY(int i) {
2166:                return (i / 8) * 20 + 23;
2167:            }
2168:
2169:            /**
2170:             * Retrieves crayons image for the crayon panel of color chooser.
2171:             * 
2172:             * @return Crayons image.
2173:             */
2174:            public static Image getCrayonsImage() {
2175:                int iw = 195;
2176:                int ih = 208;
2177:                Image image = SubstanceCoreUtilities.getBlankImage(iw, ih);
2178:                Graphics2D graphics = (Graphics2D) image.getGraphics().create();
2179:                graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
2180:                        RenderingHints.VALUE_ANTIALIAS_ON);
2181:
2182:                graphics.setColor(new Color(240, 240, 240));
2183:                graphics.fillRect(0, 0, iw, ih);
2184:
2185:                for (int i = 0; i < SubstanceImageCreator.crayonColors.length; i++) {
2186:                    Color crayonColor = new Color(
2187:                            0xff000000 | SubstanceImageCreator.crayonColors[i]);
2188:                    Image crayonImage = SubstanceImageCreator.getSingleCrayon(
2189:                            crayonColor, 22, 120);
2190:                    graphics
2191:                            .drawImage(crayonImage, SubstanceImageCreator
2192:                                    .crayonX(i), SubstanceImageCreator
2193:                                    .crayonY(i), null);
2194:                }
2195:
2196:                graphics.setColor(new Color(190, 190, 190));
2197:                graphics.drawRoundRect(0, 1, iw - 1, ih - 2, 4, 4);
2198:
2199:                graphics.dispose();
2200:                return image;
2201:            }
2202:
2203:            // /**
2204:            // * Returns an error marker of specified dimension with an <code>X</code>
2205:            // * inside. The resulting image is a circular icon with a diagonal cross
2206:            // and
2207:            // * border.
2208:            // *
2209:            // * @param dimension
2210:            // * The diameter of the resulting marker.
2211:            // * @param colorScheme
2212:            // * Color scheme for the marker.
2213:            // * @return Error marker of specified dimension with an <code>X</code>
2214:            // * inside
2215:            // */
2216:            // public static BufferedImage getErrorMarker(int dimension,
2217:            // ColorScheme colorScheme) {
2218:            // // new RGB image with transparency channel
2219:            // BufferedImage image = new BufferedImage(dimension, dimension,
2220:            // BufferedImage.TYPE_INT_ARGB);
2221:            //
2222:            // // create new graphics and set anti-aliasing hint
2223:            // Graphics2D graphics = (Graphics2D) image.getGraphics().create();
2224:            // graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
2225:            // RenderingHints.VALUE_ANTIALIAS_ON);
2226:            //
2227:            // // background fill
2228:            // graphics.setColor(colorScheme.getMidColor());
2229:            // graphics.fillOval(0, 0, dimension - 1, dimension - 1);
2230:            //
2231:            // // create spot in the upper-left corner using temporary graphics
2232:            // // with clip set to the icon outline
2233:            // GradientPaint spot = new GradientPaint(0, 0, new Color(255, 255, 255,
2234:            // 200), dimension, dimension, new Color(255, 255, 255, 0));
2235:            // Graphics2D tempGraphics = (Graphics2D) graphics.create();
2236:            // tempGraphics.setPaint(spot);
2237:            // tempGraphics.setClip(new Ellipse2D.Double(0, 0, dimension - 1,
2238:            // dimension - 1));
2239:            // tempGraphics.fillRect(0, 0, dimension, dimension);
2240:            // tempGraphics.dispose();
2241:            //
2242:            // // draw outline of the icon
2243:            // graphics.setColor(colorScheme.getUltraDarkColor());
2244:            // graphics.drawOval(0, 0, dimension - 1, dimension - 1);
2245:            //
2246:            // // draw the X sign using two paths
2247:            // float dimOuter = (float) (0.5f * Math.pow(dimension, 0.75));
2248:            // float dimInner = (float) (0.28f * Math.pow(dimension, 0.75));
2249:            // float ds = 0.28f * (dimension - 1);
2250:            // float de = 0.72f * (dimension - 1);
2251:            //
2252:            // // create the paths
2253:            // GeneralPath gp1 = new GeneralPath();
2254:            // gp1.moveTo(ds, ds);
2255:            // gp1.lineTo(de, de);
2256:            // GeneralPath gp2 = new GeneralPath();
2257:            // gp2.moveTo(de, ds);
2258:            // gp2.lineTo(ds, de);
2259:            // graphics.setStroke(new BasicStroke(dimOuter, BasicStroke.CAP_ROUND,
2260:            // BasicStroke.JOIN_ROUND));
2261:            // graphics.setColor(colorScheme.getUltraDarkColor());
2262:            // graphics.draw(gp1);
2263:            // graphics.draw(gp2);
2264:            // graphics.setStroke(new BasicStroke(dimInner, BasicStroke.CAP_ROUND,
2265:            // BasicStroke.JOIN_ROUND));
2266:            // graphics.setColor(colorScheme.getUltraLightColor().brighter());
2267:            // graphics.draw(gp1);
2268:            // graphics.draw(gp2);
2269:            //
2270:            // // dispose
2271:            // graphics.dispose();
2272:            // return image;
2273:            // }
2274:            //
2275:            // /**
2276:            // * Returns an error marker of specified dimension with an <code>X</code>
2277:            // * inside. The resulting image is a circular icon with a diagonal cross
2278:            // and
2279:            // * border.
2280:            // *
2281:            // * @param dimension
2282:            // * The diameter of the resulting marker.
2283:            // * @param colorScheme
2284:            // * Color scheme for the marker.
2285:            // * @return Error marker of specified dimension with an <code>X</code>
2286:            // * inside
2287:            // */
2288:            // public static Icon getErrorMarkerIcon(int dimension, ColorScheme
2289:            // colorScheme) {
2290:            // return new ImageIcon(SubstanceImageCreator.getErrorMarker(dimension,
2291:            // colorScheme));
2292:            // }
2293:            //
2294:            // /**
2295:            // * Returns a warning marker of specified dimension with an <code>!</code>
2296:            // * inside. The resulting image is a triangular icon with an exclamation
2297:            // * mark.
2298:            // *
2299:            // * @param dimension
2300:            // * The side of the resulting marker.
2301:            // * @param colorScheme
2302:            // * Color scheme for the marker.
2303:            // * @return Warning marker of specified dimension with an <code>!</code>
2304:            // * inside.
2305:            // */
2306:            // public static BufferedImage getWarningMarker(int dimension,
2307:            // ColorScheme colorScheme) {
2308:            // // new RGB image with transparency channel
2309:            // BufferedImage image = new BufferedImage(dimension, dimension,
2310:            // BufferedImage.TYPE_INT_ARGB);
2311:            //
2312:            // // create new graphics and set anti-aliasing hint
2313:            // Graphics2D graphics = (Graphics2D) image.getGraphics().create();
2314:            // graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
2315:            // RenderingHints.VALUE_ANTIALIAS_ON);
2316:            //
2317:            // // create path for the outline
2318:            // GeneralPath iconOutlinePath = new GeneralPath();
2319:            // float d = dimension - 1;
2320:            // float d32 = (float) (0.1 * d * Math.sqrt(3.0) / 2.0);
2321:            // float height = (float) (1.1 * d * Math.sqrt(3.0) / 2.0);
2322:            // iconOutlinePath.moveTo(0.45f * d, d32);
2323:            // iconOutlinePath.quadTo(0.5f * d, 0, 0.55f * d, d32);
2324:            // iconOutlinePath.lineTo(0.95f * d, height - d32);
2325:            // iconOutlinePath.quadTo(d, height, 0.9f * d, height);
2326:            // iconOutlinePath.lineTo(0.1f * d, height);
2327:            // iconOutlinePath.quadTo(0, height, 0.05f * d, height - d32);
2328:            // iconOutlinePath.lineTo(0.45f * d, d32);
2329:            //
2330:            // // fill inside
2331:            // graphics.setColor(colorScheme.getMidColor());
2332:            // graphics.fill(iconOutlinePath);
2333:            //
2334:            // // create spot in the upper-left corner using temporary graphics
2335:            // // with clip set to the icon outline
2336:            // GradientPaint spot = new GradientPaint(0, 0, new Color(255, 255, 255,
2337:            // 200), dimension, dimension, new Color(255, 255, 255, 0));
2338:            // Graphics2D tempGraphics = (Graphics2D) graphics.create();
2339:            // tempGraphics.setPaint(spot);
2340:            // tempGraphics.setClip(iconOutlinePath);
2341:            // tempGraphics.fillRect(0, 0, dimension, dimension);
2342:            // tempGraphics.dispose();
2343:            //
2344:            // // draw outline of the icon
2345:            // graphics.setColor(colorScheme.getUltraDarkColor());
2346:            // graphics.draw(iconOutlinePath);
2347:            //
2348:            // // draw the ! sign
2349:            // float dimOuter = (float) (0.5f * Math.pow(dimension, 0.75));
2350:            // float dimInner = (float) (0.28f * Math.pow(dimension, 0.75));
2351:            // GeneralPath markerPath = new GeneralPath();
2352:            // markerPath.moveTo((float) 0.5 * d, (float) 0.3 * height);
2353:            // markerPath.lineTo((float) 0.5 * d, (float) 0.6 * height);
2354:            // markerPath.moveTo((float) 0.5 * d, (float) 0.85 * height);
2355:            // markerPath.lineTo((float) 0.5 * d, (float) 0.85 * height);
2356:            // graphics.setStroke(new BasicStroke(dimOuter, BasicStroke.CAP_ROUND,
2357:            // BasicStroke.JOIN_ROUND));
2358:            // graphics.setColor(colorScheme.getUltraDarkColor());
2359:            // graphics.draw(markerPath);
2360:            // graphics.setStroke(new BasicStroke(dimInner, BasicStroke.CAP_ROUND,
2361:            // BasicStroke.JOIN_ROUND));
2362:            // graphics.setColor(colorScheme.getUltraLightColor().brighter());
2363:            // graphics.draw(markerPath);
2364:            //
2365:            // // dispose
2366:            // graphics.dispose();
2367:            // return image;
2368:            // }
2369:            //
2370:            // /**
2371:            // * Returns an info marker of specified dimension with an <code>!</code>
2372:            // * inside. The resulting image is a triangular icon with an exclamation
2373:            // * mark.
2374:            // *
2375:            // * @param dimension
2376:            // * The side of the resulting marker.
2377:            // * @param colorScheme
2378:            // * Color scheme for the marker.
2379:            // * @return Info marker of specified dimension with an <code>!</code>
2380:            // * inside.
2381:            // */
2382:            // public static BufferedImage getInfoMarker(int dimension,
2383:            // ColorScheme colorScheme) {
2384:            // // new RGB image with transparency channel
2385:            // BufferedImage image = new BufferedImage(dimension, dimension,
2386:            // BufferedImage.TYPE_INT_ARGB);
2387:            //
2388:            // // create new graphics and set anti-aliasing hint
2389:            // Graphics2D graphics = (Graphics2D) image.getGraphics().create();
2390:            // graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
2391:            // RenderingHints.VALUE_ANTIALIAS_ON);
2392:            //
2393:            // // create path for the outline
2394:            // GeneralPath iconOutlinePath = new GeneralPath();
2395:            // float d = dimension - 1;
2396:            // float d32 = (float) (0.1 * d * Math.sqrt(3.0) / 2.0);
2397:            // float height = (float) (1.1 * d * Math.sqrt(3.0) / 2.0);
2398:            // iconOutlinePath.moveTo(0.45f * d, d32);
2399:            // iconOutlinePath.quadTo(0.5f * d, 0, 0.55f * d, d32);
2400:            // iconOutlinePath.lineTo(0.95f * d, height - d32);
2401:            // iconOutlinePath.quadTo(d, height, 0.9f * d, height);
2402:            // iconOutlinePath.lineTo(0.1f * d, height);
2403:            // iconOutlinePath.quadTo(0, height, 0.05f * d, height - d32);
2404:            // iconOutlinePath.lineTo(0.45f * d, d32);
2405:            //
2406:            // // fill inside
2407:            // graphics.setColor(colorScheme.getMidColor());
2408:            // graphics.fill(iconOutlinePath);
2409:            //
2410:            // // create spot in the upper-left corner using temporary graphics
2411:            // // with clip set to the icon outline
2412:            // GradientPaint spot = new GradientPaint(0, 0, new Color(255, 255, 255,
2413:            // 200), dimension, dimension, new Color(255, 255, 255, 0));
2414:            // Graphics2D tempGraphics = (Graphics2D) graphics.create();
2415:            // tempGraphics.setPaint(spot);
2416:            // tempGraphics.setClip(iconOutlinePath);
2417:            // tempGraphics.fillRect(0, 0, dimension, dimension);
2418:            // tempGraphics.dispose();
2419:            //
2420:            // // draw outline of the icon
2421:            // graphics.setColor(colorScheme.getUltraDarkColor());
2422:            // graphics.draw(iconOutlinePath);
2423:            //
2424:            // // draw the ! sign
2425:            // float dimOuter = (float) (0.5f * Math.pow(dimension, 0.75));
2426:            // float dimInner = (float) (0.28f * Math.pow(dimension, 0.75));
2427:            // GeneralPath markerPath = new GeneralPath();
2428:            // markerPath.moveTo((float) 0.5 * d, (float) 0.3 * height);
2429:            // markerPath.lineTo((float) 0.5 * d, (float) 0.3 * height);
2430:            // markerPath.moveTo((float) 0.5 * d, (float) 0.55 * height);
2431:            // markerPath.lineTo((float) 0.5 * d, (float) 0.8 * height);
2432:            // graphics.setStroke(new BasicStroke(dimOuter, BasicStroke.CAP_ROUND,
2433:            // BasicStroke.JOIN_ROUND));
2434:            // graphics.setColor(colorScheme.getUltraDarkColor());
2435:            // graphics.draw(markerPath);
2436:            // graphics.setStroke(new BasicStroke(dimInner, BasicStroke.CAP_ROUND,
2437:            // BasicStroke.JOIN_ROUND));
2438:            // graphics.setColor(colorScheme.getUltraLightColor().brighter());
2439:            // graphics.draw(markerPath);
2440:            //
2441:            // // dispose
2442:            // graphics.dispose();
2443:            // return image;
2444:            // }
2445:            //
2446:            // /**
2447:            // * Returns an info marker of specified dimension with an <code>!</code>
2448:            // * inside. The resulting image is a triangular icon with an exclamation
2449:            // * mark.
2450:            // *
2451:            // * @param dimension
2452:            // * The diameter of the resulting marker.
2453:            // * @param colorScheme
2454:            // * Color scheme for the marker.
2455:            // * @return Info marker of specified dimension with an <code>!</code>
2456:            // * inside
2457:            // */
2458:            // public static Icon getInfoMarkerIcon(int dimension, ColorScheme
2459:            // colorScheme) {
2460:            // return new ImageIcon(SubstanceImageCreator.getInfoMarker(dimension,
2461:            // colorScheme));
2462:            // }
2463:            //
2464:            // /**
2465:            // * Returns a warning marker of specified dimension with an <code>!</code>
2466:            // * inside. The resulting image is a triangular icon with an exclamation
2467:            // * mark.
2468:            // *
2469:            // * @param dimension
2470:            // * The side of the resulting marker.
2471:            // * @param colorScheme
2472:            // * Color scheme for the marker.
2473:            // * @return Warning marker of specified dimension with an <code>!</code>
2474:            // * inside.
2475:            // */
2476:            // public static Icon getWarningMarkerIcon(int dimension,
2477:            // ColorScheme colorScheme) {
2478:            // return new ImageIcon(SubstanceImageCreator.getWarningMarker(dimension,
2479:            // colorScheme));
2480:            // }
2481:            //
2482:            // /**
2483:            // * Returns an error marker of specified dimension with an <code>X</code>
2484:            // * inside. The resulting image is a circular icon with a question mark.
2485:            // *
2486:            // * @param dimension
2487:            // * The diameter of the resulting marker.
2488:            // * @param colorScheme
2489:            // * Color scheme for the marker.
2490:            // * @return Error marker of specified dimension with an <code>?</code>
2491:            // * inside
2492:            // */
2493:            // public static BufferedImage getQuestionMarker(int dimension,
2494:            // ColorScheme colorScheme) {
2495:            // // new RGB image with transparency channel
2496:            // BufferedImage image = new BufferedImage(dimension, dimension,
2497:            // BufferedImage.TYPE_INT_ARGB);
2498:            //
2499:            // // create new graphics and set anti-aliasing hint
2500:            // Graphics2D graphics = (Graphics2D) image.getGraphics().create();
2501:            // graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
2502:            // RenderingHints.VALUE_ANTIALIAS_ON);
2503:            //
2504:            // // background fill
2505:            // graphics.setColor(colorScheme.getMidColor());
2506:            // graphics.fillOval(0, 0, dimension - 1, dimension - 1);
2507:            //
2508:            // // create spot in the upper-left corner using temporary graphics
2509:            // // with clip set to the icon outline
2510:            // GradientPaint spot = new GradientPaint(0, 0, new Color(255, 255, 255,
2511:            // 200), dimension, dimension, new Color(255, 255, 255, 0));
2512:            // Graphics2D tempGraphics = (Graphics2D) graphics.create();
2513:            // tempGraphics.setPaint(spot);
2514:            // tempGraphics.setClip(new Ellipse2D.Double(0, 0, dimension - 1,
2515:            // dimension - 1));
2516:            // tempGraphics.fillRect(0, 0, dimension, dimension);
2517:            // tempGraphics.dispose();
2518:            //
2519:            // // draw outline of the icon
2520:            // graphics.setColor(colorScheme.getUltraDarkColor());
2521:            // graphics.drawOval(0, 0, dimension - 1, dimension - 1);
2522:            //
2523:            // // draw the ? sign
2524:            // float d = dimension - 1;
2525:            // float dimOuter = (float) (0.5f * Math.pow(dimension, 0.75));
2526:            // float dimInner = (float) (0.28f * Math.pow(dimension, 0.75));
2527:            //
2528:            // // create the paths
2529:            // GeneralPath markerPath = new GeneralPath();
2530:            // markerPath.moveTo((float) 0.3 * d, (float) 0.32 * d);
2531:            // markerPath.quadTo((float) 0.3 * d, (float) 0.18 * d, (float) 0.5 * d,
2532:            // (float) 0.18 * d);
2533:            // markerPath.quadTo((float) 0.7 * d, (float) 0.18 * d, (float) 0.7 * d,
2534:            // (float) 0.32 * d);
2535:            // markerPath.quadTo((float) 0.7 * d, (float) 0.45 * d, (float) 0.6 * d,
2536:            // (float) 0.45 * d);
2537:            // markerPath.quadTo((float) 0.5 * d, (float) 0.45 * d, (float) 0.5 * d,
2538:            // (float) 0.6 * d);
2539:            // markerPath.moveTo((float) 0.5 * d, (float) 0.85 * d);
2540:            // markerPath.lineTo((float) 0.5 * d, (float) 0.85 * d);
2541:            // graphics.setStroke(new BasicStroke(dimOuter, BasicStroke.CAP_ROUND,
2542:            // BasicStroke.JOIN_ROUND));
2543:            // graphics.setColor(colorScheme.getUltraDarkColor());
2544:            // graphics.draw(markerPath);
2545:            // graphics.setStroke(new BasicStroke(dimInner, BasicStroke.CAP_ROUND,
2546:            // BasicStroke.JOIN_ROUND));
2547:            // graphics.setColor(colorScheme.getUltraLightColor().brighter());
2548:            // graphics.draw(markerPath);
2549:            //
2550:            // // dispose
2551:            // graphics.dispose();
2552:            // return image;
2553:            // }
2554:            //
2555:            // /**
2556:            // * Returns an error marker of specified dimension with an <code>X</code>
2557:            // * inside. The resulting image is a circular icon with a question mark.
2558:            // *
2559:            // * @param dimension
2560:            // * The diameter of the resulting marker.
2561:            // * @param colorScheme
2562:            // * Color scheme for the marker.
2563:            // * @return Error marker of specified dimension with an <code>?</code>
2564:            // * inside
2565:            // */
2566:            // public static Icon getQuestionMarkerIcon(int dimension,
2567:            // ColorScheme colorScheme) {
2568:            // return new ImageIcon(SubstanceImageCreator.getQuestionMarker(dimension,
2569:            // colorScheme));
2570:            // }
2571:            //
2572:            /**
2573:             * Returns small icon representation of the specified integer value. The
2574:             * remainder of dividing the integer by 16 is translated to four circles
2575:             * arranged in 2*2 grid.
2576:             * 
2577:             * @param value
2578:             *            Integer value to represent.
2579:             * @param theme
2580:             *            Icon theme.
2581:             * @return Icon representation of the specified integer value.
2582:             */
2583:            public static Icon getHexaMarker(int value, SubstanceTheme theme) {
2584:                BufferedImage result = SubstanceCoreUtilities.getBlankImage(9,
2585:                        9);
2586:
2587:                value %= 16;
2588:                Color offColor = null;
2589:                Color onColor = null;
2590:                if (theme == null) {
2591:                    return new ImageIcon(result);
2592:                }
2593:                ColorScheme colorScheme = theme.getColorScheme();
2594:                boolean isDark = SubstanceCoreUtilities.isThemeDark(theme);
2595:                offColor = isDark ? colorScheme.getMidColor() : colorScheme
2596:                        .getMidColor().darker();
2597:                onColor = isDark ? SubstanceColorUtilities
2598:                        .getInterpolatedColor(colorScheme.getUltraLightColor(),
2599:                                Color.white, 0.2) : colorScheme
2600:                        .getUltraDarkColor().darker();
2601:
2602:                boolean bit1 = ((value & 0x1) != 0);
2603:                boolean bit2 = ((value & 0x2) != 0);
2604:                boolean bit3 = ((value & 0x4) != 0);
2605:                boolean bit4 = ((value & 0x8) != 0);
2606:
2607:                Graphics2D graphics = (Graphics2D) result.getGraphics()
2608:                        .create();
2609:                graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
2610:                        RenderingHints.VALUE_ANTIALIAS_ON);
2611:
2612:                graphics.setColor(bit1 ? onColor : offColor);
2613:                graphics.fillOval(5, 5, 4, 4);
2614:                graphics.setColor(bit2 ? onColor : offColor);
2615:                graphics.fillOval(5, 0, 4, 4);
2616:                graphics.setColor(bit3 ? onColor : offColor);
2617:                graphics.fillOval(0, 5, 4, 4);
2618:                graphics.setColor(bit4 ? onColor : offColor);
2619:                graphics.fillOval(0, 0, 4, 4);
2620:
2621:                graphics.dispose();
2622:                return new ImageIcon(result);
2623:            }
2624:
2625:            /**
2626:             * Returns big icon representation of the specified integer value. The
2627:             * remainder of dividing the integer by 16 is translated to four circles
2628:             * arranged in 2*2 grid.
2629:             * 
2630:             * @param value
2631:             *            Integer value to represent.
2632:             * @param theme
2633:             *            Icon theme.
2634:             * @return Icon representation of the specified integer value.
2635:             */
2636:            public static Image getBigHexaMarker(int value, SubstanceTheme theme) {
2637:                int iSize = SubstanceSizeUtils.getTitlePaneIconSize();
2638:                BufferedImage result = SubstanceCoreUtilities.getBlankImage(
2639:                        iSize, iSize);
2640:
2641:                value %= 16;
2642:                Color offColor = null;
2643:                Color onColor = null;
2644:                if (theme == null)
2645:                    return result;
2646:                ColorScheme colorScheme = theme.getColorScheme();
2647:                boolean isDark = SubstanceCoreUtilities.isThemeDark(theme);
2648:                offColor = isDark ? colorScheme.getMidColor() : colorScheme
2649:                        .getMidColor().darker();
2650:                onColor = isDark ? SubstanceColorUtilities
2651:                        .getInterpolatedColor(colorScheme.getUltraLightColor(),
2652:                                Color.white, 0.2) : colorScheme
2653:                        .getUltraDarkColor().darker();
2654:
2655:                boolean bit1 = ((value & 0x1) != 0);
2656:                boolean bit2 = ((value & 0x2) != 0);
2657:                boolean bit3 = ((value & 0x4) != 0);
2658:                boolean bit4 = ((value & 0x8) != 0);
2659:
2660:                Graphics2D graphics = (Graphics2D) result.getGraphics()
2661:                        .create();
2662:                graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
2663:                        RenderingHints.VALUE_ANTIALIAS_ON);
2664:
2665:                graphics.setColor(bit1 ? onColor : offColor);
2666:                graphics.fillOval(9, 9, 6, 6);
2667:                graphics.setColor(bit2 ? onColor : offColor);
2668:                graphics.fillOval(9, 2, 6, 6);
2669:                graphics.setColor(bit3 ? onColor : offColor);
2670:                graphics.fillOval(2, 9, 6, 6);
2671:                graphics.setColor(bit4 ? onColor : offColor);
2672:                graphics.fillOval(2, 2, 6, 6);
2673:
2674:                graphics.dispose();
2675:                return result;
2676:            }
2677:
2678:            /**
2679:             * Returns search icon.
2680:             * 
2681:             * @param dimension
2682:             *            Icon dimension.
2683:             * @param theme
2684:             *            Icon theme.
2685:             * @param leftToRight
2686:             *            LTR indication of the resulting icon.
2687:             * @return Search icon.
2688:             */
2689:            public static Icon getSearchIcon(int dimension,
2690:                    SubstanceTheme theme, boolean leftToRight) {
2691:                // BufferedImage themeSearchIcon = SubstanceImageCreator.getThemeImage(
2692:                // new ImageIcon(SubstanceImageCreator.class.getClassLoader()
2693:                // .getResource("resource/system-search.png")), theme);
2694:                // if (leftToRight) {
2695:                // themeSearchIcon = getHorizontalFlip(themeSearchIcon);
2696:                // }
2697:                // return new ImageIcon(themeSearchIcon);
2698:                //
2699:                BufferedImage result = SubstanceCoreUtilities.getBlankImage(
2700:                        dimension, dimension);
2701:
2702:                Graphics2D graphics = (Graphics2D) result.getGraphics()
2703:                        .create();
2704:                graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
2705:                        RenderingHints.VALUE_ANTIALIAS_ON);
2706:
2707:                Color color = SubstanceCoreUtilities.getMarkColor(theme, true);
2708:                // theme.getColorScheme().getForegroundColor();
2709:                graphics.setColor(color);
2710:
2711:                graphics.setStroke(new BasicStroke(1.5f));
2712:                if (leftToRight) {
2713:                    int xc = (int) (0.6 * dimension);
2714:                    int yc = (int) (0.45 * dimension);
2715:                    int r = (int) (0.3 * dimension);
2716:
2717:                    graphics.drawOval(xc - r, yc - r, 2 * r, 2 * r);
2718:
2719:                    graphics.setStroke(new BasicStroke(3.0f));
2720:                    GeneralPath handle = new GeneralPath();
2721:                    handle.moveTo((float) (xc - r / Math.sqrt(2.0)),
2722:                            (float) (yc + r / Math.sqrt(2.0)));
2723:                    handle.lineTo(1.8f, dimension - 2.2f);
2724:                    graphics.draw(handle);
2725:                } else {
2726:                    int xc = (int) (0.4 * dimension);
2727:                    int yc = (int) (0.45 * dimension);
2728:                    int r = (int) (0.3 * dimension);
2729:
2730:                    graphics.drawOval(xc - r, yc - r, 2 * r, 2 * r);
2731:
2732:                    graphics.setStroke(new BasicStroke(3.0f));
2733:                    GeneralPath handle = new GeneralPath();
2734:                    handle.moveTo((float) (xc + r / Math.sqrt(2.0)),
2735:                            (float) (yc + r / Math.sqrt(2.0)));
2736:                    handle.lineTo(dimension - 2.5f, dimension - 2.2f);
2737:                    graphics.draw(handle);
2738:                }
2739:
2740:                graphics.dispose();
2741:                return new ImageIcon(result);
2742:                // return new ImageIcon(getThemeImage(new ImageIcon(result), theme
2743:                // .getDefaultTheme()));
2744:            }
2745:
2746:            /**
2747:             * Returns an icon that matches the specified theme.
2748:             * 
2749:             * @param theme
2750:             *            Theme instance.
2751:             * @return Icon that matches the specified theme.
2752:             */
2753:            public static Icon getThemeIcon(SubstanceTheme theme) {
2754:                int iSize = SubstanceSizeUtils.getTitlePaneIconSize();
2755:                BufferedImage result = SubstanceCoreUtilities.getBlankImage(
2756:                        iSize, iSize);
2757:                Graphics2D graphics = (Graphics2D) result.getGraphics()
2758:                        .create();
2759:                graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
2760:                        RenderingHints.VALUE_ANTIALIAS_ON);
2761:
2762:                boolean isMixed = (theme != null)
2763:                        && (((theme.getKind() == ThemeKind.MIXED)));
2764:                if (!isMixed) {
2765:                    Color color1 = (theme == null) ? Color.red : theme
2766:                            .getColorScheme().getUltraDarkColor();
2767:                    Color color2 = (theme == null) ? Color.green : theme
2768:                            .getColorScheme().getMidColor();
2769:                    Color color3 = (theme == null) ? Color.blue : theme
2770:                            .getColorScheme().getExtraLightColor();
2771:
2772:                    graphics.setColor(color1);
2773:                    graphics.fillOval(5, 2, 6, 6);
2774:                    graphics.setColor(color1.darker());
2775:                    graphics.drawOval(5, 2, 6, 6);
2776:
2777:                    graphics.setColor(color2);
2778:                    graphics.fillOval(1, 9, 6, 6);
2779:                    graphics.setColor(color2.darker());
2780:                    graphics.drawOval(1, 9, 6, 6);
2781:
2782:                    graphics.setColor(color3);
2783:                    graphics.fillOval(9, 9, 6, 6);
2784:                    graphics.setColor(color3.darker());
2785:                    graphics.drawOval(9, 9, 6, 6);
2786:                } else {
2787:                    SubstanceTheme[] origThemes = ((SubstanceMixTheme) theme)
2788:                            .getOriginalThemes();
2789:                    SubstanceTheme theme1 = origThemes[0];
2790:                    SubstanceTheme theme2 = origThemes[origThemes.length - 1];
2791:
2792:                    Color color1_1 = theme1.getColorScheme()
2793:                            .getUltraDarkColor();
2794:                    Color color2_1 = theme1.getColorScheme().getMidColor();
2795:                    Color color3_1 = theme1.getColorScheme()
2796:                            .getExtraLightColor();
2797:                    Color color1_2 = theme2.getColorScheme()
2798:                            .getUltraDarkColor();
2799:                    Color color2_2 = theme2.getColorScheme().getMidColor();
2800:                    Color color3_2 = theme2.getColorScheme()
2801:                            .getExtraLightColor();
2802:
2803:                    graphics.setClip(5, 2, 3, 7);
2804:                    graphics.setColor(color1_1);
2805:                    graphics.fillOval(5, 2, 6, 7);
2806:                    graphics.setColor(color1_1.darker());
2807:                    graphics.drawOval(5, 2, 6, 6);
2808:
2809:                    graphics.setClip(8, 2, 4, 7);
2810:                    graphics.setColor(color1_2);
2811:                    graphics.fillOval(5, 2, 6, 6);
2812:                    graphics.setColor(color1_2.darker());
2813:                    graphics.drawOval(5, 2, 6, 6);
2814:
2815:                    graphics.setClip(1, 9, 3, 7);
2816:                    graphics.setColor(color2_1);
2817:                    graphics.fillOval(1, 9, 6, 6);
2818:                    graphics.setColor(color2_1.darker());
2819:                    graphics.drawOval(1, 9, 6, 6);
2820:
2821:                    graphics.setClip(4, 9, 4, 7);
2822:                    graphics.setColor(color2_2);
2823:                    graphics.fillOval(1, 9, 6, 6);
2824:                    graphics.setColor(color2_2.darker());
2825:                    graphics.drawOval(1, 9, 6, 6);
2826:
2827:                    graphics.setClip(9, 9, 3, 7);
2828:                    graphics.setColor(color3_1);
2829:                    graphics.fillOval(9, 9, 6, 6);
2830:                    graphics.setColor(color3_1.darker());
2831:                    graphics.drawOval(9, 9, 6, 6);
2832:
2833:                    graphics.setClip(12, 9, 4, 7);
2834:                    graphics.setColor(color3_2);
2835:                    graphics.fillOval(9, 9, 6, 6);
2836:                    graphics.setColor(color3_2.darker());
2837:                    graphics.drawOval(9, 9, 6, 6);
2838:                }
2839:
2840:                graphics.dispose();
2841:                return new ImageIcon(result);
2842:            }
2843:
2844:            /**
2845:             * Returns an icon that matches the specified watermark.
2846:             * 
2847:             * @param watermark
2848:             *            Watermark instance.
2849:             * @return Icon that matches the specified watermark.
2850:             */
2851:            public static Icon getWatermarkIcon(SubstanceWatermark watermark) {
2852:                int iSize = SubstanceSizeUtils.getTitlePaneIconSize();
2853:                BufferedImage result = SubstanceCoreUtilities.getBlankImage(
2854:                        iSize, iSize);
2855:                Graphics2D graphics = (Graphics2D) result.getGraphics()
2856:                        .create();
2857:                graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
2858:                        RenderingHints.VALUE_ANTIALIAS_ON);
2859:
2860:                watermark.previewWatermark(graphics, 0, 0, iSize, iSize);
2861:                graphics.dispose();
2862:                return new ImageIcon(result);
2863:            }
2864:
2865:            /**
2866:             * Returns a lock icon that matches the specified scheme.
2867:             * 
2868:             * @param scheme
2869:             *            Scheme instance.
2870:             * @return Lock icon that matches the specified scheme.
2871:             */
2872:            public static Icon getSmallLockIcon(ColorScheme scheme) {
2873:                int extraPadding = SubstanceSizeUtils
2874:                        .getExtraPadding(SubstanceSizeUtils
2875:                                .getControlFontSize());
2876:                BufferedImage result = SubstanceCoreUtilities.getBlankImage(
2877:                        6 + 2 * extraPadding, 8 + 2 * extraPadding);
2878:
2879:                Color fore = scheme.getForegroundColor();
2880:                Color fill = new Color(208, 208, 48);
2881:
2882:                Graphics2D graphics = (Graphics2D) result.getGraphics()
2883:                        .create();
2884:                graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
2885:                        RenderingHints.VALUE_ANTIALIAS_OFF);
2886:
2887:                graphics.setColor(fill);
2888:                // lock fill
2889:                graphics.fillRect(1, 2 + extraPadding, 4 + 2 * extraPadding,
2890:                        4 + 2 * extraPadding);
2891:                graphics.setColor(fore);
2892:                // lock left side
2893:                graphics.drawLine(0, 3 + extraPadding, 0, 7 + 2 * extraPadding);
2894:                // lock right side
2895:                graphics.drawLine(5 + 2 * extraPadding, 3 + extraPadding,
2896:                        5 + 2 * extraPadding, 7 + 2 * extraPadding);
2897:                // lock bottom side
2898:                graphics.drawLine(0, 7 + 2 * extraPadding,
2899:                        5 + 2 * extraPadding, 7 + 2 * extraPadding);
2900:                // lock top side
2901:                graphics.drawLine(1, 2 + extraPadding, 4 + 2 * extraPadding,
2902:                        2 + extraPadding);
2903:                // lock left handle
2904:                graphics.drawLine(1 + extraPadding, 1, 1 + extraPadding,
2905:                        2 + extraPadding);
2906:                // lock right handle
2907:                graphics.drawLine(4 + extraPadding, 1, 4 + extraPadding,
2908:                        2 + extraPadding);
2909:                // lock top handle
2910:                graphics.drawLine(2 + extraPadding, 0, 3 + extraPadding, 0);
2911:                // lock keyhole
2912:                graphics.fillRect(2 + extraPadding, 4 + extraPadding, 2,
2913:                        2 + extraPadding);
2914:
2915:                graphics.dispose();
2916:                return new ImageIcon(result);
2917:            }
2918:
2919:            /**
2920:             * Returns the negative of the specified image.
2921:             * 
2922:             * @param bi
2923:             *            Image.
2924:             * @return The negative of the specified image.
2925:             */
2926:            public static BufferedImage getNegated(BufferedImage bi) {
2927:                int w = bi.getWidth();
2928:                int h = bi.getHeight();
2929:                BufferedImage result = SubstanceCoreUtilities.getBlankImage(w,
2930:                        h);
2931:                for (int i = 0; i < w; i++) {
2932:                    for (int j = 0; j < h; j++) {
2933:                        result.setRGB(i, j, SubstanceColorUtilities
2934:                                .getNegativeColor(bi.getRGB(i, j)));
2935:                    }
2936:                }
2937:                return result;
2938:            }
2939:
2940:            // /**
2941:            // * Returns <code>pin down</code> icon.
2942:            // *
2943:            // * @param theme
2944:            // * Theme for the icon.
2945:            // * @return <code>Pin down</code> icon.
2946:            // */
2947:            // public static Icon getPinDownIcon(SubstanceTheme theme) {
2948:            // int iSize = SubstanceSizeUtils.getTitlePaneIconSize();
2949:            // BufferedImage image = SubstanceCoreUtilities
2950:            // .getBlankImage(iSize, iSize);
2951:            // Graphics2D graphics = (Graphics2D) image.getGraphics();
2952:            // int start = (iSize / 4);
2953:            // int end = (3 * iSize / 4) - 1;
2954:            // int center = (start + end) / 2;
2955:            // graphics.setColor(theme.getColorScheme().getForegroundColor());
2956:            // graphics.drawRect(start, start, end - start, end - start);
2957:            // graphics.fillRect(center, center, 2, 2);
2958:            // return new ImageIcon(SubstanceImageCreator.overlayEcho(image, 1, 1));
2959:            // }
2960:
2961:            // /**
2962:            // * Returns <code>pin down</code> icon.
2963:            // *
2964:            // * @param theme
2965:            // * Theme for the icon.
2966:            // * @return <code>Pin down</code> icon.
2967:            // */
2968:            // public static Icon getPinUpIcon(SubstanceTheme theme) {
2969:            // int iSize = SubstanceSizeUtils.getTitlePaneIconSize();
2970:            // BufferedImage image = SubstanceCoreUtilities
2971:            // .getBlankImage(iSize, iSize);
2972:            // Graphics2D graphics = (Graphics2D) image.getGraphics();
2973:            // int start = (iSize / 4) - 1;
2974:            // int end = (3 * iSize / 4);
2975:            // int center = (start + end) / 2;
2976:            // graphics.setColor(theme.getColorScheme().getForegroundColor());
2977:            //
2978:            // graphics.drawLine(start, start, center - 1, start);
2979:            // graphics.drawLine(center + 2, start, end, start);
2980:            // graphics.drawLine(end, start, end, center - 1);
2981:            // graphics.drawLine(end, center + 2, end, end);
2982:            // graphics.drawLine(end, end, center + 2, end);
2983:            // graphics.drawLine(center - 1, end, start, end);
2984:            // graphics.drawLine(start, end, start, center + 2);
2985:            // graphics.drawLine(start, center - 1, start, start);
2986:            // return new ImageIcon(SubstanceImageCreator.overlayEcho(image, 1, 1));
2987:            // }
2988:
2989:            // /**
2990:            // * Retrieves computer icon.
2991:            // *
2992:            // * @return Computer icon.
2993:            // */
2994:            // public static BufferedImage getComputerIcon() {
2995:            // BufferedImage result = SubstanceCoreUtilities.getBlankImage(18, 18);
2996:            // Graphics2D graphics = (Graphics2D) result.getGraphics();
2997:            //
2998:            // ColorScheme colorScheme = SubstanceCoreUtilities.getActiveScheme(null);
2999:            //
3000:            // graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
3001:            // RenderingHints.VALUE_ANTIALIAS_ON);
3002:            //
3003:            // // tower
3004:            // graphics.setPaint(new GradientPaint(0, 0, colorScheme
3005:            // .getUltraLightColor(), 17, 17, colorScheme.getMidColor()));
3006:            // graphics.fillRect(1, 4, 4, 11);
3007:            // graphics.setPaint(new GradientPaint(0, 0, colorScheme.getDarkColor(),
3008:            // 17, 17, colorScheme.getUltraDarkColor()));
3009:            // graphics.drawRect(1, 4, 4, 11);
3010:            // graphics.drawLine(2, 6, 4, 6);
3011:            // graphics.drawLine(2, 8, 4, 8);
3012:            // graphics.drawLine(3, 12, 3, 12);
3013:            //
3014:            // // screen
3015:            // graphics.setPaint(new GradientPaint(0, 0, colorScheme
3016:            // .getUltraLightColor(), 17, 17, colorScheme.getMidColor()));
3017:            // graphics.fillRoundRect(8, 4, 9, 8, 2, 2);
3018:            // graphics.setPaint(new GradientPaint(0, 0, colorScheme.getDarkColor(),
3019:            // 17, 17, colorScheme.getUltraDarkColor()));
3020:            // graphics.drawRoundRect(7, 4, 9, 8, 2, 2);
3021:            // graphics.drawRoundRect(9, 6, 5, 4, 2, 2);
3022:            // graphics.fillRect(11, 12, 2, 3);
3023:            // graphics.drawLine(9, 15, 14, 15);
3024:            //
3025:            // float[] BLUR = { 0.03f, 0.03f, 0.03f, 0.03f, 0.86f, 0.03f, 0.03f,
3026:            // 0.03f, 0.03f };
3027:            // ConvolveOp vBlurOp = new ConvolveOp(new Kernel(3, 3, BLUR));
3028:            // BufferedImage blurred = vBlurOp.filter(result, null);
3029:            // return blurred;
3030:            // }
3031:            //
3032:            // /**
3033:            // * Retrieves disk icon.
3034:            // *
3035:            // * @param isDark
3036:            // * Indication whether the color scheme is drak.
3037:            // * @return Disk icon.
3038:            // */
3039:            // public static BufferedImage getDiskIcon(boolean isDark) {
3040:            // BufferedImage result = SubstanceCoreUtilities.getBlankImage(18, 18);
3041:            // Graphics2D graphics = (Graphics2D) result.getGraphics();
3042:            //
3043:            // ColorScheme colorScheme = SubstanceCoreUtilities.getActiveScheme(null);
3044:            //
3045:            // graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
3046:            // RenderingHints.VALUE_ANTIALIAS_ON);
3047:            //
3048:            // Color gradColor1 = isDark ? colorScheme.getUltraLightColor().brighter()
3049:            // : colorScheme.getUltraLightColor();
3050:            // Color gradColor2 = isDark ? colorScheme.getUltraLightColor()
3051:            // : colorScheme.getMidColor();
3052:            // graphics.setPaint(new GradientPaint(0, 0, gradColor1, 17, 17,
3053:            // gradColor2));
3054:            // graphics.fillRect(3, 4, 10, 10);
3055:            // graphics.fillArc(3, 2, 10, 4, 0, 180);
3056:            // graphics.fillArc(3, 12, 10, 4, 180, 180);
3057:            //
3058:            // Color gradColor3 = isDark ? colorScheme.getUltraLightColor()
3059:            // : colorScheme.getDarkColor();
3060:            // Color gradColor4 = isDark ? colorScheme.getLightColor() : colorScheme
3061:            // .getUltraDarkColor();
3062:            // graphics.setPaint(new GradientPaint(0, 0, gradColor3, 17, 17,
3063:            // gradColor4));
3064:            //
3065:            // graphics.drawOval(3, 2, 10, 4);
3066:            // graphics.drawArc(3, 12, 10, 4, 180, 180);
3067:            // graphics.drawArc(3, 9, 10, 4, 180, 180);
3068:            // graphics.drawArc(3, 6, 10, 4, 180, 180);
3069:            // graphics.drawLine(3, 4, 3, 14);
3070:            // graphics.drawLine(13, 4, 13, 14);
3071:            //
3072:            // return result;
3073:            // }
3074:            //
3075:            // /**
3076:            // * Retrieves floppy icon.
3077:            // *
3078:            // * @param isDark
3079:            // * Indication whether the color scheme is drak.
3080:            // * @return Floppy icon.
3081:            // */
3082:            // public static BufferedImage getFloppyIcon(boolean isDark) {
3083:            // BufferedImage result = SubstanceCoreUtilities.getBlankImage(18, 18);
3084:            // Graphics2D graphics = (Graphics2D) result.getGraphics();
3085:            //
3086:            // ColorScheme colorScheme = SubstanceCoreUtilities.getActiveScheme(null);
3087:            //
3088:            // graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
3089:            // RenderingHints.VALUE_ANTIALIAS_ON);
3090:            //
3091:            // Polygon outline = new Polygon();
3092:            // outline.addPoint(3, 3);
3093:            // outline.addPoint(13, 3);
3094:            // outline.addPoint(14, 4);
3095:            // outline.addPoint(14, 15);
3096:            // outline.addPoint(2, 15);
3097:            // outline.addPoint(2, 4);
3098:            //
3099:            // Color gradColor1 = isDark ? colorScheme.getUltraLightColor().brighter()
3100:            // : colorScheme.getUltraLightColor();
3101:            // Color gradColor2 = isDark ? colorScheme.getUltraLightColor()
3102:            // : colorScheme.getMidColor();
3103:            // graphics.setPaint(new GradientPaint(0, 0, gradColor1, 17, 17,
3104:            // gradColor2));
3105:            // graphics.fillPolygon(outline);
3106:            //
3107:            // Color gradColor3 = isDark ? colorScheme.getUltraLightColor()
3108:            // : colorScheme.getDarkColor();
3109:            // Color gradColor4 = isDark ? colorScheme.getLightColor() : colorScheme
3110:            // .getUltraDarkColor();
3111:            // graphics.setPaint(new GradientPaint(0, 0, gradColor3, 17, 17,
3112:            // gradColor4));
3113:            //
3114:            // graphics.drawPolygon(outline);
3115:            //
3116:            // graphics.drawRect(5, 3, 6, 3);
3117:            // graphics.fillRect(9, 3, 3, 3);
3118:            //
3119:            // graphics.drawRect(4, 9, 8, 6);
3120:            // graphics.drawLine(6, 11, 10, 11);
3121:            // graphics.drawLine(6, 13, 10, 13);
3122:            //
3123:            // return result;
3124:            // }
3125:            //
3126:            // /**
3127:            // * Retrieves list view icon.
3128:            // *
3129:            // * @param isDark
3130:            // * Indication whether the color scheme is drak.
3131:            // * @return List view icon.
3132:            // */
3133:            // public static BufferedImage getListViewIcon(boolean isDark) {
3134:            // BufferedImage result = SubstanceCoreUtilities.getBlankImage(16, 16);
3135:            // Graphics2D graphics = (Graphics2D) result.getGraphics();
3136:            //
3137:            // ColorScheme colorScheme = SubstanceCoreUtilities.getActiveScheme(null);
3138:            //
3139:            // graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
3140:            // RenderingHints.VALUE_ANTIALIAS_OFF);
3141:            //
3142:            // Color color = colorScheme.getForegroundColor();
3143:            // graphics.setColor(color);
3144:            // graphics.drawRect(1, 1, 4, 4);
3145:            // graphics.drawLine(7, 4, 7, 4);
3146:            // graphics.drawRect(9, 1, 4, 4);
3147:            // graphics.drawLine(15, 4, 15, 4);
3148:            // graphics.drawRect(1, 9, 4, 4);
3149:            // graphics.drawLine(7, 11, 7, 11);
3150:            // graphics.drawRect(9, 9, 4, 4);
3151:            // graphics.drawLine(15, 11, 15, 11);
3152:            //
3153:            // return result;
3154:            // }
3155:            //
3156:            // /**
3157:            // * Retrieves details view icon.
3158:            // *
3159:            // * @param isDark
3160:            // * Indication whether the color scheme is drak.
3161:            // * @return Details view icon.
3162:            // */
3163:            // public static BufferedImage getDetailsViewIcon(boolean isDark) {
3164:            // BufferedImage result = SubstanceCoreUtilities.getBlankImage(16, 16);
3165:            // Graphics2D graphics = (Graphics2D) result.getGraphics();
3166:            //
3167:            // ColorScheme colorScheme = SubstanceCoreUtilities.getActiveScheme(null);
3168:            //
3169:            // graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
3170:            // RenderingHints.VALUE_ANTIALIAS_OFF);
3171:            //
3172:            // Color color = colorScheme.getForegroundColor();
3173:            // graphics.setColor(color);
3174:            // graphics.drawRect(1, 1, 4, 4);
3175:            // graphics.drawLine(7, 4, 14, 4);
3176:            // graphics.drawRect(1, 9, 4, 4);
3177:            // graphics.drawLine(7, 11, 14, 11);
3178:            //
3179:            // return result;
3180:            // }
3181:
3182:            /**
3183:             * Creates a new version of the specified icon that is rendered in the
3184:             * colors of the specified theme.
3185:             * 
3186:             * @param comp
3187:             *            Component.
3188:             * @param original
3189:             *            The original icon.
3190:             * @param theme
3191:             *            Theme.
3192:             * @param toSaturate
3193:             *            Indicates whether the resulting image should be saturated.
3194:             * @return Theme-based version of the original icon.
3195:             */
3196:            public static BufferedImage getThemeImage(Component comp,
3197:                    Icon original, SubstanceTheme theme, boolean toSaturate) {
3198:                int w = original.getIconWidth();
3199:                int h = original.getIconHeight();
3200:                BufferedImage origImage = SubstanceCoreUtilities.getBlankImage(
3201:                        w, h);
3202:                original.paintIcon(comp, origImage.getGraphics(), 0, 0);
3203:
3204:                return getThemeImage(origImage, theme, toSaturate);
3205:            }
3206:
3207:            /**
3208:             * Creates a new version of the specified image that is rendered in the
3209:             * colors of the specified theme.
3210:             * 
3211:             * @param original
3212:             *            The original image.
3213:             * @param theme
3214:             *            Theme.
3215:             * @param toSaturate
3216:             *            Indicates whether the resulting image should be saturated.
3217:             * @return Theme-based version of the original icon.
3218:             */
3219:            public static BufferedImage getThemeImage(BufferedImage original,
3220:                    SubstanceTheme theme, boolean toSaturate) {
3221:                int w = original.getWidth();
3222:                int h = original.getHeight();
3223:                ColorScheme scheme = theme.getActiveTheme().getColorScheme();
3224:                if (toSaturate) {
3225:                    scheme = new ShiftColorScheme(new SaturatedColorScheme(
3226:                            scheme, 0.2), scheme.getDarkColor(), 0.2);
3227:                }
3228:
3229:                // collect the brightness factors of the color scheme
3230:                Map<Integer, Color> schemeColorMapping = new TreeMap<Integer, Color>();
3231:                schemeColorMapping.put(SubstanceColorUtilities
3232:                        .getColorBrightness(scheme.getUltraLightColor()
3233:                                .getRGB()), scheme.getUltraLightColor());
3234:                schemeColorMapping.put(SubstanceColorUtilities
3235:                        .getColorBrightness(scheme.getExtraLightColor()
3236:                                .getRGB()), scheme.getExtraLightColor());
3237:                schemeColorMapping.put(SubstanceColorUtilities
3238:                        .getColorBrightness(scheme.getLightColor().getRGB()),
3239:                        scheme.getLightColor());
3240:                schemeColorMapping.put(SubstanceColorUtilities
3241:                        .getColorBrightness(scheme.getMidColor().getRGB()),
3242:                        scheme.getMidColor());
3243:                schemeColorMapping.put(SubstanceColorUtilities
3244:                        .getColorBrightness(scheme.getDarkColor().getRGB()),
3245:                        scheme.getDarkColor());
3246:                schemeColorMapping.put(
3247:                        SubstanceColorUtilities.getColorBrightness(scheme
3248:                                .getUltraDarkColor().getRGB()), scheme
3249:                                .getUltraDarkColor());
3250:
3251:                List<Integer> schemeBrightness = new ArrayList<Integer>();
3252:                schemeBrightness.addAll(schemeColorMapping.keySet());
3253:                Collections.sort(schemeBrightness);
3254:
3255:                int lowestSchemeBrightness = schemeBrightness.get(0);
3256:                int highestSchemeBrightness = schemeBrightness
3257:                        .get(schemeBrightness.size() - 1);
3258:
3259:                Map<Integer, Color> stretchedColorMapping = new TreeMap<Integer, Color>();
3260:                for (Map.Entry<Integer, Color> entry : schemeColorMapping
3261:                        .entrySet()) {
3262:                    int brightness = entry.getKey();
3263:                    int stretched = 255
3264:                            - 255
3265:                            * (highestSchemeBrightness - brightness)
3266:                            / (highestSchemeBrightness - lowestSchemeBrightness);
3267:                    stretchedColorMapping.put(stretched, entry.getValue());
3268:                }
3269:                schemeBrightness = new ArrayList<Integer>();
3270:                schemeBrightness.addAll(stretchedColorMapping.keySet());
3271:                Collections.sort(schemeBrightness);
3272:
3273:                BufferedImage result = SubstanceCoreUtilities.getBlankImage(w,
3274:                        h);
3275:                for (int i = 0; i < w; i++) {
3276:                    for (int j = 0; j < h; j++) {
3277:                        int color = original.getRGB(i, j);
3278:                        int transp = (color >>> 24) & 0xFF;
3279:
3280:                        int brightness = SubstanceColorUtilities
3281:                                .getColorBrightness(color);
3282:                        Color pixelColor = null;
3283:                        if (schemeBrightness.contains(brightness)) {
3284:                            pixelColor = stretchedColorMapping.get(brightness);
3285:                        } else {
3286:                            int currIndex = 0;
3287:                            while (true) {
3288:                                int currStopValue = schemeBrightness
3289:                                        .get(currIndex);
3290:                                int nextStopValue = schemeBrightness
3291:                                        .get(currIndex + 1);
3292:                                if ((brightness > currStopValue)
3293:                                        && (brightness < nextStopValue)) {
3294:                                    // interpolate
3295:                                    Color currStopColor = stretchedColorMapping
3296:                                            .get(currStopValue);
3297:                                    Color nextStopColor = stretchedColorMapping
3298:                                            .get(nextStopValue);
3299:                                    pixelColor = SubstanceColorUtilities
3300:                                            .getInterpolatedColor(
3301:                                                    currStopColor,
3302:                                                    nextStopColor,
3303:                                                    1.0
3304:                                                            - (double) (brightness - currStopValue)
3305:                                                            / (double) (nextStopValue - currStopValue));
3306:                                    break;
3307:                                }
3308:                                currIndex++;
3309:                            }
3310:                        }
3311:                        result.setRGB(i, j, SubstanceColorUtilities
3312:                                .getAlphaColor(pixelColor, transp).getRGB());
3313:                    }
3314:                }
3315:                return result;
3316:            }
3317:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.