Skip to content

Commit 5e5f166

Browse files
committed
Initial conversion
1 parent 1e981d1 commit 5e5f166

10 files changed

Lines changed: 105 additions & 119 deletions

build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import org.nlogo.build.{ ExtensionDocumentationPlugin, NetLogoExtension }
22

33
enablePlugins(NetLogoExtension, ExtensionDocumentationPlugin)
44

5-
scalaVersion := "2.13.16"
5+
scalaVersion := "3.7.0"
66

77
name := "LevelSpace"
88
version := "2.3.4"
99
isSnapshot := true
1010

1111
netLogoExtName := "ls"
1212
netLogoClassManager := "org.nlogo.ls.LevelSpace"
13-
netLogoVersion := "7.0.0-internal1-df97144"
13+
netLogoVersion := "7.0.0-beta1"
1414
netLogoTestExtras += (baseDirectory.value / "test")
1515

1616
Compile / scalaSource := baseDirectory.value / "src" / "main"

src/main/ChildModel.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ abstract class ChildModel(val parentWorkspace: Workspace, val modelID: Int) exte
5353
// can't change once model is loaded
5454
lazy val usesLevelSpace: Boolean =
5555
workspace.getExtensionManager.loadedExtensions.asScala.exists(
56-
_.getClass.toString equals classOf[LevelSpace].toString
56+
_.getClass.toString == classOf[LevelSpace].toString
5757
)
5858

5959
def show(): Unit = frame.foreach { f => onEDT { f.setVisible(true) } }

src/main/GUIChildModel.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,24 @@ class GUIChildModel @throws(classOf[InterruptedException]) @throws(classOf[Exten
5959
def setSpeed(d: Double): Unit = {
6060
// Note the panel will update and store the speed even if the frame is not visible. The thing is, we don't want
6161
// to slow the model down if it's not visible
62-
workspace.updateManager().speed = d
62+
workspace.updateManager.speed = d
6363
// Wakes up the workspace if the speed slider is super low.
6464
// Makes it so there's not a long pause after increasing
6565
// the speed slider from a low position. BCH 6/18/2016
66-
workspace.updateManager().nudgeSleeper()
66+
workspace.updateManager.nudgeSleeper()
6767
onEDT {
6868
panel.speedSlider.setValue((d * 2).intValue)
6969
}
7070
}
7171

7272
override def hide(): Unit = {
73-
workspace.updateManager().speed = 50
74-
workspace.updateManager().nudgeSleeper()
73+
workspace.updateManager.speed = 50
74+
workspace.updateManager.nudgeSleeper()
7575
super.hide()
7676
}
7777

7878
override def show(): Unit = {
79-
workspace.updateManager().speed = panel.speedSlider.getValue / 2.0
79+
workspace.updateManager.speed = panel.speedSlider.getValue / 2.0
8080
syncTheme()
8181
super.show()
8282
}

src/main/GUIPanel.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ extends ModelPanel(ws, panel, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, 1)
7777
val speedSlider = new JSlider(-110, 112, ws.speedSliderPosition().toInt)
7878
speedSlider.addChangeListener((_: ChangeEvent) => {
7979
ws.speedSliderPosition(speedSlider.getValue / 2)
80-
ws.updateManager().nudgeSleeper()
80+
ws.updateManager.nudgeSleeper()
8181
})
8282
speedSliderPanel.add(speedSlider)
8383
controlStrip.add(speedSliderPanel, BorderLayout.CENTER)

src/main/HeadlessChildModel.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import org.nlogo.workspace.{AbstractWorkspace, AbstractWorkspaceScala}
1313
class HeadlessChildModel (parentWorkspace: AbstractWorkspace, path: String, modelID: Int)
1414
extends ChildModel(parentWorkspace, modelID) {
1515

16-
val world: World with CompilationManagement = if(Version.is3D) new World3D() else new World2D()
16+
val world: World & CompilationManagement = if(Version.is3D) new World3D() else new World2D()
1717

1818
var frame: Option[ViewFrame] = None
1919

src/main/InterfaceComponent.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ with ThemeSync {
3232
val listenerManager = new NetLogoListenerManager
3333
val world: World = if(Version.is3D) new World3D() else new World2D()
3434

35-
// KioskLevel.NONE - We want a 3d button
36-
val workspace: GUIWorkspace = new GUIWorkspace(world, GUIWorkspace.KioskLevel.NONE, frame, frame, null, new ExternalFileManager, listenerManager, new ErrorDialogManager(frame), this) {
35+
// KioskLevel.None - We want a 3d button
36+
val workspace: GUIWorkspace = new GUIWorkspace(world, GUIWorkspace.KioskLevel.None, frame, frame, null, new ExternalFileManager, listenerManager, new ErrorDialogManager(frame), this) {
3737
val compiler = new Compiler(if (Version.is3D) NetLogoThreeDDialect else NetLogoLegacyDialect)
3838

3939
lazy val updateManager = new UpdateManager {
@@ -72,7 +72,7 @@ with ThemeSync {
7272
addLinkComponent(workspace.aggregateManager)
7373
addLinkComponent(workspace)
7474
addLinkComponent(procedures)
75-
addLinkComponent(new CompilerManager(workspace, workspace.world.asInstanceOf[World with CompilationManagement], procedures))
75+
addLinkComponent(new CompilerManager(workspace, workspace.world.asInstanceOf[World & CompilationManagement], procedures))
7676
addLinkComponent(new CompiledEvent.Handler {
7777
override def handle(e: CompiledEvent): Unit = {
7878
if (e.error != null)

src/main/LevelSpace.scala

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,8 @@ import java.util.Objects
88
import java.util.concurrent.ConcurrentHashMap
99
import javax.swing.JMenuItem
1010

11-
import org.nlogo.api.{
12-
Argument
13-
, DefaultClassManager
14-
, ExtensionException
15-
, ExtensionManager
16-
, ImportErrorHandler
17-
, LogoException
18-
, PrimitiveManager
19-
, Version
20-
}
11+
import org.nlogo.api.{ Argument, DefaultClassManager, ExtensionException, ExtensionManager, ImportErrorHandler,
12+
LogoException, PrimitiveManager, Version }
2113
import org.nlogo.app.{ App, ToolsMenu }
2214
import org.nlogo.awt.EventQueue
2315
import org.nlogo.core.LogoList
@@ -115,7 +107,7 @@ class LevelSpace extends DefaultClassManager with ThemeSync { // This can be acc
115107

116108
def containsModel(id: Int): Boolean = models.contains(id)
117109

118-
def modelList: Seq[Integer] = Seq(ArraySeq.unsafeWrapArray(models.keys.toArray.sorted): _*)
110+
def modelList: Seq[Integer] = Seq(ArraySeq.unsafeWrapArray(models.keys.toArray.sorted)*)
119111

120112
def numModels: Integer = models.size
121113

src/main/LevelSpaceMenu.scala

Lines changed: 84 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -66,115 +66,109 @@ class LevelSpaceMenu(tabManager: TabManager, val backingModelManager: ModelManag
6666
}
6767
}
6868

69-
object LevelSpaceMenu {
70-
abstract class NewTabAction(name: String, modelManager: ModelManager) extends AbstractAction(name) {
71-
val tabManager = App.app.tabManager
69+
object LevelSpaceMenu {
70+
abstract class NewTabAction(name: String, modelManager: ModelManager) extends AbstractAction(name) {
71+
val tabManager = App.app.tabManager
7272

73-
def filePath: Option[String]
73+
def filePath: Option[String]
7474

75-
def actingTab: Option[CodeTab] =
76-
filePath.flatMap(path => locateExistingTab(path) orElse createNewTab(path))
75+
def actingTab: Option[CodeTab] =
76+
filePath.flatMap(path => locateExistingTab(path) orElse createNewTab(path))
7777

78-
private def locateExistingTab(path: String): Option[CodeTab] =
79-
modelManager.existingTab(path)
78+
private def locateExistingTab(path: String): Option[CodeTab] =
79+
modelManager.existingTab(path)
8080

81-
private def createNewTab(path: String): Option[CodeTab] = {
82-
modelManager.registerTab(path) { workspace =>
83-
val tab = new ModelCodeTab(workspace, tabManager, modelManager)
84-
tabManager.addTab(tab, tab.tabName)
85-
tab
86-
}
81+
private def createNewTab(path: String): Option[CodeTab] = {
82+
modelManager.registerTab(path) { workspace =>
83+
val tab = new ModelCodeTab(workspace, tabManager, modelManager)
84+
tabManager.addTab(tab, tab.tabName)
85+
tab
8786
}
88-
89-
override def actionPerformed(actionEvent: ActionEvent): Unit =
90-
actingTab.foreach(tabManager.setSelectedTab)
9187
}
9288

93-
class OpenModelAction(fileName: String, modelManager: ModelManager)
94-
extends NewTabAction(fileName, modelManager) {
95-
override def filePath: Option[String] = Some(fileName)
96-
}
89+
override def actionPerformed(actionEvent: ActionEvent): Unit =
90+
actingTab.foreach(tabManager.setSelectedTab)
91+
}
9792

98-
class SelectModelAction(name: String, modelManager: ModelManager)
99-
extends NewTabAction(name, modelManager) {
100-
101-
override def filePath: Option[String] = selectFile
102-
103-
override def actingTab: Option[CodeTab] =
104-
try {
105-
super.actingTab
106-
} catch {
107-
case e: CompilerException =>
108-
// we shouldn't have to raise an exception here, we should just be able to open it, but
109-
// in order to do that, we'll need to change child models not to compile in their constructors
110-
throw new ExtensionException(s"$filePath did not compile properly. There is probably something wrong " +
111-
s"with its code. Exception said ${e.getMessage}")
112-
case e: IOException =>
113-
throw new ExtensionException(s"There was no model file at the path: \"$filePath\"")
114-
}
93+
class OpenModelAction(fileName: String, modelManager: ModelManager) extends NewTabAction(fileName, modelManager) {
94+
override def filePath: Option[String] = Some(fileName)
95+
}
96+
97+
class SelectModelAction(name: String, modelManager: ModelManager) extends NewTabAction(name, modelManager) {
98+
override def filePath: Option[String] = selectFile
99+
100+
override def actingTab: Option[CodeTab] =
101+
try {
102+
super.actingTab
103+
} catch {
104+
case e: CompilerException =>
105+
// we shouldn't have to raise an exception here, we should just be able to open it, but
106+
// in order to do that, we'll need to change child models not to compile in their constructors
107+
throw new ExtensionException(s"$filePath did not compile properly. There is probably something wrong " +
108+
s"with its code. Exception said ${e.getMessage}")
109+
case e: IOException =>
110+
throw new ExtensionException(s"There was no model file at the path: \"$filePath\"")
111+
}
112+
113+
private def selectFile: Option[String] =
114+
showLoadSelection.flatMap(path =>
115+
if (ModelsLibrary.getModelPaths.contains(path)) {
116+
showLibraryModelErrorMessage()
117+
None
118+
} else
119+
Some(path))
120+
121+
private def showLoadSelection: Option[String] =
122+
try {
123+
Some(FileDialog.showFiles(App.app.frame, "Load a LevelSpace Model...", LOADFILE))
124+
} catch {
125+
case e: UserCancelException =>
126+
Exceptions.ignore(e)
127+
None
128+
}
115129

130+
private def showLibraryModelErrorMessage(): Unit =
131+
JOptionPane.showMessageDialog(
132+
App.app.frame,
133+
"""|The model you selected is a library model, which cannot be opened in a LevelSpace code tab.
134+
|Please save the model elsewhere and try re-opening""".stripMargin)
135+
}
116136

117-
private def selectFile: Option[String] =
118-
showLoadSelection.flatMap(path =>
119-
if (ModelsLibrary.getModelPaths.contains(path)) {
120-
showLibraryModelErrorMessage()
121-
None
122-
} else
123-
Some(path))
137+
class NewModelAction(name: String, modelManager: ModelManager) extends NewTabAction(name, modelManager) {
138+
override def filePath: Option[String] = {
139+
FileDialog.setDirectory(App.app.workspace.getModelDir)
124140

125-
private def showLoadSelection: Option[String] =
141+
val ws = App.app.workspace
142+
val loader = FileFormat.basicLoader
143+
val controller = new SaveModel.Controller {
144+
def chooseFilePath(modelType: org.nlogo.api.ModelType): Option[java.net.URI] = {
126145
try {
127-
Some(FileDialog.showFiles(App.app.frame, "Load a LevelSpace Model...", LOADFILE))
146+
val userEntry = FileDialog.showFiles(App.app.frame, "Select a path for new Model...", SAVEFILE)
147+
// we basically need to write an empty NetLogo model in before we read...
148+
val fileName =
149+
if (userEntry.endsWith(".nlogo") || userEntry.endsWith(".nlogox")) userEntry else userEntry + ".nlogox"
150+
val path = Paths.get(fileName)
151+
if (Files.exists(path)) {
152+
val fileAlreadyExists = s"The file $fileName already exists. Please choose a different name"
153+
throw new ExtensionException(fileAlreadyExists)
154+
}
155+
Some(path.toUri)
128156
} catch {
129157
case e: UserCancelException =>
130158
Exceptions.ignore(e)
131159
None
132160
}
133-
134-
private def showLibraryModelErrorMessage(): Unit =
135-
JOptionPane.showMessageDialog(
136-
App.app.frame,
137-
"""|The model you selected is a library model, which cannot be opened in a LevelSpace code tab.
138-
|Please save the model elsewhere and try re-opening""".stripMargin)
139-
}
140-
141-
class NewModelAction(name: String, modelManager: ModelManager)
142-
extends NewTabAction(name, modelManager) {
143-
144-
override def filePath: Option[String] = {
145-
FileDialog.setDirectory(App.app.workspace.getModelDir)
146-
147-
val ws = App.app.workspace
148-
val loader = FileFormat.basicLoader
149-
val controller = new SaveModel.Controller {
150-
def chooseFilePath(modelType: org.nlogo.api.ModelType): Option[java.net.URI] = {
151-
try {
152-
val userEntry = FileDialog.showFiles(App.app.frame, "Select a path for new Model...", SAVEFILE)
153-
// we basically need to write an empty NetLogo model in before we read...
154-
val fileName =
155-
if (userEntry.endsWith(".nlogo") || userEntry.endsWith(".nlogox")) userEntry else userEntry + ".nlogox"
156-
val path = Paths.get(fileName)
157-
if (Files.exists(path)) {
158-
val fileAlreadyExists = s"The file $fileName already exists. Please choose a different name"
159-
throw new ExtensionException(fileAlreadyExists)
160-
}
161-
Some(path.toUri)
162-
} catch {
163-
case e: UserCancelException =>
164-
Exceptions.ignore(e)
165-
None
166-
}
167-
}
168-
def shouldSaveModelOfDifferingVersion(version: String): Boolean = true
169-
def warnInvalidFileFormat(format: String): Unit = {
170-
// we force users to save in NetLogo, so this doesn't happen
171-
}
172161
}
173-
val modelTracker = new ModelTracker {
174-
def compiler = App.app.workspace.compiler
175-
def getExtensionManager() = App.app.workspace.getExtensionManager
162+
def shouldSaveModelOfDifferingVersion(version: String): Boolean = true
163+
def warnInvalidFileFormat(format: String): Unit = {
164+
// we force users to save in NetLogo, so this doesn't happen
176165
}
177-
SaveModel(org.nlogo.core.Model(), loader, controller, modelTracker, Version).flatMap(_.apply().toOption.map(uri => Paths.get(uri).toString))
178166
}
167+
val modelTracker = new ModelTracker {
168+
def compiler = App.app.workspace.compiler
169+
def getExtensionManager() = App.app.workspace.getExtensionManager
170+
}
171+
SaveModel(org.nlogo.core.Model(), loader, controller, modelTracker, Version).flatMap(_.apply().toOption.map(uri => Paths.get(uri).toString))
179172
}
180173
}
174+
}

src/main/Prims.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ object ModelRunner {
8484
}
8585
i += 1
8686
}
87-
Seq(ArraySeq.unsafeWrapArray(results): _*)
87+
Seq(ArraySeq.unsafeWrapArray(results)*)
8888
}
8989

9090
}

src/main/ZoomableInterfaceComponent.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ trait ZoomableContainer
4949
_zoomFactor = (_zoomFactor + (step * 0.1)) max zoomMin
5050

5151
private def registerScalableAttributes(c: Component): Unit = {
52-
unitAttributes += c -> (c.scalableAttributes scale unitScaleFactor)
52+
unitAttributes += c -> (c.scalableAttributes.scale(unitScaleFactor))
5353
c.addComponentListener(this)
5454
c match {
5555
case container: Container => container.addContainerListener(this)
@@ -75,7 +75,7 @@ trait ZoomableContainer
7575
def zoomComponent(c: Component): Unit =
7676
recursively(c, { (com: Component) =>
7777
com.removeComponentListener(this)
78-
com.scaleTo(unitAttributes(c) scale zoomFactor)
78+
com.scaleTo(unitAttributes(c).scale(zoomFactor))
7979
com.invalidate()
8080
com.validate()
8181
com.addComponentListener(this)
@@ -96,12 +96,12 @@ trait ZoomableContainer
9696

9797
override def componentMoved(componentEvent: ComponentEvent): Unit = {
9898
val component = componentEvent.getComponent
99-
unitAttributes(component) = component.scalableAttributes scale unitScaleFactor
99+
unitAttributes(component) = component.scalableAttributes.scale(unitScaleFactor)
100100
}
101101

102102
override def componentResized(componentEvent: ComponentEvent): Unit = {
103103
val component = componentEvent.getComponent
104-
unitAttributes(component) = component.scalableAttributes scale unitScaleFactor
104+
unitAttributes(component) = component.scalableAttributes.scale(unitScaleFactor)
105105
}
106106

107107
override def componentAdded(containerEvent: ContainerEvent): Unit =

0 commit comments

Comments
 (0)