-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUploadSequenceActionListener.java
244 lines (224 loc) · 14.7 KB
/
UploadSequenceActionListener.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.*;
/**
* Created by shikhar.kumar-gupta on 28.08.2014.
*/
public class UploadSequenceActionListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent e){
final JFrame chooseSequencesListFrame = new JFrame("DNA Sequences Lists");
chooseSequencesListFrame.setBackground(Color.DARK_GRAY);
chooseSequencesListFrame.setResizable(false);
chooseSequencesListFrame.setIconImage(MainFrame.imag);
chooseSequencesListFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JPanel mainPanel = new JPanel();
mainPanel.setBackground(Color.DARK_GRAY);
mainPanel.setLayout(new GridBagLayout());
GridBagConstraints dimensionFrameGridBagConstraints = new GridBagConstraints();
dimensionFrameGridBagConstraints.insets = new Insets(3, 3, 3, 3);
JLabel chooseSequencesListLabel = new JLabel("<html><style>h4{color:white;}</style><h4>Select List:</h4></html>");
final JRadioButton randomSequencesListRadioButton = new JRadioButton("<html><style>h4{color:white;}</style><h4>Random Sequences</h4></html>");
randomSequencesListRadioButton.setBackground(Color.DARK_GRAY);
if (MainFrame.isRandomSequencesListEnabled)
randomSequencesListRadioButton.setSelected(true);
final JRadioButton importSequencesListRadioButton = new JRadioButton("<html><style>h4{color:white;}</style><h4>Import Sequences</h4></html>");
importSequencesListRadioButton.setBackground(Color.DARK_GRAY);
if (MainFrame.isImportSequencesListEnabled)
importSequencesListRadioButton.setSelected(true);
ButtonGroup sequencesListGroup = new ButtonGroup();
sequencesListGroup.add(randomSequencesListRadioButton);
sequencesListGroup.add(importSequencesListRadioButton);
JButton okButton = new JButton("OK");
okButton.setBackground(Color.DARK_GRAY);
dimensionFrameGridBagConstraints.gridx = 0;
dimensionFrameGridBagConstraints.gridy = 0;
mainPanel.add(chooseSequencesListLabel, dimensionFrameGridBagConstraints);
dimensionFrameGridBagConstraints.gridx = 0;
dimensionFrameGridBagConstraints.gridy = 1;
mainPanel.add(randomSequencesListRadioButton, dimensionFrameGridBagConstraints);
dimensionFrameGridBagConstraints.gridx = 0;
dimensionFrameGridBagConstraints.gridy = 2;
mainPanel.add(importSequencesListRadioButton, dimensionFrameGridBagConstraints);
dimensionFrameGridBagConstraints.gridx = 0;
dimensionFrameGridBagConstraints.gridy = 3;
mainPanel.add(okButton, dimensionFrameGridBagConstraints);
chooseSequencesListFrame.add(mainPanel, BorderLayout.CENTER);
chooseSequencesListFrame.pack();
chooseSequencesListFrame.setVisible(true);
chooseSequencesListFrame.setLocation(MainFrame.screenWidth / 3, MainFrame.screenHeight / 4);
okButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (randomSequencesListRadioButton.isSelected()){
MainFrame.isRandomSequencesListEnabled = true;
MainFrame.isYonggangSequencesListEnabled = false;
MainFrame.isImportSequencesListEnabled =false;
}
else if (importSequencesListRadioButton.isSelected()) {
final boolean[] is16ntSelected = {false};
final boolean[] is32ntSelected = {false};
final boolean[] is48ntSelected = {false};
final JTextArea log;
log = new JTextArea(5, 40);
log.setEditable(false);
log.setMargin(new Insets(5, 5, 5, 5));
JScrollPane logScrollPane = new JScrollPane(log);
final JFileChooser halfBrickSequenceFileChooser = new JFileChooser();
halfBrickSequenceFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
final JFileChooser fullBrickSequenceFileChooser = new JFileChooser();
fullBrickSequenceFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
final JFileChooser boundaryBrickSequenceFileChooser = new JFileChooser();
boundaryBrickSequenceFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
final JFrame importcsvFrame = new JFrame("Import .csv files");
importcsvFrame.setBackground(Color.DARK_GRAY);
ImageIcon img = new ImageIcon("icons/software_logo.png");
Image imag = img.getImage();
importcsvFrame.setIconImage(imag);
importcsvFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JPanel mainPanel = new JPanel(new BorderLayout());
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS));
mainPanel.setBackground(Color.DARK_GRAY);
JButton halfBrickListButton = new JButton("Select 16nt file");
halfBrickListButton.setAlignmentX(Component.CENTER_ALIGNMENT);
halfBrickListButton.setBackground(Color.DARK_GRAY);
JButton fullBrickListButton = new JButton("Select 32nt file");
fullBrickListButton.setAlignmentX(Component.CENTER_ALIGNMENT);
fullBrickListButton.setBackground(Color.DARK_GRAY);
JButton boundaryBrickListButton = new JButton("Select 48nt file");
boundaryBrickListButton.setAlignmentX(Component.CENTER_ALIGNMENT);
boundaryBrickListButton.setBackground(Color.DARK_GRAY);
JButton okButton = new JButton("OK");
okButton.setAlignmentX(Component.CENTER_ALIGNMENT);
okButton.setBackground(Color.DARK_GRAY);
mainPanel.add(halfBrickListButton, BorderLayout.CENTER);
mainPanel.add(Box.createVerticalStrut(10));
mainPanel.add(fullBrickListButton, BorderLayout.CENTER);
mainPanel.add(Box.createVerticalStrut(10));
mainPanel.add(boundaryBrickListButton, BorderLayout.CENTER);
mainPanel.add(Box.createVerticalStrut(10));
mainPanel.add(logScrollPane, BorderLayout.CENTER);
mainPanel.add(okButton, BorderLayout.CENTER);
importcsvFrame.add(mainPanel, BorderLayout.CENTER);
importcsvFrame.pack();
importcsvFrame.setVisible(true);
importcsvFrame.setLocation(MainFrame.screenWidth / 3, MainFrame.screenHeight / 3);
halfBrickListButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int returnValue = halfBrickSequenceFileChooser.showOpenDialog(null);
if (returnValue == JFileChooser.APPROVE_OPTION) {
File importedHalfBrickFile = halfBrickSequenceFileChooser.getSelectedFile();
MainFrame.importedHalfBrickFilePath = new String();
MainFrame.importedHalfBrickFilePath = importedHalfBrickFile.getAbsolutePath();
log.append("Selected file for 16nt:" + importedHalfBrickFile.getName() + "\n");
log.setCaretPosition(log.getDocument().getLength());
is16ntSelected[0] = true;
if (is16ntSelected[0] == true && is32ntSelected[0] == true && is48ntSelected[0] == true) {
MainFrame.isYonggangSequencesListEnabled = false;
MainFrame.isRandomSequencesListEnabled = false;
MainFrame.isImportSequencesListEnabled = true;
log.append("All files selected\n");
log.setCaretPosition(log.getDocument().getLength());
}
try {
System.out.println(importedHalfBrickFile.getName());
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
});
fullBrickListButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int returnValue = fullBrickSequenceFileChooser.showOpenDialog(null);
if (returnValue == JFileChooser.APPROVE_OPTION) {
File importedFullBrickFile = fullBrickSequenceFileChooser.getSelectedFile();
MainFrame.importedFullBrickFilePath = new String();
MainFrame.importedFullBrickFilePath = importedFullBrickFile.getAbsolutePath();
log.append("Selected file for 32nt:" + importedFullBrickFile.getName() + "\n");
log.setCaretPosition(log.getDocument().getLength());
is32ntSelected[0] = true;
if (is16ntSelected[0] == true && is32ntSelected[0] == true && is48ntSelected[0] == true) {
MainFrame.isImportSequencesListEnabled = true;
MainFrame.isYonggangSequencesListEnabled = false;
MainFrame.isRandomSequencesListEnabled = false;
log.append("All files selected\n");
log.setCaretPosition(log.getDocument().getLength());
}
try {
System.out.println(importedFullBrickFile.getName());
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
});
boundaryBrickListButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int returnValue = boundaryBrickSequenceFileChooser.showOpenDialog(null);
if (returnValue == JFileChooser.APPROVE_OPTION) {
File importedBoundaryBrickFile = boundaryBrickSequenceFileChooser.getSelectedFile();
MainFrame.importedBoundaryBrickFilePath = new String();
MainFrame.importedBoundaryBrickFilePath = importedBoundaryBrickFile.getAbsolutePath();
log.append("Selected file for 48nt:" + importedBoundaryBrickFile.getName() + "\n");
log.setCaretPosition(log.getDocument().getLength());
is48ntSelected[0] = true;
if (is16ntSelected[0] == true && is32ntSelected[0] == true && is48ntSelected[0] == true) {
MainFrame.isImportSequencesListEnabled = true;
MainFrame.isYonggangSequencesListEnabled = false;
MainFrame.isRandomSequencesListEnabled = false;
log.append("All files selected\n");
log.setCaretPosition(log.getDocument().getLength());
}
try {
System.out.println(importedBoundaryBrickFile.getName());
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
});
okButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (MainFrame.importedHalfBrickFilePath == null) {
MainFrame.printLog("error: no file chosen for 16nt sequences", Color.yellow);
}
if (MainFrame.importedFullBrickFilePath == null) {
MainFrame.printLog("error: no file chosen for 32nt sequences", Color.yellow);
}
if (MainFrame.importedBoundaryBrickFilePath == null) {
MainFrame.printLog("error: no file chosen for 48nt sequences", Color.yellow);
}
if ((MainFrame.importedHalfBrickFilePath != null)) {
MainFrame.printLog("File imported for 16nt sequences: " + MainFrame.importedHalfBrickFilePath, Color.cyan);
}
if ((MainFrame.importedFullBrickFilePath != null)) {
MainFrame.printLog("File imported for 32nt sequences: " + MainFrame.importedFullBrickFilePath, Color.cyan);
}
if ((MainFrame.importedBoundaryBrickFilePath != null)) {
MainFrame.printLog("File imported for 48nt sequences: " + MainFrame.importedBoundaryBrickFilePath, Color.cyan);
}
importcsvFrame.dispose();
}
});
importcsvFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
importcsvFrame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
}
});
}
chooseSequencesListFrame.dispose();
}
});
chooseSequencesListFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
}