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 |
/**
|
---|---|
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 |
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 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
37 |
|
38 |
/**
|
39 |
* JSE (Desktop Java) implementation of {@link GraphicsUtils}
|
40 |
*
|
41 |
* @see GraphicsUtils
|
42 |
*
|
43 |
*/
|
44 |
public class SEGraphUtils implements GraphicsUtils{ |
45 |
|
46 |
@Override
|
47 |
public BufferedImage copyBufferedImage(BufferedImage img) { |
48 |
BufferedImage newImage =
|
49 |
ToolsSwingLocator.getToolsSwingManager() |
50 |
.copyBufferedImage(img); |
51 |
return newImage;
|
52 |
} |
53 |
|
54 |
public BufferedImage createBufferedImage(int w, int h, int type) { |
55 |
return ToolsSwingLocator.getToolsSwingManager().createBufferedImage(w, h, type);
|
56 |
} |
57 |
|
58 |
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 |
* value from Java Toolkit.
|
69 |
*/
|
70 |
public int getScreenDPI() { |
71 |
|
72 |
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 |
|
81 |
} |
82 |
|
83 |
public void setRenderingHintsForDrawing(Graphics2D g) { |
84 |
|
85 |
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 |
|
94 |
} |
95 |
|
96 |
public void setRenderingHintsForPrinting(Graphics2D g) { |
97 |
|
98 |
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 |
|
105 |
} |
106 |
|
107 |
} |