-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathUsagiMain.java
More file actions
214 lines (186 loc) · 7.11 KB
/
Copy pathUsagiMain.java
File metadata and controls
214 lines (186 loc) · 7.11 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
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
/*******************************************************************************
* Copyright 2019 Observational Health Data Sciences and Informatics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package org.ohdsi.usagi.ui;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import javax.swing.*;
import org.ohdsi.usagi.BerkeleyDbEngine;
import org.ohdsi.usagi.UsagiSearchEngine;
import org.ohdsi.usagi.ui.actions.*;
import org.ohdsi.utilities.files.ReadTextFile;
/**
* The main application class
*/
public class UsagiMain implements ActionListener {
public static String version = "1.4.3";
public static void main(String[] args) {
new UsagiMain(args);
}
public UsagiMain(String[] args) {
JFrame frame = new JFrame("Usagi v" + UsagiMain.version);
// Initialize global variables:
Global.mapping = new Mapping();
if (args.length == 1) {
Global.folder = args[0];
} else {
Global.folder = new File("").getAbsolutePath();
}
Global.usagiSearchEngine = new UsagiSearchEngine(Global.folder);
Global.dbEngine = new BerkeleyDbEngine(Global.folder);
if (Global.usagiSearchEngine.mainIndexExists()) {
Global.usagiSearchEngine.openIndexForSearching(false);
Global.dbEngine.openForReading();
}
loadAuthor(Global.folder);
loadVocabularyVersion(Global.folder);
Global.conceptClassIds = loadVectorFromFile(Global.folder + "/ConceptClassIds.txt");
Global.vocabularyIds = loadVectorFromFile(Global.folder + "/VocabularyIds.txt");
Global.domainIds = loadVectorFromFile(Global.folder + "/DomainIds.txt");
Global.conceptInformationDialog = new ConceptInformationDialog();
Global.frame = frame;
Global.openAction = new OpenAction();
Global.applyPreviousMappingAction = new ApplyPreviousMappingAction();
Global.importAction = new ImportAction();
Global.exportAction = new ExportSourceToConceptMapAction();
Global.exportForReviewAction = new ExportForReviewAction();
Global.exportCandidatesAction = new ExportCandidatesAction();
Global.saveAction = new SaveAction();
Global.saveAsAction = new SaveAsAction();
Global.approveAction = new ApproveAction();
Global.flagAction = new FlagAction();
Global.reviewerAssignmentAction = new ReviewerAssignmentAction();
Global.conceptInfoAction = new ConceptInformationAction();
Global.athenaAction = new AthenaAction();
Global.googleSearchAction = new GoogleSearchAction();
Global.showStatsAction = new ShowStatsAction();
Global.showReviewStatsAction = new ShowReviewStatsAction();
Global.aboutAction = new AboutAction();
Global.rebuildIndexAction = new RebuildIndexAction();
Global.exitAction = new ExitAction();
Global.applyPreviousMappingAction.setEnabled(false);
Global.saveAction.setEnabled(false);
Global.saveAsAction.setEnabled(false);
Global.exportAction.setEnabled(false);
Global.exportForReviewAction.setEnabled(false);
Global.exportCandidatesAction.setEnabled(false);
Global.approveAction.setEnabled(false);
Global.flagAction.setEnabled(false);
Global.clearSelectedAction = new ClearSelectedAction();
Global.clearSelectedAction.setEnabled(false);
Global.conceptInfoAction.setEnabled(false);
Global.athenaAction.setEnabled(false);
Global.googleSearchAction.setEnabled(false);
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
if (UsagiDialogs.askBeforeClose()) {
Global.dbEngine.shutdown();
System.exit(0);
}
}
});
frame.setLayout(new BorderLayout());
frame.setJMenuBar(new UsagiMenubar());
JPanel main = new JPanel();
main.setLayout(new BorderLayout());
Global.mappingTablePanel = new MappingTablePanel();
Global.mappingDetailPanel = new MappingDetailPanel();
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, Global.mappingTablePanel, Global.mappingDetailPanel);
Global.mappingTablePanel.setMinimumSize(new Dimension(500, 100));
Global.mappingDetailPanel.setMinimumSize(new Dimension(500, 400));
main.add(splitPane, BorderLayout.CENTER);
Global.mappingTablePanel.addCodeSelectedListener(Global.mappingDetailPanel);
frame.add(main, BorderLayout.CENTER);
Global.statusBar = new UsagiStatusBar();
frame.add(Global.statusBar, BorderLayout.SOUTH);
loadIcons(frame);
frame.pack();
frame.setVisible(true);
if (!Global.usagiSearchEngine.mainIndexExists())
Global.rebuildIndexAction.actionPerformed(null);
if (args.length > 1 && args[0].equals("--file")) {
OpenAction.open(new File(args[1]));
}
}
private void loadVocabularyVersion(String folder) {
String versionFileName = folder + "/vocabularyVersion.txt";
Global.vocabularyVersion = "Unknown";
if (new File(versionFileName).exists()) {
for (String line : new ReadTextFile(versionFileName)) {
Global.vocabularyVersion = line;
}
}
}
private void loadAuthor(String folder) {
String authorFileName = folder + "/authorName.txt";
if (new File(authorFileName).exists()) {
// Read from file
for (String line : new ReadTextFile(authorFileName)) {
Global.author = line;
}
} else {
// Dialog to ask user to input name
AuthorDialog authorDialog = new AuthorDialog();
authorDialog.setAuthorFileName(authorFileName);
authorDialog.setVisible(true);
}
}
@Override
public void actionPerformed(ActionEvent event) {
}
protected static void loadIcons(JFrame f) {
List<Image> icons = new ArrayList<Image>();
icons.add(loadIcon("Usagi16.png", f));
icons.add(loadIcon("Usagi32.png", f));
icons.add(loadIcon("Usagi48.png", f));
icons.add(loadIcon("Usagi64.png", f));
icons.add(loadIcon("Usagi128.png", f));
icons.add(loadIcon("Usagi256.png", f));
f.setIconImages(icons);
}
private static Image loadIcon(String name, JFrame f) {
Image icon = Toolkit.getDefaultToolkit().getImage(UsagiMain.class.getResource(name));
MediaTracker mediaTracker = new MediaTracker(f);
mediaTracker.addImage(icon, 0);
try {
mediaTracker.waitForID(0);
return icon;
} catch (Exception e1) {
e1.printStackTrace();
}
return null;
}
private Vector<String> loadVectorFromFile(String fileName) {
if (new File(fileName).exists()) {
Vector<String> vector = new Vector<>();
for (String line : new ReadTextFile(fileName))
vector.add(line);
return vector;
} else
return new Vector<>();
}
}