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 @ 40559
History | View | Annotate | Download (3.4 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.awt.image.WritableRaster; |
||
32 | import java.util.prefs.Preferences; |
||
33 | |||
34 | import org.gvsig.compat.lang.GraphicsUtils; |
||
35 | import org.gvsig.compat.print.PrintAttributes; |
||
36 | import org.gvsig.compat.se.print.SePrintAttributes; |
||
37 | |||
38 | /**
|
||
39 | * JSE (Desktop Java) implementation of {@link GraphicsUtils}
|
||
40 | *
|
||
41 | * @author Juan Lucas Dominguez Rubio jldominguez at prodevelop.es
|
||
42 | *
|
||
43 | * @see GraphicsUtils
|
||
44 | *
|
||
45 | */
|
||
46 | public class SEGraphUtils implements GraphicsUtils{ |
||
47 | |||
48 | public BufferedImage copyBufferedImage(BufferedImage img) { |
||
49 | |||
50 | BufferedImage image = new BufferedImage(img.getWidth(), img.getHeight(), img.getType()); |
||
51 | WritableRaster w = image.getRaster();
|
||
52 | img.copyData(w); |
||
53 | return image;
|
||
54 | } |
||
55 | |||
56 | public BufferedImage createBufferedImage(int w, int h, int type) { |
||
57 | BufferedImage res = new BufferedImage( |
||
58 | w, |
||
59 | h, |
||
60 | type); |
||
61 | return res;
|
||
62 | } |
||
63 | |||
64 | public PrintAttributes createPrintAttributes() {
|
||
65 | return new SePrintAttributes(); |
||
66 | } |
||
67 | |||
68 | public Font deriveFont(Font srcfont, float newheight) { |
||
69 | return srcfont.deriveFont(newheight);
|
||
70 | } |
||
71 | |||
72 | /**
|
||
73 | * Tries to use DPI value from gvSIG preferences. If this does not exist, gets
|
||
74 | * value from Java Toolkit.
|
||
75 | */
|
||
76 | public int getScreenDPI() { |
||
77 | |||
78 | Preferences prefsResolution = Preferences.userRoot().node("gvsig.configuration.screen"); |
||
79 | Toolkit kit = Toolkit.getDefaultToolkit(); |
||
80 | int dpi = prefsResolution.getInt("dpi", kit.getScreenResolution()); |
||
81 | return dpi;
|
||
82 | } |
||
83 | |||
84 | public void translate(Graphics2D g, double x, double y) { |
||
85 | g.translate(x, y); |
||
86 | |||
87 | } |
||
88 | |||
89 | public void setRenderingHintsForDrawing(Graphics2D g) { |
||
90 | |||
91 | RenderingHints renderHints = new RenderingHints( |
||
92 | RenderingHints.KEY_ANTIALIASING,
|
||
93 | RenderingHints.VALUE_ANTIALIAS_ON);
|
||
94 | renderHints.put(RenderingHints.KEY_RENDERING,
|
||
95 | RenderingHints.VALUE_RENDER_QUALITY);
|
||
96 | renderHints.put(RenderingHints.KEY_TEXT_ANTIALIASING,
|
||
97 | RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||
98 | g.setRenderingHints(renderHints); |
||
99 | |||
100 | } |
||
101 | |||
102 | public void setRenderingHintsForPrinting(Graphics2D g) { |
||
103 | |||
104 | RenderingHints renderHints = new RenderingHints( |
||
105 | RenderingHints.KEY_ANTIALIASING,
|
||
106 | RenderingHints.VALUE_ANTIALIAS_ON);
|
||
107 | renderHints.put(RenderingHints.KEY_RENDERING,
|
||
108 | RenderingHints.VALUE_RENDER_QUALITY);
|
||
109 | g.setRenderingHints(renderHints); |
||
110 | |||
111 | } |
||
112 | |||
113 | } |