1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.scenegraph.utils;
14 import java.awt.Graphics2D;
15 import java.awt.RenderingHints;
18 * Rendering quality hints
20 * @author Toni Kalajainen
22 public class QualityHints {
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);
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);
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);
42 public static QualityHints getHints(Quality forQuality) {
43 if (forQuality == null)
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;
53 public final Object rendering;
54 public final Object antialiasing;
55 public final Object textAntiAliasing;
56 public final Object interpolation;
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;
65 public void setQuality(Graphics2D g) {
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);
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)