Source Code Cross Referenced for AbstractPolygonBorder.java in  » Swing-Library » InfoNode-Tabbed-Panel » net » infonode » gui » shaped » border » 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 Tabbed Panel » net.infonode.gui.shaped.border 
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: AbstractPolygonBorder.java,v 1.18 2005/12/04 13:46:04 jesper Exp $
023:        package net.infonode.gui.shaped.border;
024:
025:        import net.infonode.gui.GraphicsUtil;
026:        import net.infonode.gui.HighlightPainter;
027:        import net.infonode.gui.InsetsUtil;
028:        import net.infonode.gui.colorprovider.BackgroundPainterColorProvider;
029:        import net.infonode.gui.colorprovider.ColorProvider;
030:        import net.infonode.gui.colorprovider.FixedColorProvider;
031:        import net.infonode.gui.shaped.ShapedUtil;
032:        import net.infonode.gui.shaped.panel.ShapedPanel;
033:
034:        import java.awt.*;
035:
036:        /**
037:         * @author johan
038:         */
039:        abstract public class AbstractPolygonBorder extends
040:                AbstractShapedBorder {
041:            private static final long serialVersionUID = 1;
042:
043:            private static final Insets HIGHLIGHT_INSETS = new Insets(1, 1, 0,
044:                    0);
045:            private ColorProvider lineColor;
046:            private ColorProvider highlightColor = new FixedColorProvider(
047:                    new Color(255, 255, 255));
048:            private ColorProvider middleColor;
049:            private ColorProvider shadowColor;
050:
051:            protected AbstractPolygonBorder(ColorProvider lineColor) {
052:                this (lineColor, FixedColorProvider.WHITE);
053:            }
054:
055:            protected AbstractPolygonBorder(ColorProvider lineColor,
056:                    ColorProvider highlightColor) {
057:                this (lineColor, highlightColor,
058:                        BackgroundPainterColorProvider.INSTANCE, null);
059:            }
060:
061:            protected AbstractPolygonBorder(ColorProvider lineColor,
062:                    ColorProvider highlightColor, ColorProvider middleColor,
063:                    ColorProvider shadowColor) {
064:                this .lineColor = lineColor;
065:                this .highlightColor = highlightColor;
066:                this .middleColor = middleColor;
067:                this .shadowColor = shadowColor;
068:            }
069:
070:            public Shape getShape(Component c, int x, int y, int width,
071:                    int height) {
072:                int w = ShapedUtil.getWidth(c, width, height);
073:                int h = ShapedUtil.getHeight(c, width, height);
074:                Polygon polygon = getPolygon(c, x, y, w, h);
075:
076:                //printPoints(polygon);
077:
078:                //System.out.println("Polygon: width=" + w + " height=" + h);
079:
080:                return polygon;
081:            }
082:
083:            public boolean isBorderOpaque() {
084:                return false;
085:            }
086:
087:            public void paintBorder(Component c, Graphics g, int x, int y,
088:                    int width, int height) {
089:                Shape clip = g.getClip();
090:                g.clipRect(x, y, width, height);
091:
092:                try {
093:                    int w = ShapedUtil.getWidth(c, width, height);
094:                    height = ShapedUtil.getHeight(c, width, height);
095:                    width = w;
096:
097:                    Polygon polygon = getPolygon(c, x, y, width, height);
098:                    Graphics2D g2 = (Graphics2D) g;
099:
100:                    if (highlightColor != null) {
101:                        paintHighlight(c, g2, polygon, width, height);
102:                    }
103:
104:                    if (lineColor != null) {
105:                        g.setColor(lineColor.getColor());
106:                        paintPolygon(c, g2, polygon, width, height);
107:                    }
108:                } finally {
109:                    g.setClip(clip);
110:                }
111:            }
112:
113:            public Insets getBorderInsets(Component c) {
114:                Insets insets = getShapedBorderInsets(c);
115:                insets = ShapedUtil.transformInsets(c, insets);
116:                return highlightColor != null ? InsetsUtil.add(
117:                        getShapedBorderHighlightInsets(c), insets) : insets;
118:            }
119:
120:            protected Insets getShapedBorderInsets(Component c) {
121:                return new Insets(0, 0, 0, 0);
122:            }
123:
124:            protected Insets getShapedBorderHighlightInsets(Component c) {
125:                return HIGHLIGHT_INSETS;
126:            }
127:
128:            protected Polygon createPolygon(Component c, int width, int height) {
129:                return new Polygon();
130:            }
131:
132:            protected void paintPolygon(Component c, Graphics2D g,
133:                    Polygon polygon, int width, int height) {
134:                int i = 0;
135:
136:                while (i < polygon.npoints) {
137:                    if (lineIsDrawn(i, polygon)) {
138:                        int ni = (i + 1) % polygon.npoints;
139:                        GraphicsUtil.drawOptimizedLine(g, polygon.xpoints[i],
140:                                polygon.ypoints[i], polygon.xpoints[ni],
141:                                polygon.ypoints[ni]);
142:                    }
143:
144:                    i++;
145:                }
146:            }
147:
148:            protected void paintHighlight(Component c, Graphics2D g,
149:                    Polygon polygon, int width, int height) {
150:                Color c1 = highlightColor == null ? null : highlightColor
151:                        .getColor(c);
152:                Color c2 = middleColor.getColor(c);
153:                Color c3 = shadowColor == null ? null : shadowColor.getColor(c);
154:
155:                boolean clockWise = isPointsClockwise(c);
156:
157:                for (int i = 0; i < polygon.npoints; i++) {
158:                    int ni = (i + 1) % polygon.npoints;
159:
160:                    if (lineIsDrawn(i, polygon)) {
161:                        HighlightPainter.drawLine(g, polygon.xpoints[i],
162:                                polygon.ypoints[i], polygon.xpoints[ni],
163:                                polygon.ypoints[ni], clockWise, true, c1, c2,
164:                                c3);
165:                    }
166:                }
167:            }
168:
169:            protected boolean lineIsDrawn(int index, Polygon polygon) {
170:                return true;
171:            }
172:
173:            /*  protected int getWidth(Component c) {
174:             Insets i = getOuterInsets(c);
175:             Direction d = ShapedUtil.getDirection(c);
176:             if (d == Direction.UP || d == Direction.DOWN)
177:             return c.getHeight() - i.top - i.bottom;
178:
179:             return c.getWidth() - i.left - i.right;
180:             }
181:
182:             protected int getHeight(Component c) {
183:             Insets i = getOuterInsets(c);
184:             Direction d = ShapedUtil.getDirection(c);
185:             if (d == Direction.UP || d == Direction.DOWN)
186:             return c.getWidth() - i.left - i.right;
187:
188:             return c.getHeight() - i.top - i.bottom;
189:             }
190:             */
191:            protected boolean isHighlightable(int deltaX, int deltaY) {
192:                return deltaX > deltaY;
193:            }
194:
195:            protected boolean isPointsClockwise(Component c) {
196:                if (c instanceof  ShapedPanel)
197:                    return !(((ShapedPanel) c).isHorizontalFlip() ^ ((ShapedPanel) c)
198:                            .isVerticalFlip());
199:
200:                return true;
201:            }
202:
203:            protected int getHighlightOffsetX(int deltaX, int deltaY) {
204:                return deltaY - deltaX > 0 ? (deltaX + deltaY > 0 ? -1 : 0)
205:                        : (deltaX + deltaY > 0 ? 0 : 1); //-deltaY > deltaX ? 1 : 0;
206:            }
207:
208:            protected int getHighlightOffsetY(int deltaX, int deltaY) {
209:                return deltaY - deltaX > 0 ? (deltaX + deltaY > 0 ? 0 : -1)
210:                        : (deltaX + deltaY > 0 ? 1 : 0); //-deltaY > deltaX ? 1 : 0;
211:            }
212:
213:            protected void setPoint(Polygon polygon, int x, int y) {
214:                polygon.xpoints[polygon.npoints] = x;
215:                polygon.ypoints[polygon.npoints] = y;
216:                polygon.npoints++;
217:            }
218:
219:            private Polygon getPolygon(Component c, int x, int y, int width,
220:                    int height) {
221:                Polygon polygon = createPolygon(c, width, height);
222:                flipPolygon(c, polygon, width, height);
223:                rotatePolygon(c, polygon, width, height);
224:                fixGraphicsOffset(c, polygon, x, y);
225:                return polygon;
226:            }
227:
228:            private void flipPolygon(Component c, Polygon polygon, int width,
229:                    int height) {
230:                if (c instanceof  ShapedPanel) {
231:                    if (((ShapedPanel) c).isHorizontalFlip()) {
232:                        for (int i = 0; i < polygon.npoints; i++)
233:                            polygon.xpoints[i] = Math.abs(width
234:                                    - polygon.xpoints[i]) - 1;
235:                    }
236:
237:                    if (((ShapedPanel) c).isVerticalFlip()) {
238:                        for (int i = 0; i < polygon.npoints; i++)
239:                            polygon.ypoints[i] = Math.abs(height
240:                                    - polygon.ypoints[i]) - 1;
241:                    }
242:                }
243:            }
244:
245:            private void rotatePolygon(Component c, Polygon polygon, int width,
246:                    int height) {
247:                ShapedUtil.rotate(polygon, ShapedUtil.getDirection(c), width,
248:                        height);
249:            }
250:
251:            private void fixGraphicsOffset(Component c, Polygon polygon, int x,
252:                    int y) {
253:                for (int i = 0; i < polygon.npoints; i++) {
254:                    polygon.xpoints[i] += x;
255:                    polygon.ypoints[i] += y;
256:                }
257:            }
258:
259:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.