import javax.swing.JFileChooser
import javax.swing.ScrollPaneConstants
import javax.swing.WindowConstants as WC
import net.miginfocom.swing.MigLayout
import java.awt.Color
import java.awt.Font
import javax.imageio.ImageIO

 def createButton(buttonString, action) {
        jxbutton(borderPainted: false, contentAreaFilled: false, focusPainted: false,
                icon: imageIcon(getClass().getResource(buttonString + '-button.png')),
                pressedIcon: imageIcon(getClass().getResource(buttonString + '-button-pressed.png')),
                actionPerformed: action)
    }

application(title:'GriffonFlubber',  size: [300, 500], locaiton:[50,50],locationByPlatform:true, defaultCloseOperation:WC.EXIT_ON_CLOSE ) {
	startButton = createButton('start', controller.startButtonMouseReleased)

        stopButton = createButton('stop', controller.stopButtonMouseReleased)

        flubButton = createButton('flub', controller.flubButtonMouseReleased)
        flubButton.setFont(new Font('Dialog', 1, 18))
        flubButton.setPreferredSize(new java.awt.Dimension(90, 91))

        saveButton = createButton('save', controller.saveButtonMouseReleased)
        clearButton = createButton('clear', controller.clearButtonMouseReleased)

        flubPointsTextArea = textArea(columns: 10, rows: 8)

    jxpanel(backgroundPainter:imagePainter(image: ImageIO.read(getClass().getResource("/wood.png")), verticalRepeat:true, horizontalRepeat:true), layout:new MigLayout()) {
		def x = controller.centerObject(261)
		def cp = jxcompoundPainter() {
			imagePainter(image: ImageIO.read(getClass().getResource("/metal.png")),
					scaleToFit: true)
			model.timeLabel = textPainter(id: 'txtPainter', text:bind{model.timeText}, font: new Font("Arial", Font.PLAIN, 36), fillPaint: Color.white) {
				shadowPathEffect()
			}
		}
		jxpanel(id:'timePanel', backgroundPainter: cp, constraints: "id timeLabel, w 261!, h 81!, x " + x-10)
		widget(startButton, constraints: 'id startButton,x timeLabel.x+5, y timeLabel.y2+10')

		widget(stopButton, constraints: 'id stopButton, x startButton.x2+45, y startButton.y, x2 timeLabel.x2')
		flubX = controller.centerObject(flubButton.getSize().getWidth())
		
		widget(flubButton, constraints: 'id flubButton, x 85, y 150,wrap')
		scrollPane(constraints: 'id scrollPane,x timeLabel.x, x2 timeLabel.x2, y flubButton.y2+10',
				horizontalScrollBarPolicy: ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER) {
			textArea(columns: 10, rows: 8, text:bind{model.flubText})
		}
		widget(saveButton, constraints: 'x startButton.x, y scrollPane.y2+20')
		widget(clearButton, constraints: 'x stopButton.x, y scrollPane.y2+20, x2 timeLabel.x2')
            
    }
}
