Source Code Cross Referenced for PatternHighlighter.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: PatternHighlighter.java,v 1.7 2005/10/26 14:30:00 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.util.regex.Pattern;
026:        import java.util.regex.PatternSyntaxException;
027:
028:        /**
029:         * PatternHighlighter
030:         * 
031:         * @author Ramesh Gupta
032:         */
033:        public class PatternHighlighter extends ConditionalHighlighter
034:                implements  PatternMatcher {
035:
036:            protected Pattern pattern = null;
037:
038:            /**
039:             * Constructs a <code>PatternHighlighter</code> instance with no
040:             * background or foreground color and no pattern
041:             */
042:            public PatternHighlighter() {
043:                // default constructor
044:                this (null, null, null, 0, 0); // match flags = 0; test column = 0
045:            }
046:
047:            /**
048:             * <p>
049:             * Constructs a <code>PatternHighlighter</code> instance with the
050:             * specified background and foreground colors that will be used to decorate
051:             * the renderer component for all cell in a row if and only if the specified
052:             * regExString defines a valid {@link java.util.regex.Pattern}, and the
053:             * value of the cell in the specified testColumn of that row matches that
054:             * pattern.
055:             * </p>
056:             * 
057:             * @param background
058:             *            background color for decorated cells, or null, if background
059:             *            should not be changed
060:             * @param foreground
061:             *            foreground color for decorated cells, or null, if foreground
062:             *            should not be changed
063:             * @param regExString
064:             *            the regular expression string to compile, or null to leave the
065:             *            pattern undefined
066:             * @param testColumn
067:             *            column to which the pattern matching test is applied; must be
068:             *            a valid column index in model coordinates
069:             * @throws java.util.regex.PatternSyntaxException
070:             *             if regExString is not null, but it does not define a valid
071:             *             {@link java.util.regex.Pattern}
072:             * @see java.util.regex.Pattern
073:             */
074:            public PatternHighlighter(Color background, Color foreground,
075:                    String regExString, int matchFlags, int testColumn)
076:                    throws PatternSyntaxException {
077:                this (background, foreground, regExString, matchFlags,
078:                        testColumn, -1);
079:            }
080:
081:            /**
082:             * <p>
083:             * Constructs a <code>PatternHighlighter</code> instance with the
084:             * specified background and foreground colors that will be used to decorate
085:             * the renderer component for a cell in the specified decorateColumn of any
086:             * row if and only if the specified regExString and matchFlags define a
087:             * valid {@link java.util.regex.Pattern}, and the value of the cell in the
088:             * specified testColumn of the same row matches that pattern.
089:             * </p>
090:             * 
091:             * @param background
092:             *            background color for decorated cells, or null, if background
093:             *            should not be changed
094:             * @param foreground
095:             *            foreground color for decorated cells, or null, if foreground
096:             *            should not be changed
097:             * @param regExString
098:             *            the regular expression string to compile, or null to leave the
099:             *            pattern undefined
100:             * @param matchFlags
101:             *            a bit mask that may include
102:             *            {@link java.util.regex.Pattern#CASE_INSENSITIVE},
103:             *            {@link java.util.regex.Pattern#MULTILINE},
104:             *            {@link java.util.regex.Pattern#DOTALL},
105:             *            {@link java.util.regex.Pattern#UNICODE_CASE}, and
106:             *            {@link java.util.regex.Pattern#CANON_EQ}
107:             * @param testColumn
108:             *            column to which the pattern matching test is applied; must be
109:             *            a valid column index in model coordinates
110:             * @param decorateColumn
111:             *            column to which decorator attributes will be applied; may be a
112:             *            valid column index in model coordinates, or -1 to indicate all
113:             *            columns
114:             * @throws java.util.regex.PatternSyntaxException
115:             *             if regExString is not null, but regExString and matchFlags do
116:             *             not define a valid {@link java.util.regex.Pattern}
117:             * @see java.util.regex.Pattern
118:             */
119:            public PatternHighlighter(Color background, Color foreground,
120:                    String regExString, int matchFlags, int testColumn,
121:                    int decorateColumn) throws PatternSyntaxException {
122:                super (background, foreground, testColumn, decorateColumn);
123:                setPattern(regExString, matchFlags);
124:            }
125:
126:            /**
127:             * Tests whether the string representation of the value of the cell
128:             * identified by the specified adapter matches the pattern, if any, that is
129:             * set for this <code>PatternHighlighter</code>, and returns true if the
130:             * test succeeds; Otherwise, it returns false.
131:             * 
132:             * @param adapter
133:             *            the current cell rendering adapter
134:             * @return true if the test succeeds; false otherwise
135:             */
136:            protected boolean test(ComponentAdapter adapter) {
137:                if (pattern == null) {
138:                    return false;
139:                }
140:
141:                if (!adapter.isTestable(testColumn))
142:                    return false;
143:                Object value = adapter.getFilteredValueAt(adapter.row,
144:                        testColumn);
145:
146:                if (value == null) {
147:                    return false;
148:                } else {
149:                    boolean matches = pattern.matcher(value.toString()).find();
150:                    return matches;
151:                }
152:            }
153:
154:            /**
155:             * Returns the pattern used by this cell decorator for matching against a
156:             * cell's value to determine if the conditions for cell decoration are met.
157:             * 
158:             * @return the pattern used by this cell decorator for matching
159:             * @see java.util.regex.Pattern
160:             */
161:            public Pattern getPattern() {
162:                return pattern;
163:            }
164:
165:            public void setPattern(String regularExpr, int matchFlags) {
166:                if ((regularExpr == null) || (regularExpr.length() == 0)) {
167:                    regularExpr = ".*";
168:                }
169:                setPattern(Pattern.compile(regularExpr, matchFlags));
170:            }
171:
172:            /**
173:             * Sets the pattern used by this cell decorator to match against a cell's
174:             * value to determine if the conditions for cell decoration are met.
175:             * 
176:             * @param pattern
177:             *            the pattern used by this cell decorator for matching
178:             * @see java.util.regex.Pattern
179:             */
180:            public void setPattern(Pattern pattern) {
181:                this.pattern = pattern;
182:                fireStateChanged();
183:            }
184:
185:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.