Skip to content

Instantly share code, notes, and snippets.

@marcelluethi
Created June 17, 2021 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcelluethi/88af79700ac05bf903f0deff63b41f62 to your computer and use it in GitHub Desktop.
Save marcelluethi/88af79700ac05bf903f0deff63b41f62 to your computer and use it in GitHub Desktop.
Custom UI
package example
import scalismo.ui.api.{ScalismoUI, SimplePluginAPI, TriangleMeshView}
import java.awt.Color
import scala.swing.event.ButtonClicked
import scala.swing.{Button, FlowPanel, Reactor}
class CustomUIExample(val ui : ScalismoUI) extends SimplePluginAPI with Reactor {
// Create a panel with a single button using Scala Swing
val panel = new FlowPanel() {
val button = new Button("press me")
this.contents += button
}
// Tell the plugin to listen to events from the button and install the handlers
listenTo(panel.button)
reactions += {
case ButtonClicked(panel.`button`) => message("button was pressed")
}
// this method is called when the plugin is activated
override def onActivated(): Unit = {
// Install the panel in the toolbar
addToToolbar(panel)
// Just for testing we create a new group
val testGroup = ui.createGroup("testGroup")
// We install a callback function, which is called whenever a Triangle mesh
// is added to the group. In this case, we simply color the mesh red and display
// a message in the status bar.
ui.onNodeAdded(testGroup, (view : TriangleMeshView) => {
view.color = Color.RED
message(s"A mesh with name ${view.name} was added to the group")
})
message("plugin activated")
}
// This method is called when the plugin is deactivated
override def onDeactivated(): Unit = {
removeFromToolbar(panel)
message("plugin deactivated")
}
}
object CustomUIExample {
def main(args : Array[String]) : Unit = {
val ui = ScalismoUI()
val plugin = new CustomUIExample(ui)
plugin.activate()
// plugin.deactivate
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment