alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Groovy example source code file (Caricature.groovy)

This example Groovy source code file (Caricature.groovy) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

awt, border, effects, effects, eyes, face, gui, hair, jcaricature, mouth, rotation, rotation, scale, style, style, swing, titledborder, titledborder

The Groovy Caricature.groovy source code

package swing.binding.caricature

import groovy.swing.SwingBuilder
import java.awt.Color
import javax.swing.border.TitledBorder

SwingBuilder.build {
    frame(pack:true, show:true,
        defaultCloseOperation:javax.swing.JFrame.DISPOSE_ON_CLOSE)
    {
        borderLayout()
        panel(constraints:CENTER,) {
            // place in panel to insure square layout
            caricature = widget(new JCaricature(
                background:Color.WHITE, opaque:true))
        }
        hbox(constraints:SOUTH) {
            panel(border:new TitledBorder("Style")) {
                gridLayout(new java.awt.GridLayout(5, 2))
                label("Eyes") // font stuff
                eyeSlider = slider(minimum:0, maximum:4,
                    value:bind(target:caricature,
                        targetProperty:'eyeStyle',
                        value:2))
                label("Face") // font stuff
                faceSlider = slider(minimum:0, maximum:4,
                    value:bind(target:caricature,
                        targetProperty:'faceStyle',
                        value:2))
                label("Mouth") // font stuff
                mouthSlider = slider(minimum:0, maximum:4,
                    value:bind(target:caricature,
                        targetProperty:'mouthStyle',
                        value:2))
                label("Hair") // font stuff
                hairSlider = slider(minimum:0, maximum:4,
                    value:bind(target:caricature,
                        targetProperty:'hairStyle',
                        value:2))
                label("Nose") // font stuff
                noseSlider = slider(minimum:0, maximum:4,
                    value:bind(target:caricature,
                        targetProperty:'noseStyle',
                        value:2))
            }
            panel(border:new TitledBorder("Effects")) {
                gridLayout(new java.awt.GridLayout(2, 5))
                label("Rotation") // font stuff
                rotationSlider = slider(maximum:360,
                    value:bind(target:caricature,
                        targetProperty:'rotation',
                        value:0))
                label("Scale") // font stuff
                scaleSlider = slider(maximum: 150, minimum:50,
                    value:bind(target:caricature,
                        targetProperty:'scale',
                        converter: {it / 100f}, value:100))
            }
        }
    }
}

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy Caricature.groovy source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.