-
Notifications
You must be signed in to change notification settings - Fork 0
/
PLPRuntimeFrame.java
160 lines (132 loc) · 3.91 KB
/
PLPRuntimeFrame.java
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package cop5556sp17;
import java.awt.Component;
import java.awt.Container;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.lang.reflect.InvocationTargetException;
//import cop5555.runtime.Image;
import javax.swing.*;
@SuppressWarnings("serial")
public class PLPRuntimeFrame extends JFrame {
static StringBuilder log;
public static void setLog(StringBuilder log){
PLPRuntimeFrame.log = log;
};
private ImageIcon icon;
BufferedImage image;
boolean verbose = true;
static Component last = null;
public final static String JVMClassName = "cop5556sp17/PLPRuntimeFrame";
public final static String JVMDesc = "Lcop5556sp17/PLPRuntimeFrame;";
/**
* Use this routine when the target of a BinaryChain is a frame. It will instantiate a frame if
* necessary and set the image
*
* @param i
* @return
*/
public final static String createOrSetFrameSig = "(" + PLPRuntimeImageIO.BufferedImageDesc + JVMDesc + ")" + JVMDesc;
public static PLPRuntimeFrame createOrSetFrame(BufferedImage i, PLPRuntimeFrame f) {
PLPRuntimeLog.globalLogAddEntry("createOrSetFrame");
if (f == null) {
return createFrame(i);
} else
f.setImage(i);
return f;
}
private static PLPRuntimeFrame createFrame(BufferedImage i) {
final PLPRuntimeFrame frame = new PLPRuntimeFrame(i);
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
try {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
frame.initialize();
}
});
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
return frame;
}
private PLPRuntimeFrame(BufferedImage image) {
this.image = image;
}
// initializes frame for display
private void initialize() {
Container contentPane = getContentPane();
icon = new ImageIcon();
icon.setImage(image);
contentPane.add(new JLabel(icon));
pack();
setLocationRelativeTo(last); //initial location is centered.
last = this;
}
public static final String moveFrameDesc = "(II)" + JVMDesc;
public PLPRuntimeFrame moveFrame(final int x, final int y) {
PLPRuntimeLog.globalLogAddEntry("moveFrame");
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
setLocation(x,y);
}
});
} catch (InvocationTargetException e) {
e.printStackTrace();
throw new RuntimeException(e);
} catch (InterruptedException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
return this;
}
public static String showImageDesc = "()" + JVMDesc;
public PLPRuntimeFrame showImage() {
PLPRuntimeLog.globalLogAddEntry("showImage");
setVisible(true);
return this;
}
public static String hideImageDesc = "()" + JVMDesc;
public PLPRuntimeFrame hideImage() {
PLPRuntimeLog.globalLogAddEntry("hideImage");
setVisible(false);
return this;
}
private void setImage(final BufferedImage image2) {
PLPRuntimeLog.globalLogAddEntry("showImage");
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
BufferedImage image1 = image2;
icon.setImage(image1);
pack();
repaint();
}
});
} catch (InterruptedException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
public static final String getXValDesc = "()I";
public int getXVal(){
PLPRuntimeLog.globalLogAddEntry("getX");
return super.getX();
}
public static final String getYValDesc = "()I";
public int getYVal(){
PLPRuntimeLog.globalLogAddEntry("getY");
return super.getY();
}
public final static String getScreenWidthSig = "()I";
public static int getScreenWidth() {
PLPRuntimeLog.globalLogAddEntry("getScreenWidth");
return (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth();
}
public final static String getScreenHeightSig = "()I";
public static int getScreenHeight() {
PLPRuntimeLog.globalLogAddEntry("getScreenHeight");
return (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight();
}
}