Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ scalaVersion := "2.9.2"

retrieveManaged := true

javaSource in Compile <<= baseDirectory(_ / "src" / "main")
javaSource in Compile <<= baseDirectory(_ / "src" / "main")

scalaSource in Compile <<= baseDirectory(_ / "src" / "main")

scalaSource in Test <<= baseDirectory(_ / "src" / "test")

Expand Down
100 changes: 0 additions & 100 deletions src/main/GUIChildModel.java

This file was deleted.

80 changes: 80 additions & 0 deletions src/main/GUIChildModel.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import java.awt._
import java.awt.event.{ WindowAdapter, WindowEvent }
import java.util.concurrent.Callable
import javax.swing.{ FocusManager, JFrame, JMenuBar, JOptionPane, WindowConstants }
import org.nlogo.api._
import org.nlogo.lite.{LiteWorkspace, InterfaceComponent}
import org.nlogo.nvm.HaltException
import org.nlogo.window.Events.ZoomedEvent
import org.nlogo.window.Widget.LoadHelper
import org.nlogo.window._
import org.nlogo.workspace.AbstractWorkspace

class GUIChildModel @throws(classOf[InterruptedException]) @throws(classOf[ExtensionException]) @throws(classOf[HaltException]) (parentWorld: World, path: String, levelsSpaceNumber: Int)
extends ChildModel(parentWorld, levelsSpaceNumber) {

final val _frame: JFrame = new JFrame

var panel: GUIPanel = null

val component: InterfaceComponent =
runUISafely(new Callable[InterfaceComponent]() {
@throws(classOf[Exception])
def call: InterfaceComponent = {
val component: InterfaceComponent = new ZoomableInterfaceComponent(frame())
panel = new GUIPanel(component)
frame().add(panel)
val currentlyFocused: Window = FocusManager.getCurrentManager.getActiveWindow
frame().setLocationRelativeTo(currentlyFocused)
frame().setLocationByPlatform(true)
frame().setVisible(true)
currentlyFocused.toFront()
component.open(path)
val c: Array[Component] = component.workspace.viewWidget.controlStrip.getComponents
for (co <- c) {
if (co.isInstanceOf[SpeedSliderPanel]) {
co.setVisible(false)
(co.asInstanceOf[SpeedSliderPanel]).setValue(0)
}
}
frame.pack()
frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE)
frame.addWindowListener(new WindowAdapter() {
override def windowClosing(windowEvent: WindowEvent) {
val options: Array[AnyRef] = Array("Close Model", "Run in Background", "Cancel")
val n: Int = JOptionPane.showOptionDialog(frame, "Close the model, run it in the background, or do nothing?", null, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options(2))
n match {
case 0 =>
try {
LevelsSpace.closeModel(levelsSpaceNumber)
} catch {
case e: ExtensionException => throw new RuntimeException(e)
case e: HaltException =>
}
case 1 => hide()
case 2 =>
}
}
})
val newMenuBar = new JMenuBar()
val zoomMenuClass = Class.forName("org.nlogo.app.ZoomMenu")
newMenuBar.add(zoomMenuClass.newInstance().asInstanceOf[org.nlogo.swing.Menu])
frame.setJMenuBar(newMenuBar)
component
}
})
init()

def setSpeed(d: Double): Unit = {
val c: Array[Component] = component.workspace.viewWidget.controlStrip.getComponents
for (co <- c) {
if (co.isInstanceOf[SpeedSliderPanel]) {
(co.asInstanceOf[SpeedSliderPanel]).setValue(d.toInt)
}
}
}

def workspace: AbstractWorkspace = component.workspace

def frame(): JFrame = _frame
}
44 changes: 0 additions & 44 deletions src/main/GUIPanel.java

This file was deleted.

26 changes: 26 additions & 0 deletions src/main/GUIPanel.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import org.nlogo.app.CommandCenter
import org.nlogo.lite.InterfaceComponent
import org.nlogo.window.{Zoomable, Events}
import javax.swing._
import java.awt._
import java.awt.event.ActionEvent

class GUIPanel(ws: InterfaceComponent) extends JPanel with Events.OutputEvent.Handler {
setLayout(new BorderLayout)
var cc = new CommandCenter(ws.workspace, new AbstractAction() {
def actionPerformed(actionEvent: ActionEvent) {
}
})
val scrollPane: JScrollPane = new JScrollPane(ws, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED)
val splitPane: JSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, scrollPane, cc)
splitPane.setOneTouchExpandable(true)
splitPane.setResizeWeight(1)
add(splitPane)

def handle(outputEvent: Events.OutputEvent): Unit = {
if (outputEvent.clear)
cc.output.clear
else
cc.output.append(outputEvent.outputObject, outputEvent.wrapLines)
}
}
Loading