-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathAppFrame.java
126 lines (115 loc) · 4.46 KB
/
AppFrame.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
import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Properties;
import java.io.IOException;
import java.io.OutputStream;
import java.io.InputStream;
@SuppressWarnings("serial")
public class AppFrame extends JFrame{
private static AppFrame instance = null;
private ProgramPanel programPanel;
private InputPanel inputPanel;
private ProcessingPanel processingPanel;
private OutputPanel outputPanel;
private GridBagLayout gridBagLayoutAppFrame;
private BoxLayout boxLayout;
private GuiControl guiControl = new GuiControl();
private static final String PROPERTIES_PATH = "SACDExtractGUI.properties";
private AppFrame(){
setupGUI();
}
public static AppFrame getInstance(){
if(instance == null){
instance = new AppFrame();
}
return instance;
}
private String getVersion(){
InputStream is = SACDExtractGUI.class.getResourceAsStream("Version.properties");
String s;
Properties props = new Properties();
try{
props.load(is);
s = props.getProperty("version");
if(s == null){
s = "";
}
}
catch(Exception e){
s = "";
}
return s;
}
private String getRepository(){
InputStream is = SACDExtractGUI.class.getResourceAsStream("Version.properties");
String s;
Properties props = new Properties();
try{
props.load(is);
s = props.getProperty("repository");
if(s == null){
s = "";
}
}
catch(Exception e){
s = "";
}
return s;
}
public void setupGUI(){
Properties properties = null;
String version, repository;
final ProgramState programState = new ProgramState();
this.setTitle("SACDExtractGUI");
this.setMinimumSize(new Dimension(550,800));
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
boxLayout = new BoxLayout(getContentPane(), BoxLayout.PAGE_AXIS);
this.getContentPane().setLayout(boxLayout);
programPanel = new ProgramPanel();
inputPanel = new InputPanel();
processingPanel = new ProcessingPanel();
outputPanel = new OutputPanel();
inputPanel.setMaximumSize(new Dimension(Short.MAX_VALUE, inputPanel.getPreferredSize().height));
processingPanel.setMaximumSize(new Dimension(Short.MAX_VALUE,processingPanel.getPreferredSize().height));
programPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
inputPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
processingPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
outputPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
programState.setFrame(this);
programState.setPanels(programPanel, inputPanel, processingPanel, outputPanel);
// Registering panels to guiControl
guiControl.setFrame(this);
guiControl.setProgramPanel(programPanel);
guiControl.setInputPanel(inputPanel);
guiControl.setProcessingPanel(processingPanel);
guiControl.setOutputPanel(outputPanel);
// Registering guiControl to panels
programPanel.setControl(guiControl);
inputPanel.setControl(guiControl);
processingPanel.setControl(guiControl);
outputPanel.setControl(guiControl);
this.getContentPane().add(programPanel);
this.getContentPane().add(inputPanel);
this.getContentPane().add(processingPanel);
this.getContentPane().add(outputPanel);
this.addWindowListener(new WindowAdapter(){
@Override
public void windowClosing(WindowEvent e){
// Kill the running process
guiControl.killExec();
// Save the GUI state
programState.setInputDirectory(guiControl.getInputDirectory());
programState.writeState(PROPERTIES_PATH);
}
});
version = getVersion();
repository = getRepository();
guiControl.initGui();
outputPanel.appendTextArea("SACDExtractGUI " + version + "\n" + repository + "\n\nUse of this program that results in any form of copyright infringement is strictly prohibited.\n\n");
programState.readState(PROPERTIES_PATH);
programState.renderState();
guiControl.setInputDirectory(programState.getInputDirectory());
}
}