Source Code Cross Referenced for EnhancedTableCellRenderer.java in  » IDE-Netbeans » cvsclient » org » netbeans » lib » profiler » ui » components » table » 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 » cvsclient » org.netbeans.lib.profiler.ui.components.table 
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:         * The Original Software is NetBeans. The Initial Developer of the Original
026:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
027:         * Microsystems, Inc. All Rights Reserved.
028:         *
029:         * If you wish your version of this file to be governed by only the CDDL
030:         * or only the GPL Version 2, indicate your decision by adding
031:         * "[Contributor] elects to include this software in this distribution
032:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
033:         * single choice of license, a recipient has the option to distribute
034:         * your version of this file under either the CDDL, the GPL Version 2 or
035:         * to extend the choice of license to its licensees as provided above.
036:         * However, if you add GPL Version 2 code and therefore, elected the GPL
037:         * Version 2 license, then the option applies only if the new code is
038:         * made subject to such option by the copyright holder.
039:         */
040:
041:        package org.netbeans.lib.profiler.ui.components.table;
042:
043:        import org.netbeans.lib.profiler.ui.UIUtils;
044:        import java.awt.*;
045:        import javax.swing.*;
046:        import javax.swing.border.Border;
047:        import javax.swing.table.TableCellRenderer;
048:
049:        /** An abstract superclass for table cell renderers to be used throughout the profiler.
050:         * It implements alrenating background colors for odd and even rows, and simplifies the writing of
051:         * concrete renderers by masking Swing's ugly CellRenderer API (by forcing "this" to be returned as the renderer).
052:         *
053:         * @author Ian Formanek
054:         * @author Jiri Sedlacek
055:         */
056:        public abstract class EnhancedTableCellRenderer extends JPanel
057:                implements  TableCellRendererPersistent {
058:            //~ Instance fields ----------------------------------------------------------------------------------------------------------
059:
060:            protected boolean supportsFocusBorder;
061:            private Border originalBorder;
062:            private Color darkerUnselectedBackground;
063:            private Color unselectedBackground;
064:            private Color unselectedForeground;
065:            private Insets originalBorderInsets;
066:            private int horizontalAlignment;
067:
068:            //~ Constructors -------------------------------------------------------------------------------------------------------------
069:
070:            /** Creates a default table cell renderer with LEADING horizontal alignment showing border when focused.
071:             *  Rendering of focused cell border is disabled by default, to enable it, use setSupportsFocusBorder(true).
072:             */
073:            public EnhancedTableCellRenderer() {
074:                setOpaque(true);
075:                supportsFocusBorder = false;
076:                horizontalAlignment = SwingConstants.LEADING;
077:                unselectedBackground = UIUtils.getProfilerResultsBackground();
078:                darkerUnselectedBackground = UIUtils
079:                        .getDarker(unselectedBackground);
080:            }
081:
082:            //~ Methods ------------------------------------------------------------------------------------------------------------------
083:
084:            public void setBorder(Border border) {
085:                super .setBorder(border);
086:                originalBorder = border;
087:
088:                if (originalBorder != null) {
089:                    originalBorderInsets = originalBorder.getBorderInsets(this );
090:                }
091:            }
092:
093:            public void setHorizontalAlignment(int horizontalAlignment) {
094:                this .horizontalAlignment = horizontalAlignment;
095:            }
096:
097:            public int getHorizontalAlignment() {
098:                return horizontalAlignment;
099:            }
100:
101:            /** Sets whether or not the renderer supports drawing border around the focused cell */
102:            public void setSupportsFocusBorder(boolean supportsFocusBorder) {
103:                this .supportsFocusBorder = supportsFocusBorder;
104:
105:                if ((supportsFocusBorder) && (originalBorder == null)) {
106:                    setBorder(BorderFactory.createEmptyBorder());
107:                }
108:            }
109:
110:            public boolean getSupportsFocusBorder() {
111:                return supportsFocusBorder;
112:            }
113:
114:            // ----------------------------------------------------------------------------
115:            // Cell renderer functionality
116:
117:            /**
118:             * Returns the default table cell renderer.
119:             *
120:             * @param table      the <code>JTable</code>
121:             * @param value      the value to assign to the cell at
122:             *                   <code>[row, column]</code>
123:             * @param isSelected true if cell is selected
124:             * @param hasFocus   true if cell has focus
125:             * @param row        the row of the cell to render
126:             * @param column     the column of the cell to render
127:             * @return the default table cell renderer
128:             */
129:            public final Component getTableCellRendererComponent(JTable table,
130:                    Object value, boolean isSelected, boolean hasFocus,
131:                    int row, int column) {
132:                if (supportsFocusBorder) {
133:                    if ((hasFocus) && (isSelected) && (originalBorder != null)) {
134:                        Border focusBorder = BorderFactory
135:                                .createCompoundBorder(
136:                                        BorderFactory
137:                                                .createLineBorder(UIUtils
138:                                                        .getDarkerLine(
139:                                                                table
140:                                                                        .getSelectionBackground(),
141:                                                                0.65f)),
142:                                        BorderFactory.createEmptyBorder(
143:                                                originalBorderInsets.top,
144:                                                originalBorderInsets.left - 1,
145:                                                originalBorderInsets.bottom,
146:                                                originalBorderInsets.right));
147:                        super .setBorder(focusBorder);
148:                    } else {
149:                        super .setBorder(originalBorder);
150:                    }
151:                }
152:
153:                if (isSelected && table.isEnabled()) {
154:                    setRowForeground(table.isFocusOwner() ? table
155:                            .getSelectionForeground() : UIUtils
156:                            .getUnfocusedSelectionForeground());
157:                    setRowBackground(table.isFocusOwner() ? table
158:                            .getSelectionBackground() : UIUtils
159:                            .getUnfocusedSelectionBackground());
160:                } else if (!table.isEnabled()) {
161:                    setRowForeground(UIManager
162:                            .getColor("TextField.inactiveForeground")); // NOI18N
163:                    setRowBackground(UIManager
164:                            .getColor("TextField.inactiveBackground")); // NOI18N
165:                } else {
166:                    if ((row & 0x1) == 0) { //even row
167:                        setRowForeground((unselectedForeground != null) ? unselectedForeground
168:                                : table.getForeground());
169:                        setRowBackground((darkerUnselectedBackground != null) ? darkerUnselectedBackground
170:                                : UIUtils.getDarker(table.getBackground()));
171:                    } else {
172:                        setRowForeground((unselectedForeground != null) ? unselectedForeground
173:                                : table.getForeground());
174:                        setRowBackground((unselectedBackground != null) ? unselectedBackground
175:                                : table.getBackground());
176:                    }
177:                }
178:
179:                setState(table, value, isSelected, hasFocus, row, column);
180:                setValue(table, value, row, column);
181:
182:                return this ;
183:            }
184:
185:            /**
186:             * Returns persistent (new) table cell renderer with provided parameters.
187:             *
188:             * @param table      the <code>JTable</code>
189:             * @param value      the value to assign to the cell at
190:             *                   <code>[row, column]</code>
191:             * @param isSelected true if cell is selected
192:             * @param hasFocus   true if cell has focus
193:             * @param row        the row of the cell to render
194:             * @param column     the column of the cell to render
195:             * @return the default table cell renderer
196:             */
197:            public abstract Component getTableCellRendererComponentPersistent(
198:                    JTable table, Object value, boolean isSelected,
199:                    boolean hasFocus, int row, int column);
200:
201:            // ----------------------------------------------------------------------------
202:            // Private impl
203:            public static Color getDarker(Color c) {
204:                return UIUtils.getSafeColor((int) (c.getRed() - 30), (int) (c
205:                        .getGreen() - 30), (int) (c.getBlue() - 30));
206:            }
207:
208:            /**
209:             * Called each time this renderer is to be used to render a specific row, with the color
210:             * to be used for painting background of this row. The default implementation sets the
211:             * background of the panel to this color, so this method does not need to be overriden unless
212:             * the subclass has any opaque components placed into the panel that should alternate their background
213:             * on each line and change on selected lines.
214:             *
215:             * @param c the color to be used for row background
216:             */
217:            protected void setRowBackground(Color c) {
218:                setBackground(c);
219:            }
220:
221:            // ----------------------------------------------------------------------------
222:            // API for subclasses
223:
224:            /**
225:             * Called each time this renderer is to be used to render a specific row, with the color
226:             * to be used for painting foreground of this row (based on table's getSelectionForeground).
227:             * The default implementation sets the foreground of the panel to this color.
228:             * Subclasses should override this to meaningfully change the rendering when the selection changes.
229:             *
230:             * @param c the color to be used for row foreground
231:             */
232:            protected void setRowForeground(Color c) {
233:                setForeground(c);
234:            }
235:
236:            /**
237:             * Called each time this renderer is to be used to render a specific value on specified row/column.
238:             * Subclasses need to implement this method to render the value.
239:             *
240:             * @param table the table in which the rendering occurs
241:             * @param value the value to be rendered
242:             * @param row the row at which the value is located
243:             * @param column the column at which the value is located
244:             */
245:            protected abstract void setValue(JTable table, Object value,
246:                    int row, int column);
247:
248:            /**
249:             * Called each time this renderer is to be used to render a specific value on specified row/column.
250:             * Subclasses can override this method to set their states according to provided values.
251:             *
252:             * @param table      the <code>JTable</code>
253:             * @param value      the value to assign to the cell at
254:             *                   <code>[row, column]</code>
255:             * @param isSelected true if cell is selected
256:             * @param hasFocus   true if cell has focus
257:             * @param row        the row of the cell to render
258:             * @param column     the column of the cell to render
259:             */
260:            protected void setState(JTable table, Object value,
261:                    boolean isSelected, boolean hasFocus, int row, int column) {
262:            }
263:        }
ww__w__.j__a_v__a__2__s.com_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.