Skip to content

Instantly share code, notes, and snippets.

@mresetar
Forked from anonymous/gist:800225
Created May 9, 2011 13:19
Show Gist options
  • Save mresetar/962501 to your computer and use it in GitHub Desktop.
Save mresetar/962501 to your computer and use it in GitHub Desktop.
UUID generator
import groovy.swing.SwingBuilder
import java.awt.BorderLayout as BL
import java.awt.datatransfer.Clipboard
import java.awt.datatransfer.StringSelection
import java.awt.Toolkit
import javax.swing.*
class UUIDgenerator {
def readIcon() {
byte[] iconBytes = new byte[990]
def stream = this.getClass().getClassLoader().getResourceAsStream('barcode.gif')
assert stream : 'Icon not found!'
// read icon
stream.read(iconBytes)
def imageIcon = new ImageIcon(iconBytes)
}
def start() {
def icon = readIcon().image
def window = SwingBuilder.build {
frame(title:'UUID generator', size:[300,250], location:[300,300], pack: true, show: true, defaultCloseOperation:JFrame.EXIT_ON_CLOSE, iconImage:icon, resizable: false) {
borderLayout()
scrollPane(constraints: BL.NORTH) {
textlabel = textArea(rows:10,columns:40,text:"", autoscrolls:true)
}
button(text:'Generate',
actionPerformed: {String uuid = UUID.randomUUID().toString();
textlabel.text+=uuid + '\n';
StringSelection stringSelection = new StringSelection( uuid );
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents( stringSelection, null );},
constraints:BL.SOUTH)
}
}
}
public static void main(String[] args){
new UUIDgenerator().start()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment