-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFdTest.java
189 lines (173 loc) · 5.27 KB
/
FdTest.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/**
*Class for UI
*@author kalyam
*@version 0.0.1 Dec 8,2012
*/
import java.awt.*;
import java.io.*;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
import javax.swing.border.Border;
public class FdTest extends Frame {
TextField tb;
/**
*Label value changes accirding to user interaction
*/
Label myLabel;
Button loadButton;
Button proceed;
/**
*Panel which fits ui
*/
Panel p;
/**
*Threshold to be extracted
*/
int percent;
/**
*input filename
*/
static String filename;
/**
*output filename
*/
static String opfilename;
/**
Generates panel according to flow of events to interact with user
@param i gives the stage and based on which panel is created
*/
FdTest (int i) {
super ("PDF Summarizer --- eskratch");
if(i==0){
p = new Panel ();
p.add (loadButton = new Button ("Load"));
//p.add (saveButton = new Button ("Save"));
add ("North", myLabel = new Label ("This dialog box will guide you through the process..\n Step1: Select your input pdf file"));
add ("South", p);
//add ("Center", myTextArea = new TextArea (10, 40));
Menu m = new Menu ("File");
m.add (new MenuItem ("Quit"));
MenuBar mb = new MenuBar();
mb.add (m);
setMenuBar (mb);
pack();
}
else if(i==1)
{
//super ("File Dialog Tester");
p = new Panel ();
p.add(tb=new TextField(4));
p.add (proceed = new Button ("Proceed"));
//p.add (saveButton = new Button ("Save"));
add ("North", myLabel = new Label ("Step2: Specify the amount of compression you want(1-100).. Lower the value hgher compression"));
add ("South", p);
//add ("Center", myTextArea = new TextArea (10, 40));
Menu m = new Menu ("File");
m.add (new MenuItem ("Quit"));
MenuBar mb = new MenuBar();
mb.add (m);
setMenuBar (mb);
pack();
}
else if(i==2)
{
p = new Panel ();
add ("North", myLabel = new Label ("Processing.. It will take few minutes"));
//add ("Center", myTextArea = new TextArea (10, 40));
add("South",p);
Menu m = new Menu ("File");
m.add (new MenuItem ("Quit"));
MenuBar mb = new MenuBar();
mb.add (m);
setMenuBar (mb);
pack();
}
else if(i==3)
{
p = new Panel ();
add ("North", myLabel = new Label ("The output will be a pdf file in the same folder as input file with the name eskratch+filename"));
p.add(new Label("If the output file is not generated, there might be some issue with the input"));
p.add(new Label("Close the dialog using File->Quit"));
//add ("Center", myTextArea = new TextArea (10, 40));
add("South",p);
Menu m = new Menu ("File");
m.add (new MenuItem ("Quit"));
MenuBar mb = new MenuBar();
mb.add (m);
setMenuBar (mb);
pack();
}
}
/**
*This is where program starts
*/
public static void main (String args[]) {
FdTest f = new FdTest(0);
f.show();
}
/**
*To handle window events
*/
public boolean handleEvent (Event e) {
if (e.id == Event.WINDOW_DESTROY) {
hide();
dispose ();
System.exit(0);
return true; // never gets here
}
return super.handleEvent (e);
}
/**
*To handle button events
*/
public boolean action (Event e, Object o) {
if (e.target instanceof MenuItem) {
hide();
dispose ();
System.exit(0);
return true; // never gets here
} else if (e.target instanceof Button) {
int state;
String msg;
if (e.target == loadButton) {
state = FileDialog.LOAD;
msg = "Load File";
FileDialog file = new FileDialog (this, msg, state);
file.setFile ("*.pdf"); // set initial filename filter
file.show();
String curFile;
if ((curFile = file.getFile()) != null) {
filename = file.getDirectory() + curFile;
opfilename = file.getDirectory() + "eskratch"+curFile ;
// curFile ends in .*.* if file does not exist
hide();
dispose();
FdTest f=new FdTest(1);
f.show();
}
return true;
}
if (e.target == proceed) {
try{
String value = tb.getText();
percent=Integer.parseInt(value);
myLabel.setText("Processing...It will take few minutes");
p.remove(proceed);
p.remove(tb);
int ret=extractText.extractiveSummarizer(filename,percent,opfilename);
System.out.println(ret);
hide();
dispose();
FdTest f=new FdTest(3);
f.show();
}
catch(Exception e2){
}
// curFile ends in .*.* if file does not exist
return true;
}
}
return false;
}
}