4
import java.awt.Dimension;
6
4
import java.util.ArrayList;
7
import java.util.HashMap;
9
import javax.swing.BorderFactory;
10
6
import javax.swing.JOptionPane;
11
import javax.swing.JScrollPane;
12
import javax.swing.JSplitPane;
13
7
import javax.swing.JTabbedPane;
14
import javax.swing.border.EmptyBorder;
15
import javax.swing.border.LineBorder;
16
import javax.swing.text.BadLocationException;
18
import pipe.dataLayer.Arc;
19
9
import pipe.dataLayer.DataLayer;
20
import pipe.dataLayer.NetType;
21
import pipe.dataLayer.PetriNetObject;
22
import pipe.dataLayer.Place;
23
import pipe.dataLayer.TAPNQuery;
24
import pipe.dataLayer.TimedArc;
25
import pipe.dataLayer.TimedPlace;
26
import pipe.dataLayer.TransportArc;
27
import pipe.dataLayer.colors.ColoredInhibitorArc;
28
import pipe.dataLayer.colors.ColoredInputArc;
29
import pipe.dataLayer.colors.ColoredOutputArc;
30
import pipe.dataLayer.colors.ColoredTimedPlace;
31
import pipe.dataLayer.colors.ColoredTransportArc;
32
import pipe.gui.widgets.JSplitPaneFix;
33
import pipe.gui.widgets.LeftConstantsPane;
34
import pipe.gui.widgets.LeftQueryPane;
10
import dk.aau.cs.gui.TabContent;
35
11
import dk.aau.cs.verification.UPPAAL.Verifyta;
38
13
public class CreateGui {
40
private static final double DIVIDER_LOCATION = 0.5;
41
15
public static GuiFrame appGui;
42
16
private static Animator animator;
43
17
private static JTabbedPane appTab;
44
private static ArrayList<TabData> tabs = new ArrayList<TabData>();
18
private static ArrayList<TabContent> tabs = new ArrayList<TabContent>();
20
private static boolean usingGTKFileBrowser = true;
46
22
public static String imgPath, userPath; // useful for stuff
48
public static class TabData { // a structure for holding a tab's data
49
public DataLayer appModel;
50
public HashMap<PetriNetObject, String> oldGuards;
51
public GuiView appView;
55
/** The Module will go in the top pane, the animation window in the bottom pane */
56
private static JSplitPane leftPane;
57
private static AnimationHistory animBox;
58
static AnimationController animControlerBox;
59
private static JScrollPane scroller;
60
private static JScrollPane scroller2;
61
private static LeftQueryPane queries;
62
private static LeftConstantsPane leftBottomPanel;
63
private static JSplitPane pane;
64
private static AnimationHistory abstractAnimationPane=null;
66
24
public static void init() {
67
25
imgPath = "resources/Images" + System.getProperty("file.separator");
69
// make the initial dir for browsing be My Documents (win), ~ (*nix), etc
27
// make the initial dir for browsing be My Documents (win), ~ (*nix),
73
31
appGui = new GuiFrame(Pipe.TOOL + " " + Pipe.VERSION);
79
35
appTab = new JTabbedPane();
81
37
animator = new Animator();
82
appGui.setTab(); // sets Tab properties
85
queries = new LeftQueryPane(new ArrayList<TAPNQuery>());
86
leftPane = new JSplitPaneFix(JSplitPane.VERTICAL_SPLIT);
87
leftPane.setPreferredSize(new Dimension(262, 100)); // height is ignored because the component is stretched
88
leftPane.setMinimumSize(new Dimension(175,100));
91
pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,leftPane,appTab);
93
pane.setContinuousLayout(true);
94
pane.setOneTouchExpandable(true);
95
pane.setBorder(null); // avoid multiple borders
97
pane.setDividerSize(8);
100
appGui.getContentPane().add(pane);
102
//appGui.createNewTabFromFile(null);
39
appGui.setTab(); // sets Tab properties
41
appGui.getContentPane().add(appTab);
43
// appGui.createNewTabFromFile(null);
104
45
appGui.setVisible(true);
46
appGui.activateSelectAction();
107
47
Verifyta.trySetupFromEnvironmentVariable();
109
49
VersionChecker versionChecker = new VersionChecker();
110
if(versionChecker.checkForNewVersion()){
111
StringBuffer message = new StringBuffer(
112
"There is a new version of TAPAAL available at www.tapaal.net.");
50
if (versionChecker.checkForNewVersion()) {
51
StringBuffer message = new StringBuffer("There is a new version of TAPAAL available at www.tapaal.net.");
113
52
message.append("\n\nCurrent version: ");
114
53
message.append(Pipe.VERSION);
115
54
message.append("\nNew version: ");
116
message.append(versionChecker.getNewVersionNumber());
55
message.append(versionChecker.getNewVersionNumber());
118
JOptionPane.showMessageDialog(appGui,
120
"New version available!",
121
JOptionPane.INFORMATION_MESSAGE);
57
JOptionPane.showMessageDialog(appGui, message.toString(),
58
"New version available!", JOptionPane.INFORMATION_MESSAGE);
126
public static GuiFrame getApp() { //returns a reference to the application
62
public static GuiFrame getApp() { // returns a reference to the application
131
66
public static DataLayer getModel() {
132
67
return getModel(appTab.getSelectedIndex());
140
TabData tab = (getTabDataForTab(index));
141
if (tab.appModel == null) {
142
tab.appModel = new DataLayer();
148
static TabData getTabDataForTab(int index) {
149
return tabs.get(index);
153
public static GuiView getView(int index) {
75
TabContent tab = (tabs.get(index));
76
return tab.getModel();
79
public static DrawingSurfaceImpl getDrawingSurface() {
80
return getDrawingSurface(appTab.getSelectedIndex());
83
public static DrawingSurfaceImpl getDrawingSurface(int index) {
158
TabData tab = (getTabDataForTab(index));
159
while (tab.appView == null) {
89
TabContent tab = (tabs.get(index));
90
while (tab.drawingSurface() == null) {
161
tab.appView = new GuiView(tab.appModel);
162
} catch (Exception e){
93
tab.setDrawingSurface(new DrawingSurfaceImpl(tab.getModel(),
95
} catch (Exception e) {
163
96
e.printStackTrace();
170
public static GuiView getView() {
171
return getView(appTab.getSelectedIndex());
99
return tab.drawingSurface();
102
public static DrawingSurfaceImpl getView() {
103
return getDrawingSurface(appTab.getSelectedIndex());
175
106
public static File getFile() {
176
TabData tab = (tabs.get(appTab.getSelectedIndex()));
107
return getFile(appTab.getSelectedIndex());
181
110
public static void setFile(File modelfile, int fileNo) {
182
111
if (fileNo >= tabs.size()) {
185
TabData tab = (getTabDataForTab(fileNo));
186
tab.appFile = modelfile;
115
TabContent tab = (tabs.get(fileNo));
116
tab.setFile(modelfile);
190
120
public static int getFreeSpace() {
191
tabs.add(new TabData());
121
tabs.add(new TabContent());
192
122
return tabs.size() - 1;
196
125
public static void removeTab(int index) {
197
126
tabs.remove(index);
204
129
public static JTabbedPane getTab() {
133
public static TabContent getTab(int index) {
134
return tabs.get(index);
137
public static TabContent getCurrentTab() {
138
return tabs.get(appTab.getSelectedIndex());
208
141
public static Animator getAnimator() {
212
/** returns the current dataLayer object -
213
* used to get a reference to pass to the modules */
146
* returns the current dataLayer object - used to get a reference to pass to
214
149
public static DataLayer currentPNMLData() {
215
150
if (appTab.getSelectedIndex() < 0) {
218
TabData tab = (tabs.get(appTab.getSelectedIndex()));
222
public static void setupModelForSimulation(){
223
if (appTab.getSelectedIndex() >= 0) {
224
TabData tab = (tabs.get(appTab.getSelectedIndex()));
225
//DataLayer model = tab.appModel.clone();
226
if(!tab.appModel.isUsingColors()){
227
HashMap<PetriNetObject, String> oldGuards = transformToModelWithoutConstants(tab.appModel);
228
tab.oldGuards = oldGuards;
230
configureNetToShowValues(tab.appModel, true);
235
private static void configureNetToShowValues(DataLayer model, boolean showValues) {
236
for(Place tp : model.getPlaces()){
237
ColoredTimedPlace place = (ColoredTimedPlace)tp;
238
place.displayValues(showValues);
241
for(Arc arc : model.getArcs()){
242
if(arc instanceof ColoredTransportArc){
243
((ColoredTransportArc)arc).displayValues(showValues);
244
}else if(arc instanceof ColoredInputArc){
245
((ColoredInputArc)arc).displayValues(showValues);
246
}else if(arc instanceof ColoredInhibitorArc){
247
((ColoredInhibitorArc)arc).displayValues(showValues);
248
}else if(arc instanceof ColoredOutputArc){
249
((ColoredOutputArc)arc).displayValues(showValues);
255
public static void restoreModelForEditing(){
256
if (appTab.getSelectedIndex() >= 0) {
257
TabData tab = (tabs.get(appTab.getSelectedIndex()));
258
if(tab.appModel.isUsingColors()){
259
configureNetToShowValues(tab.appModel, false);
261
if(tab.oldGuards != null){
262
setupModelWithOldGuards(tab.appModel, tab.oldGuards);
263
tab.oldGuards = null;
269
static void setupModelWithOldGuards(DataLayer model,
270
HashMap<PetriNetObject, String> oldGuards) {
271
for(Place p : model.getPlaces()){
272
if(p instanceof TimedPlace){
273
String inv = oldGuards.get(p);
274
((TimedPlace)p).setInvariant(inv);
278
for(Arc arc : model.getArcs()){
279
if(arc instanceof TimedArc || arc instanceof TransportArc){
280
TimedArc tarc = (TimedArc)arc;
281
String guard = oldGuards.get(arc);
282
tarc.setGuard(guard);
288
public static HashMap<PetriNetObject, String> transformToModelWithoutConstants(DataLayer model) {
289
HashMap<PetriNetObject, String> oldGuards = new HashMap<PetriNetObject, String>();
291
for(Place p : model.getPlaces()){
292
if(p instanceof TimedPlace){
293
oldGuards.put(p, ((TimedPlace) p).getInvariant());
294
String inv = getInvariant(p, model);
295
((TimedPlace)p).setInvariant(inv);
299
for(Arc arc : model.getArcs()){
300
if(arc instanceof TimedArc || arc instanceof TransportArc){
301
oldGuards.put(arc, ((TimedArc) arc).getGuard());
302
TimedArc tarc = (TimedArc)arc;
303
String guard = getGuard(tarc, model);
304
tarc.setGuard(guard);
311
private static String getGuard(TimedArc arc, DataLayer model) {
312
String guard = arc.getGuard();
313
String leftDelim = guard.substring(0,1);
314
String rightDelim = guard.substring(guard.length()-1, guard.length());
315
String first = guard.substring(1, guard.indexOf(","));
316
String second = guard.substring(guard.indexOf(",")+1, guard.length()-1);
318
boolean isFirstConstant = false;
319
boolean isSecondConstant = false;
322
Integer.parseInt(first);
323
}catch(NumberFormatException e){
324
isFirstConstant = true;
328
Integer.parseInt(second);
329
}catch(NumberFormatException e){
330
if(!second.equals("inf")) isSecondConstant = true;
334
first = String.valueOf(model.getConstantValue(first));
337
if(isSecondConstant){
338
second = String.valueOf(model.getConstantValue(second));
341
return leftDelim + first + "," + second + rightDelim;
344
private static String getInvariant(Place place, DataLayer model) {
345
String inv = ((TimedPlace)place).getInvariant();
346
String operator = inv.contains("<=") ? "<=" : "<";
348
String bound = inv.substring(operator.length());
350
boolean isConstant = false;
352
Integer.parseInt(bound);
353
}catch(NumberFormatException e){
354
if(!bound.equals("inf")) isConstant = true;
358
bound = String.valueOf(model.getConstantValue(bound));
360
return operator + bound;
364
/** Creates a new animationHistory text area, and returns a reference to it*/
365
public static void addAnimationHistory() {
367
animBox = new AnimationHistory();
368
//animBox.setEditable(false);
370
scroller = new JScrollPane(animBox);
371
scroller.setBorder(BorderFactory.createCompoundBorder(
372
BorderFactory.createTitledBorder("Simulation History"),
373
BorderFactory.createEmptyBorder(3,3,3,3)));
374
leftPane.setBottomComponent(scroller);
375
//animBox.setScroller(scroller);
376
// leftPane.setDividerLocation(0.5);
377
leftPane.setResizeWeight(0.05f);
379
leftPane.setDividerSize(8);
380
} catch (javax.swing.text.BadLocationException be) {
381
be.printStackTrace();
386
public static AnimationHistory getAbstractAnimationPane(){
387
return abstractAnimationPane;
154
TabContent tab = (tabs.get(appTab.getSelectedIndex()));
155
return tab.getModel();
158
/** Creates a new animationHistory text area, and returns a reference to it */
159
public static void switchToAnimationComponents() {
160
TabContent tab = (tabs.get(appTab.getSelectedIndex()));
161
tab.switchToAnimationComponents();
164
public static void switchToEditorComponents() {
165
TabContent tab = (tabs.get(appTab.getSelectedIndex()));
166
tab.switchToEditorComponents();
169
public static AnimationHistoryComponent getAbstractAnimationPane() {
170
TabContent tab = (tabs.get(appTab.getSelectedIndex()));
171
return tab.getUntimedAnimationHistory();
390
175
public static void addAbstractAnimationPane() {
394
abstractAnimationPane=new AnimationHistory();
395
} catch (BadLocationException e) {
396
// TODO Auto-generated catch block
399
//abstractAnimationPane.setVerticalAlignment(SwingConstants.TOP);
401
//Create a new empty animBox
403
animBox = new AnimationHistory();
404
//animBox.setEditable(false);
405
} catch (BadLocationException e) {
406
// TODO Auto-generated catch block
412
new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,animBox,abstractAnimationPane);
414
pane2.setContinuousLayout(true);
415
pane2.setOneTouchExpandable(true);
416
pane2.setBorder(null); // avoid multiple borders
418
pane2.setDividerSize(8);
420
leftPane.setBottomComponent(pane2);
421
abstractAnimationPane.setBorder(new LineBorder(Color.black));
176
TabContent tab = (tabs.get(appTab.getSelectedIndex()));
177
tab.addAbstractAnimationPane();
180
public static AnimationController getAnimationController() {
181
TabContent tab = (tabs.get(appTab.getSelectedIndex()));
182
return tab.getAnimationController();
425
186
public static void removeAbstractAnimationPane() {
426
abstractAnimationPane=null;
427
scroller = new JScrollPane(animBox);
428
scroller.setBorder(new EmptyBorder(0,0,0,0)); // make it less bad on XP
429
leftPane.setBottomComponent(scroller);
432
public static void addAnimationControler() {
434
animControlerBox = new AnimationController("Simulation Controler\n");
436
scroller2 = new JScrollPane(animControlerBox);
437
scroller2.setBorder(new EmptyBorder(0,0,0,0)); // make it less bad on XP
438
scroller2.setMinimumSize(new Dimension(200,95));
439
scroller2.setPreferredSize(new Dimension(200,95));
440
leftPane.setTopComponent(scroller2);
442
// leftPane.setDividerLocation(0.5);
443
leftPane.setDividerSize(8);
444
leftPane.resetToPreferredSizes();
445
//shortcutBottons should be usable from start of
446
animControlerBox.requestFocus(true);
447
} catch (javax.swing.text.BadLocationException be) {
448
be.printStackTrace();
449
System.out.println("There where an error in creating the AnimationControler");
453
public static void removeAnimationHistory() {
454
if (scroller != null) {
455
leftPane.remove(scroller);
456
leftPane.setDividerLocation(DIVIDER_LOCATION);
457
leftPane.setDividerSize(0);
460
public static void removeAnimationControler() {
461
if (scroller != null) {
462
leftPane.remove(scroller2);
463
leftPane.setDividerLocation(DIVIDER_LOCATION);
464
leftPane.setDividerSize(0);
469
public static AnimationHistory getAnimationHistory() {
473
public static void createLeftPane(){
474
DataLayer model = CreateGui.getModel();
475
boolean enableAddButton = model == null ? true : !model.netType().equals(NetType.UNTIMED);
476
leftBottomPanel = new LeftConstantsPane(enableAddButton);
477
queries = new LeftQueryPane(
478
getModel() == null ? new ArrayList<TAPNQuery>() : getModel().getQueries()
480
leftPane.setDividerLocation(DIVIDER_LOCATION);
481
leftPane.setResizeWeight(0.5);
482
leftPane.setTopComponent(queries);
483
leftPane.setBottomComponent(leftBottomPanel);
484
leftPane.setContinuousLayout(true);
485
leftPane.setDividerSize(0);
486
leftPane.setPreferredSize(new Dimension(290,400));
490
public static void emptyLeftPane(){
491
leftPane.setTopComponent(null);
492
leftPane.setBottomComponent(null);
495
public static void updateConstantsList(){
496
leftBottomPanel.showConstants();
499
public static void updateLeftPanel() {
187
TabContent tab = (tabs.get(appTab.getSelectedIndex()));
188
tab.removeAbstractAnimationPane();
191
// public static void addAnimationController() {
192
// TabContent tab = (tabs.get(appTab.getSelectedIndex()));
193
// //tab.addAnimationController();
196
// public static void removeAnimationHistory() {
197
// TabContent tab = (tabs.get(appTab.getSelectedIndex()));
198
// tab.removeAnimationHistory();
201
// public static void removeAnimationController() {
202
// TabContent tab = (tabs.get(appTab.getSelectedIndex()));
203
// tab.removeAnimationController();
206
public static AnimationHistoryComponent getAnimationHistory() {
207
TabContent tab = (tabs.get(appTab.getSelectedIndex()));
208
return tab.getAnimationHistory();
211
public static void updateConstantsList() {
212
TabContent tab = (tabs.get(appTab.getSelectedIndex()));
213
tab.updateConstantsList();
504
216
public static void undoGetFreeSpace() {
505
tabs.remove(tabs.size()-1);
217
tabs.remove(tabs.size() - 1);
220
public static File getFile(int index) {
221
TabContent tab = tabs.get(index);
222
return tab.getFile();
225
public static void setUsingGTKFileBrowser(boolean useGTKFileBrowser) {
226
usingGTKFileBrowser = useGTKFileBrowser;
229
public static boolean usingGTKFileBrowser() {
230
return usingGTKFileBrowser;