-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathJSGraphicsEnvironment.java
More file actions
75 lines (60 loc) · 1.86 KB
/
Copy pathJSGraphicsEnvironment.java
File metadata and controls
75 lines (60 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package swingjs;
import java.awt.Dimension;
import java.awt.Toolkit;
import jsjava.awt.Color;
import jsjava.awt.Font;
import jsjava.awt.Graphics2D;
import jsjava.awt.GraphicsDevice;
import jsjava.awt.GraphicsEnvironment;
import jsjava.awt.Point;
import jsjava.awt.Transparency;
import jsjava.awt.image.BufferedImage;
import jsjava.util.Locale;
public class JSGraphicsEnvironment extends GraphicsEnvironment {
private static GraphicsDevice device;
/*
* NOTE: This class is called from jsjava.awt.GraphicsEnvironment
* within in j2sNative block.
*
*/
public JSGraphicsEnvironment(){
System.out.println("JSGraphicsEnvironment initialized");
}
@Override
public Graphics2D createGraphics(BufferedImage img) {
Graphics2D g = (Graphics2D) img.getImageGraphic().create();
//if (img.getTransparency() == Transparency.OPAQUE)
//g.setBackground(Color.WHITE);
return g;
}
private static Font[] availableFonts;
@Override
public Font[] getAllFonts() {
if (availableFonts == null) {
String[] names = getAvailableFontFamilyNames();
availableFonts = new Font[names.length];
for (int i = names.length; --i >= 0;)
availableFonts[i] = new Font(names[i], Font.PLAIN, 1);
}
return availableFonts;
}
@Override
public String[] getAvailableFontFamilyNames() {
return Toolkit.getDefaultToolkit().getFontList();
}
@Override
public String[] getAvailableFontFamilyNames(Locale l) {
return Toolkit.getDefaultToolkit().getFontList();
}
@Override
public GraphicsDevice getDefaultScreenDevice() {
if (device == null)
device = (GraphicsDevice) JSToolkit.getInstance("swingjs.JSScreenDevice");
return device;
}
@Override
public Point getCenterPoint() {
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
return new Point(d.width / 2, d.height / 2);
}
}