Source Code Cross Referenced for ShapedGradientTheme.java in  » Swing-Library » InfoNode-Docking-Windows » net » infonode » tabbedpanel » theme » 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 » InfoNode Docking Windows » net.infonode.tabbedpanel.theme 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) 2004 NNL Technology AB
003:         * Visit www.infonode.net for information about InfoNode(R) 
004:         * products and how to contact NNL Technology AB.
005:         *
006:         * This program is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU General Public License
008:         * as published by the Free Software Foundation; either version 2
009:         * of the License, or (at your option) any later version.
010:         *
011:         * This program is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014:         * GNU General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU General Public License
017:         * along with this program; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, 
019:         * MA 02111-1307, USA.
020:         */
021:
022:        // $Id: ShapedGradientTheme.java,v 1.14 2005/12/04 13:46:05 jesper Exp $
023:        package net.infonode.tabbedpanel.theme;
024:
025:        import net.infonode.gui.HighlightPainter;
026:        import net.infonode.gui.InsetsUtil;
027:        import net.infonode.gui.colorprovider.*;
028:        import net.infonode.gui.componentpainter.GradientComponentPainter;
029:        import net.infonode.tabbedpanel.Tab;
030:        import net.infonode.tabbedpanel.TabbedPanelProperties;
031:        import net.infonode.tabbedpanel.TabbedUtils;
032:        import net.infonode.tabbedpanel.border.OpenContentBorder;
033:        import net.infonode.tabbedpanel.internal.SlopedTabLineBorder;
034:        import net.infonode.tabbedpanel.titledtab.TitledTabBorderSizePolicy;
035:        import net.infonode.tabbedpanel.titledtab.TitledTabProperties;
036:        import net.infonode.tabbedpanel.titledtab.TitledTabStateProperties;
037:
038:        import javax.swing.border.Border;
039:        import java.awt.*;
040:
041:        /**
042:         * A theme with tabs with rounded edges, gradient backgrounds and support for
043:         * slopes on left/right side of tab.
044:         *
045:         * @author $Author: jesper $
046:         * @version $Revision: 1.14 $
047:         * @since ITP 1.2.0
048:         */
049:        public class ShapedGradientTheme extends TabbedPanelTitledTabTheme {
050:            private static final int CORNER_INSET = 3;
051:
052:            private ColorProvider highlightColor;
053:            private ColorProvider lineColor;
054:            private ColorProvider controlColor;
055:            private ColorProvider darkControlColor;
056:            private ColorProvider alternateHighlight;
057:            private int leftSlopeHeight;
058:            private int rightSlopeHeight;
059:
060:            private static class TabBorder extends SlopedTabLineBorder {
061:                private boolean bottomLeftRounded;
062:                private boolean isNormal;
063:                private boolean hasLeftSlope;
064:                private int raised;
065:                private int cornerInset;
066:
067:                TabBorder(ColorProvider lineColor,
068:                        ColorProvider highlightColor, float leftSlope,
069:                        float rightSlope, int leftHeight, int rightHeight,
070:                        boolean bottomLeftRounded, boolean topLeftRounded,
071:                        boolean topRightRounded, boolean bottomRightRounded,
072:                        boolean isNormal, boolean highlightBottomLeftRounded,
073:                        int raised) {
074:                    super (lineColor, highlightColor, false, leftSlope,
075:                            rightSlope, leftHeight, rightHeight,
076:                            isNormal ? false : bottomLeftRounded,
077:                            topLeftRounded, topRightRounded, bottomRightRounded);
078:
079:                    this .bottomLeftRounded = bottomLeftRounded;
080:                    this .isNormal = isNormal;
081:                    this .raised = raised;
082:                    hasLeftSlope = leftSlope > 0;
083:
084:                    cornerInset = highlightBottomLeftRounded ? CORNER_INSET : 0;
085:                }
086:
087:                protected Polygon createPolygon(Component c, int width,
088:                        int height) {
089:                    Polygon p = super .createPolygon(c, width, height);
090:                    if (isNormal) {
091:                        int leftX = width / 2;
092:                        boolean first = isFirst(c);
093:                        for (int i = 0; i < p.npoints; i++) {
094:                            if (p.xpoints[i] < leftX)
095:                                p.xpoints[i] = p.xpoints[i] + raised
096:                                        + (first ? 0 : cornerInset);
097:                            else
098:                                p.xpoints[i] = p.xpoints[i] - raised
099:                                        - cornerInset;
100:                        }
101:                    }
102:
103:                    return p;
104:                }
105:
106:                protected Insets getShapedBorderInsets(Component c) {
107:                    Insets i = super .getShapedBorderInsets(c);
108:
109:                    Insets addInsets = new Insets(0, 0, 0, 1 + raised);
110:                    //Insets addInsets = new Insets(0, raised, 0, raised);
111:                    if (isNormal && !isFirst(c))
112:                        addInsets.left = addInsets.left + cornerInset;
113:                    if (!isNormal)
114:                        addInsets.right = addInsets.right - cornerInset;
115:
116:                    return InsetsUtil.add(i, addInsets);
117:                }
118:
119:                private boolean isFirst(Component c) {
120:                    if (!hasLeftSlope) {
121:                        Tab tab = TabbedUtils.getParentTab(c);
122:                        if (tab != null && tab.getTabbedPanel() != null) {
123:                            return tab.getTabbedPanel().getTabAt(0) == tab;
124:                        }
125:                    }
126:
127:                    return false;
128:                }
129:
130:                protected boolean isBottomLeftRounded(Component c) {
131:                    return isFirst(c) ? false : bottomLeftRounded;
132:                }
133:            }
134:
135:            private TabbedPanelProperties tabbedPanelProperties = new TabbedPanelProperties();
136:            private TitledTabProperties titledTabProperties = new TitledTabProperties();
137:
138:            /**
139:             * Creates a default theme with sloped border on the right side of the tab
140:             * and with colors based on the active look and feel
141:             */
142:            public ShapedGradientTheme() {
143:                this (0f, 0.5f);
144:            }
145:
146:            /**
147:             * Creates a theme with the given slopes on the left and right side of the tab
148:             * and with colors based on the active look and feel
149:             *
150:             * @param leftSlope  leaning of left slope defined as left slope width divided by left slope height
151:             * @param rightSlope leaning of right slope defined as right slope width divided by right slope height
152:             */
153:            public ShapedGradientTheme(float leftSlope, float rightSlope) {
154:                this (leftSlope, rightSlope,
155:                        UIManagerColorProvider.TABBED_PANE_DARK_SHADOW,
156:                        UIManagerColorProvider.TABBED_PANE_HIGHLIGHT);
157:            }
158:
159:            /**
160:             * Creates a theme with the given slopes on the left and right side of the tab
161:             * and with the given colors
162:             *
163:             * @param leftSlope      leaning of left slope defined as left slope width divided
164:             *                       by left slope height
165:             * @param rightSlope     leaning of right slope defined as right slope width divided
166:             *                       by right slope height
167:             * @param lineColor      color provider for the lines
168:             * @param highlightColor color provider for the highlighting, null for no highlighting
169:             */
170:            public ShapedGradientTheme(float leftSlope, float rightSlope,
171:                    ColorProvider lineColor, ColorProvider highlightColor) {
172:                this (leftSlope, rightSlope, 25, lineColor, highlightColor);
173:            }
174:
175:            /**
176:             * Creates a theme with the given slopes on the left and right side of
177:             * the tab and with the given colors
178:             *
179:             * @param leftSlope      leaning of left slope defined as left slope width divided
180:             *                       by left slope height
181:             * @param rightSlope     leaning of right slope defined as right slope width divided
182:             *                       by right slope height
183:             * @param slopeHeight    slope height in pixels, used when estimating slope width
184:             * @param lineColor      color provider for the lines
185:             * @param highlightColor color provider for the highlighting, null for no highlighting
186:             */
187:            public ShapedGradientTheme(float leftSlope, float rightSlope,
188:                    int slopeHeight, ColorProvider lineColor,
189:                    ColorProvider highlightColor) {
190:                this .leftSlopeHeight = slopeHeight;
191:                this .rightSlopeHeight = slopeHeight;
192:                this .highlightColor = highlightColor;
193:                this .lineColor = lineColor;
194:                this .controlColor = UIManagerColorProvider.CONTROL_COLOR;
195:                darkControlColor = UIManagerColorProvider.TABBED_PANE_BACKGROUND;
196:                alternateHighlight = highlightColor != null ? new ColorBlender(
197:                        highlightColor, controlColor, 0.3f)
198:                        : (ColorProvider) new ColorMultiplier(controlColor, 1.2);
199:
200:                GradientComponentPainter blendedComponentPainter = new GradientComponentPainter(
201:                        alternateHighlight, alternateHighlight, controlColor,
202:                        controlColor);
203:
204:                int leftSlopeWidth = (int) (leftSlope * leftSlopeHeight);
205:                int rightSlopeWidth = (int) (rightSlope * rightSlopeHeight);
206:                int highlightedRaised = 2;
207:
208:                boolean bottomLeftRounded = true;
209:                boolean topLeftRounded = true;
210:                boolean topRightRounded = true;
211:                boolean bottomRightRounded = true;
212:
213:                titledTabProperties.setHighlightedRaised(highlightedRaised)
214:                        .setBorderSizePolicy(
215:                                TitledTabBorderSizePolicy.EQUAL_SIZE);
216:
217:                TitledTabStateProperties normalState = titledTabProperties
218:                        .getNormalProperties();
219:                TitledTabStateProperties highlightState = titledTabProperties
220:                        .getHighlightedProperties();
221:                TitledTabStateProperties disabledState = titledTabProperties
222:                        .getDisabledProperties();
223:
224:                Border normalBorder = new TabBorder(lineColor, null, leftSlope,
225:                        rightSlope, leftSlopeHeight, rightSlopeHeight, false,
226:                        topLeftRounded, topRightRounded, false, true, true,
227:                        highlightedRaised);
228:                Border highlightBorder = new TabBorder(lineColor,
229:                        highlightColor, leftSlope, rightSlope, leftSlopeHeight,
230:                        rightSlopeHeight, bottomLeftRounded, topLeftRounded,
231:                        topRightRounded, bottomRightRounded, false, true,
232:                        highlightedRaised);
233:
234:                normalState.getComponentProperties().setBorder(normalBorder)
235:                        .setInsets(new Insets(0, 0, 0, 0));
236:                highlightState.getComponentProperties().setBorder(
237:                        highlightBorder);
238:
239:                ColorProvider darkControlColor1 = new ColorMultiplier(
240:                        darkControlColor, 1.1);
241:                ColorProvider darkControlColor2 = new ColorMultiplier(
242:                        darkControlColor, 0.92);
243:                GradientComponentPainter normalComponentPainter = new GradientComponentPainter(
244:                        darkControlColor1, darkControlColor1,
245:                        darkControlColor2, darkControlColor2);
246:                normalState.getShapedPanelProperties().setOpaque(false)
247:                        .setComponentPainter(normalComponentPainter);
248:                disabledState.getShapedPanelProperties().setComponentPainter(
249:                        normalComponentPainter);
250:
251:                if (highlightColor == null)
252:                    highlightState.getShapedPanelProperties()
253:                            .setComponentPainter(blendedComponentPainter);
254:                else
255:                    highlightState.getShapedPanelProperties()
256:                            .setComponentPainter(
257:                                    new GradientComponentPainter(
258:                                            highlightColor, highlightColor,
259:                                            controlColor, controlColor));
260:
261:                Insets insets = normalBorder.getBorderInsets(null);
262:                int tabSpacing = 1 + insets.left + insets.right
263:                        - (topLeftRounded ? CORNER_INSET : 0)
264:                        - (topRightRounded ? CORNER_INSET : 0)
265:                        - (int) (0.2 * (leftSlopeWidth + rightSlopeWidth));
266:                tabbedPanelProperties.setTabSpacing(-tabSpacing)
267:                        .setShadowEnabled(false);
268:
269:                tabbedPanelProperties.getTabAreaComponentsProperties()
270:                        .getComponentProperties().setBorder(
271:                                new SlopedTabLineBorder(lineColor,
272:                                        highlightColor, false, 0f, 0f, 0, 0,
273:                                        false, topLeftRounded, topRightRounded,
274:                                        false)).setInsets(
275:                                new Insets(0, 0, 0, 0));
276:
277:                tabbedPanelProperties.getTabAreaComponentsProperties()
278:                        .getShapedPanelProperties().setComponentPainter(
279:                                blendedComponentPainter);
280:
281:                tabbedPanelProperties.getTabAreaProperties()
282:                        .getShapedPanelProperties().setOpaque(false);
283:
284:                tabbedPanelProperties
285:                        .getContentPanelProperties()
286:                        .getComponentProperties()
287:                        .setBorder(
288:                                new OpenContentBorder(
289:                                        lineColor,
290:                                        lineColor,
291:                                        highlightColor == null ? null
292:                                                : new ColorBlender(
293:                                                        highlightColor,
294:                                                        BackgroundPainterColorProvider.INSTANCE,
295:                                                        HighlightPainter
296:                                                                .getBlendFactor(
297:                                                                        1, 0)),
298:                                        1));
299:            }
300:
301:            /**
302:             * Gets the theme name
303:             *
304:             * @return name for this theme
305:             */
306:            public String getName() {
307:                return "Shaped Gradient Theme";
308:            }
309:
310:            /**
311:             * Gets the TabbedPanelProperties for this theme
312:             *
313:             * @return the TabbedPanelProperties
314:             */
315:            public TabbedPanelProperties getTabbedPanelProperties() {
316:                return tabbedPanelProperties;
317:            }
318:
319:            /**
320:             * Gets the TitledTabProperties for this theme
321:             *
322:             * @return the TitledTabProperties
323:             */
324:            public TitledTabProperties getTitledTabProperties() {
325:                return titledTabProperties;
326:            }
327:
328:            /**
329:             * Gets the line color provider
330:             *
331:             * @return the line color provider
332:             */
333:            public ColorProvider getLineColor() {
334:                return lineColor;
335:            }
336:
337:            /**
338:             * Gets the highlight color provider
339:             *
340:             * @return the highlight color provider, null if no highlight
341:             */
342:            public ColorProvider getHighlightColor() {
343:                return highlightColor;
344:            }
345:
346:            /**
347:             * Gets the alternate highlight color provider used for tab area
348:             * components gradient background and highlighted tab background
349:             * (when no highlight color is specified)
350:             *
351:             * @return the alternate highlight color provider
352:             */
353:            public ColorProvider getAlternateHighlightColor() {
354:                return alternateHighlight;
355:            }
356:
357:            /**
358:             * Gets the control background color
359:             *
360:             * @return the control background color provider
361:             */
362:            public ColorProvider getControlColor() {
363:                return controlColor;
364:            }
365:
366:            /**
367:             * Gets the dark control background color used for gradient for
368:             * normal tab and disabled tab
369:             *
370:             * @return the dark control background color provider
371:             */
372:            public ColorProvider getDarkControlColor() {
373:                return darkControlColor;
374:            }
375:
376:            /**
377:             * Creates a tab border
378:             *
379:             * @param lineColor                  line color provider
380:             * @param highlightColor             highlight color provider, null for no highlight
381:             * @param leftSlope                  left slope
382:             * @param rightSlope                 right slope
383:             * @param bottomLeftRounded          true if bottom left should be rounded
384:             * @param topLeftRounded             true if top left should be rounded
385:             * @param topRightRounded            true if top right should be rounded
386:             * @param bottomRightRounded         true if bottom right should be rounded
387:             * @param isNormal                   true if this is a normal rendered border
388:             * @param highlightBottomLeftRounded true if highlight has bottom left rounded
389:             * @param raised                     raised
390:             * @return the created border
391:             */
392:            public Border createTabBorder(ColorProvider lineColor,
393:                    ColorProvider highlightColor, float leftSlope,
394:                    float rightSlope, boolean bottomLeftRounded,
395:                    boolean topLeftRounded, boolean topRightRounded,
396:                    boolean bottomRightRounded, boolean isNormal,
397:                    boolean highlightBottomLeftRounded, int raised) {
398:                return new TabBorder(lineColor, highlightColor, leftSlope,
399:                        rightSlope, 25, 25, bottomLeftRounded, topLeftRounded,
400:                        topRightRounded, bottomRightRounded, isNormal,
401:                        highlightBottomLeftRounded, raised);
402:            }
403:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.