-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.pde
More file actions
106 lines (93 loc) · 3.97 KB
/
Copy pathMenu.pde
File metadata and controls
106 lines (93 loc) · 3.97 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
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import java.io.IOException;
public class Menu {
JFrame frame;
ActionEvent pubEvent;
boolean reportVal = false;
JMenuItem new_file;
JMenuItem new_report;
JMenuItem action_exit;
public Menu(PApplet app, String name, int width, int height){
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); //set look and feel of Java GUI to system default
}catch(Exception ie){
System.out.println(ie);
}
frame = (JFrame) ((processing.awt.PSurfaceAWT.SmoothCanvas)app.getSurface().getNative()).getFrame(); //wrape JFrame around PApplet
fileDrop fd = new fileDrop(frame); //add file dropping ability to JFrame
frame.setTitle(name); //set title of program
frame.setSize(width, height); //set program width and height
frame.setLocationRelativeTo(null); //load program in the middle of screen
frame.setResizable(true); //allow window to be resized by user (required by PSurfaceAWT or program won't functino)
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //set default close operation
JMenuBar menu_bar = new JMenuBar(); //create menubar
frame.setJMenuBar(menu_bar); //set menubar to JFrame
JMenu import_menu = new JMenu("File"); //create JMenu
menu_bar.add(import_menu); //add JMenu to menubar
/* Init JMenuItems */
new_file = new JMenuItem("Import file"); //import file button. Opens JFileChooser
new_report = new JMenuItem("Generate Report"); //Generates html report
action_exit = new JMenuItem("Exit"); //exits program
/* Adds JMenuItems to JMenu */
import_menu.add(new_file);
import_menu.add(new_report);
import_menu.addSeparator();
import_menu.add(action_exit);
new_report.setEnabled(reportVal); //disables genearate report button
/*----------------------------------------*/
/* Import new file button action listener */
new_file.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
try {
createFileChooser fc = new createFileChooser("Select text document", "FILES_AND_DIRECTORIES"); //creates file chooser
String fileText;
String entireFileText = new Scanner(new File(fc.getSelection())).useDelimiter("\\A").next(); //parses content of file
String uscanner = entireFileText;
fileText = uscanner;
textArea.setText(fileText, 500); //set user text area to the selected file contents
} catch (Exception ex) {
System.out.println(ex);
}
pubEvent = arg0;
}
}
);
/*----------------------------------------*/
/*----------------------------------------*/
/* Generate report button action listener */
new_report.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
getScreen(450, 90, 500, 256); //take selection of screen to include sentiment visualizer
String new_title = "Report_" + year() + "_" + month() + "_" + hour() + "_" + minute(); //gets time of day
documentExport de = new documentExport(docText, styleText, log, new_title); //generate html document
pubEvent = arg0;
}
}
);
/*----------------------------------------*/
/*----------------------------------------*/
/* Exit button action listener */
action_exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
exit(); //exits program
pubEvent = arg0;
}
}
);
frame.setVisible(true);
}
/*----------------------------------------*/
/*----------------------------------------*/
/* Enable 'Generate Report' button */
void activateReport(){
new_report.setEnabled(true);
}
/*----------------------------------------*/
}