Wrapping JFreeChart as a builder for Groovy by Dave Cherry
| Keywords: | groovy jfreechart charting |
| Last Change: | 03-Feb-2008 17:00 |
I’ve started looking into the possibility of wrapping up JFreeChart to make it a little groovier. I know there’s no end of web packages for graphing, but what if you don’t want to transmit sensitive data across the internet, what if you don’t want the data in the URL, what if the application in question is a Swing GUI thats not connected to the internet.
Its for all those situations that I have looked at wrapping up the excellent http://www.jfree.org/jfreechart API in a Groovy builder. My proposed name is FreeChartBuilder.
FreeChartBuilder is an early look at how a builder object using the state machine pattern could provide fairly complete support for the underlying Java API. The currently attached source archive gives an example of what can be achieved for pie and simple line charts.
import com.thecoderscorner.gfreechart.GFreeChartBuilder
import javax.swing.ImageIcon
import java.awt.Color
import groovy.swing.SwingBuilder
import javax.swing.JFrame
import java.awt.BorderLayout
def chart = new GFreeChartBuilder();
chart.createPie(title: "Pie Chart", legend: true, size: [400,200]) {
dataset {
First(20)
Second(30)
Third(10)
Fourth(40)
}
antiAlias true
backgroundPaint Color.WHITE
plot {
sectionOutlinesVisible true
font name: 'arial', height: 15
labelGap 0.02
simpleGradient start: new Color(0,0,255), end: new Color(255,255,255)
}
}
ImageIcon pieImg = chart.getIconImage()
def sb = new SwingBuilder()
def fr = sb.frame( title : 'Test Graph', size:[800,600], defaultCloseOperation: JFrame.EXIT_ON_CLOSE) {
label(icon: pieImg, constraints: BorderLayout.CENTER)
}
fr.pack();
fr.show();
Right now, the prototype source is available from this location. Be aware that its not ready for prime time yet.
On 03-Feb-2008 18:29, Andres Almiray wrote:
Dave, this are great news! there is a previous attempt of creating a groovy builder for jfreechart located at http://groovychart.dev.java.net (it has gone dormant), so if you care to take over the mantle that would be good.
Please consider using FactoryBuilderSupport for your builder, I think it is better suited for these type of builders and will eventually lead to making all FBS based builders work together (think and uber UI builder).
On 03-Feb-2008 18:41, Dave Cherry wrote:
Thanks Andres, great work on the SwingBuilder blog entries - I've read through the series with interest.
I will take a look at this project on java.net and also take a look at using FactoryBuilderSupport instead.
On 17-Feb-2008 10:54, Tiago Antao wrote:
This is really a great idea.
I am a JFreeChart user (One of my projects is an free software JavaWebStart application written in Jython to detect genes under selection - http://popgen.eu/soft/lositan ), and the library suffers from the typical "over engineering disease" of Java, a wrapper like this would make life easier to newcomers to JFreeChart.
I am currently moving to Groovy and I hope you take this project to good port, I would certainly be a user!
Good luck!
Please leave a comment
(C) 1997-2009 by nutricherry Ltd,
please read our terms and conditions of use.
|
January, 2009 |
|
||||
| Su | Mo | Tu | We | Th | Fr | Sa |
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |