Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.compat / org.gvsig.compat.se / src / main / java / org / gvsig / compat / se / lang / SEGraphUtils.java @ 43235

History | View | Annotate | Download (3.34 KB)

1 40559 jjdelcerro
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24 40435 jjdelcerro
package org.gvsig.compat.se.lang;
25
26
import java.awt.Font;
27
import java.awt.Graphics2D;
28
import java.awt.RenderingHints;
29
import java.awt.Toolkit;
30
import java.awt.image.BufferedImage;
31
import java.util.prefs.Preferences;
32
33
import org.gvsig.compat.lang.GraphicsUtils;
34
import org.gvsig.compat.print.PrintAttributes;
35
import org.gvsig.compat.se.print.SePrintAttributes;
36 43228 fdiaz
import org.gvsig.tools.swing.api.ToolsSwingLocator;
37 40435 jjdelcerro
38
/**
39
 * JSE (Desktop Java) implementation of {@link GraphicsUtils}
40 43228 fdiaz
 *
41 40435 jjdelcerro
 * @see GraphicsUtils
42
 *
43
 */
44
public class SEGraphUtils implements GraphicsUtils{
45
46 43230 jjdelcerro
    @Override
47 43228 fdiaz
    public BufferedImage copyBufferedImage(BufferedImage img) {
48
        BufferedImage newImage =
49
            ToolsSwingLocator.getToolsSwingManager()
50
                .copyBufferedImage(img);
51
        return newImage;
52
    }
53 40435 jjdelcerro
54 43230 jjdelcerro
    public BufferedImage createBufferedImage(int w, int h, int type) {
55 43235 fdiaz
        return ToolsSwingLocator.getToolsSwingManager().createBufferedImage(w, h, type);
56 43230 jjdelcerro
        }
57
58 40435 jjdelcerro
        public PrintAttributes createPrintAttributes() {
59
                return new SePrintAttributes();
60
        }
61
62
        public Font deriveFont(Font srcfont, float newheight) {
63
                return srcfont.deriveFont(newheight);
64
        }
65
66
        /**
67
         * Tries to use DPI value from gvSIG preferences. If this does not exist, gets
68 43228 fdiaz
         * value from Java Toolkit.
69 40435 jjdelcerro
         */
70
        public int getScreenDPI() {
71 43228 fdiaz
72 40435 jjdelcerro
                Preferences prefsResolution = Preferences.userRoot().node("gvsig.configuration.screen");
73
                Toolkit kit = Toolkit.getDefaultToolkit();
74
                int dpi = prefsResolution.getInt("dpi", kit.getScreenResolution());
75
                return dpi;
76
        }
77
78
        public void translate(Graphics2D g, double x, double y) {
79
                g.translate(x, y);
80 43228 fdiaz
81 40435 jjdelcerro
        }
82
83
        public void setRenderingHintsForDrawing(Graphics2D g) {
84 43228 fdiaz
85 40435 jjdelcerro
                RenderingHints renderHints = new RenderingHints(
86
                                RenderingHints.KEY_ANTIALIASING,
87
                                RenderingHints.VALUE_ANTIALIAS_ON);
88
                renderHints.put(RenderingHints.KEY_RENDERING,
89
                                RenderingHints.VALUE_RENDER_QUALITY);
90
                renderHints.put(RenderingHints.KEY_TEXT_ANTIALIASING,
91
                                RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
92
                g.setRenderingHints(renderHints);
93 43228 fdiaz
94 40435 jjdelcerro
        }
95
96
        public void setRenderingHintsForPrinting(Graphics2D g) {
97 43228 fdiaz
98 40435 jjdelcerro
                RenderingHints renderHints = new RenderingHints(
99
                                RenderingHints.KEY_ANTIALIASING,
100
                                RenderingHints.VALUE_ANTIALIAS_ON);
101
                renderHints.put(RenderingHints.KEY_RENDERING,
102
                                RenderingHints.VALUE_RENDER_QUALITY);
103
                g.setRenderingHints(renderHints);
104 43228 fdiaz
105 40435 jjdelcerro
        }
106
107
}