Source Code Cross Referenced for WinXPEditorTabCellRenderer.java in  » IDE-Netbeans » library » org » netbeans » swing » tabcontrol » plaf » 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 » IDE Netbeans » library » org.netbeans.swing.tabcontrol.plaf 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:        /*
042:         * WinXPEditorTabCellRenderer.java
043:         *
044:         * Created on 09 December 2003, 16:54
045:         */
046:
047:        package org.netbeans.swing.tabcontrol.plaf;
048:
049:        import javax.swing.*;
050:        import java.awt.*;
051:        import java.awt.geom.Area;
052:        import java.awt.geom.Point2D;
053:        import org.netbeans.swing.tabcontrol.TabDisplayer;
054:
055:        /**
056:         * Windows xp implementation of tab renderer
057:         *
058:         * @author Tim Boudreau
059:         */
060:        final class WinXPEditorTabCellRenderer extends AbstractTabCellRenderer {
061:            //Default insets values for XP look and feel
062:            private static final int TOP_INSET = 0;
063:            private static final int LEFT_INSET = 3;
064:            private static final int RIGHT_INSET = 0;
065:            static final int BOTTOM_INSET = 3;
066:
067:            //Painters which will be used for the various states, to pass to superclass
068:            //constructor
069:            private static final TabPainter leftClip = new WinXPLeftClipPainter();
070:            private static final TabPainter rightClip = new WinXPRightClipPainter();
071:            private static final TabPainter normal = new WinXPPainter();
072:
073:            /**
074:             * Creates a new instance of WinXPEditorTabCellRenderer
075:             */
076:            public WinXPEditorTabCellRenderer() {
077:                super (leftClip, normal, rightClip, new Dimension(32, 42));
078:            }
079:
080:            /**
081:             * XP look and feel makes selected tab wider by 2 pixels on each side
082:             */
083:            @Override
084:            public int getPixelsToAddToSelection() {
085:                return 4;
086:            }
087:
088:            @Override
089:            public Dimension getPadding() {
090:                Dimension d = super .getPadding();
091:                d.width = isShowCloseButton()
092:                        && !Boolean.getBoolean("nb.tabs.suppressCloseButton") ? 32
093:                        : 16;
094:                return d;
095:            }
096:
097:            private static final Color getTopInactiveSelectedColor() {
098:                Color result = UIManager.getColor("tab_sel_fill_bright"); //NOI18N
099:                if (result == null) {
100:                    result = new Color(252, 250, 244);
101:                }
102:                return result;
103:            }
104:
105:            private static final Color getBottomInactiveSelectedColor() {
106:                Color result = UIManager.getColor("tab_sel_fill_dark"); //NOI18N
107:                if (result == null) {
108:                    result = new Color(243, 241, 224);
109:                }
110:                return result;
111:            }
112:
113:            private static final Color getTopActiveSelectedColor() {
114:                Color result = UIManager.getColor("tab_focus_fill_bright"); //NOI18N
115:                if (result == null) {
116:                    result = new Color(210, 220, 243);
117:                }
118:                return result;
119:            }
120:
121:            private static final Color getBottomActiveSelectedColor() {
122:                Color result = UIManager.getColor("tab_focus_fill_dark"); //NOI18N
123:                if (result == null) {
124:                    result = new Color(238, 242, 253);
125:                }
126:                return result;
127:            }
128:
129:            private static final Color getTopUnselectedColor() {
130:                Color result = UIManager.getColor("tab_unsel_fill_bright"); //NOI18N
131:                if (result == null) {
132:                    result = Color.white;
133:                }
134:                return result;
135:            }
136:
137:            private static final Color getBottomUnselectedColor() {
138:                Color result = UIManager.getColor("tab_unsel_fill_dark"); //NOI18N
139:                if (result == null) {
140:                    result = new Color(236, 235, 229);
141:                }
142:                return result;
143:            }
144:
145:            static final Color getBorderColor() {
146:                Color result = UIManager.getColor("tab_bottom_border"); //NOI18N
147:                if (result == null) {
148:                    result = new Color(127, 187, 185);
149:                }
150:                return result;
151:            }
152:
153:            private static final Color getCloseButtonColor(
154:                    WinXPEditorTabCellRenderer ren) {
155:                String key = ren.inCloseButton() ? "close_button_highlight"
156:                        : "close_button"; //NOI18N
157:                Color result = UIManager.getColor(key);
158:                if (result == null) {
159:                    result = ren.inCloseButton() ? new Color(172, 57, 28)
160:                            : Color.black;
161:                }
162:                return result;
163:            }
164:
165:            static final Color getSelectedTabBottomLineColor() {
166:                Color result = UIManager.getColor("tab_sel_bottom_border"); //NOI18N
167:                if (result == null) {
168:                    result = new Color(238, 235, 218);
169:                }
170:                return result;
171:            }
172:
173:            private static final Color getShadowBorderColor(
174:                    WinXPEditorTabCellRenderer ren) {
175:                //Preserving in case open issue about borders is decided that
176:                //there should be some difference between shadow/hl borders
177:                return getBorderColor();
178:            }
179:
180:            private static final Color getHighlightBorderColor(
181:                    WinXPEditorTabCellRenderer ren) {
182:                //Preserving in case open issue about borders is decided that
183:                //there should be some difference between shadow/hl borders
184:                return getBorderColor();
185:            }
186:
187:            private static final Color getHighlightColor() {
188:                Color result = UIManager
189:                        .getColor("TabbedPane.selectionIndicator"); //NOI18N
190:                if (result == null) {
191:                    result = new Color(255, 199, 60); //XXX derive from a system color
192:                }
193:                return result;
194:            }
195:
196:            private static final Color getTopHighlightColor() {
197:                Color result = UIManager.getColor("tab_highlight_header"); //NOI18N
198:                if (result == null) {
199:                    result = new Color(230, 139, 44);
200:                }
201:                return result;
202:            }
203:
204:            @Override
205:            public Color getSelectedActivatedForeground() {
206:                Color result = UIManager.getColor("textText"); //NOI18N
207:                if (result == null) {
208:                    result = Color.BLACK;
209:                }
210:                return result;
211:            }
212:
213:            private static final Color getRightEdgeSelectedShadow() {
214:                Color result = UIManager.getColor("close_button_border_focus"); //NOI18N
215:                if (result == null) {
216:                    result = new Color(181, 201, 243);
217:                }
218:                return result;
219:            }
220:
221:            @Override
222:            public Color getSelectedActivatedBackground() {
223:                Color top = UIManager.getColor("tab_focus_fill_bright"); //NOI18N
224:                Color bot = UIManager.getColor("tab_focus_fill_dark"); //NOI18N
225:                if (top == null) {
226:                    top = new Color(238, 242, 253);
227:                }
228:                if (bot == null) {
229:                    bot = new Color(210, 220, 243);
230:                }
231:                Color result = ColorUtil.getMiddle(top, bot);
232:                return result;
233:            }
234:
235:            public static Color getCloseButtonAAColor(
236:                    WinXPEditorTabCellRenderer ren) {
237:                Color towards = ren.getBackground();
238:                Color base = getCloseButtonColor(ren);
239:
240:                Color result = org.netbeans.swing.tabcontrol.plaf.ColorUtil
241:                        .getMiddle(base, towards);
242:                int factor = ren.inCloseButton() ? 35 : 74;
243:                factor *= ColorUtil.isBrighter(towards, base) ? 1 : -1;
244:                result = ColorUtil.adjustBy(result, factor);
245:                return result;
246:            }
247:
248:            private static Color getCloseButtonBorderColor(
249:                    WinXPEditorTabCellRenderer ren) {
250:                String key = ren.isActive() && ren.isSelected() ? "close_button_border_focus"
251:                        : ren.isSelected() ? "close_button_border_selected"
252:                                : "close_button_border_unsel"; //NOI18N
253:                Color result = UIManager.getColor(key);
254:                if (result == null) {
255:                    result = ren.isActive() && ren.isSelected() ? new Color(
256:                            181, 201, 243) : ren.isSelected() ? new Color(203,
257:                            202, 187) : new Color(200, 201, 192);
258:                }
259:                return result;
260:            }
261:
262:            public static Color getCloseButtonHighlight(
263:                    WinXPEditorTabCellRenderer ren) {
264:                Color result = ren.isPressed() && ren.inCloseButton() ? getCloseButtonBorderColor(ren)
265:                        : ren.isActive() && ren.isSelected() ? UIManager
266:                                .getColor("tab_sel_fill_dark") : UIManager
267:                                .getColor("tab_sel_fill_bright");
268:                if (result == null) {
269:                    result = Color.white;
270:                }
271:                return result;
272:            }
273:
274:            public static Color getCloseButtonShadow(
275:                    WinXPEditorTabCellRenderer ren) {
276:                return ren.isPressed() && ren.inCloseButton() ? Color.WHITE
277:                        : getCloseButtonBorderColor(ren);
278:            }
279:
280:            private static final Paint getPaint(WinXPEditorTabCellRenderer ren,
281:                    TabPainter p) {
282:                Insets ins = p.getBorderInsets(ren);
283:                int xTop = ins.left;
284:                int yTop = ins.top;
285:                int xBot = ins.left;
286:                int yBot = ren.getHeight() - (ins.top + ins.bottom + 1);
287:                if (ren.isSelected() || ren.isArmed()) {
288:                    yTop += 3;
289:                }
290:                return getPaint(xTop, yTop, xBot, yBot, ren);
291:            }
292:
293:            private static final Paint getPaint(int xTop, int yTop, int xBot,
294:                    int yBot, WinXPEditorTabCellRenderer ren) {
295:
296:                if (!ren.isSelected() && !ren.isPressed() && ren.isAttention()) {
297:                    Color a = new Color(255, 255, 128);
298:                    Color b = new Color(230, 200, 64);
299:                    return ColorUtil.getGradientPaint(xTop, yTop, a, xBot,
300:                            yBot, b);
301:                } else if (ren.isSelected()
302:                        || (ren.isPressed() && !ren.inCloseButton())) {
303:                    if (ren.isActive()) {
304:                        return ColorUtil.getGradientPaint(xTop, yTop,
305:                                getTopActiveSelectedColor(), xBot, yBot,
306:                                getBottomActiveSelectedColor());
307:                    } else {
308:                        Color a = getTopInactiveSelectedColor();
309:                        Color b = getBottomInactiveSelectedColor();
310:                        if (a == b) {
311:                            return a;
312:                        } else {
313:                            return ColorUtil.getGradientPaint(xTop, yTop, a,
314:                                    xBot, yBot, b);
315:                        }
316:                    }
317:                } else {
318:                    return ColorUtil.getGradientPaint(xTop, yTop,
319:                            getTopUnselectedColor(), xBot, yBot,
320:                            getBottomUnselectedColor());
321:                }
322:            }
323:
324:            private static final void paintGradient(Graphics g,
325:                    WinXPEditorTabCellRenderer ren, TabPainter p) {
326:                Graphics2D g2d = (Graphics2D) g;
327:                //draw gradient
328:                Insets ins = p.getBorderInsets(ren);
329:                Paint gp = getPaint(ren, p);
330:                g2d.setPaint(gp);
331:                Polygon poly = p.getInteriorPolygon(ren);
332:                g.fillPolygon(poly);
333:                if (ren.isArmed() || ren.isSelected()) {
334:                    paintTopLine(g, ren, p);
335:                }
336:            }
337:
338:            private static final void paintTopLine(Graphics g,
339:                    WinXPEditorTabCellRenderer ren, TabPainter p) {
340:                Polygon poly = p.getInteriorPolygon(ren);
341:                ((Graphics2D) g).setPaint(getHighlightColor());
342:                g.setColor(getHighlightColor());
343:                Shape clip = g.getClip();
344:                Insets ins = p.getBorderInsets(ren);
345:                try {
346:                    if (clip != null) {
347:                        Area a = new Area(clip);
348:                        a.intersect(new Area(poly));
349:                        g.setClip(a);
350:                    } else {
351:                        g.setClip(poly);
352:                    }
353:                    g.fillRect(0, ins.top, ren.getWidth(), 3);
354:                } finally {
355:                    g.setClip(clip);
356:                }
357:            }
358:
359:            @Override
360:            protected int getCaptionYAdjustment() {
361:                return 1;
362:            }
363:
364:            private static class WinXPPainter implements  TabPainter {
365:
366:                public Insets getBorderInsets(Component c) {
367:                    return new Insets(TOP_INSET, LEFT_INSET, BOTTOM_INSET,
368:                            RIGHT_INSET);
369:                }
370:
371:                public void getCloseButtonRectangle(JComponent jc,
372:                        final Rectangle rect, Rectangle bounds) {
373:
374:                    WinXPEditorTabCellRenderer ren = (WinXPEditorTabCellRenderer) jc;
375:                    if (!ren.isShowCloseButton()) {
376:                        rect.x = -100;
377:                        rect.y = -100;
378:                        rect.width = 0;
379:                        rect.height = 0;
380:                        return;
381:                    }
382:                    String iconPath = findIconPath(ren);
383:                    Icon icon = TabControlButtonFactory.getIcon(iconPath);
384:                    int iconWidth = icon.getIconWidth();
385:                    int iconHeight = icon.getIconHeight();
386:                    rect.x = bounds.x + bounds.width - iconWidth - 2;
387:                    rect.y = bounds.y
388:                            + (Math.max(0, bounds.height / 2 - iconHeight / 2));
389:                    rect.width = iconWidth;
390:                    rect.height = iconHeight;
391:                }
392:
393:                public Polygon getInteriorPolygon(Component c) {
394:                    WinXPEditorTabCellRenderer ren = (WinXPEditorTabCellRenderer) c;
395:
396:                    Insets ins = getBorderInsets(c);
397:                    Polygon p = new Polygon();
398:                    //            int x = ren.isLeftmost() ? 1 : 0;
399:                    int x = 0;
400:                    int y = 0;
401:
402:                    int h = c.getHeight() - ins.bottom;
403:
404:                    int width = ren.isRightmost() ? c.getWidth() - 1 : c
405:                            .getWidth();
406:                    int height = ren.isSelected() ? h + 1 : h;
407:
408:                    p.addPoint(x, y + ins.top + 2);
409:                    p.addPoint(x + 2, y + ins.top);
410:                    p.addPoint(x + width - 2, y + ins.top);
411:                    p.addPoint(x + width, y + ins.top + 2);
412:                    p.addPoint(x + width, y + height - 1);
413:                    p.addPoint(x, y + height - 1);
414:                    return p;
415:                }
416:
417:                public boolean isBorderOpaque() {
418:                    return true;
419:                }
420:
421:                public void paintBorder(Component c, Graphics g, int x, int y,
422:                        int width, int height) {
423:                    WinXPEditorTabCellRenderer ren = (WinXPEditorTabCellRenderer) c;
424:                    Polygon p = getInteriorPolygon(c);
425:                    g.setColor(getHighlightBorderColor(ren));
426:
427:                    int[] xpoints = p.xpoints;
428:                    int[] ypoints = p.ypoints;
429:
430:                    g.drawLine(xpoints[0], ypoints[0], xpoints[p.npoints - 1],
431:                            ypoints[p.npoints - 1]);
432:
433:                    Color prev = null;
434:                    boolean topColor = ren.isArmed() || ren.isSelected();
435:                    for (int i = 0; i < p.npoints - 1; i++) {
436:                        if (i == 0 && topColor) {
437:                            prev = g.getColor();
438:                            g.setColor(getTopHighlightColor());
439:                        } else if (i == 3 && topColor) {
440:                            g.setColor(prev);
441:                        }
442:                        g.drawLine(xpoints[i], ypoints[i] + (i == 3 ? 1 : 0),
443:                                xpoints[i + 1], ypoints[i + 1]);
444:                    }
445:
446:                    //Find a color to antialias the top with the tab area background
447:                    g.setColor(ColorUtil.adjustComponentsTowards(
448:                            topColor ? getTopHighlightColor()
449:                                    : getHighlightBorderColor(ren), UIManager
450:                                    .getColor("control"))); //NOI18N
451:
452:                    //Antialias the corners of the polygon
453:                    g.drawLine(xpoints[0], ypoints[0] - 1, xpoints[1] - 1,
454:                            ypoints[1]);
455:                    g.drawLine(xpoints[2] + 1, ypoints[2], xpoints[3],
456:                            ypoints[3] - 1);
457:
458:                    if (ren.isSelected()) {
459:                        g.setColor(getRightEdgeSelectedShadow());
460:                        Insets ins = getBorderInsets(c);
461:                        g.drawLine(
462:                                ren.getWidth() - (ren.isRightmost() ? 2 : 1),
463:                                ins.top + 3, width
464:                                        - (ren.isRightmost() ? 2 : 1), height
465:                                        - ins.bottom);
466:
467:                        GradientPaint paint = (GradientPaint) getPaint(
468:                                ins.top + 3, 0, height
469:                                        - (ins.top + ins.bottom + 2), 1, ren);
470:                        ((Graphics2D) g).setPaint(paint);
471:                        //Flip the gradient
472:                        Point2D p1 = paint.getPoint1();
473:                        Point2D p2 = paint.getPoint2();
474:                        paint = ColorUtil.getGradientPaint(Math
475:                                .round(p2.getX()), Math.round(p2.getY()), paint
476:                                .getColor1(), Math.round(p1.getX()), Math
477:                                .round(p1.getY()), paint.getColor2(), false);
478:                        //Paint the left edge inverse gradient line
479:                        int rpos = x + 1;
480:                        g.fillRect(rpos, y + ins.top + 3, rpos
481:                                + (ren.isLeftmost() ? 1 : 0),
482:                                (height - (ins.top + ins.bottom + 3)));
483:
484:                        g.setColor(getSelectedTabBottomLineColor());
485:                        g.drawLine(1, height - ins.bottom, width - 2, height
486:                                - ins.bottom);
487:                    }
488:                }
489:
490:                public void paintInterior(Graphics g, Component c) {
491:                    WinXPEditorTabCellRenderer ren = (WinXPEditorTabCellRenderer) c;
492:                    //Use the utility method to paint the interior gradient
493:                    paintGradient(g, ren, this );
494:
495:                    Rectangle r = new Rectangle();
496:                    //Get the close button bounds, more or less
497:                    getCloseButtonRectangle(ren, r, new Rectangle(0, 0, ren
498:                            .getWidth(), ren.getHeight()));
499:
500:                    if (!g.hitClip(r.x, r.y, r.width, r.height)) {
501:                        return;
502:                    }
503:
504:                    //Draw the close button itself
505:                    String iconPath = findIconPath(ren);
506:                    Icon icon = TabControlButtonFactory.getIcon(iconPath);
507:                    icon.paintIcon(ren, g, r.x, r.y);
508:                }
509:
510:                /**
511:                 * Returns path of icon which is correct for currect state of tab at given
512:                 * index
513:                 */
514:                private String findIconPath(WinXPEditorTabCellRenderer renderer) {
515:                    if (renderer.inCloseButton() && renderer.isPressed()) {
516:                        return "org/netbeans/swing/tabcontrol/resources/xp_close_pressed.png"; // NOI18N
517:                    }
518:                    if (renderer.inCloseButton()) {
519:                        return "org/netbeans/swing/tabcontrol/resources/xp_close_rollover.png"; // NOI18N
520:                    }
521:                    return "org/netbeans/swing/tabcontrol/resources/xp_close_enabled.png"; // NOI18N       
522:                }
523:
524:                public boolean supportsCloseButton(JComponent renderer) {
525:                    return renderer instanceof  TabDisplayer ? ((TabDisplayer) renderer)
526:                            .isShowCloseButton()
527:                            : true;
528:                }
529:
530:            }
531:
532:            private static class WinXPLeftClipPainter implements  TabPainter {
533:
534:                public Insets getBorderInsets(Component c) {
535:                    return new Insets(TOP_INSET, LEFT_INSET, BOTTOM_INSET,
536:                            RIGHT_INSET);
537:                }
538:
539:                public Polygon getInteriorPolygon(Component c) {
540:                    WinXPEditorTabCellRenderer ren = (WinXPEditorTabCellRenderer) c;
541:
542:                    Insets ins = getBorderInsets(c);
543:                    Polygon p = new Polygon();
544:                    int x = -3;
545:                    int y = 0;
546:
547:                    int h = c.getHeight() - ins.bottom;
548:
549:                    int width = c.getWidth() + 3;
550:                    int height = ren.isSelected() ? h + 1 : h;
551:
552:                    p.addPoint(x, y + ins.top + 2);
553:                    p.addPoint(x + 2, y + ins.top);
554:                    p.addPoint(x + width - 2, y + ins.top);
555:                    p.addPoint(x + width, y + ins.top + 2);
556:                    p.addPoint(x + width, y + height - 1);
557:                    p.addPoint(x, y + height - 1);
558:                    return p;
559:                }
560:
561:                public void paintBorder(Component c, Graphics g, int x, int y,
562:                        int width, int height) {
563:                    WinXPEditorTabCellRenderer ren = (WinXPEditorTabCellRenderer) c;
564:                    Polygon p = getInteriorPolygon(c);
565:                    g.setColor(getHighlightBorderColor(ren));
566:
567:                    int[] xpoints = p.xpoints;
568:                    int[] ypoints = p.ypoints;
569:
570:                    g.drawLine(xpoints[0], ypoints[0], xpoints[p.npoints - 1],
571:                            ypoints[p.npoints - 1]);
572:                    Color prev = null;
573:                    boolean topColor = ren.isArmed() || ren.isSelected();
574:                    for (int i = 0; i < p.npoints - 1; i++) {
575:                        if (i == 1 && topColor) {
576:                            prev = g.getColor();
577:                            g.setColor(getTopHighlightColor());
578:                        } else if (i == 2 && topColor) {
579:                            g.setColor(prev);
580:                        }
581:                        g.drawLine(xpoints[i], ypoints[i], xpoints[i + 1],
582:                                ypoints[i + 1]);
583:                        if (i == p.npoints - 4) {
584:                            g.setColor(getShadowBorderColor(ren));
585:                            g.drawLine(xpoints[i] + 1, ypoints[i] + 1,
586:                                    xpoints[i] + 2, ypoints[i] + 2);
587:                        }
588:                    }
589:                    //Find a color to antialias the top with the tab area background
590:                    g.setColor(ColorUtil.adjustComponentsTowards(
591:                            topColor ? getTopHighlightColor()
592:                                    : getHighlightBorderColor(ren), UIManager
593:                                    .getColor("control"))); //NOI18N
594:
595:                    //Antialias the corners of the polygon
596:                    g.drawLine(xpoints[0] - 1, ypoints[0], xpoints[1] - 1,
597:                            ypoints[1]);
598:                    g.drawLine(xpoints[2] + 1, ypoints[2], xpoints[3] + 1,
599:                            ypoints[3]);
600:
601:                    if (ren.isSelected()) {
602:                        g.setColor(getRightEdgeSelectedShadow());
603:                        Insets ins = getBorderInsets(c);
604:                        g.drawLine(ren.getWidth() - 1, ins.top + 3, width - 1,
605:                                height - ins.bottom);
606:                        g.setColor(getSelectedTabBottomLineColor());
607:                        g.drawLine(0, height - ins.bottom, width - 2, height
608:                                - ins.bottom);
609:
610:                    }
611:                }
612:
613:                public void paintInterior(Graphics g, Component c) {
614:                    WinXPEditorTabCellRenderer ren = (WinXPEditorTabCellRenderer) c;
615:                    paintGradient(g, ren, this );
616:                }
617:
618:                public boolean isBorderOpaque() {
619:                    return true;
620:                }
621:
622:                public boolean supportsCloseButton(JComponent renderer) {
623:                    return false;
624:                }
625:
626:                public void getCloseButtonRectangle(JComponent jc,
627:                        final Rectangle rect, Rectangle bounds) {
628:                    rect.setBounds(-20, -20, 0, 0);
629:                }
630:
631:            }
632:
633:            private static class WinXPRightClipPainter implements  TabPainter {
634:
635:                public Insets getBorderInsets(Component c) {
636:                    return new Insets(TOP_INSET, LEFT_INSET, BOTTOM_INSET,
637:                            RIGHT_INSET);
638:                }
639:
640:                public boolean isBorderOpaque() {
641:                    return true;
642:                }
643:
644:                public Polygon getInteriorPolygon(Component c) {
645:                    WinXPEditorTabCellRenderer ren = (WinXPEditorTabCellRenderer) c;
646:
647:                    Insets ins = getBorderInsets(c);
648:                    Polygon p = new Polygon();
649:                    int x = 0;
650:                    int y = 0;
651:
652:                    int h = c.getHeight() - ins.bottom;
653:
654:                    int width = c.getWidth() + 3;
655:                    int height = ren.isSelected() ? h + 1 : h;//ren.isSelected() ? h + 2 : h - 1;
656:
657:                    p.addPoint(x, y + ins.top + 2);
658:                    p.addPoint(x + 2, y + ins.top);
659:                    p.addPoint(x + width, y + ins.top);
660:                    p.addPoint(x + width, y + height - 1);
661:                    p.addPoint(x, y + height - 1);
662:                    return p;
663:                }
664:
665:                public void paintBorder(Component c, Graphics g, int x, int y,
666:                        int width, int height) {
667:                    WinXPEditorTabCellRenderer ren = (WinXPEditorTabCellRenderer) c;
668:                    Polygon p = getInteriorPolygon(c);
669:                    g.setColor(getHighlightBorderColor(ren));
670:
671:                    int[] xpoints = p.xpoints;
672:                    int[] ypoints = p.ypoints;
673:
674:                    g.drawLine(xpoints[0], ypoints[0], xpoints[p.npoints - 1],
675:                            ypoints[p.npoints - 1]);
676:
677:                    Color prev = null;
678:                    boolean topColor = ren.isArmed() || ren.isSelected();
679:                    for (int i = 0; i < p.npoints - 1; i++) {
680:                        if (i == 1 && topColor) {
681:                            prev = g.getColor();
682:                            g.setColor(getTopHighlightColor());
683:                        } else if (i == 2 && topColor) {
684:                            g.setColor(prev);
685:                        }
686:                        g.drawLine(xpoints[i], ypoints[i], xpoints[i + 1],
687:                                ypoints[i + 1]);
688:                    }
689:
690:                    //Find a color to antialias the top with the tab area background
691:                    g.setColor(ColorUtil.adjustComponentsTowards(
692:                            topColor ? getTopHighlightColor()
693:                                    : getHighlightBorderColor(ren), UIManager
694:                                    .getColor("control"))); //NOI18N
695:
696:                    //Antialias the corners of the polygon
697:                    g.drawLine(xpoints[0] - 1, ypoints[0], xpoints[1] - 1,
698:                            ypoints[1]);
699:                    //            g.drawLine(xpoints[2]+1, ypoints[2], xpoints[3]+1, ypoints[3]);
700:
701:                    if (ren.isSelected()) {
702:                        Insets ins = getBorderInsets(c);
703:
704:                        GradientPaint paint = (GradientPaint) getPaint(
705:                                ins.top + 3, 0, height
706:                                        - (ins.top + ins.bottom + 2), 1, ren);
707:                        ((Graphics2D) g).setPaint(paint);
708:                        //Flip the gradient
709:                        Point2D p1 = paint.getPoint1();
710:                        Point2D p2 = paint.getPoint2();
711:                        paint = ColorUtil.getGradientPaint(Math
712:                                .round(p2.getX()), Math.round(p2.getY()), paint
713:                                .getColor1(), Math.round(p1.getX()), Math
714:                                .round(p1.getY()), paint.getColor2(), false);
715:                        //Paint the left edge inverse gradient line
716:                        g.fillRect(x + 1, y + ins.top + 3, x + 1,
717:                                (height - (ins.top + ins.bottom + 3)));
718:
719:                        g.setColor(getSelectedTabBottomLineColor());
720:                        g.drawLine(1, height - ins.bottom, width - 1, height
721:                                - ins.bottom);
722:                    }
723:                }
724:
725:                public void paintInterior(Graphics g, Component c) {
726:                    WinXPEditorTabCellRenderer ren = (WinXPEditorTabCellRenderer) c;
727:                    paintGradient(g, ren, this );
728:                }
729:
730:                public boolean supportsCloseButton(JComponent renderer) {
731:                    return false;
732:                }
733:
734:                public void getCloseButtonRectangle(JComponent jc,
735:                        final Rectangle rect, Rectangle bounds) {
736:                    rect.setBounds(-20, -20, 0, 0);
737:                }
738:            }
739:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.