/
AnnotatorTab.java
282 lines (230 loc) · 8.67 KB
/
AnnotatorTab.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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
package semgen.annotation;
import semgen.GlobalActions;
import semgen.SemGen;
import semgen.SemGenSettings;
import semgen.SemGenSettings.SettingChange;
import semgen.annotation.annotatorpane.AnnotationPanel;
import semgen.annotation.annotatorpane.CodewordAnnotationPanel;
import semgen.annotation.annotatorpane.SubmodelAnnotationPanel;
import semgen.annotation.componentlistpanes.AnnotatorButtonTree;
import semgen.annotation.componentlistpanes.CodewordListPane;
import semgen.annotation.componentlistpanes.SubmodelListPane;
import semgen.annotation.dialog.modelanns.ModelLevelMetadataDialog;
import semgen.annotation.termlibrarydialog.ReferenceLibraryDialog;
import semgen.annotation.workbench.AnnotatorWorkbench;
import semgen.annotation.workbench.AnnotatorWorkbench.LibraryRequest;
import semgen.annotation.workbench.AnnotatorWorkbench.WBEvent;
import semgen.annotation.workbench.drawers.AnnotatorDrawer;
import semgen.utilities.SemGenFont;
import semgen.utilities.SemGenIcon;
import semgen.utilities.uicomponent.SemGenScrollPane;
import semgen.utilities.uicomponent.SemGenTab;
import semsim.SemSimObject;
import semsim.fileaccessors.ModelAccessor;
import java.net.URI;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import javax.swing.text.BadLocationException;
import java.util.Observable;
import java.util.Observer;
import java.math.BigDecimal;
public class AnnotatorTab extends SemGenTab implements Observer {
private static final long serialVersionUID = -5360722647774877228L;
public ModelAccessor modelaccessor; //Model location originally loaded at start of Annotation session (could be in SBML, MML, CellML, PROJ or SemSim format)
private AnnotatorWorkbench workbench;
public static int initwidth;
public static int initheight;
private AnnotatorToolBar toolbar;
private JSplitPane splitpane;
private JSplitPane eastsplitpane;
private JSplitPane westsplitpane;
private SemGenScrollPane annotatorscrollpane = new SemGenScrollPane();
private SemGenScrollPane treeviewscrollpane;
private AnnotatorButtonTree tree;
private SubmodelListPane smpane;
private CodewordListPane cwpane;
private AnnotationPanel<? extends AnnotatorDrawer<? extends SemSimObject>> annotatorpane;
private AnnotatorTabCodePanel codearea;
private ReferenceLibraryDialog libdialog;
public AnnotatorTab(SemGenSettings sets, GlobalActions gacts, AnnotatorWorkbench bench) {
super(bench.getCurrentModelName(), SemGenIcon.annotatoricon, "Annotating " + bench.getCurrentModelName(), sets, gacts);
workbench = bench;
modelaccessor = workbench.getModelAccessor();
workbench.addObserver(this);
settings.addObserver(this);
workbench.addObservertoModelAnnotator(this);
}
public void loadTab() {
toolbar = new AnnotatorToolBar(globalactions, workbench, settings );
initwidth = settings.getAppWidth();
initheight = settings.getAppHeight();
setOpaque(false);
setLayout(new BorderLayout());
codearea = new AnnotatorTabCodePanel(workbench);
SemGenScrollPane legacycodescrollpane = new SemGenScrollPane(codearea);
legacycodescrollpane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.gray),
"Model source code", TitledBorder.CENTER, TitledBorder.TOP, SemGenFont.defaultBold(2)));
annotatorscrollpane.setBackground(SemGenSettings.lightblue);
annotatorscrollpane.getViewport().setBackground(SemGenSettings.lightblue);
westsplitpane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, null, null);
westsplitpane.setOneTouchExpandable(true);
eastsplitpane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, annotatorscrollpane, legacycodescrollpane);
eastsplitpane.setOneTouchExpandable(true);
splitpane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, westsplitpane, eastsplitpane);
splitpane.setOneTouchExpandable(true);
NewAnnotatorAction();
}
// --------------------------------//
// METHODS
// --------------------------------//
public void NewAnnotatorAction(){
SemGen.logfilewriter.println("Started new annotater");
add(toolbar, BorderLayout.NORTH);
add(splitpane, BorderLayout.CENTER);
setVisible(true);
int iniwloc = settings.scaleWidthforScreen(360);
int inihloc = settings.scaleHeightforScreen(initheight-150);
tree = new AnnotatorButtonTree(workbench, settings);
treeviewscrollpane = new SemGenScrollPane(tree);
cwpane = new CodewordListPane(workbench, settings);
smpane = new SubmodelListPane(workbench, settings);
splitpane.setDividerLocation(iniwloc);
BigDecimal locbd = new BigDecimal(inihloc/1.75);
eastsplitpane.setDividerLocation(locbd.intValue());
westsplitpane.setDividerLocation(locbd.intValue());
// If we are hiding the imported codewords, select the first one that is editable
changeComponentView();
showSelectAnnotationObjectMessage();
}
private void subModelSelected() {
if (annotatorpane!= null) annotatorpane.destroy();
annotatorpane = new SubmodelAnnotationPanel(workbench, settings, globalactions);
}
private void codewordSelected() throws BadLocationException {
if (annotatorpane!= null) annotatorpane.destroy();
annotatorpane = new CodewordAnnotationPanel(workbench, settings, globalactions);
// Highlight occurrences of codeword in legacy code
codearea.setCodeword(workbench.openCodewordDrawer().getFocusLookupName());
codearea.HighlightOccurances(true);
}
private void changeComponentView() {
if (settings.useTreeView()) {
toolbar.enableSort(false);
westsplitpane.setTopComponent(treeviewscrollpane);
westsplitpane.setBottomComponent(null);
}
else {
cwpane.update();
smpane.update();
toolbar.enableSort(true);
westsplitpane.setTopComponent(cwpane);
westsplitpane.setBottomComponent(smpane);
}
}
private void annotationObjectAction() {
annotatorscrollpane.setViewportView(annotatorpane);
annotatorscrollpane.scrollToTop();
annotatorscrollpane.scrollToLeft();
}
// Refresh the display of codewords and submodels based on the view options selected in the Annotate menu
public void refreshAnnotatableElements(){
int divLoc = splitpane.getDividerLocation();
if(divLoc==-1)
divLoc = (int)(settings.getAppWidth())/4;
splitpane.setDividerLocation(divLoc);
}
private void showSelectAnnotationObjectMessage(){
annotatorscrollpane.getViewport().removeAll();
JPanel panel = new JPanel(new BorderLayout());
JLabel label = new JLabel("Select a codeword or submodel to view annotations");
label.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 0));
panel.add(label, BorderLayout.CENTER);
annotatorscrollpane.getViewport().add(panel);
annotatorscrollpane.scrollToTop();
codearea.removeAllHighlights();
}
public void openReferenceLibrary() {
if (libdialog==null) {
libdialog = new ReferenceLibraryDialog(settings, workbench);
}
libdialog.toFront();
}
public boolean fileURIMatches(URI uri) {
return (uri.toString().equals(modelaccessor.getFileThatContainsModelAsURI().toString()));
}
public boolean closeTab() {
if (libdialog!=null) {
libdialog.dispose();
}
return workbench.unsavedChanges();
}
@Override
public boolean isSaved() {
return workbench.getModelSaved();
}
@Override
public void requestSave() {
workbench.saveModel(0);
}
@Override
public void requestSaveAs() {
setCursor(new Cursor(Cursor.WAIT_CURSOR));
if (workbench.saveModelAs(0)!=null) {
setTabName(workbench.getCurrentModelName());
setToolTipText("Annotating " + workbench.getCurrentModelName());
}
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
@Override
public void requestExport(){
setCursor(new Cursor(Cursor.WAIT_CURSOR));
workbench.exportModel(0);
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
public void requestEditModelLevelMetadata() {
new ModelLevelMetadataDialog(workbench);
}
@Override
public void update(Observable arg0, Object arg1) {
if (arg0==workbench) {
if (arg1 == WBEvent.IMPORT_FREETEXT) {
if (annotatorpane!=null) {
annotatorpane.setFreeText(codearea.getHighlightedText());
}
}
if (arg1==WBEvent.CWSELECTION) {
try {
codewordSelected();
} catch (BadLocationException e) {
e.printStackTrace();
}
annotationObjectAction() ;
}
if (arg1==WBEvent.SMSELECTION) {
this.subModelSelected();
annotationObjectAction();
}
if (arg1==LibraryRequest.REQUEST_LIBRARY) {
openReferenceLibrary();
libdialog.openReferenceTab();
}
if (arg1==LibraryRequest.REQUEST_CREATOR) {
openReferenceLibrary();
libdialog.openCreatorTab();
}
if (arg1==LibraryRequest.REQUEST_IMPORT) {
openReferenceLibrary();
libdialog.openImportTab();
}
if (arg1==LibraryRequest.CLOSE_LIBRARY) {
libdialog=null;
}
}
if (arg0==settings) {
if (arg1==SettingChange.TOGGLETREE) {
changeComponentView();
}
}
}
}