]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/G2DRenderingHints.java
Render elements using custom color filters
[simantics/platform.git] / bundles / org.simantics.scenegraph / src / org / simantics / scenegraph / g2d / G2DRenderingHints.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.scenegraph.g2d;
13
14 import java.awt.Component;
15 import java.awt.geom.AffineTransform;
16 import java.awt.geom.Rectangle2D;
17 import java.util.Map;
18
19 import org.simantics.scenegraph.g2d.color.ColorFilter;
20
21 /**
22  * @author Tuukka Lehtonen
23  * See {@link G2DPDFRenderingHints}
24  */
25 public final class G2DRenderingHints {
26
27     public static final Key KEY_BEGIN_ELEMENT = new G2DRenderingHints.Key(0);
28     public static final Key KEY_END_ELEMENT = new G2DRenderingHints.Key(1);
29     public static final Key KEY_ELEMENT_ID = new G2DRenderingHints.Key(2);
30
31     public static class Key extends java.awt.RenderingHints.Key {
32
33         public Key(int privateKey) {
34             super(privateKey);    
35         }
36     
37         @Override
38         public boolean isCompatibleValue(Object val) {
39             switch (intKey()) {
40                 case 0:
41                     return val == null || val instanceof String 
42                             || val instanceof Map;
43                 case 1:
44                     return val == null || val instanceof Object;
45                 case 2:
46                     return val == null || val instanceof Object;
47                 default:
48                     throw new RuntimeException("Not possible!");
49             }
50         }
51     }
52         
53     /**
54      * A rendering hint for storing the boundaries of the control area within a
55      * Graphics2D instance.
56      */
57     public static final Key KEY_CONTROL_BOUNDS = new Key(1000) {
58         @Override
59         public boolean isCompatibleValue(Object val) {
60             return val instanceof Rectangle2D;
61         }
62     };
63
64     /**
65      * A rendering hint for storing the root AWT Component on which the scene
66      * graph is rendered within a Graphics2D instance.
67      */
68     public static final Key KEY_COMPONENT      = new Key(1001) {
69         @Override
70         public boolean isCompatibleValue(Object val) {
71             return val instanceof Component;
72         }
73     };
74
75     /**
76      * If this hint is not specified, the default interpretation should be
77      * {@value #AS_PATHS}.
78      * 
79      * @since 1.31.0
80      */
81     public static enum TextRenderingMode {
82         AS_PATHS,
83         AS_TEXT
84     }
85
86     /**
87      * A rendering hint for telling text rendering Simantics G2D scene graph node
88      * implementations how to render the text: as text or paths.
89      * 
90      * @since 1.31.0
91      */
92     public static final Key KEY_TEXT_RENDERING_MODE = new Key(2004) {
93         @Override
94         public boolean isCompatibleValue(Object val) {
95             return val instanceof TextRenderingMode;
96         }
97     };
98
99     /**
100      * Instead of rendering SVGNode using SVG Salamander pass it to G2D as SVGPassthruShape in String format.
101      * 
102      * @since 1.31.0
103      */
104     public static final Key KEY_SVG_PASSTHRU = new Key(2005) {
105         @Override
106         public boolean isCompatibleValue(Object val) {
107             return val instanceof Boolean;
108         }
109     };
110
111     /**
112      * The current Graphics2D AffineTransform for all nodes under the special
113      * spatialRoot : RTreeNode.
114      * 
115      * This can be used to optimize the creation and of new AffineTransforms by
116      * not having to use Graphics2D.getTransform to retrieve the current
117      * transformation which always creates new instances.
118      */
119     public static final Key KEY_TRANSFORM_UNDER_SPATIAL_ROOT = new Key(2006) {
120         @Override
121         public boolean isCompatibleValue(Object val) {
122             return val instanceof AffineTransform || val == null;
123         }
124     };
125
126     /*
127      * A rendering hint for storing the active ColorFilter which can be used e.g. 
128      * for coloring BufferedImages.  
129      */
130     public static final Key KEY_COLOR_FILTER = new Key(2007) {
131         @Override
132         public boolean isCompatibleValue(Object val) {
133             return val instanceof ColorFilter || val == null;
134         }
135     };
136
137 }