]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/utils/QualityHints.java
G2DParentNode handles "undefined" child bounds separately
[simantics/platform.git] / bundles / org.simantics.scenegraph / src / org / simantics / scenegraph / utils / QualityHints.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.utils;
13
14 import java.awt.Graphics2D;
15 import java.awt.RenderingHints;
16
17 /**
18  * Rendering quality hints
19  * 
20  * @author Toni Kalajainen
21  */
22 public class QualityHints {
23
24     public static final QualityHints HIGH_QUALITY_HINTS =
25         new QualityHints(RenderingHints.VALUE_RENDER_QUALITY,
26                 RenderingHints.VALUE_ANTIALIAS_ON,
27                 RenderingHints.VALUE_TEXT_ANTIALIAS_ON,
28                 RenderingHints.VALUE_INTERPOLATION_BICUBIC);
29
30     public static final QualityHints GOOD_QUALITY_HINTS =
31         new QualityHints(RenderingHints.VALUE_RENDER_DEFAULT,
32                 RenderingHints.VALUE_ANTIALIAS_ON,
33                 RenderingHints.VALUE_TEXT_ANTIALIAS_ON,
34                 RenderingHints.VALUE_INTERPOLATION_BILINEAR);
35
36     public static final QualityHints LOW_QUALITY_HINTS =
37         new QualityHints(RenderingHints.VALUE_RENDER_SPEED,
38                 RenderingHints.VALUE_ANTIALIAS_OFF,
39                 RenderingHints.VALUE_TEXT_ANTIALIAS_OFF,
40                 RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
41
42     public static QualityHints getHints(Quality forQuality) {
43         if (forQuality == null)
44             return null;
45         switch (forQuality) {
46             case GOOD: return GOOD_QUALITY_HINTS;
47             case HIGH: return HIGH_QUALITY_HINTS;
48             case LOW: return LOW_QUALITY_HINTS;
49             default: return HIGH_QUALITY_HINTS;
50         }
51     }
52
53     public final Object rendering;
54     public final Object antialiasing;
55     public final Object textAntiAliasing;
56     public final Object interpolation;
57
58     public QualityHints(Object rendering, Object antialiasing, Object textAntiAliasing, Object interpolation) {
59         this.rendering = rendering;
60         this.antialiasing = antialiasing;
61         this.textAntiAliasing = textAntiAliasing;
62         this.interpolation = interpolation;
63     }
64
65     public void setQuality(Graphics2D g) {
66         if (rendering!=null)
67             g.setRenderingHint(RenderingHints.KEY_RENDERING, rendering);
68         if (antialiasing!=null)
69             g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, antialiasing);
70         if (textAntiAliasing!=null)
71             g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, textAntiAliasing);
72         if (interpolation!=null)
73             g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, interpolation);
74     }
75
76     public static QualityHints getQuality(Graphics2D g) {
77         return new QualityHints(
78                 g.getRenderingHint(RenderingHints.KEY_RENDERING),
79                 g.getRenderingHint(RenderingHints.KEY_ANTIALIASING),
80                 g.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING),
81                 g.getRenderingHint(RenderingHints.KEY_INTERPOLATION)
82         );
83     }
84
85 }