Source Code Cross Referenced for AlternateRowHighlighter.java in  » Swing-Library » swingx » org » jdesktop » swingx » decorator » 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 » swingx » org.jdesktop.swingx.decorator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: AlternateRowHighlighter.java,v 1.5 2005/11/22 12:21:39 kleopatra Exp $
003:         *
004:         * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
005:         * Santa Clara, California 95054, U.S.A. All rights reserved.
006:         *
007:         * This library is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU Lesser General Public
009:         * License as published by the Free Software Foundation; either
010:         * version 2.1 of the License, or (at your option) any later version.
011:         * 
012:         * This library is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         * Lesser General Public License for more details.
016:         * 
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this library; if not, write to the Free Software
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
020:         */
021:
022:        package org.jdesktop.swingx.decorator;
023:
024:        import java.awt.Color;
025:        import java.awt.Component;
026:        import java.util.HashMap;
027:
028:        import javax.swing.UIManager;
029:
030:        /**
031:         * AlternateRowHighlighter prepares a cell renderer to use different background
032:         * colors for alternating rows in a data view. The size (in terms of row count) of
033:         * an alternating group is configurable (defaults to 1);
034:         *
035:         * @author Ramesh Gupta
036:         */
037:        public class AlternateRowHighlighter extends Highlighter {
038:            private final static Color defaultOddRowColor = Color.white;
039:            private final static Color defaultEvenRowColor = new Color(0xF0,
040:                    0xF0, 0xE0);
041:
042:            public final static Highlighter beige = new AlternateRowHighlighter(
043:                    Color.white, new Color(245, 245, 220), null, true);
044:
045:            public final static Highlighter linePrinter = new AlternateRowHighlighter(
046:                    Color.white, new Color(0xCC, 0xCC, 0xFF), null, true);
047:
048:            public final static Highlighter classicLinePrinter = new AlternateRowHighlighter(
049:                    Color.white, new Color(0xCC, 0xFF, 0xCC), null, true);
050:
051:            public final static Highlighter floralWhite = new AlternateRowHighlighter(
052:                    Color.white, new Color(255, 250, 240), null, true);
053:
054:            public final static Highlighter quickSilver = new AlternateRowHighlighter(
055:                    Color.white, defaultEvenRowColor, null, true);
056:
057:            public final static AlternateRowHighlighter genericGrey = new AlternateRowHighlighter(
058:                    Color.white, new Color(229, 229, 229), null, true);
059:
060:            private Color oddRowBackground = defaultOddRowColor;
061:            private Color evenRowBackground = defaultEvenRowColor;
062:            private int linesPerGroup = 1;
063:
064:            /**
065:             * Constructs a default <code>AlternateRowHighlighter</code> that prepares a
066:             * cell renderer to paint a white background for odd rows and a silver
067:             * <code>(0xF0, 0xF0, 0xE0)</code> background for even rows.
068:             */
069:            public AlternateRowHighlighter() {
070:            }
071:
072:            /**
073:             * Constructs an <code>AlternateRowHighlighter</code> that prepares a
074:             * cell renderer to paint the specified background colors for odd and even
075:             * and even rows. A foreground color may also be specified. If null is
076:             * specified for the foreground color, the foreground color for the renderer
077:             * is unchanged. Otherwise, it is set to the specified foreground color for
078:             * both odd and even rows.
079:             *
080:             * @param oddRowBackground
081:             * @param evenRowBackground
082:             * @param foreground
083:             */
084:            public AlternateRowHighlighter(Color oddRowBackground,
085:                    Color evenRowBackground, Color foreground) {
086:                this (oddRowBackground, evenRowBackground, foreground, false);
087:            }
088:
089:            public AlternateRowHighlighter(Color oddRowBackground,
090:                    Color evenRowBackground, Color foreground, boolean immutable) {
091:                super (oddRowBackground, foreground, immutable); // same background for odd and even
092:                this .oddRowBackground = oddRowBackground;
093:                this .evenRowBackground = evenRowBackground;
094:            }
095:
096:            /**
097:             * Returns the background color for odd rows, or null if the background color
098:             * of the cell renderer should be left unchanged for odd rows.
099:             *
100:             * @return the background color for odd rows, or null if the background color
101:             * of the cell renderer should be left unchanged for odd rows
102:             */
103:            public Color getOddRowBackground() {
104:                return oddRowBackground;
105:            }
106:
107:            /**
108:             * Sets the background color for odd rows to the specified color. If null is
109:             * specified, the background color for odd rows is left unchanged in the
110:             * renderer
111:
112:             *
113:             * @param color the background color for odd rows, or null if the background
114:             * color of the cell renderer should be left unchanged for odd rows
115:             */
116:            public void setOddRowBackground(Color color) {
117:                if (isImmutable())
118:                    return;
119:                oddRowBackground = color;
120:                fireStateChanged();
121:            }
122:
123:            /**
124:             * Returns the background color for even rows, or null if the background color
125:             * of the cell renderer should be left unchanged for even rows.
126:             *
127:             * @return the background color for even rows, or null if the background color
128:             * of the cell renderer should be left unchanged for even rows
129:             */
130:            public Color getEvenRowBackground() {
131:                return evenRowBackground;
132:            }
133:
134:            /**
135:             * Sets the background color for even rows to the specified color. If null is
136:             * specified, the background color for even rows is left unchanged in the
137:             * renderer.
138:             *
139:             * @param color the background color for even rows, or null if the background
140:             * color of the cell renderer should be left unchanged for even rows
141:             */
142:            public void setEvenRowBackground(Color color) {
143:                if (isImmutable())
144:                    return;
145:                evenRowBackground = color;
146:                fireStateChanged();
147:            }
148:
149:            @Override
150:            protected Color computeUnselectedBackground(Component renderer,
151:                    ComponentAdapter adapter) {
152:                return isOddRow(adapter) ? oddRowBackground : evenRowBackground;
153:            }
154:
155:            /**
156:             * @param adapter
157:             * @return true if the adapter's row should be colored with the oddRowBackground,
158:             *          false is not
159:             */
160:            protected boolean isOddRow(ComponentAdapter adapter) {
161:                return ((adapter.row / getLinesPerGroup()) % 2) == 0;
162:            }
163:
164:            public int getLinesPerGroup() {
165:                return linesPerGroup;
166:            }
167:
168:            public void setLinesPerGroup(int linesPerGroup) {
169:                if (isImmutable())
170:                    return;
171:                this .linesPerGroup = Math.max(1, linesPerGroup);
172:                fireStateChanged();
173:            }
174:
175:            public static class UIAlternateRowHighlighter extends
176:                    AlternateRowHighlighter implements  UIHighlighter {
177:
178:                private HashMap<Color, Color> colorMap;
179:
180:                public UIAlternateRowHighlighter() {
181:                    super (Color.WHITE, null, null);
182:                    initColorMap();
183:                    updateUI();
184:                }
185:
186:                public void updateUI() {
187:
188:                    Color selection = UIManager
189:                            .getColor("Table.selectionBackground");
190:                    Color highlight = getMappedColor(selection);
191:
192:                    setEvenRowBackground(highlight);
193:                }
194:
195:                private Color getMappedColor(Color selection) {
196:                    Color color = colorMap.get(selection);
197:                    if (color == null) {
198:                        color = AlternateRowHighlighter.genericGrey
199:                                .getEvenRowBackground();
200:                    }
201:                    return color;
202:                }
203:
204:                /** 
205:                 * this is a hack until we can think about something better!
206:                 * we map all known selection colors to highlighter colors.
207:                 *
208:                 */
209:                private void initColorMap() {
210:                    colorMap = new HashMap<Color, Color>();
211:                    // Ocean
212:                    colorMap.put(new Color(184, 207, 229), new Color(230, 238,
213:                            246));
214:                    // xp blue
215:                    colorMap.put(new Color(49, 106, 197), new Color(224, 233,
216:                            246));
217:                    // xp silver
218:                    colorMap.put(new Color(178, 180, 191), new Color(235, 235,
219:                            236));
220:                    // xp olive
221:                    colorMap.put(new Color(147, 160, 112), new Color(228, 231,
222:                            219));
223:                    // win classic
224:                    colorMap.put(new Color(10, 36, 106), new Color(218, 222,
225:                            233));
226:                    // win 2k?
227:                    colorMap
228:                            .put(new Color(0, 0, 128), new Color(218, 222, 233));
229:                    // default metal
230:                    colorMap.put(new Color(205, 205, 255), new Color(235, 235,
231:                            255));
232:                    // mac OS X
233:                    colorMap.put(new Color(56, 117, 215), new Color(237, 243,
234:                            254));
235:
236:                }
237:
238:            }
239:
240:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.