-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGUI.java
157 lines (121 loc) · 3.55 KB
/
GUI.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
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.applet.*;
public class GUI extends Frame {
private Image lennaImage;
private Insets insets;
public String fileName;
// public final static int IMAGE_WIDTH = 256;
// public final static int IMAGE_HEIGHT = 256;
public static int IMAGE_WIDTH;
public static int IMAGE_HEIGHT;
private final static int[] factors = {100, 99, 90, 80, 70, 60, 50, 40, 30, 20, 10, 5, 1};
private ImageUtil imgUtil;
private int[] img;
public GUI( String fileName, int xSize, int ySize )
{
super( "Original Image" );
IMAGE_WIDTH = xSize;
IMAGE_HEIGHT = ySize;
this.fileName = fileName;
imgUtil = new ImageUtil( getImageName(), IMAGE_WIDTH, IMAGE_HEIGHT );
initMenu();
initImage();
setSize(IMAGE_WIDTH, IMAGE_HEIGHT);
this.pack();
this.show();
insets = getInsets();
setSize(insets.left + GUI.IMAGE_WIDTH, insets.top + GUI.IMAGE_HEIGHT);
}
public
String getImageName()
{
return fileName;
}
public
ImageUtil getImageUtil()
{
return imgUtil;
}
private
void initImage()
{
img = imgUtil.loadImage();
lennaImage = createImage( imgUtil.getImageObject(img) );
}
private
MenuItem createMenuItem( String label, char shortcut, final int factor, final boolean standard, final int blockSize )
{
// MenuItem item = new MenuItem( label, new MenuShortcut(shortcut) );
MenuItem item = new MenuItem( label );
class MenuItemListener implements ActionListener {
public
void actionPerformed( ActionEvent e )
{
if (standard )
new FFTFrame( GUI.this, img, factor, blockSize );
else
new ExtendedFFTFrame( GUI.this, img, factor );
}
}
ActionListener listener = new MenuItemListener();
item.addActionListener(listener);
return item;
}
private
void initMenu()
{
MenuBar menubar = new MenuBar();
this.setMenuBar( menubar );
Menu standard = new Menu( "Compress" );
Menu standard16x16 = new Menu( "Compress 16x16" );
Menu extended = new Menu( "Extended" );
menubar.add( standard );
menubar.add( standard16x16 );
menubar.add( extended );
MenuItem c1, q;
MenuItem []itm = new MenuItem[ factors.length ];
for( int i=0; i < itm.length; i++) {
itm[i] = createMenuItem( String.valueOf(factors[i]) +"%", (char)(KeyEvent.VK_A + i), factors[i], true, IMAGE_WIDTH );
standard.add( itm[i] );
}
standard.add( q = new MenuItem( "Quit", new MenuShortcut(KeyEvent.VK_Q) ));
MenuItem []itm2 = new MenuItem[ factors.length ];
for( int i=0; i < itm2.length; i++) {
itm2[i] = createMenuItem( String.valueOf(factors[i]) +"%", (char)(KeyEvent.VK_A + i), factors[i], true, 16 );
standard16x16.add( itm2[i] );
}
MenuItem []extItm = new MenuItem[ factors.length ];
for( int i=0; i < itm.length; i++) {
extItm[i] = createMenuItem( String.valueOf(factors[i]) +"%", (char)(KeyEvent.VK_A + i), factors[i], false, IMAGE_WIDTH );
extended.add( extItm[i] );
}
/*
c1.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e ) {
// code here
new FFTFrame( GUI.this, img, 1 );
}
} );
*/
q.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e ) {
// code here
dispose();
System.exit(0);
}
});
this.addWindowListener( new WindowAdapter() {
public void windowClosing( WindowEvent e ) {
dispose();
System.exit(0);
}
} );
}
public void paint(Graphics g) {
// Draw the animated image
g.drawImage(lennaImage, insets.left, insets.top, this);
}
}