]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/G2DRenderingHints.java
G2DParentNode handles "undefined" child bounds separately
[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 /**
20  * @author Tuukka Lehtonen
21  * See {@link G2DPDFRenderingHints}
22  */
23 public final class G2DRenderingHints {
24
25     public static final Key KEY_BEGIN_ELEMENT = new G2DRenderingHints.Key(0);
26     public static final Key KEY_END_ELEMENT = new G2DRenderingHints.Key(1);
27     public static final Key KEY_ELEMENT_ID = new G2DRenderingHints.Key(2);
28
29     public static class Key extends java.awt.RenderingHints.Key {
30
31         public Key(int privateKey) {
32             super(privateKey);    
33         }
34     
35         @Override
36         public boolean isCompatibleValue(Object val) {
37             switch (intKey()) {
38                 case 0:
39                     return val == null || val instanceof String 
40                             || val instanceof Map;
41                 case 1:
42                     return val == null || val instanceof Object;
43                 case 2:
44                     return val == null || val instanceof Object;
45                 default:
46                     throw new RuntimeException("Not possible!");
47             }
48         }
49     }
50         
51     /**
52      * A rendering hint for storing the boundaries of the control area within a
53      * Graphics2D instance.
54      */
55     public static final Key KEY_CONTROL_BOUNDS = new Key(1000) {
56         @Override
57         public boolean isCompatibleValue(Object val) {
58             return val instanceof Rectangle2D;
59         }
60     };
61
62     /**
63      * A rendering hint for storing the root AWT Component on which the scene
64      * graph is rendered within a Graphics2D instance.
65      */
66     public static final Key KEY_COMPONENT      = new Key(1001) {
67         @Override
68         public boolean isCompatibleValue(Object val) {
69             return val instanceof Component;
70         }
71     };
72
73     /**
74      * If this hint is not specified, the default interpretation should be
75      * {@value #AS_PATHS}.
76      * 
77      * @since 1.31.0
78      */
79     public static enum TextRenderingMode {
80         AS_PATHS,
81         AS_TEXT
82     }
83
84     /**
85      * A rendering hint for telling text rendering Simantics G2D scene graph node
86      * implementations how to render the text: as text or paths.
87      * 
88      * @since 1.31.0
89      */
90     public static final Key KEY_TEXT_RENDERING_MODE = new Key(2004) {
91         @Override
92         public boolean isCompatibleValue(Object val) {
93             return val instanceof TextRenderingMode;
94         }
95     };
96
97     /**
98      * Instead of rendering SVGNode using SVG Salamander pass it to G2D as SVGPassthruShape in String format.
99      * 
100      * @since 1.31.0
101      */
102     public static final Key KEY_SVG_PASSTHRU = new Key(2005) {
103         @Override
104         public boolean isCompatibleValue(Object val) {
105             return val instanceof Boolean;
106         }
107     };
108
109     /**
110      * The current Graphics2D AffineTransform for all nodes under the special
111      * spatialRoot : RTreeNode.
112      * 
113      * This can be used to optimize the creation and of new AffineTransforms by
114      * not having to use Graphics2D.getTransform to retrieve the current
115      * transformation which always creates new instances.
116      */
117     public static final Key KEY_TRANSFORM_UNDER_SPATIAL_ROOT = new Key(2006) {
118         @Override
119         public boolean isCompatibleValue(Object val) {
120             return val instanceof AffineTransform || val == null;
121         }
122     };
123
124 }