@@ -14,7 +14,6 @@ import org.nlogo.app.{ App, ToolsMenu }
1414import org .nlogo .awt .EventQueue
1515import org .nlogo .core .LogoList
1616import org .nlogo .nvm .HaltException
17- import org .nlogo .theme .ThemeSync
1817import org .nlogo .workspace .{ AbstractWorkspace , ExtensionManager => WorkspaceExtensionManager }
1918
2019import scala .collection .immutable .ArraySeq
@@ -55,9 +54,15 @@ object LevelSpace {
5554 }
5655}
5756
58- class LevelSpace extends DefaultClassManager with ThemeSync { // This can be accessed by both the JobThread and EDT (when halting)
57+ class LevelSpace extends DefaultClassManager { // This can be accessed by both the JobThread and EDT (when halting)
5958 LevelSpace .checkSupportNetLogoVersion()
6059
60+ private var functionID : Option [Long ] = None
61+
62+ private def addSyncFunction (): Unit = {
63+ functionID = Some (App .app.addSyncFunction(() => syncTheme()))
64+ }
65+
6166 final private val models = new ConcurrentHashMap [Integer , ChildModel ].asScala
6267 // counter for keeping track of new models
6368 private var modelCounter = 0
@@ -96,9 +101,6 @@ class LevelSpace extends DefaultClassManager with ThemeSync { // This can be acc
96101 primitiveManager.addPrimitive(" uses-level-space?" , new UsesLS (this ))
97102 primitiveManager.addPrimitive(" random-seed" , new RandomSeed (this ))
98103 primitiveManager.addPrimitive(" assign" , new Assign (this ))
99- // We need to actually listen for halt actions because gui child models can be running independently on their own
100- // job threads if the user is interacting with them.
101- haltButton.foreach(_.addActionListener(haltListener))
102104 }
103105
104106 def isMainModel (myEM : ExtensionManager ): Boolean = myEM eq App .app.workspace.getExtensionManager
@@ -115,11 +117,14 @@ class LevelSpace extends DefaultClassManager with ThemeSync { // This can be acc
115117
116118 @ throws[ExtensionException ]
117119 override def unload (em : ExtensionManager ): Unit = {
118- if (! LevelSpace .isHeadless && isMainModel(em)) {
119- App .app.frame.getJMenuBar.remove(modelManager.guiComponent)
120- App .app.removeSyncComponent(this )
120+ if (! LevelSpace .isHeadless) {
121+ if (isMainModel(em)) {
122+ App .app.frame.getJMenuBar.remove(modelManager.guiComponent)
123+ functionID.foreach(App .app.removeSyncFunction)
124+ }
125+
126+ haltButton.foreach(_.removeActionListener(haltListener))
121127 }
122- haltButton.foreach(_.removeActionListener(haltListener))
123128 try reset()
124129 catch {
125130 case _ : HaltException =>
@@ -211,20 +216,30 @@ class LevelSpace extends DefaultClassManager with ThemeSync { // This can be acc
211216 em.asInstanceOf [WorkspaceExtensionManager ].workspace.isInstanceOf [AbstractWorkspace ] &&
212217 em.asInstanceOf [WorkspaceExtensionManager ].workspace.asInstanceOf [AbstractWorkspace ].isHeadless
213218
214- if (! LevelSpace .isHeadless) { modelManager = new BackingModelManager }
219+ if (! LevelSpace .isHeadless) {
220+ modelManager = new BackingModelManager
221+ // We need to actually listen for halt actions because gui child models can be running independently on their own
222+ // job threads if the user is interacting with them.
223+ haltButton.foreach(_.addActionListener(haltListener))
224+ }
215225 modelManager.updateChildModels(models)
216226 if (! LevelSpace .isHeadless && isMainModel(em)) {
217227 val menuBar = App .app.frame.getJMenuBar
218228 if (menuBar.getComponentIndex(modelManager.guiComponent) == - 1 ) {
219229 menuBar.add(modelManager.guiComponent)
220230 }
221- App .app.addSyncComponent( this )
231+ addSyncFunction( )
222232 }
223233 }
224234
225235 private def haltChildModels (): Unit = models.values.foreach(_.halt())
226236
227237 def syncTheme (): Unit = {
228- modelManager.syncTheme()
238+ modelManager match {
239+ case guiManager : BackingModelManager =>
240+ guiManager.syncTheme()
241+
242+ case _ =>
243+ }
229244 }
230245}
0 commit comments