Source Code Cross Referenced for CellPainter.java in  » Swing-Library » abeille-forms-designer » com » jeta » forms » gui » form » 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 » abeille forms designer » com.jeta.forms.gui.form 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2004 JETA Software, Inc.  All rights reserved.
003:         * 
004:         * Redistribution and use in source and binary forms, with or without modification, 
005:         * are permitted provided that the following conditions are met:
006:         *
007:         *  o Redistributions of source code must retain the above copyright notice, 
008:         *    this list of conditions and the following disclaimer.
009:         *
010:         *  o Redistributions in binary form must reproduce the above copyright notice, 
011:         *    this list of conditions and the following disclaimer in the documentation 
012:         *    and/or other materials provided with the distribution.
013:         *
014:         *  o Neither the name of JETA Software nor the names of its contributors may 
015:         *    be used to endorse or promote products derived from this software without 
016:         *    specific prior written permission.
017:         *
018:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
019:         * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
020:         * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
021:         * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
022:         * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
023:         * INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
024:         * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
025:         * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
026:         * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
027:         * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028:         */
029:
030:        package com.jeta.forms.gui.form;
031:
032:        import java.awt.Color;
033:        import java.awt.Graphics;
034:        import java.awt.Graphics2D;
035:        import java.awt.Paint;
036:        import java.awt.Rectangle;
037:
038:        import javax.swing.JPanel;
039:
040:        import com.jeta.forms.gui.effects.Painter;
041:        import com.jeta.forms.store.properties.effects.PaintProperty;
042:
043:        /**
044:         * This class is a Swing component that paints fill effects for cells in the
045:         * GridView. It iterates over all invalid cells (i.e. needing repaint) and
046:         * paints those cells if they have an assigned painter object. Examples of fill
047:         * effects are: solid, texture, linear gradient, and radial gradient. See:
048:         * {@link com.jeta.forms.gui.effects.Painter}
049:         * 
050:         * @author Jeff Tassin
051:         */
052:        public class CellPainter extends JPanel {
053:            /**
054:             * The view associated with this grid painter.
055:             */
056:            private GridView m_view;
057:
058:            /**
059:             * The parent form for the GridView
060:             */
061:            private FormComponent m_form;
062:
063:            /**
064:             * We keep a rectangle around so we don't have to instantiate with every
065:             * paint.
066:             */
067:            private Rectangle m_gc_rect = new Rectangle();
068:
069:            /**
070:             * Creates a <code>CellPainter</code> associated with the given view.
071:             * 
072:             * @param view
073:             *            the GridView associated with this cell painter.
074:             */
075:            public CellPainter(GridView view) {
076:                m_view = view;
077:                setOpaque(false);
078:            }
079:
080:            /**
081:             * Override paintComponent so can render the fill effects for each cell that
082:             * needs it.
083:             */
084:            public void paintComponent(Graphics g) {
085:                Graphics2D g2 = (Graphics2D) g;
086:                Color old_c = g2.getColor();
087:                Paint old_paint = g2.getPaint();
088:
089:                /**
090:                 * we need to increase the height of the clip rectangle by 2 pixels
091:                 * because the bottom line of the grid overlay is not painted for
092:                 * composite child views in some cases
093:                 */
094:                Rectangle clip_rect = g.getClipBounds();
095:                clip_rect.setBounds(clip_rect.x, clip_rect.y,
096:                        clip_rect.width + 2, clip_rect.height + 2);
097:                g.setClip(clip_rect.x, clip_rect.y, clip_rect.width,
098:                        clip_rect.height);
099:                int clip_x1 = (int) clip_rect.x;
100:                int clip_x2 = (int) clip_rect.x + clip_rect.width;
101:                int clip_y1 = (int) clip_rect.y;
102:                int clip_y2 = (int) clip_rect.y + clip_rect.height;
103:
104:                int min_row = -1;
105:                int max_row = -1;
106:
107:                int min_col = -1;
108:                int max_col = -1;
109:
110:                for (int row = 1; row <= m_view.getRowCount(); row++) {
111:                    int row_y1 = m_view.getRowOrgY(row);
112:                    int row_y2 = row_y1 + m_view.getRowHeight(row);
113:                    if (clip_y1 >= row_y1 && clip_y1 <= row_y2) {
114:                        if (min_row < 0)
115:                            min_row = row;
116:                        else
117:                            max_row = row;
118:                    } else if (clip_y2 >= row_y1 && clip_y2 <= row_y2) {
119:                        if (min_row < 0)
120:                            min_row = row;
121:                        else
122:                            max_row = row;
123:
124:                    } else if (row_y1 >= clip_y1 && row_y2 <= clip_y2) {
125:                        // here, the row is contained entirely in the clip
126:                        if (min_row < 0)
127:                            min_row = row;
128:                        else
129:                            max_row = row;
130:                    }
131:                }
132:
133:                for (int col = 1; col <= m_view.getColumnCount(); col++) {
134:                    int col_x1 = m_view.getColumnOrgX(col);
135:                    int col_x2 = col_x1 + m_view.getColumnWidth(col);
136:                    if (clip_x1 >= col_x1 && clip_x1 <= col_x2) {
137:                        if (min_col < 0)
138:                            min_col = col;
139:                        else
140:                            max_col = col;
141:                    } else if (clip_x2 >= col_x1 && clip_x2 <= col_x2) {
142:                        if (min_col < 0)
143:                            min_col = col;
144:                        else
145:                            max_col = col;
146:
147:                    } else if (col_x1 >= clip_x1 && col_x2 <= clip_x2) {
148:                        // here, the col is contained entirely in the clip
149:                        if (min_col < 0)
150:                            min_col = col;
151:                        else
152:                            max_col = col;
153:                    }
154:                }
155:
156:                if (min_row < 0 || min_col < 0)
157:                    return;
158:
159:                if (max_row < 0)
160:                    max_row = min_row;
161:                if (max_col < 0)
162:                    max_col = min_col;
163:
164:                for (int row = min_row; row <= max_row; row++) {
165:                    for (int col = min_col; col <= max_col; col++) {
166:                        PaintProperty pp = m_view.getPaintProperty(col, row);
167:                        if (pp != null) {
168:                            Painter painter = pp.createPainter();
169:                            if (painter != null) {
170:                                GridComponent gc = m_view.getGridComponent(col,
171:                                        row);
172:                                if (gc == null) {
173:                                    m_gc_rect.setBounds(m_view
174:                                            .getColumnOrgX(col), m_view
175:                                            .getRowOrgY(row), m_view
176:                                            .getColumnWidth(col), m_view
177:                                            .getRowHeight(row));
178:                                } else {
179:                                    m_gc_rect.setBounds(gc.getCellX(), gc
180:                                            .getCellY(), gc.getCellWidth(), gc
181:                                            .getCellHeight());
182:                                }
183:
184:                                if (m_gc_rect.intersects(clip_rect)) {
185:                                    painter.paint(this, g, m_gc_rect);
186:                                }
187:                            }
188:                        }
189:                    }
190:                }
191:                g2.setColor(old_c);
192:                g2.setPaint(old_paint);
193:            }
194:
195:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.