-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMainWindow.java
More file actions
73 lines (60 loc) · 2.12 KB
/
Copy pathMainWindow.java
File metadata and controls
73 lines (60 loc) · 2.12 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
package jdip;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
public class MainWindow extends JFrame {
private static final long serialVersionUID = 1L;
private JSplitPane splPane = null;
private ViewPanel pnlView = null;
private Image imageInProcess;
private MainWindow() {
this("rice.png");
}
private MainWindow(String picture) {
super();
initialize(picture);
}
public static void main(String[] args) {
if (args.length > 0) {
System.out.println("Loading " + args[0]);
new MainWindow(args[0]);
} else {
new MainWindow();
}
}
private void initialize(String picture) {
this.setSize(new Dimension(800, 350));
this.setTitle("Digital Image Processing In Java");
this.setContentPane(getSplPane());
this.setVisible(true);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
loadImage(picture);
}
private JSplitPane getSplPane() {
if (splPane == null) {
splPane = new JSplitPane();
splPane.setDividerLocation(200);
splPane.setOneTouchExpandable(false);
splPane.setContinuousLayout(true);
splPane.setDividerSize(0);
SelectPanel pnlSelect = new SelectPanel(this);
pnlView = new ViewPanel();
splPane.setLeftComponent(pnlSelect);
splPane.setRightComponent(pnlView);
}
return splPane;
}
void loadImage(String path) {
imageInProcess = Toolkit.getDefaultToolkit().getImage(path);
pnlView.updateOriginal(imageInProcess);
}
void doOperation(BufferedImageOp operation) {
BufferedImage mBufferedImage = new BufferedImage(imageInProcess
.getWidth(null), imageInProcess.getHeight(null),
BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = mBufferedImage.createGraphics();
g2.drawImage(imageInProcess, null, null);
pnlView.updateModified(ImageProcessing.process(mBufferedImage, operation));
}
}