Source Code Cross Referenced for StyleBuilder.java in  » GIS » GeoTools-2.4.1 » org » geotools » styling » 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 » GIS » GeoTools 2.4.1 » org.geotools.styling 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         *    GeoTools - OpenSource mapping toolkit
0003:         *    http://geotools.org
0004:         *    (C) 2002-2006, GeoTools Project Managment Committee (PMC)
0005:         *     
0006:         *    This library is free software; you can redistribute it and/or
0007:         *    modify it under the terms of the GNU Lesser General Public
0008:         *    License as published by the Free Software Foundation;
0009:         *    version 2.1 of the License.
0010:         *
0011:         *    This library is distributed in the hope that it will be useful,
0012:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
0013:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014:         *    Lesser General Public License for more details.
0015:         */
0016:        package org.geotools.styling;
0017:
0018:        import java.awt.Color;
0019:        import java.util.Arrays;
0020:        import java.util.Iterator;
0021:
0022:        import org.geotools.factory.CommonFactoryFinder;
0023:        import org.geotools.factory.GeoTools;
0024:        import org.geotools.feature.Feature;
0025:        import org.geotools.feature.FeatureCollection;
0026:        import org.geotools.feature.FeatureType;
0027:        import org.geotools.filter.IllegalFilterException;
0028:        import org.opengis.filter.FilterFactory;
0029:        import org.opengis.filter.PropertyIsBetween;
0030:        import org.opengis.filter.PropertyIsGreaterThan;
0031:        import org.opengis.filter.PropertyIsLessThan;
0032:        import org.opengis.filter.expression.Expression;
0033:        import org.opengis.filter.expression.PropertyName;
0034:
0035:        /**
0036:         * An utility class designed to ease style building by convinience methods.
0037:         *
0038:         * @author aaime
0039:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/main/java/org/geotools/styling/StyleBuilder.java $
0040:         */
0041:        public class StyleBuilder {
0042:            private static final java.util.logging.Logger LOGGER = org.geotools.util.logging.Logging
0043:                    .getLogger("org.geotools.styling");
0044:            public static final String LINE_JOIN_MITRE = "mitre";
0045:            public static final String LINE_JOIN_ROUND = "round";
0046:            public static final String LINE_JOIN_BEVEL = "bevel";
0047:            public static final String LINE_CAP_BUTT = "butt";
0048:            public static final String LINE_CAP_ROUND = "round";
0049:            public static final String LINE_CAP_SQUARE = "square";
0050:            public static final String MARK_SQUARE = "square";
0051:            public static final String MARK_CIRCLE = "circle";
0052:            public static final String MARK_TRIANGLE = "triangle";
0053:            public static final String MARK_STAR = "star";
0054:            public static final String MARK_CROSS = "cross";
0055:            public static final String MARK_ARROW = "arrow";
0056:            public static final String MARK_X = "x";
0057:            public static final String FONT_STYLE_NORMAL = "normal";
0058:            public static final String FONT_STYLE_ITALIC = "italic";
0059:            public static final String FONT_STYLE_OBLIQUE = "oblique";
0060:            public static final String FONT_WEIGHT_NORMAL = "normal";
0061:            public static final String FONT_WEIGHT_BOLD = "bold";
0062:
0063:            private StyleFactory sf;
0064:            private FilterFactory ff;
0065:
0066:            /**
0067:             * use the default StyleFactory and FilterFactory
0068:             */
0069:            public StyleBuilder() {
0070:                this (CommonFactoryFinder.getStyleFactory(GeoTools
0071:                        .getDefaultHints()));
0072:            }
0073:
0074:            /**
0075:             * Use the supplied StyleFactory when building styles
0076:             *
0077:             * @param styleFactory the StyleFactory to use in building Styles
0078:             */
0079:            public StyleBuilder(StyleFactory styleFactory) {
0080:                this (styleFactory, CommonFactoryFinder
0081:                        .getFilterFactory(GeoTools.getDefaultHints()));
0082:            }
0083:
0084:            /**
0085:             * Use the supplied FilterFactory when building styles
0086:             *
0087:             * @param filterFactory Use this FilterFactory to build the style
0088:             */
0089:            public StyleBuilder(FilterFactory filterFactory) {
0090:                this (CommonFactoryFinder.getStyleFactory(GeoTools
0091:                        .getDefaultHints()), filterFactory);
0092:            }
0093:
0094:            /**
0095:             * Use the supplied StyleFactory and FilterFactory when building styles
0096:             *
0097:             * @param styleFactory the StyleFactory to use
0098:             * @param filterFactory the FilterFactory to use
0099:             */
0100:            public StyleBuilder(StyleFactory styleFactory,
0101:                    FilterFactory filterFactory) {
0102:                this .sf = styleFactory;
0103:                this .ff = filterFactory;
0104:            }
0105:
0106:            /**
0107:             * Documented setter injection, StyleBuilder uses a StyleFactory for creation.
0108:             * 
0109:             * @param factory
0110:             */
0111:            public void setStyleFactory(StyleFactory factory) {
0112:                sf = factory;
0113:            }
0114:
0115:            /**
0116:             * getter for StyleFactory
0117:             *
0118:             * @return the StyleFactory being used
0119:             */
0120:            public StyleFactory getStyleFactory() {
0121:                return sf;
0122:            }
0123:
0124:            /**
0125:             * Documented setter injection, StyleBuilder uses a StyleFactory for creation.
0126:             * 
0127:             * @param factory
0128:             */
0129:            public void setFilterFactory(FilterFactory factory) {
0130:                ff = factory;
0131:            }
0132:
0133:            /**
0134:             * getter for filterFactory
0135:             *
0136:             * @return the FilterFactory being used
0137:             */
0138:            public FilterFactory getFilterFactory() {
0139:                return ff;
0140:            }
0141:
0142:            /**
0143:             * create a default Stroke
0144:             *
0145:             * @return the Stroke created
0146:             */
0147:            public Stroke createStroke() {
0148:                return sf.getDefaultStroke();
0149:            }
0150:
0151:            /**
0152:             * create a default stroke with the supplied width
0153:             *
0154:             * @param width the width of the line
0155:             *
0156:             * @return the stroke created
0157:             */
0158:            public Stroke createStroke(double width) {
0159:                return createStroke(Color.BLACK, width);
0160:            }
0161:
0162:            /**
0163:             * Create a default stroke with the supplied color
0164:             *
0165:             * @param color the color of the line
0166:             *
0167:             * @return the created stroke
0168:             */
0169:            public Stroke createStroke(Color color) {
0170:                return createStroke(color, 1);
0171:            }
0172:
0173:            /**
0174:             * create a stroke with the supplied width and color
0175:             *
0176:             * @param color the color of the line
0177:             * @param width the width of the line
0178:             *
0179:             * @return the created stroke
0180:             */
0181:            public Stroke createStroke(Color color, double width) {
0182:                return sf.createStroke(colorExpression(color),
0183:                        literalExpression(width));
0184:            }
0185:
0186:            /**
0187:             * create a stroke with color, width, linejoin type and lineCap type.
0188:             *
0189:             * @param color the color of the line
0190:             * @param width the width of the line
0191:             * @param lineJoin the type of join to be used at points along the line
0192:             * @param lineCap the type of cap to be used at the end of the line
0193:             *
0194:             * @return the stroke created
0195:             */
0196:            public Stroke createStroke(Color color, double width,
0197:                    String lineJoin, String lineCap) {
0198:                Stroke stroke = createStroke(color, width);
0199:                stroke.setLineJoin(literalExpression(lineJoin));
0200:                stroke.setLineCap(literalExpression(lineCap));
0201:
0202:                return stroke;
0203:            }
0204:
0205:            /**
0206:             * create a dashed line of color and width
0207:             *
0208:             * @param color the color of the line
0209:             * @param width the width of the line
0210:             * @param dashArray an array of floats describing the length of line and spaces
0211:             *
0212:             * @return the stroke created
0213:             */
0214:            public Stroke createStroke(Color color, double width,
0215:                    float[] dashArray) {
0216:                Stroke stroke = createStroke(color, width);
0217:                stroke.setDashArray(dashArray);
0218:
0219:                return stroke;
0220:            }
0221:
0222:            /**
0223:             * create a stroke with the color and width supplied
0224:             *
0225:             * @param color an Expression representing the color of the line
0226:             * @param width an Expression representing the width of the line
0227:             *
0228:             * @return the Stroke created
0229:             */
0230:            public Stroke createStroke(Expression color, Expression width) {
0231:                return sf.createStroke(color, width);
0232:            }
0233:
0234:            /**
0235:             * create a stroke with color, width and opacity supplied
0236:             *
0237:             * @param color the color of the line
0238:             * @param width the width of the line
0239:             * @param opacity the opacity or <I>see throughness</I> of the line, 0 - is transparent, 1 is
0240:             *        completely drawn
0241:             *
0242:             * @return the stroke created
0243:             */
0244:            public Stroke createStroke(Color color, double width, double opacity) {
0245:                return sf.createStroke(colorExpression(color),
0246:                        literalExpression(width), literalExpression(opacity));
0247:            }
0248:
0249:            /**
0250:             * create a stroke with color, width and opacity supplied
0251:             *
0252:             * @param color an Expression representing the color of the line
0253:             * @param width an Expression representing the width of the line
0254:             * @param opacity an Expression representing opacity the opacity or <I>see throughness</I> of
0255:             *        the line, 0 - is transparent, 1 is completely drawn
0256:             *
0257:             * @return the stroke created
0258:             */
0259:            public Stroke createStroke(Expression color, Expression width,
0260:                    Expression opacity) {
0261:                return sf.createStroke(color, width, opacity);
0262:            }
0263:
0264:            /**
0265:             * create a default fill 50% gray
0266:             *
0267:             * @return the fill created
0268:             */
0269:            public Fill createFill() {
0270:                Fill f = sf.getDefaultFill();
0271:                f.setColor(literalExpression("#808080"));
0272:                f.setBackgroundColor(literalExpression("#808080"));
0273:                f.setOpacity(literalExpression(1.0));
0274:
0275:                return f;
0276:            }
0277:
0278:            /**
0279:             * create a fill of color
0280:             *
0281:             * @param fillColor the color of the fill
0282:             *
0283:             * @return the fill created
0284:             */
0285:            public Fill createFill(Color fillColor) {
0286:                return createFill(colorExpression(fillColor));
0287:            }
0288:
0289:            /**
0290:             * create a fill of color
0291:             *
0292:             * @param fillColor an Expression representing the color of the fill
0293:             *
0294:             * @return the fill constructed
0295:             */
0296:            public Fill createFill(Expression fillColor) {
0297:                return sf.createFill(fillColor);
0298:            }
0299:
0300:            /**
0301:             * create a fill with the supplied color and opacity
0302:             *
0303:             * @param fillColor the color to fill with
0304:             * @param opacity the opacity of the fill 0 - transparent, 1 - completly filled
0305:             *
0306:             * @return the fill created
0307:             */
0308:            public Fill createFill(Color fillColor, double opacity) {
0309:                return sf.createFill(colorExpression(fillColor),
0310:                        literalExpression(opacity));
0311:            }
0312:
0313:            /**
0314:             * create a fill with the supplied color and opacity
0315:             *
0316:             * @param color an expression representing the color to fill with
0317:             * @param opacity an expression representing the opacity of the fill 0 - transparent, 1 -
0318:             *        completly filled
0319:             *
0320:             * @return the fill created
0321:             */
0322:            public Fill createFill(Expression color, Expression opacity) {
0323:                return sf.createFill(color, opacity);
0324:            }
0325:
0326:            /**
0327:             * create a fill with color, background color and opacity supplied and uses the graphic
0328:             * supplied for the fill
0329:             *
0330:             * @param color the foreground color
0331:             * @param backgroundColor the background color
0332:             * @param opacity the opacity of the fill
0333:             * @param fill the graphic object to use to fill the fill
0334:             *
0335:             * @return the fill created
0336:             */
0337:            public Fill createFill(Color color, Color backgroundColor,
0338:                    double opacity, Graphic fill) {
0339:                return sf.createFill(colorExpression(color),
0340:                        colorExpression(backgroundColor),
0341:                        literalExpression(opacity), fill);
0342:            }
0343:
0344:            /**
0345:             * create a fill with color, background color and opacity supplied and uses the graphic
0346:             * supplied for the fill
0347:             *
0348:             * @param color an Expression representing the foreground color
0349:             * @param backgroundColor an Expression representing the background color
0350:             * @param opacity an Expression representing the opacity of the fill
0351:             * @param fill the graphic object to use to fill the fill
0352:             *
0353:             * @return the fill created
0354:             */
0355:            public Fill createFill(Expression color,
0356:                    Expression backgroundColor, Expression opacity, Graphic fill) {
0357:                return sf.createFill(color, backgroundColor, opacity, fill);
0358:            }
0359:
0360:            /**
0361:             * Returns the array of all the well known mark names
0362:             *
0363:             * @return DOCUMENT ME!
0364:             */
0365:            public String[] getWellKnownMarkNames() {
0366:                return new String[] { MARK_SQUARE, MARK_CIRCLE, MARK_TRIANGLE,
0367:                        MARK_STAR, MARK_CROSS, MARK_ARROW, MARK_X };
0368:            }
0369:
0370:            /**
0371:             * create the named mark
0372:             *
0373:             * @param wellKnownName the wellknown name of the mark
0374:             *
0375:             * @return the mark created
0376:             */
0377:            public Mark createMark(String wellKnownName) {
0378:                Mark mark = sf.createMark();
0379:                mark.setWellKnownName(literalExpression(wellKnownName));
0380:
0381:                return mark;
0382:            }
0383:
0384:            /**
0385:             * create the named mark with the colors etc supplied
0386:             *
0387:             * @param wellKnownName the well known name of the mark
0388:             * @param fillColor the color of the mark
0389:             * @param borderColor the outline color of the mark
0390:             * @param borderWidth the width of the outline
0391:             *
0392:             * @return the mark created
0393:             */
0394:            public Mark createMark(String wellKnownName, Color fillColor,
0395:                    Color borderColor, double borderWidth) {
0396:                Mark mark = sf.createMark();
0397:                mark.setWellKnownName(literalExpression(wellKnownName));
0398:                mark.setStroke(createStroke(borderColor, borderWidth));
0399:                mark.setFill(createFill(fillColor));
0400:
0401:                return mark;
0402:            }
0403:
0404:            /**
0405:             * create a mark with default fill (50% gray) and the supplied outline
0406:             *
0407:             * @param wellKnownName the well known name of the mark
0408:             * @param borderColor the outline color
0409:             * @param borderWidth the outline width
0410:             *
0411:             * @return the mark created
0412:             */
0413:            public Mark createMark(String wellKnownName, Color borderColor,
0414:                    double borderWidth) {
0415:                Mark mark = sf.createMark();
0416:                mark.setWellKnownName(literalExpression(wellKnownName));
0417:                mark.setStroke(createStroke(borderColor, borderWidth));
0418:
0419:                return mark;
0420:            }
0421:
0422:            /**
0423:             * create a mark of the supplied color and a default outline (black)
0424:             *
0425:             * @param wellKnownName the well known name of the mark
0426:             * @param fillColor the color of the mark
0427:             *
0428:             * @return the created mark
0429:             */
0430:            public Mark createMark(String wellKnownName, Color fillColor) {
0431:                Mark mark = sf.createMark();
0432:                mark.setWellKnownName(literalExpression(wellKnownName));
0433:                mark.setFill(createFill(fillColor, 1.0));
0434:                mark.setStroke(null);
0435:
0436:                return mark;
0437:            }
0438:
0439:            /**
0440:             * create a mark with the supplied fill and stroke
0441:             *
0442:             * @param wellKnownName the well known name of the mark
0443:             * @param fill the fill to use
0444:             * @param stroke the stroke to use
0445:             *
0446:             * @return the mark created
0447:             */
0448:            public Mark createMark(String wellKnownName, Fill fill,
0449:                    Stroke stroke) {
0450:                Mark mark = sf.createMark();
0451:                mark.setWellKnownName(literalExpression(wellKnownName));
0452:                mark.setStroke(stroke);
0453:                mark.setFill(fill);
0454:
0455:                return mark;
0456:            }
0457:
0458:            /**
0459:             * create a mark with the supplied fill and stroke
0460:             *
0461:             * @param wellKnownName an Expression representing the well known name of the mark
0462:             * @param fill the fill to use
0463:             * @param stroke the stroke to use
0464:             *
0465:             * @return the mark created
0466:             */
0467:            public Mark createMark(Expression wellKnownName, Fill fill,
0468:                    Stroke stroke) {
0469:                Mark mark = sf.createMark();
0470:                mark.setWellKnownName(wellKnownName);
0471:                mark.setStroke(stroke);
0472:                mark.setFill(fill);
0473:
0474:                return mark;
0475:            }
0476:
0477:            /**
0478:             * wrapper for stylefactory method
0479:             *
0480:             * @param uri the uri of the image
0481:             * @param format mime type of the image
0482:             *
0483:             * @return the external graphic
0484:             */
0485:            public ExternalGraphic createExternalGraphic(String uri,
0486:                    String format) {
0487:                return sf.createExternalGraphic(uri, format);
0488:            }
0489:
0490:            /**
0491:             * wrapper for stylefactory method
0492:             *
0493:             * @param url the url of the image
0494:             * @param format mime type of the image
0495:             *
0496:             * @return the external graphic
0497:             */
0498:            public ExternalGraphic createExternalGraphic(java.net.URL url,
0499:                    String format) {
0500:                return sf.createExternalGraphic(url, format);
0501:            }
0502:
0503:            /**
0504:             * Creates the default graphic object
0505:             *
0506:             * @return the graphic object
0507:             */
0508:            public Graphic createGraphic() {
0509:                Graphic gr = sf.getDefaultGraphic();
0510:
0511:                Mark mark = createMark(MARK_SQUARE, Color.decode("#808080"),
0512:                        Color.BLACK, 1);
0513:                gr.setMarks(new Mark[] { mark });
0514:                gr.setSize(literalExpression(6.0));
0515:
0516:                return gr;
0517:            }
0518:
0519:            /**
0520:             * creates a graphic object
0521:             *
0522:             * @param externalGraphic an external graphic to use if displayable
0523:             * @param mark a mark to use
0524:             * @param symbol a symbol to use
0525:             *
0526:             * @return the graphic object
0527:             */
0528:            public Graphic createGraphic(ExternalGraphic externalGraphic,
0529:                    Mark mark, Symbol symbol) {
0530:                Graphic gr = sf.getDefaultGraphic();
0531:
0532:                if (symbol != null) {
0533:                    gr.setSymbols(new Symbol[] { symbol });
0534:                } else {
0535:                    gr.setSymbols(new Symbol[0]);
0536:                }
0537:
0538:                if (externalGraphic != null) {
0539:                    gr
0540:                            .setExternalGraphics(new ExternalGraphic[] { externalGraphic });
0541:                }
0542:
0543:                if (mark != null) {
0544:                    gr.setMarks(new Mark[] { mark });
0545:                } else {
0546:                    gr.setMarks(new Mark[0]);
0547:                }
0548:
0549:                return gr;
0550:            }
0551:
0552:            /**
0553:             * creates a graphic object
0554:             *
0555:             * @param externalGraphic an external graphic to use if displayable
0556:             * @param mark a mark to use
0557:             * @param symbol a symbol to use
0558:             * @param opacity - the opacity of the graphic
0559:             * @param size - the size of the graphic
0560:             * @param rotation - the rotation from the top of the page of the graphic
0561:             *
0562:             * @return the graphic created
0563:             */
0564:            public Graphic createGraphic(ExternalGraphic externalGraphic,
0565:                    Mark mark, Symbol symbol, double opacity, double size,
0566:                    double rotation) {
0567:                ExternalGraphic[] egs = null;
0568:                Mark[] marks = null;
0569:                Symbol[] symbols = null;
0570:
0571:                if (externalGraphic != null) {
0572:                    egs = new ExternalGraphic[] { externalGraphic };
0573:                }
0574:
0575:                if (mark != null) {
0576:                    marks = new Mark[] { mark };
0577:                }
0578:
0579:                if (symbol != null) {
0580:                    symbols = new Symbol[] { symbol };
0581:                }
0582:
0583:                return createGraphic(egs, marks, symbols,
0584:                        literalExpression(opacity), literalExpression(size),
0585:                        literalExpression(rotation));
0586:            }
0587:
0588:            /**
0589:             * creates a graphic object
0590:             *
0591:             * @param externalGraphics an array of external graphics to use if displayable
0592:             * @param marks an array of marks to use
0593:             * @param symbols an array of symbols to use
0594:             * @param opacity - the opacity of the graphic
0595:             * @param size - the size of the graphic
0596:             * @param rotation - the rotation from the top of the page of the graphic
0597:             *
0598:             * @return the graphic created
0599:             */
0600:            public Graphic createGraphic(ExternalGraphic[] externalGraphics,
0601:                    Mark[] marks, Symbol[] symbols, double opacity,
0602:                    double size, double rotation) {
0603:                return createGraphic(externalGraphics, marks, symbols,
0604:                        literalExpression(opacity), literalExpression(size),
0605:                        literalExpression(rotation));
0606:            }
0607:
0608:            /**
0609:             * creates a graphic object
0610:             *
0611:             * @param externalGraphics an array of external graphics to use if displayable
0612:             * @param marks an array of marks to use
0613:             * @param symbols an array of symbols to use
0614:             * @param opacity - an Expression representing the opacity of the graphic
0615:             * @param size - an Expression representing the size of the graphic
0616:             * @param rotation - an Expression representing the rotation from the top of the page of the
0617:             *        graphic
0618:             *
0619:             * @return the graphic created
0620:             */
0621:            public Graphic createGraphic(ExternalGraphic[] externalGraphics,
0622:                    Mark[] marks, Symbol[] symbols, Expression opacity,
0623:                    Expression size, Expression rotation) {
0624:                ExternalGraphic[] exg = externalGraphics;
0625:
0626:                if (exg == null) {
0627:                    exg = new ExternalGraphic[0];
0628:                }
0629:
0630:                Mark[] m = marks;
0631:
0632:                if (m == null) {
0633:                    m = new Mark[0];
0634:                }
0635:
0636:                Symbol[] s = symbols;
0637:
0638:                if (s == null) {
0639:                    s = new Symbol[0];
0640:                }
0641:
0642:                return sf.createGraphic(exg, m, s, opacity, size, rotation);
0643:            }
0644:
0645:            /**
0646:             * wrapper round Stylefactory Method
0647:             *
0648:             * @param x - the x coordinate of the anchor
0649:             * @param y - the y coordinate of the anchor
0650:             *
0651:             * @return the AnchorPoint created
0652:             */
0653:            public AnchorPoint createAnchorPoint(double x, double y) {
0654:                return sf.createAnchorPoint(literalExpression(x),
0655:                        literalExpression(y));
0656:            }
0657:
0658:            /**
0659:             * wrapper round Stylefactory Method
0660:             *
0661:             * @param x - an Expression representing the x coordinate of the anchor
0662:             * @param y - an Expression representing the y coordinate of the anchor
0663:             *
0664:             * @return the AnchorPoint created
0665:             */
0666:            public AnchorPoint createAnchorPoint(Expression x, Expression y) {
0667:                return sf.createAnchorPoint(x, y);
0668:            }
0669:
0670:            /**
0671:             * wrapper round Stylefactory Method
0672:             *
0673:             * @param x - the x displacement
0674:             * @param y - the y displacement
0675:             *
0676:             * @return the Displacement created
0677:             */
0678:            public Displacement createDisplacement(double x, double y) {
0679:                return sf.createDisplacement(literalExpression(x),
0680:                        literalExpression(y));
0681:            }
0682:
0683:            /**
0684:             * wrapper round Stylefactory Method
0685:             *
0686:             * @param x - an Expression representing the x displacement
0687:             * @param y - an Expression representing the y displacement
0688:             *
0689:             * @return the Displacement created
0690:             */
0691:            public Displacement createDisplacement(Expression x, Expression y) {
0692:                return sf.createDisplacement(x, y);
0693:            }
0694:
0695:            /**
0696:             * wrapper round Stylefactory Method
0697:             *
0698:             * @return the default pointplacement
0699:             */
0700:            public PointPlacement createPointPlacement() {
0701:                return sf.getDefaultPointPlacement();
0702:            }
0703:
0704:            /**
0705:             * wrapper round Stylefactory Method
0706:             *
0707:             * @param anchorX - the X coordinate
0708:             * @param anchorY - the Y coordinate
0709:             * @param rotation - the rotaion of the label
0710:             *
0711:             * @return the pointplacement created
0712:             */
0713:            public PointPlacement createPointPlacement(double anchorX,
0714:                    double anchorY, double rotation) {
0715:                AnchorPoint anchorPoint = createAnchorPoint(anchorX, anchorY);
0716:
0717:                return sf.createPointPlacement(anchorPoint, null,
0718:                        literalExpression(rotation));
0719:            }
0720:
0721:            /**
0722:             * wrapper round Stylefactory Method
0723:             *
0724:             * @param anchorX - the X coordinate
0725:             * @param anchorY - the Y coordinate
0726:             * @param displacementX - the X distance from the anchor
0727:             * @param displacementY - the Y distance from the anchor
0728:             * @param rotation - the rotaion of the label
0729:             *
0730:             * @return the pointplacement created
0731:             */
0732:            public PointPlacement createPointPlacement(double anchorX,
0733:                    double anchorY, double displacementX, double displacementY,
0734:                    double rotation) {
0735:                AnchorPoint anchorPoint = createAnchorPoint(anchorX, anchorY);
0736:                Displacement displacement = createDisplacement(displacementX,
0737:                        displacementY);
0738:
0739:                return sf.createPointPlacement(anchorPoint, displacement,
0740:                        literalExpression(rotation));
0741:            }
0742:
0743:            /**
0744:             * wrapper round Stylefactory Method
0745:             *
0746:             * @param anchorPoint - the anchor point of the label
0747:             * @param displacement - the displacement of the label
0748:             * @param rotation - an Expresson representing the rotation of the label
0749:             *
0750:             * @return the pointplacement created
0751:             */
0752:            public PointPlacement createPointPlacement(AnchorPoint anchorPoint,
0753:                    Displacement displacement, Expression rotation) {
0754:                return sf.createPointPlacement(anchorPoint, displacement,
0755:                        rotation);
0756:            }
0757:
0758:            /**
0759:             * wrapper round Stylefactory Method
0760:             *
0761:             * @param offset - the distance between the line and the label
0762:             *
0763:             * @return the LinePlacement created
0764:             */
0765:            public LinePlacement createLinePlacement(double offset) {
0766:                return sf.createLinePlacement(literalExpression(offset));
0767:            }
0768:
0769:            /**
0770:             * wrapper round Stylefactory Method
0771:             *
0772:             * @param offset - an Expression representing the distance between the line and the label
0773:             *
0774:             * @return the LinePlacement created
0775:             */
0776:            public LinePlacement createLinePlacement(Expression offset) {
0777:                return sf.createLinePlacement(offset);
0778:            }
0779:
0780:            /**
0781:             * create a geotools font object from a java font
0782:             *
0783:             * @param font - the font to be converted
0784:             *
0785:             * @return - the geotools font
0786:             */
0787:            public Font createFont(java.awt.Font font) {
0788:                Expression family = literalExpression(font.getFamily());
0789:                Expression style;
0790:                Expression weight;
0791:
0792:                if (font.isBold()) {
0793:                    weight = literalExpression(FONT_WEIGHT_BOLD);
0794:                } else {
0795:                    weight = literalExpression(FONT_WEIGHT_NORMAL);
0796:                }
0797:
0798:                if (font.isItalic()) {
0799:                    style = literalExpression(FONT_STYLE_ITALIC);
0800:                } else {
0801:                    style = literalExpression(FONT_STYLE_NORMAL);
0802:                }
0803:
0804:                return sf.createFont(family, style, weight,
0805:                        literalExpression(font.getSize2D()));
0806:            }
0807:
0808:            /**
0809:             * create font of supplied family and size
0810:             *
0811:             * @param fontFamily - the font family
0812:             * @param fontSize - the size of the font in points
0813:             *
0814:             * @return the font object created
0815:             */
0816:            public Font createFont(String fontFamily, double fontSize) {
0817:                Expression family = literalExpression(fontFamily);
0818:                Expression style = literalExpression(FONT_STYLE_NORMAL);
0819:                Expression weight = literalExpression(FONT_WEIGHT_NORMAL);
0820:
0821:                return sf.createFont(family, style, weight,
0822:                        literalExpression(fontSize));
0823:            }
0824:
0825:            /**
0826:             * create font of supplied family, size and weight/style
0827:             *
0828:             * @param fontFamily - the font family
0829:             * @param italic - should the font be italic?
0830:             * @param bold - should the font be bold?
0831:             * @param fontSize - the size of the font in points
0832:             *
0833:             * @return the new font object
0834:             */
0835:            public Font createFont(String fontFamily, boolean italic,
0836:                    boolean bold, double fontSize) {
0837:                Expression family = literalExpression(fontFamily);
0838:                Expression style;
0839:                Expression weight;
0840:
0841:                if (bold) {
0842:                    weight = literalExpression(FONT_WEIGHT_BOLD);
0843:                } else {
0844:                    weight = literalExpression(FONT_WEIGHT_NORMAL);
0845:                }
0846:
0847:                if (italic) {
0848:                    style = literalExpression(FONT_STYLE_ITALIC);
0849:                } else {
0850:                    style = literalExpression(FONT_STYLE_NORMAL);
0851:                }
0852:
0853:                return sf.createFont(family, style, weight,
0854:                        literalExpression(fontSize));
0855:            }
0856:
0857:            /**
0858:             * wrapper round StyleFactory method
0859:             *
0860:             * @param fontFamily - Expression representing Font family
0861:             * @param fontStyle - Expression representing Font style
0862:             * @param fontWeight - Expression representing Font weight
0863:             * @param fontSize - Expression representing Font size
0864:             *
0865:             * @return the new font object
0866:             */
0867:            public Font createFont(Expression fontFamily, Expression fontStyle,
0868:                    Expression fontWeight, Expression fontSize) {
0869:                return sf.createFont(fontFamily, fontStyle, fontWeight,
0870:                        fontSize);
0871:            }
0872:
0873:            /**
0874:             * wrapper round StyleFactory method to create default halo
0875:             *
0876:             * @return the new halo
0877:             */
0878:            public Halo createHalo() {
0879:                return sf.createHalo(createFill(Color.WHITE),
0880:                        literalExpression(1));
0881:            }
0882:
0883:            /**
0884:             * wrapper round StyleFactory method to create halo
0885:             *
0886:             * @param color - the color of the halo
0887:             * @param radius - the width of the halo
0888:             *
0889:             * @return the new halo
0890:             */
0891:            public Halo createHalo(Color color, double radius) {
0892:                return sf.createHalo(createFill(color),
0893:                        literalExpression(radius));
0894:            }
0895:
0896:            /**
0897:             * wrapper round StyleFactory method to create halo
0898:             *
0899:             * @param color - the color of the halo
0900:             * @param opacity - the opacity of the halo fill 0 - transparent 1 - solid
0901:             * @param radius - the width of the halo
0902:             *
0903:             * @return the new halo
0904:             */
0905:            public Halo createHalo(Color color, double opacity, double radius) {
0906:                return sf.createHalo(createFill(color, opacity),
0907:                        literalExpression(radius));
0908:            }
0909:
0910:            /**
0911:             * wrapper round StyleFactory method to create halo
0912:             *
0913:             * @param fill - the fill of the halo
0914:             * @param radius - the width of the halo
0915:             *
0916:             * @return the new halo
0917:             */
0918:            public Halo createHalo(Fill fill, double radius) {
0919:                return sf.createHalo(fill, literalExpression(radius));
0920:            }
0921:
0922:            /**
0923:             * wrapper round StyleFactory method to create halo
0924:             *
0925:             * @param fill - the fill of the halo
0926:             * @param radius - an Expression representing the width of the halo
0927:             *
0928:             * @return the new halo
0929:             */
0930:            public Halo createHalo(Fill fill, Expression radius) {
0931:                return sf.createHalo(fill, radius);
0932:            }
0933:
0934:            /**
0935:             * create a default line symboliser
0936:             *
0937:             * @return the new line symbolizer
0938:             */
0939:            public LineSymbolizer createLineSymbolizer() {
0940:                return sf.getDefaultLineSymbolizer();
0941:            }
0942:
0943:            /**
0944:             * create a new line symbolizer
0945:             *
0946:             * @param width the width of the line
0947:             *
0948:             * @return the new line symbolizer
0949:             */
0950:            public LineSymbolizer createLineSymbolizer(double width) {
0951:                return createLineSymbolizer(createStroke(width), null);
0952:            }
0953:
0954:            /**
0955:             * create a LineSymbolizer
0956:             *
0957:             * @param color - the color of the line
0958:             *
0959:             * @return the new line symbolizer
0960:             */
0961:            public LineSymbolizer createLineSymbolizer(Color color) {
0962:                return createLineSymbolizer(createStroke(color), null);
0963:            }
0964:
0965:            /**
0966:             * create a LineSymbolizer
0967:             *
0968:             * @param color - the color of the line
0969:             * @param width - the width of the line
0970:             *
0971:             * @return the new line symbolizer
0972:             */
0973:            public LineSymbolizer createLineSymbolizer(Color color, double width) {
0974:                return createLineSymbolizer(createStroke(color, width), null);
0975:            }
0976:
0977:            /**
0978:             * create a LineSymbolizer
0979:             *
0980:             * @param color - the color of the line
0981:             * @param width - the width of the line
0982:             * @param geometryPropertyName - the name of the geometry to be drawn
0983:             *
0984:             * @return the new line symbolizer
0985:             */
0986:            public LineSymbolizer createLineSymbolizer(Color color,
0987:                    double width, String geometryPropertyName) {
0988:                return createLineSymbolizer(createStroke(color, width),
0989:                        geometryPropertyName);
0990:            }
0991:
0992:            /**
0993:             * create a LineSymbolizer
0994:             *
0995:             * @param stroke - the stroke to be used to draw the line
0996:             *
0997:             * @return the new line symbolizer
0998:             */
0999:            public LineSymbolizer createLineSymbolizer(Stroke stroke) {
1000:                return sf.createLineSymbolizer(stroke, null);
1001:            }
1002:
1003:            /**
1004:             * create a LineSymbolizer
1005:             *
1006:             * @param stroke - the stroke to be used to draw the line
1007:             * @param geometryPropertyName - the name of the geometry to be drawn
1008:             *
1009:             * @return the new line symbolizer
1010:             */
1011:            public LineSymbolizer createLineSymbolizer(Stroke stroke,
1012:                    String geometryPropertyName) {
1013:                return sf.createLineSymbolizer(stroke, geometryPropertyName);
1014:            }
1015:
1016:            /**
1017:             * create a default polygon symbolizer
1018:             *
1019:             * @return the new polygon symbolizer
1020:             */
1021:            public PolygonSymbolizer createPolygonSymbolizer() {
1022:                PolygonSymbolizer ps = sf.createPolygonSymbolizer();
1023:                ps.setFill(createFill());
1024:                ps.setStroke(createStroke());
1025:
1026:                return ps;
1027:            }
1028:
1029:            /**
1030:             * create a polygon symbolizer
1031:             *
1032:             * @param fillColor - the color to fill the polygon
1033:             *
1034:             * @return the new polygon symbolizer
1035:             */
1036:            public PolygonSymbolizer createPolygonSymbolizer(Color fillColor) {
1037:                return createPolygonSymbolizer(null, createFill(fillColor));
1038:            }
1039:
1040:            /**
1041:             * create a polygon symbolizer
1042:             *
1043:             * @param fillColor - the color to fill the polygon
1044:             * @param borderColor - the outline color of the polygon
1045:             * @param borderWidth - the width of the outline
1046:             *
1047:             * @return the new polygon symbolizer
1048:             */
1049:            public PolygonSymbolizer createPolygonSymbolizer(Color fillColor,
1050:                    Color borderColor, double borderWidth) {
1051:                return createPolygonSymbolizer(createStroke(borderColor,
1052:                        borderWidth), createFill(fillColor));
1053:            }
1054:
1055:            /**
1056:             * create a polygon symbolizer
1057:             *
1058:             * @param borderColor - the outline color of the polygon
1059:             * @param borderWidth - the width of the outline
1060:             *
1061:             * @return the new polygon symbolizer
1062:             */
1063:            public PolygonSymbolizer createPolygonSymbolizer(Color borderColor,
1064:                    double borderWidth) {
1065:                return createPolygonSymbolizer(createStroke(borderColor,
1066:                        borderWidth), null);
1067:            }
1068:
1069:            /**
1070:             * create a polygon symbolizer
1071:             *
1072:             * @param stroke - the stroke to use to outline the polygon
1073:             * @param fill - the fill to use to color the polygon
1074:             *
1075:             * @return the new polygon symbolizer
1076:             */
1077:            public PolygonSymbolizer createPolygonSymbolizer(Stroke stroke,
1078:                    Fill fill) {
1079:                return createPolygonSymbolizer(stroke, fill, null);
1080:            }
1081:
1082:            /**
1083:             * create a polygon symbolizer
1084:             *
1085:             * @param stroke - the stroke to use to outline the polygon
1086:             * @param fill - the fill to use to color the polygon
1087:             * @param geometryPropertyName - the name of the geometry to be drawn
1088:             *
1089:             * @return the new polygon symbolizer
1090:             */
1091:            public PolygonSymbolizer createPolygonSymbolizer(Stroke stroke,
1092:                    Fill fill, String geometryPropertyName) {
1093:                return sf.createPolygonSymbolizer(stroke, fill,
1094:                        geometryPropertyName);
1095:            }
1096:
1097:            /**
1098:             * create a default point symbolizer
1099:             *
1100:             * @return the new point symbolizer
1101:             */
1102:            public PointSymbolizer createPointSymbolizer() {
1103:                return sf.getDefaultPointSymbolizer();
1104:            }
1105:
1106:            /**
1107:             * create a point symbolizer
1108:             *
1109:             * @param graphic - the graphic object to draw at the point
1110:             *
1111:             * @return the new point symbolizer
1112:             */
1113:            public PointSymbolizer createPointSymbolizer(Graphic graphic) {
1114:                PointSymbolizer ps = sf.createPointSymbolizer();
1115:                ps.setGraphic(graphic);
1116:
1117:                return ps;
1118:            }
1119:
1120:            /**
1121:             * create a point symbolizer
1122:             *
1123:             * @param graphic - the graphic object to draw at the point
1124:             * @param geometryPropertyName - the name of the geometry to be drawn
1125:             *
1126:             * @return the new point symbolizer
1127:             */
1128:            public PointSymbolizer createPointSymbolizer(Graphic graphic,
1129:                    String geometryPropertyName) {
1130:                return sf.createPointSymbolizer(graphic, geometryPropertyName);
1131:            }
1132:
1133:            /**
1134:             * Creates a default text symbolizer. Warning: there is no definition of a default text
1135:             * symbolizer in the SLD standard, this is provided just for convenience and uniformity with
1136:             * the other symbolizers
1137:             *
1138:             * @return the default text symbolizer
1139:             */
1140:            public TextSymbolizer createTextSymbolizer() {
1141:                TextSymbolizer ts = sf.createTextSymbolizer();
1142:
1143:                ts.setFill(createFill(Color.BLACK));
1144:                ts.setLabel(literalExpression("Label"));
1145:                ts.setFonts(new Font[] { createFont("Lucida Sans", 10) });
1146:
1147:                return ts;
1148:            }
1149:
1150:            /**
1151:             * create a textsymbolizer
1152:             *
1153:             * @param color the color of the text
1154:             * @param font the font to use
1155:             * @param attributeName the attribute to use for the label
1156:             *
1157:             * @return the new textsymbolizer
1158:             *
1159:             * @throws org.geotools.filter.IllegalFilterException - if the attribute name does not exist
1160:             */
1161:            public TextSymbolizer createTextSymbolizer(Color color, Font font,
1162:                    String attributeName)
1163:                    throws org.geotools.filter.IllegalFilterException {
1164:                return createTextSymbolizer(createFill(color),
1165:                        new Font[] { font }, null,
1166:                        attributeExpression(attributeName), null, null);
1167:            }
1168:
1169:            /**
1170:             * create a textsymbolizer
1171:             *
1172:             * @param color the color of the text
1173:             * @param fonts an array of fonts to use from the first to last
1174:             * @param attributeName the attribute to use for the label
1175:             *
1176:             * @return the new textsymbolizer
1177:             *
1178:             * @throws org.geotools.filter.IllegalFilterException - if the attribute name does not exist
1179:             */
1180:            public TextSymbolizer createTextSymbolizer(Color color,
1181:                    Font[] fonts, String attributeName)
1182:                    throws org.geotools.filter.IllegalFilterException {
1183:                return createTextSymbolizer(createFill(color), fonts, null,
1184:                        attributeExpression(attributeName), null, null);
1185:            }
1186:
1187:            /**
1188:             * create a textsymbolizer which doesn't change
1189:             *
1190:             * @param color the color of the text
1191:             * @param font the font to use
1192:             * @param label the label to use
1193:             *
1194:             * @return the new textsymbolizer
1195:             */
1196:            public TextSymbolizer createStaticTextSymbolizer(Color color,
1197:                    Font font, String label) {
1198:                return createTextSymbolizer(createFill(color),
1199:                        new Font[] { font }, null, literalExpression(label),
1200:                        null, null);
1201:            }
1202:
1203:            /**
1204:             * create a textsymbolizer which doesn't change
1205:             *
1206:             * @param color the color of the text
1207:             * @param fonts an array of fonts to use from the first to last
1208:             * @param label the label to use
1209:             *
1210:             * @return the new textsymbolizer
1211:             */
1212:            public TextSymbolizer createStaticTextSymbolizer(Color color,
1213:                    Font[] fonts, String label) {
1214:                return createTextSymbolizer(createFill(color), fonts, null,
1215:                        literalExpression(label), null, null);
1216:            }
1217:
1218:            /**
1219:             * create a text symbolizer
1220:             *
1221:             * @param fill - the fill to color the text
1222:             * @param fonts - an array of fonts to use from the first to last
1223:             * @param halo - the halo to be applied to the text
1224:             * @param label - Expression representing the label
1225:             * @param labelPlacement - where to place the label
1226:             * @param geometryPropertyName - the name of the geometry to use
1227:             *
1228:             * @return the new textsymbolizer
1229:             */
1230:            public TextSymbolizer createTextSymbolizer(Fill fill, Font[] fonts,
1231:                    Halo halo, Expression label, LabelPlacement labelPlacement,
1232:                    String geometryPropertyName) {
1233:                TextSymbolizer ts = sf.createTextSymbolizer();
1234:
1235:                if (fill != null) {
1236:                    ts.setFill(fill);
1237:                }
1238:
1239:                if (halo != null) {
1240:                    ts.setHalo(halo);
1241:                }
1242:
1243:                if (label != null) {
1244:                    ts.setLabel(label);
1245:                }
1246:
1247:                if (labelPlacement != null) {
1248:                    ts.setPlacement(labelPlacement);
1249:                }
1250:
1251:                if (geometryPropertyName != null) {
1252:                    ts.setGeometryPropertyName(geometryPropertyName);
1253:                }
1254:
1255:                if (fonts != null) {
1256:                    ts.setFonts(fonts);
1257:                }
1258:
1259:                return ts;
1260:            }
1261:
1262:            /**
1263:             * create a Feature type styler
1264:             *
1265:             * @param symbolizer - the symbolizer to use
1266:             *
1267:             * @return the new feature type styler
1268:             */
1269:            public FeatureTypeStyle createFeatureTypeStyle(Symbolizer symbolizer) {
1270:                return createFeatureTypeStyle(null, symbolizer, Double.NaN,
1271:                        Double.NaN);
1272:            }
1273:
1274:            /**
1275:             * create a simple styling rule
1276:             *
1277:             * @param symbolizer - the symbolizer to use
1278:             *
1279:             * @return the new rule
1280:             */
1281:            public Rule createRule(Symbolizer symbolizer) {
1282:                return createRule(symbolizer, Double.NaN, Double.NaN);
1283:            }
1284:
1285:            /**
1286:             * reate a simple styling rule
1287:             *
1288:             * @param symbolizers - an array of symbolizers to use
1289:             *
1290:             * @return the new rule
1291:             */
1292:            public Rule createRule(Symbolizer[] symbolizers) {
1293:                return createRule(symbolizers, Double.NaN, Double.NaN);
1294:            }
1295:
1296:            /**
1297:             * create a simple styling rule, see the SLD Spec for more details of scaleDenominators
1298:             *
1299:             * @param symbolizer - the symbolizer to use
1300:             * @param minScaleDenominator - the minimim scale to draw the feature at
1301:             * @param maxScaleDenominator - the maximum scale to draw the feature at
1302:             *
1303:             * @return the new rule
1304:             */
1305:            public Rule createRule(Symbolizer symbolizer,
1306:                    double minScaleDenominator, double maxScaleDenominator) {
1307:                return createRule(new Symbolizer[] { symbolizer }, Double.NaN,
1308:                        Double.NaN);
1309:            }
1310:
1311:            /**
1312:             * create a simple styling rule, see the SLD Spec for more details of scaleDenominators
1313:             *
1314:             * @param symbolizers - an array of symbolizers to use
1315:             * @param minScaleDenominator - the minimim scale to draw the feature at
1316:             * @param maxScaleDenominator - the maximum scale to draw the feature at
1317:             *
1318:             * @return the new rule
1319:             */
1320:            public Rule createRule(Symbolizer[] symbolizers,
1321:                    double minScaleDenominator, double maxScaleDenominator) {
1322:                Rule r = sf.createRule();
1323:                r.setSymbolizers(symbolizers);
1324:
1325:                if (!Double.isNaN(maxScaleDenominator)) {
1326:                    r.setMaxScaleDenominator(maxScaleDenominator);
1327:                } else {
1328:                    r.setMaxScaleDenominator(Double.MAX_VALUE);
1329:                }
1330:
1331:                if (!Double.isNaN(minScaleDenominator)) {
1332:                    r.setMinScaleDenominator(minScaleDenominator);
1333:                } else {
1334:                    r.setMinScaleDenominator(0.0);
1335:                }
1336:
1337:                return r;
1338:            }
1339:
1340:            /**
1341:             * create a Feature type styler see the SLD Spec for more details of scaleDenominators
1342:             *
1343:             * @param symbolizer - the symbolizer to use
1344:             * @param minScaleDenominator - the minimim scale to draw the feature at
1345:             * @param maxScaleDenominator - the maximum scale to draw the feature at
1346:             *
1347:             * @return the new feature type styler
1348:             */
1349:            public FeatureTypeStyle createFeatureTypeStyle(
1350:                    Symbolizer symbolizer, double minScaleDenominator,
1351:                    double maxScaleDenominator) {
1352:                return createFeatureTypeStyle(null, symbolizer,
1353:                        minScaleDenominator, maxScaleDenominator);
1354:            }
1355:
1356:            /**
1357:             * create a Feature type styler see the SLD Spec for more details of scaleDenominators
1358:             *
1359:             * @param symbolizers - an array of symbolizers to use
1360:             * @param minScaleDenominator - the minimim scale to draw the feature at
1361:             * @param maxScaleDenominator - the maximum scale to draw the feature at
1362:             *
1363:             * @return the new feature type styler
1364:             */
1365:            public FeatureTypeStyle createFeatureTypeStyle(
1366:                    Symbolizer[] symbolizers, double minScaleDenominator,
1367:                    double maxScaleDenominator) {
1368:                return createFeatureTypeStyle(null, symbolizers,
1369:                        minScaleDenominator, maxScaleDenominator);
1370:            }
1371:
1372:            /**
1373:             * create a Feature type styler
1374:             *
1375:             * @param featureTypeName - name of the feature type
1376:             * @param symbolizer - the symbolizer to use
1377:             *
1378:             * @return the new feature type styler
1379:             */
1380:            public FeatureTypeStyle createFeatureTypeStyle(
1381:                    String featureTypeName, Symbolizer symbolizer) {
1382:                return createFeatureTypeStyle(featureTypeName, symbolizer,
1383:                        Double.NaN, Double.NaN);
1384:            }
1385:
1386:            /**
1387:             * create a Feature type styler
1388:             *
1389:             * @param featureTypeName - name of the feature type
1390:             * @param symbolizers - an array of symbolizers to use
1391:             *
1392:             * @return the new feature type styler
1393:             */
1394:            public FeatureTypeStyle createFeatureTypeStyle(
1395:                    String featureTypeName, Symbolizer[] symbolizers) {
1396:                return createFeatureTypeStyle(featureTypeName, symbolizers,
1397:                        Double.NaN, Double.NaN);
1398:            }
1399:
1400:            /**
1401:             * create a Feature type styler see the SLD Spec for more details of scaleDenominators
1402:             *
1403:             * @param typeName - The feature typeName you want to draw (use "Feature" as a wild card to match all)
1404:             * @param symbolizer - the symbolizer to use
1405:             * @param minScaleDenominator - the minimim scale to draw the feature at
1406:             * @param maxScaleDenominator - the maximum scale to draw the feature at
1407:             *
1408:             * @return the new feature type styler
1409:             */
1410:            public FeatureTypeStyle createFeatureTypeStyle(String typeName,
1411:                    Symbolizer symbolizer, double minScaleDenominator,
1412:                    double maxScaleDenominator) {
1413:                return createFeatureTypeStyle(typeName,
1414:                        new Symbolizer[] { symbolizer }, minScaleDenominator,
1415:                        maxScaleDenominator);
1416:            }
1417:
1418:            /**
1419:             * create a Feature type styler see the SLD Spec for more details of scaleDenominators
1420:             *
1421:             * @param typeName - The feature typeName you want to draw (use "Feature" as a wild card to match all)
1422:             * @param symbolizers - an array of symbolizers to use
1423:             * @param minScaleDenominator - the minimim scale to draw the feature at
1424:             * @param maxScaleDenominator - the maximum scale to draw the feature at
1425:             *
1426:             * @return the new feature type styler
1427:             */
1428:            public FeatureTypeStyle createFeatureTypeStyle(String typeName,
1429:                    Symbolizer[] symbolizers, double minScaleDenominator,
1430:                    double maxScaleDenominator) {
1431:                Rule r = createRule(symbolizers, minScaleDenominator,
1432:                        maxScaleDenominator);
1433:
1434:                // setup the feature type style
1435:                FeatureTypeStyle fts = sf.createFeatureTypeStyle();
1436:                fts.setRules(new Rule[] { r });
1437:
1438:                if (typeName != null) {
1439:                    fts.setFeatureTypeName(typeName);
1440:                }
1441:
1442:                return fts;
1443:            }
1444:
1445:            /**
1446:             * create a Feature type styler
1447:             *
1448:             * @param typeName - The feature typeName you want to draw (use "Feature" as a wild card to match all)
1449:             * @param r - the rule that driver this feature typ style
1450:             *
1451:             * @return the new feature type styler
1452:             */
1453:            public FeatureTypeStyle createFeatureTypeStyle(String typeName,
1454:                    Rule r) {
1455:                // setup the feature type style
1456:                FeatureTypeStyle fts = sf.createFeatureTypeStyle();
1457:                fts.setRules(new Rule[] { r });
1458:
1459:                if (typeName != null) {
1460:                    fts.setFeatureTypeName(typeName);
1461:                }
1462:
1463:                return fts;
1464:            }
1465:
1466:            /**
1467:             * create a Feature type styler see the SLD Spec for more details of scaleDenominators
1468:             *
1469:             * @param typeName - The feature typeName you want to draw (use "Feature" as a wild card to match all)
1470:             * @param rules - the rules that make up the FeatureTypeStyle
1471:             *
1472:             * @return the new feature type styler
1473:             */
1474:            public FeatureTypeStyle createFeatureTypeStyle(String typeName,
1475:                    Rule[] rules) {
1476:                FeatureTypeStyle fts = sf.createFeatureTypeStyle();
1477:                fts.setRules(rules);
1478:
1479:                if (typeName != null) {
1480:                    fts.setFeatureTypeName(typeName);
1481:                }
1482:
1483:                return fts;
1484:            }
1485:
1486:            /**
1487:             * create a new style
1488:             *
1489:             * @param symbolizer - the symbolizer to use
1490:             *
1491:             * @return the new style
1492:             */
1493:            public Style createStyle(Symbolizer symbolizer) {
1494:                return createStyle(null, symbolizer, Double.NaN, Double.NaN);
1495:            }
1496:
1497:            /**
1498:             * create a new style
1499:             *
1500:             * @param symbolizer - the symbolizer to use
1501:             * @param minScaleDenominator - the minimim scale to draw the feature at
1502:             * @param maxScaleDenominator - the maximum scale to draw the feature at
1503:             *
1504:             * @return the new style
1505:             */
1506:            public Style createStyle(Symbolizer symbolizer,
1507:                    double minScaleDenominator, double maxScaleDenominator) {
1508:                return createStyle(null, symbolizer, minScaleDenominator,
1509:                        maxScaleDenominator);
1510:            }
1511:
1512:            /**
1513:             * create a new style
1514:             *
1515:             * @param typeName - The feature typeName you want to draw (use "Feature" as a wild card to match all)
1516:             * @param symbolizer - the symbolizer to use
1517:             *
1518:             * @return the new style
1519:             */
1520:            public Style createStyle(String typeName, Symbolizer symbolizer) {
1521:                return createStyle(typeName, symbolizer, Double.NaN, Double.NaN);
1522:            }
1523:
1524:            /**
1525:             * create a new style
1526:             *
1527:             * @param typeName - The feature typeName you want to draw (use "Feature" as a wild card to match all)
1528:             * @param symbolizer - the symbolizer to use
1529:             * @param minScaleDenominator - the minimim scale to draw the feature at
1530:             * @param maxScaleDenominator - the maximum scale to draw the feature at
1531:             *
1532:             * @return the new style
1533:             */
1534:            public Style createStyle(String typeName, Symbolizer symbolizer,
1535:                    double minScaleDenominator, double maxScaleDenominator) {
1536:                // create the feature type style
1537:                FeatureTypeStyle fts = createFeatureTypeStyle(typeName,
1538:                        symbolizer, minScaleDenominator, maxScaleDenominator);
1539:
1540:                // and finally create the style
1541:                Style style = sf.createStyle();
1542:                style.addFeatureTypeStyle(fts);
1543:
1544:                return style;
1545:            }
1546:
1547:            /**
1548:             * create a new default style
1549:             *
1550:             * @return the new style
1551:             */
1552:            public Style createStyle() {
1553:                return sf.createStyle();
1554:            }
1555:
1556:            /**
1557:             * convert an awt color in to a literal expression representing the color
1558:             *
1559:             * @param color the color to encode
1560:             *
1561:             * @return the expression
1562:             */
1563:            public Expression colorExpression(Color color) {
1564:                if (color == null) {
1565:                    return null;
1566:                }
1567:
1568:                String redCode = Integer.toHexString(color.getRed());
1569:                String greenCode = Integer.toHexString(color.getGreen());
1570:                String blueCode = Integer.toHexString(color.getBlue());
1571:
1572:                if (redCode.length() == 1) {
1573:                    redCode = "0" + redCode;
1574:                }
1575:
1576:                if (greenCode.length() == 1) {
1577:                    greenCode = "0" + greenCode;
1578:                }
1579:
1580:                if (blueCode.length() == 1) {
1581:                    blueCode = "0" + blueCode;
1582:                }
1583:
1584:                String colorCode = "#" + redCode + greenCode + blueCode;
1585:
1586:                return ff.literal(colorCode.toUpperCase());
1587:            }
1588:
1589:            /**
1590:             * create a literal expression representing the value
1591:             *
1592:             * @param value the value to be encoded
1593:             *
1594:             * @return the expression
1595:             */
1596:            public Expression literalExpression(double value) {
1597:                return ff.literal(value);
1598:            }
1599:
1600:            /**
1601:             * create a literal expression representing the value
1602:             *
1603:             * @param value the value to be encoded
1604:             *
1605:             * @return the expression
1606:             */
1607:            public Expression literalExpression(int value) {
1608:                return ff.literal(value);
1609:            }
1610:
1611:            /**
1612:             * create a literal expression representing the value
1613:             *
1614:             * @param value the value to be encoded
1615:             *
1616:             * @return the expression
1617:             */
1618:            public Expression literalExpression(String value) {
1619:                Expression result = null;
1620:
1621:                if (value != null) {
1622:                    result = ff.literal(value);
1623:                }
1624:
1625:                return result;
1626:            }
1627:
1628:            /**
1629:             * create a literal expression representing the value
1630:             *
1631:             * @param value the value to be encoded
1632:             *
1633:             * @return the expression
1634:             *
1635:             * @throws IllegalFilterException DOCUMENT ME!
1636:             */
1637:            public Expression literalExpression(Object value)
1638:                    throws IllegalFilterException {
1639:                Expression result = null;
1640:
1641:                if (value != null) {
1642:                    result = ff.literal(value);
1643:                }
1644:
1645:                return result;
1646:            }
1647:
1648:            /**
1649:             * create an attribute expression
1650:             *
1651:             * @param attributeName the attribute to use
1652:             *
1653:             * @return the new expression
1654:             *
1655:             * @throws org.geotools.filter.IllegalFilterException if the attribute name does not exist
1656:             */
1657:            public Expression attributeExpression(String attributeName)
1658:                    throws org.geotools.filter.IllegalFilterException {
1659:                return ff.property(attributeName);
1660:            }
1661:
1662:            /**
1663:             * given a feature collection and an array of colours build a style  with the given number of
1664:             * classes on the named column
1665:             *
1666:             * @param fc DOCUMENT ME!
1667:             * @param name DOCUMENT ME!
1668:             * @param colors DOCUMENT ME!
1669:             * @param schema DOCUMENT ME!
1670:             *
1671:             * @return DOCUMENT ME!
1672:             *
1673:             * @throws IllegalFilterException DOCUMENT ME!
1674:             */
1675:            public Style buildClassifiedStyle(FeatureCollection fc,
1676:                    String name, String[] colors, FeatureType schema)
1677:                    throws IllegalFilterException {
1678:                //grab attribute col
1679:                PropertyName value = ff.property(name);
1680:                String geomName = schema.getDefaultGeometry().getName();
1681:
1682:                double[] values = new double[fc.size()];
1683:                Iterator it = fc.iterator();
1684:                int count = 0;
1685:
1686:                while (it.hasNext()) {
1687:                    Feature f = (Feature) it.next();
1688:                    values[count++] = ((Number) f.getAttribute(name))
1689:                            .doubleValue();
1690:                }
1691:
1692:                //pass to classification algorithm
1693:                EqualClasses ec = new EqualClasses(colors.length, values);
1694:
1695:                //build style
1696:                double[] breaks = ec.getBreaks();
1697:                Style ret = createStyle();
1698:
1699:                //        ret.setName(name);
1700:                Rule[] rules = new Rule[colors.length + 1];
1701:
1702:                PropertyIsLessThan cf1 = ff.less(value, ff.literal(breaks[0]));
1703:
1704:                LOGGER.fine(cf1.toString());
1705:                rules[0] = sf.createRule();
1706:                rules[0].setFilter(cf1);
1707:
1708:                //        rules[0].setName("lowest");
1709:                Color c = this .createColor(colors[0]);
1710:                PolygonSymbolizer symb1 = createPolygonSymbolizer(c,
1711:                        Color.black, 1.0);
1712:
1713:                //@todo: this should set the geometry name but currently this breaks the legend
1714:                //        symb1.setGeometryPropertyName(geomName);
1715:                rules[0].setSymbolizers(new Symbolizer[] { symb1 });
1716:                LOGGER.fine("added low class " + breaks[0] + " " + colors[0]);
1717:
1718:                //        LOGGER.fine(rules[0].toString());
1719:                for (int i = 1; i < (colors.length - 1); i++) {
1720:                    rules[i] = sf.createRule();
1721:
1722:                    Expression expr = value;
1723:                    Expression lower = ff.literal(breaks[i - 1]);
1724:                    Expression upper = ff.literal(breaks[i]);
1725:                    PropertyIsBetween cf = ff.between(expr, lower, upper);
1726:
1727:                    LOGGER.fine(cf.toString());
1728:                    c = this .createColor(colors[i]);
1729:                    LOGGER.fine("color " + c.toString());
1730:
1731:                    PolygonSymbolizer symb = createPolygonSymbolizer(c,
1732:                            Color.black, 1.0);
1733:
1734:                    //            symb.setGeometryPropertyName(geomName);
1735:                    rules[i].setSymbolizers(new Symbolizer[] { symb });
1736:                    rules[i].setFilter(cf);
1737:
1738:                    //            rules[i].setName("class "+i);
1739:                    LOGGER.fine("added class " + breaks[i - 1] + "->"
1740:                            + breaks[i] + " " + colors[i]);
1741:                }
1742:
1743:                PropertyIsGreaterThan cf2 = ff.greater(value, ff
1744:                        .literal(breaks[colors.length - 2]));
1745:
1746:                LOGGER.fine(cf2.toString());
1747:                rules[colors.length - 1] = sf.createRule();
1748:                rules[colors.length - 1].setFilter(cf2);
1749:                rules[colors.length - 1].setName(geomName);
1750:                c = this .createColor(colors[colors.length - 1]);
1751:
1752:                PolygonSymbolizer symb2 = createPolygonSymbolizer(c,
1753:                        Color.black, 1.0);
1754:
1755:                //        symb2.setGeometryPropertyName(geomName);
1756:                rules[colors.length - 1]
1757:                        .setSymbolizers(new Symbolizer[] { symb2 });
1758:                LOGGER.fine("added upper class " + breaks[colors.length - 2]
1759:                        + "  " + colors[colors.length - 1]);
1760:                rules[colors.length] = sf.createRule();
1761:
1762:                PolygonSymbolizer elsePoly = createPolygonSymbolizer(
1763:                        Color.black, 1.0);
1764:                rules[colors.length]
1765:                        .setSymbolizers(new Symbolizer[] { elsePoly });
1766:                rules[colors.length].setIsElseFilter(true);
1767:
1768:                FeatureTypeStyle ft = sf.createFeatureTypeStyle(rules);
1769:                ft.setFeatureTypeName("feature");
1770:                ft.setName(name);
1771:                ret.addFeatureTypeStyle(ft);
1772:
1773:                return ret;
1774:            }
1775:
1776:            private Color createColor(String text) {
1777:                int i = Integer.decode("0x" + text).intValue();
1778:
1779:                return Color.decode("" + i);
1780:            }
1781:
1782:            /**
1783:             * Creates the default raster symbolizer
1784:             */
1785:            public RasterSymbolizer createRasterSymbolizer() {
1786:                return sf.getDefaultRasterSymbolizer();
1787:            }
1788:
1789:            /**
1790:             * Creates a raster symbolizer
1791:             * @param colorMap The symbolizer color map
1792:             * @param opacity The whole layer opacity
1793:             *  
1794:             */
1795:            public RasterSymbolizer createRasterSymbolizer(ColorMap colorMap,
1796:                    double opacity) {
1797:                RasterSymbolizer rs = sf.getDefaultRasterSymbolizer();
1798:                rs.setColorMap(colorMap);
1799:                rs.setOpacity(literalExpression(opacity));
1800:
1801:                return rs;
1802:            }
1803:
1804:            /**
1805:             * Creates a color map based on fixed quantities and colors.
1806:             * @param quantities The values that begin a category, or break points in a ramp, 
1807:             *        or isolated values, according to the type of color map specified by Type 
1808:             * @param colors The colors that will be associated to the categories, break points, or isolated values 
1809:             * @param type Either @link ColorMap#TYPE_RAMP, @link ColorMap#TYPE_INTERVALS or @link ColorMap#TYPE_VALUES   
1810:             */
1811:            public ColorMap createColorMap(String[] labels,
1812:                    double[] quantities, Color[] colors, int type) {
1813:                ColorMap colorMap = sf.createColorMap();
1814:                colorMap.setType(type);
1815:
1816:                if ((labels == null) || (quantities == null)
1817:                        || (colors == null)
1818:                        || (labels.length != quantities.length)
1819:                        || (quantities.length != colors.length)) {
1820:                    throw new IllegalArgumentException(
1821:                            "Labels, quantities and colors arrays should be not null and have the same size");
1822:                }
1823:
1824:                for (int i = 0; i < colors.length; i++) {
1825:                    colorMap.addColorMapEntry(createColorMapEntry(labels[i],
1826:                            quantities[i], colors[i]));
1827:                }
1828:
1829:                return colorMap;
1830:            }
1831:
1832:            /**
1833:             * Creates a simple color entity based on a fixed value and a color.<br>
1834:             * The color alpha will be used as the entry's opacity
1835:             * @param quantity The entry's quantity
1836:             * @param color The entry's color. 
1837:             */
1838:            private ColorMapEntry createColorMapEntry(String label,
1839:                    double quantity, Color color) {
1840:                ColorMapEntry entry = sf.createColorMapEntry();
1841:                entry.setQuantity(literalExpression(quantity));
1842:                entry.setColor(colorExpression(color));
1843:                entry.setOpacity(literalExpression(color.getAlpha() / 255.0));
1844:                entry.setLabel(label);
1845:                return entry;
1846:            }
1847:
1848:            public class EqualClasses {
1849:                int numberClasses;
1850:                double[] breaks;
1851:                double[] collection;
1852:
1853:                /**
1854:                 * Creates a new instance of EqualClasses
1855:                 *  
1856:                 * @param numberClasses 
1857:                 * @param fc
1858:                 */
1859:                public EqualClasses(int numberClasses, double[] fc) {
1860:
1861:                    breaks = new double[numberClasses - 1];
1862:                    setCollection(fc);
1863:                    setNumberClasses(numberClasses);
1864:
1865:                }
1866:
1867:                /** Getter for property numberClasses.
1868:                 * @return Value of property numberClasses.
1869:                 *
1870:                 */
1871:                public int getNumberClasses() {
1872:                    return numberClasses;
1873:                }
1874:
1875:                /** Setter for property numberClasses.
1876:                 * @param numberClasses New value of property numberClasses.
1877:                 *
1878:                 */
1879:                public void setNumberClasses(int numberClasses) {
1880:                    this .numberClasses = numberClasses;
1881:                    if (breaks == null) {
1882:                        breaks = new double[numberClasses - 1];
1883:                    }
1884:
1885:                    Arrays.sort(collection);
1886:
1887:                    int step = collection.length / numberClasses;
1888:                    for (int i = step, j = 0; j < breaks.length; j++, i += step) {
1889:                        breaks[j] = collection[i];
1890:                    }
1891:                }
1892:
1893:                /** 
1894:                 * returns the the break points between the classes
1895:                 * <b>Note</b> You get one less breaks than number of classes.
1896:                 * @return Value of property breaks.
1897:                 *
1898:                 */
1899:                public double[] getBreaks() {
1900:                    return this .breaks;
1901:                }
1902:
1903:                /** Setter for property collection.
1904:                 * @param collection New value of property collection.
1905:                 *
1906:                 */
1907:                public void setCollection(double[] collection) {
1908:                    this.collection = collection;
1909:                }
1910:
1911:            }
1912:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.