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