Skip to content

Instantly share code, notes, and snippets.

@y-sumida
Created April 30, 2013 12:47
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 y-sumida/5488481 to your computer and use it in GitHub Desktop.
Save y-sumida/5488481 to your computer and use it in GitHub Desktop.
Yokohama.groovy #14の成果
package gbf
class GbfController {
def model
def view
def bf
def execute = {evt = null ->
bf = new GBrainFuck(model.program)
while(!bf.isFinished()) {
GBrainFuckResult result = bf.convert()
model.output = result.output
model.buffer = result.buffer
sleep(200)
}
}
def stop = {evt = null ->
bf.stop()
}
def clear = {evt = null ->
model.program = ''
model.buffer = ''
model.output = ''
bf.clear()
}
}
package gbf
import groovy.beans.Bindable
class GbfModel {
@Bindable String program = ""
@Bindable String buffer = ""
@Bindable String output = ""
}
package gbf
import static java.awt.BorderLayout.*
application(title: 'Gbf',
preferredSize: [400, 250],
pack: true,
//location: [50,50],
locationByPlatform:true,
iconImage: imageIcon('/griffon-icon-48x48.png').image,
iconImages: [imageIcon('/griffon-icon-48x48.png').image,
imageIcon('/griffon-icon-32x32.png').image,
imageIcon('/griffon-icon-16x16.png').image]) {
scrollPane(constraints:NORTH) {
hbox {
textArea editable:true, columns:20, rows:8, text:bind(target:model, 'program', mutual:true)
//textField columns:20, text: bind(target:model, 'program', mutual:true)
}
}
panel(constraints:CENTER) {
hbox {
label 'buffer '
textArea editable:false, columns:25, rows:1 , text:bind{model.buffer}
}
hbox {
label 'result '
textArea editable:false, columns:25, rows:1, text:bind{model.output}
}
}
panel(constraints:SOUTH) {
hbox {
button 'run', actionPerformed: controller.&execute
button 'stop', actionPerformed: controller.&stop
button 'clear', actionPerformed: controller.&clear
}
}
}
package gbf
class GBrainFuckResult {
final String output
final String buffer
GBrainFuckResult(String output, String buffer) {
this.output = output
this.buffer = buffer
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment