Skip to content

Commit

Permalink
Add a simple interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthieu-Riou committed Nov 25, 2014
1 parent 80a2085 commit d0685a0
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/main/scala/io/atal/butterfly/Interface.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package io.atal.butterfly

import scala.swing._
import scala.swing.event._

/**
* A simple swing demo.
*/
object HelloWorld extends SimpleSwingApplication {
def top = new MainFrame {
title = "Hello, World!"

object editor extends Label {
var buffer = new Buffer("")
var _cursor = 0

text = buffer.toString()
preferredSize = new Dimension(1000,500)

listenTo(button)
reactions += {
case ButtonClicked(button) =>
if(input.text != "")
{
buffer.insert(input.text, _cursor)
_cursor += input.text.length
text = buffer.toString()
input.text = ""
}
}
}

object button extends Button {
text = "Insert"
}

val input = new TextField(100)

contents = new BorderPanel {
add(editor, BorderPanel.Position.North)
add(input, BorderPanel.Position.West)
add(button, BorderPanel.Position.East)
border = Swing.EmptyBorder(10, 10, 10, 10)

focusable = true
requestFocus
}

}
}

0 comments on commit d0685a0

Please sign in to comment.