1 |
package appl.parallel.gui; |
2 |
|
3 |
import java.awt.GridBagConstraints; |
4 |
import java.awt.Insets; |
5 |
import java.awt.event.ActionEvent; |
6 |
import java.awt.event.ActionListener; |
7 |
|
8 |
import appl.parallel.model.AbstractParallelStepModel; |
9 |
import de.schmitzm.lang.WorkingThread; |
10 |
import de.schmitzm.lang.WorkingThreadAdapter; |
11 |
import edu.bonn.xulu.XuluModellingPlatform; |
12 |
import edu.bonn.xulu.model.XuluModel; |
13 |
import edu.bonn.xulu.plugin.gui.ModelControlContainer; |
14 |
import edu.bonn.xulu.plugin.gui.ModelControlFrame_Basic; |
15 |
|
16 |
/** |
17 |
* Introduces a new TAB into the {@link ModelControlFrame_Basic} |
18 |
* for controlling the parallel execution |
19 |
* |
20 |
* @author Dominik Appl |
21 |
*/ |
22 |
public class ModelControlFrame_parallel extends ModelControlFrame_Tabbed { |
23 |
|
24 |
protected ParallelControlPanelEngine spcEngine; |
25 |
|
26 |
private boolean parallelPaneInitalized; |
27 |
|
28 |
/** |
29 |
* @param appl |
30 |
* @param model |
31 |
*/ |
32 |
public ModelControlFrame_parallel(XuluModellingPlatform appl, |
33 |
XuluModel model) { |
34 |
super(appl, model); |
35 |
this.pack(); |
36 |
} |
37 |
|
38 |
/** |
39 |
* does basically the same as |
40 |
* {@link ModelControlFrame_Basic#initControlContainer()} |
41 |
*/ |
42 |
protected void initControlContainer() { |
43 |
spcEngine = new ParallelControlPanelEngine(appl); |
44 |
// ####### Initialize controlcomponent ####### |
45 |
controlContainer = new ModelControlContainer_parallel(model, spcEngine, |
46 |
appl); |
47 |
|
48 |
// ******************** COPIED FROM SUPERCLASS |
49 |
// ************************** |
50 |
|
51 |
// Bei Init-Aktion muessen zunaechst die Modell-Ressourcen mit den |
52 |
// ausgewaehlten |
53 |
// Datenpool-Objekten verknuepft werden; bevor das Modell initialisiert |
54 |
// wird |
55 |
controlContainer.addButtonActionListener( |
56 |
ModelControlContainer.BUTTON_INIT, new ActionListener() { |
57 |
public void actionPerformed(ActionEvent e) { |
58 |
setModelResources(); |
59 |
} |
60 |
}); |
61 |
// Waehrend das Modell laeuft, soll nichts an den Ressourcen veraendet |
62 |
// werden |
63 |
controlContainer.addThreadListener(new WorkingThreadAdapter() { |
64 |
public void threadStarted(WorkingThread thread) { |
65 |
contentContainer.setEnabled(false); |
66 |
reloadButton.setEnabled(false); |
67 |
} |
68 |
|
69 |
public void threadStopped(WorkingThread thread) { |
70 |
contentContainer.setEnabled(true); |
71 |
reloadButton.setEnabled(true); |
72 |
} |
73 |
}); |
74 |
contentPane.add(controlContainer, new GridBagConstraints(0, 0, 1, 1, |
75 |
1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, |
76 |
new Insets(5, 5, 5, 5), 0, 0)); |
77 |
} |
78 |
|
79 |
@Override |
80 |
protected void initContentPane() { |
81 |
super.initContentPane(); |
82 |
// System.out.println(model.getClass().getName()); |
83 |
if (model instanceof AbstractParallelStepModel) { |
84 |
initializeParallelPane(); |
85 |
} else |
86 |
parallelPaneInitalized = false; |
87 |
} |
88 |
|
89 |
private boolean isParallelPaneInitalized() { |
90 |
return parallelPaneInitalized; |
91 |
} |
92 |
|
93 |
@Override |
94 |
protected ModelControlFrame_parallel newInstance(XuluModel newModel) { |
95 |
ModelControlFrame_parallel frame_parallel = new ModelControlFrame_parallel( |
96 |
appl, newModel); |
97 |
// initialize the parallel pane if it was initialized before |
98 |
if (this.isParallelPaneInitalized() |
99 |
&& !frame_parallel.isParallelPaneInitalized()) { |
100 |
if (newModel.getClass().getName() |
101 |
.equals(model.getClass().getName())) { |
102 |
frame_parallel.initializeParallelPane(); |
103 |
} |
104 |
} |
105 |
return frame_parallel; |
106 |
} |
107 |
|
108 |
private void initializeParallelPane() { |
109 |
super.tabbedPane.addTab("Parallel Control", spcEngine.getPanel()); |
110 |
// The boolean parallelPaneInitalized is required because after |
111 |
// reloading |
112 |
// with a custom classloader, like the preferred classloader, the |
113 |
// 'instanceof' will no longer work properly with the reloaded class. |
114 |
// (instanceof will return false) |
115 |
parallelPaneInitalized = true; |
116 |
} |
117 |
|
118 |
} |