Repository navigation
Expand file tree
/
Copy pathExportDialog.java
More file actions
110 lines (102 loc) · 3.56 KB
/
Copy pathExportDialog.java
File metadata and controls
110 lines (102 loc) · 3.56 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
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
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import java.awt.image.BufferedImage;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
public class ExportDialog extends JPanel {
MemView parent;
JFrame frame;
Integer start;
Integer end;
Integer oldStart;
Integer oldEnd;
JTextField value1;
JTextField value2;
public ExportDialog(MemView parent) {
this.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
this.parent = parent;
this.start = null;
this.end = null;
GridLayout layout = new GridLayout(3, 3);
this.setLayout(layout);
this.add(new JLabel("Start address:"));
this.add(new JLabel("0x", SwingConstants.RIGHT));
this.value1 = new JTextField();
this.add(value1);
this.add(new JLabel("End address:"));
this.add(new JLabel("0x", SwingConstants.RIGHT));
this.value2 = new JTextField();
this.add(value2);
JButton ok = new JButton("OK");
ok.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String startString = value1.getText();
String endString = value2.getText();
if (startString != null && !startString.equals("")) start = (int)Long.parseLong(startString, 16);
if (endString != null && !endString.equals("")) end = (int)Long.parseLong(endString, 16);
if (start == null || end == null) return;
Save();
JComponent comp = (JComponent) e.getSource();
SwingUtilities.getWindowAncestor(comp).dispose();
}
});
this.add(ok);
JButton clear = new JButton("Clear");
clear.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
value1.setText("");
value2.setText("");
start = null;
end = null;
}
});
this.add(clear);
JButton cancel = new JButton("Cancel");
cancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
start = oldStart;
end = oldEnd;
JComponent comp = (JComponent) e.getSource();
SwingUtilities.getWindowAncestor(comp).dispose();
}
});
this.add(cancel);
}
public void Show(int address) {
oldStart = start;
oldEnd = end;
if (start == null) {
start = address;
} else if (end == null) {
end = address;
}
value1.setText(String.format("%x", start));
value2.setText(end == null ? "" : String.format("%x", end));
frame = new JFrame("Export as PNG");
frame.add(this);
frame.setLocationByPlatform( true );
frame.pack();
frame.setVisible( true );
}
private void Save() {
BufferedImage bi = parent.getImageFromMemory(start, 0, end, false);
File outputfile = new File("saved.png");
try {
ImageIO.write(bi, "png", outputfile);
} catch (Exception ex) {}
setVisible(false);
}
}