annotate SMART/Java/Sav/Smart.java @ 6:769e306b7933

Change the repository level.
author yufei-luo
date Fri, 18 Jan 2013 04:54:14 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
1 /**
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
2 *
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
3 * Copyright INRA-URGI 2009-2010
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
4 *
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
5 * This software is governed by the CeCILL license under French law and
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
6 * abiding by the rules of distribution of free software. You can use,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
7 * modify and/ or redistribute the software under the terms of the CeCILL
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
8 * license as circulated by CEA, CNRS and INRIA at the following URL
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
9 * "http://www.cecill.info".
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
10 *
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
11 * As a counterpart to the access to the source code and rights to copy,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
12 * modify and redistribute granted by the license, users are provided only
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
13 * with a limited warranty and the software's author, the holder of the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
14 * economic rights, and the successive licensors have only limited
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
15 * liability.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
16 *
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
17 * In this respect, the user's attention is drawn to the risks associated
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
18 * with loading, using, modifying and/or developing or reproducing the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
19 * software by the user in light of its specific status of free software,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
20 * that may mean that it is complicated to manipulate, and that also
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
21 * therefore means that it is reserved for developers and experienced
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
22 * professionals having in-depth computer knowledge. Users are therefore
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
23 * encouraged to load and test the software's suitability as regards their
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
24 * requirements in conditions enabling the security of their systems and/or
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
25 * data to be ensured and, more generally, to use and operate it in the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
26 * same conditions as regards security.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
27 *
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
28 * The fact that you are presently reading this means that you have had
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
29 * knowledge of the CeCILL license and that you accept its terms.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
30 *
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
31 */
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
32 import java.util.*;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
33 import java.awt.*;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
34 import java.awt.event.ActionEvent;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
35 import java.awt.event.ActionListener;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
36 import java.io.*;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
37 import javax.swing.*;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
38 import javax.swing.filechooser.*;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
39 import javax.swing.border.*;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
40 import javax.swing.SwingUtilities;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
41
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
42
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
43 public class Smart extends JPanel implements ActionListener {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
44
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
45 String version = "1.0.2";
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
46
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
47 JFrame mainFrame;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
48 JButton openButton;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
49 JButton comparisonGoButton;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
50
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
51 JComboBox formatTypes;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
52 JComboBox fileFormats;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
53 String[] emptyFormats = {"Choose a type first..."};
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
54
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
55 JFrame askFrame;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
56 JButton pythonButton;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
57 JButton mySqlButton;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
58 JButton rButton;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
59
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
60 HashMap <JButton, Program> callingProgram;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
61
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
62 // comparison
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
63 JList comparisonFile1List;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
64 JList comparisonFile2List;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
65 JTextField comparisonOutputTextField;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
66 JTextField comparisonFiveQueryExtensionTextField;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
67 JCheckBox comparisonColinearCheckBox;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
68 JCheckBox comparisonAntisenseCheckBox;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
69 JCheckBox comparisonInvertCheckBox;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
70
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
71 JList fileList;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
72 JTextArea logArea;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
73
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
74 // progress bar
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
75 JLabel messageField;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
76 JProgressBar progressBar;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
77 JLabel etaField;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
78
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
79 // process
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
80 Program currentProgram;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
81 Process process;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
82 javax.swing.Timer processTimer;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
83
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
84
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
85 int previousStatus;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
86
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
87 public Smart() {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
88 super(new BorderLayout());
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
89
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
90 callingProgram = new HashMap <JButton, Program> ();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
91
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
92 previousStatus = -1;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
93
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
94 processTimer = new javax.swing.Timer(1000, this);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
95 processTimer.stop();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
96
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
97 // Ask frame buttons
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
98 pythonButton = new JButton("find...");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
99 mySqlButton = new JButton("find...");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
100 rButton = new JButton("find...");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
101
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
102 // Get available formats
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
103 FormatsReader formatReader = new FormatsReader(Global.smartFormatsFileName);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
104 if (! formatReader.read()) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
105 System.out.println("Something was wrong while reading file format...");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
106 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
107
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
108 // Get screen size
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
109 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
110
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
111 // Log
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
112 logArea = new JTextArea(512, Global.logAreaSize);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
113 logArea.setPreferredSize(new Dimension(screenSize.width, (int) (screenSize.height * 0.22)));
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
114 logArea.setFont(new Font("Monospaced", logArea.getFont().getStyle(), logArea.getFont().getSize()));
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
115 JScrollPane logScroll = new JScrollPane(logArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
116 TitledBorder logBorder = BorderFactory.createTitledBorder("Log");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
117 logScroll.setBorder(logBorder);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
118 logArea.append("Using S-MART " + version + "\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
119
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
120 GridLayout horizontalLayout = new GridLayout(1, 0);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
121
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
122 // check configuration
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
123 this.readConfigurationFile();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
124 this.checkConfiguration();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
125
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
126 // Tabs
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
127 JTabbedPane tabbedPane = new JTabbedPane();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
128 tabbedPane.setPreferredSize(new Dimension(screenSize.width, (int) (screenSize.height * 0.75)));
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
129
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
130 // File panel
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
131 JPanel filePanel = new JPanel(false);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
132 filePanel.setLayout(new FlowLayout());
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
133 tabbedPane.add("Files", filePanel);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
134
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
135 // Format sub-panel
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
136 JPanel formatComboPanel = new JPanel(false);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
137 JPanel formatPanel = new JPanel(false);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
138 Vector<String> formatTypesString = Global.formats.getFormatTypes();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
139 formatPanel.setLayout(horizontalLayout);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
140 formatTypesString.insertElementAt("Choose the format type", 0);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
141 JLabel formatLabel = new JLabel("Format");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
142 formatTypes = new JComboBox(formatTypesString);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
143 fileFormats = new JComboBox(emptyFormats);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
144 formatLabel.setLabelFor(fileFormats);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
145 formatTypes.addActionListener(this);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
146 formatComboPanel.add(formatTypes);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
147 formatComboPanel.add(fileFormats);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
148
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
149 formatPanel.add(formatLabel);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
150 formatPanel.add(formatComboPanel);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
151
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
152 // File chooser sub-panel
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
153 JPanel fileChooserPanel = new JPanel(false);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
154 fileChooserPanel.setLayout(horizontalLayout);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
155 JLabel fileLabel = new JLabel("File");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
156 openButton = new JButton("Open a File...");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
157 openButton.addActionListener(this);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
158
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
159 fileChooserPanel.add(fileLabel);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
160 fileChooserPanel.add(openButton);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
161
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
162 // File list sub-panel
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
163 JPanel existingFilesPanel = new JPanel(false);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
164 existingFilesPanel.setLayout(horizontalLayout);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
165 existingFilesPanel.setMinimumSize(new Dimension(10000, 10000));
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
166 JLabel existingFilesLabel = new JLabel("Existing files");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
167 Box fileListBox = Box.createHorizontalBox();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
168 fileListBox.add(Box.createRigidArea(new Dimension(0, 100)));
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
169 JList fileList = new JList(Global.fileNames);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
170 fileList.setLayoutOrientation(JList.HORIZONTAL_WRAP);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
171 fileList.setVisibleRowCount(4);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
172 JScrollPane listScroller = new JScrollPane(fileList);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
173 fileListBox.add(listScroller);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
174
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
175 existingFilesPanel.add(existingFilesLabel);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
176 existingFilesPanel.add(fileListBox);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
177
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
178 // File panel layout
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
179 Box box = Box.createVerticalBox();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
180 box.add(formatPanel);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
181 box.add(fileChooserPanel);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
182 box.add(existingFilesPanel);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
183 filePanel.add(box);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
184
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
185 // Program panels
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
186 TreeMap < String, JTabbedPane > panels = new TreeMap < String, JTabbedPane >();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
187 PythonProgramFinder programFinder = new PythonProgramFinder("Python");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
188 String comments = programFinder.findPrograms();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
189 if (comments != null) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
190 logArea.append(comments);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
191 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
192 for (int i = 0; i < programFinder.getPrograms().size(); i++) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
193 Program program = programFinder.getPrograms().get(i);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
194 JPanel programPanel = program.getPanel();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
195 String section = program.getSection();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
196 JTabbedPane sectionPane = null;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
197 if (panels.containsKey(section)) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
198 sectionPane = panels.get(section);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
199 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
200 else {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
201 sectionPane = new JTabbedPane();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
202 tabbedPane.addTab(section, sectionPane);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
203 panels.put(section, sectionPane);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
204 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
205
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
206 JScrollPane programScroll = new JScrollPane(programPanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
207 sectionPane.addTab(program.getName(), programScroll);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
208
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
209 JButton button = program.getButton();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
210 button.addActionListener(this);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
211 callingProgram.put(button, program);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
212 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
213
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
214 // Progress bar
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
215 JPanel progressPanel = new JPanel(new GridLayout(1, 0), false);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
216 progressPanel.setPreferredSize(new Dimension(screenSize.width, (int) (screenSize.height * 0.02)));
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
217 messageField = new JLabel();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
218 progressBar = new JProgressBar(0, 100);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
219 etaField = new JLabel();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
220 messageField.setHorizontalAlignment(JLabel.LEFT);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
221 progressBar.setValue(0);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
222 etaField.setHorizontalAlignment(JLabel.RIGHT);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
223 progressBar.setStringPainted(true);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
224 progressPanel.add(messageField);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
225 progressPanel.add(progressBar);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
226 progressPanel.add(etaField);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
227
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
228 add(tabbedPane, BorderLayout.PAGE_START);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
229 add(logScroll, BorderLayout.CENTER);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
230 add(progressPanel, BorderLayout.PAGE_END);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
231 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
232
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
233
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
234 public boolean checkConfiguration() {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
235 int status = this.testConfiguration();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
236
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
237 if (status == previousStatus) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
238 logArea.append("S-MART does not seem to work properly... Tried to manage it by myself, unsuccessfully... Check documentation for further explanation...\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
239 return false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
240 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
241
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
242 switch (status) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
243 case 0:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
244 return true;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
245 case 1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
246 logArea.append("S-MART does not seem to work properly... Check documentation for further explanation...\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
247 break;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
248 case 3:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
249 this.askWhereIsProgram("python");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
250 break;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
251 case 4:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
252 break;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
253 case 5:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
254 this.askWhereIsProgram("mySQL");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
255 break;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
256 case 6:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
257 this.askWhereIsProgram("R");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
258 break;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
259 case 7:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
260 logArea.append("Please install 'ColorBrewer' R package...\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
261 break;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
262 default:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
263 logArea.append("Weird configuration test status: " + status + "...\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
264 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
265 previousStatus = status;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
266 return true;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
267 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
268
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
269
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
270 public int testConfiguration() {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
271 String[] command = {Global.pythonCommand, "Python" + java.io.File.separator + "testInstall.py"};
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
272 ProgramLauncher launcher = new ProgramLauncher(command, logArea, messageField, progressBar, etaField);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
273 String line;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
274 launcher.execute();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
275 (new Exception("hello")).printStackTrace();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
276 return launcher.getExitValue();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
277 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
278
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
279
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
280 public void readConfigurationFile() {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
281 java.io.File file = new java.io.File(Global.smartConfFileName);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
282 String line = null;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
283
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
284 if (! file.exists()) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
285 return;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
286 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
287
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
288 try {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
289 BufferedReader reader = new BufferedReader(new FileReader(file));
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
290
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
291 while ((line = reader.readLine()) != null) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
292 line = line.trim();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
293 if (line.startsWith("python:")) Global.pythonCommand = line.substring("python:".length()).trim();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
294 else if (line.startsWith("mysql:")) Global.mysqlCommand = line.substring("mysql:".length()).trim();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
295 else if (line.startsWith("r:")) Global.rCommand = line.substring("r:".length()).trim();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
296 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
297 reader.close();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
298 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
299 catch (FileNotFoundException e) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
300 logArea.append("Configuration file is empty: " + e.getMessage() + "!\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
301 return;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
302 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
303 catch (IOException e) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
304 logArea.append("Weird with configuration file: " + e.getMessage() + "!\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
305 return;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
306 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
307 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
308
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
309
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
310 public void askWhereIsProgram(String program) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
311 askFrame = new JFrame("Where is " + program + "?");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
312 askFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
313 JLabel label = new JLabel("Where is your " + program + " (or " + program + ".exe) file?");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
314 JButton button = null;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
315 if ("python".equals(program)) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
316 button = pythonButton;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
317 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
318 else if ("mySQL".equals(program)) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
319 button = mySqlButton;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
320 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
321 else if ("R".equals(program)) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
322 button = rButton;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
323 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
324 else {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
325 logArea.append("Problem with the button!\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
326 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
327 askFrame.getContentPane().add(label, BorderLayout.WEST);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
328 askFrame.getContentPane().add(button, BorderLayout.EAST);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
329 button.addActionListener(this);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
330 askFrame.pack();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
331 askFrame.setVisible(true);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
332 askFrame.setAlwaysOnTop(true);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
333 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
334
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
335
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
336 public void actionPerformed(ActionEvent e) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
337
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
338 // Python command chooser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
339 if (e.getSource() == pythonButton) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
340 JFileChooser chooser = new JFileChooser();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
341 if (chooser.showOpenDialog(mainFrame) == JFileChooser.APPROVE_OPTION) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
342 Global.pythonCommand = chooser.getSelectedFile().getPath();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
343 askFrame.setVisible(false);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
344 askFrame.dispose();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
345 try {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
346 BufferedWriter out = new BufferedWriter(new FileWriter(Global.smartConfFileName, true));
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
347 out.write("python: " + Global.pythonCommand + "\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
348 out.close();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
349 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
350 catch (IOException exception) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
351 logArea.append("Cannot write configuration file!\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
352 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
353 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
354 this.checkConfiguration();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
355 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
356 // MySQL command chooser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
357 else if (e.getSource() == mySqlButton) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
358 JFileChooser chooser = new JFileChooser();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
359 if (chooser.showOpenDialog(mainFrame) == JFileChooser.APPROVE_OPTION) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
360 Global.mysqlCommand = chooser.getSelectedFile().getPath();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
361 askFrame.setVisible(false);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
362 askFrame.dispose();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
363 try {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
364 BufferedWriter out = new BufferedWriter(new FileWriter(Global.smartConfFileName, true));
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
365 out.write("mysql: " + Global.mysqlCommand + "\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
366 out.close();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
367 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
368 catch (IOException exception) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
369 logArea.append("Cannot write configuration file!\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
370 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
371 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
372 this.checkConfiguration();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
373 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
374 // R command chooser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
375 else if (e.getSource() == rButton) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
376 JFileChooser chooser = new JFileChooser();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
377 if (chooser.showOpenDialog(mainFrame) == JFileChooser.APPROVE_OPTION) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
378 Global.rCommand = chooser.getSelectedFile().getPath();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
379 askFrame.setVisible(false);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
380 askFrame.dispose();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
381 try {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
382 BufferedWriter out = new BufferedWriter(new FileWriter(Global.smartConfFileName, true));
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
383 out.write("r: " + Global.rCommand + "\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
384 out.close();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
385 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
386 catch (IOException exception) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
387 logArea.append("Cannot write configuration file!\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
388 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
389 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
390 this.checkConfiguration();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
391 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
392 // Format type
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
393 else if (e.getSource() == formatTypes) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
394 fileFormats.removeAllItems();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
395 Vector < String > selectedFormats = Global.formats.getFormats((String) formatTypes.getSelectedItem()).getFormats();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
396 for (int i = 0; i < selectedFormats.size(); i++) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
397 fileFormats.addItem(selectedFormats.get(i));
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
398 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
399 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
400 // Main file chooser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
401 else if (e.getSource() == openButton) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
402 JFileChooser chooser = new JFileChooser();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
403 if (chooser.showOpenDialog(mainFrame) == JFileChooser.APPROVE_OPTION) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
404 String fileName = chooser.getSelectedFile().getPath();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
405 Global.fileNames.addElement(fileName);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
406 Global.files.addFile(fileName, (String) formatTypes.getSelectedItem(), (String) fileFormats.getSelectedItem());
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
407 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
408 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
409 // Other file choosers
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
410 else if (Global.otherFilesChooser.containsKey(e.getSource())) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
411 JTextField textField = Global.otherFilesChooser.get(e.getSource());
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
412 JFileChooser chooser = new JFileChooser();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
413 if (chooser.showOpenDialog(mainFrame) == JFileChooser.APPROVE_OPTION) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
414 textField.setText(chooser.getSelectedFile().getPath());
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
415 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
416 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
417 // Other directories choosers
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
418 else if (Global.otherDirectoriesChooser.containsKey(e.getSource())) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
419 JTextField textField = Global.otherDirectoriesChooser.get(e.getSource());
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
420 JFileChooser chooser = new JFileChooser();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
421 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
422 if (chooser.showOpenDialog(mainFrame) == JFileChooser.APPROVE_OPTION) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
423 textField.setText(chooser.getSelectedFile().getPath());
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
424 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
425 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
426 else if (Global.otherFileConcatenationChooser.containsKey(e.getSource())) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
427 JTextField textField = Global.otherDirectoriesChooser.get(e.getSource());
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
428 JFileChooser chooser = new JFileChooser();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
429 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
430 if (chooser.showOpenDialog(mainFrame) == JFileChooser.APPROVE_OPTION) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
431 String text = textField.getText();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
432 if ((text == null) || ("".equals(text))) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
433 textField.setText(chooser.getSelectedFile().getPath());
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
434 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
435 else {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
436 textField.setText(text + "," + chooser.getSelectedFile().getPath());
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
437 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
438 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
439 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
440 // Programs
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
441 else {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
442 currentProgram = callingProgram.get(e.getSource());
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
443 String comment = currentProgram.checkValues();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
444 if (comment != null) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
445 logArea.append(comment);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
446 return;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
447 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
448 LinkedList <String> command = currentProgram.getCommand();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
449 ProgramLauncher launcher = new ProgramLauncher(command, logArea, messageField, progressBar, etaField);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
450 launcher.execute();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
451 Vector < File > outputFiles = currentProgram.getOutputFiles();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
452 for (int i = 0; i < outputFiles.size(); i++) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
453 File file = outputFiles.get(i);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
454 if (file.getFormatType().compareToIgnoreCase("other") != 0) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
455 Global.fileNames.addElement(file.getName());
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
456 Global.files.addFile(file);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
457 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
458 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
459 currentProgram = null;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
460 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
461 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
462
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
463
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
464 private static void createAndShowGUI() {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
465 // Create and set up the window.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
466 JFrame mainFrame = new JFrame("S-Mart");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
467 mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
468
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
469 //Create and set up the content pane.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
470 JComponent newContentPane = new Smart();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
471 newContentPane.setOpaque(true);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
472 mainFrame.setContentPane(newContentPane);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
473
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
474 // Display the window.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
475 mainFrame.pack();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
476 mainFrame.setVisible(true);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
477 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
478 mainFrame.setBounds(0, 0, screenSize.width, screenSize.height);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
479 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
480
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
481
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
482 public static void main(String[] args) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
483 javax.swing.SwingUtilities.invokeLater(new Runnable() {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
484 public void run() {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
485 createAndShowGUI();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
486 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
487 });
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
488 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
489 }