#314 support for swt

open
General (246)
8
2006-08-17
2006-06-21
No

I've made an attempt to add support for the SWT
toolkit. The idea is to draw on a swt GC instead of a
Graphics2D object. My first attempt was to add draw(GC
gc) methods to jfreechart object and it worked, see
this post:
http://www.jfree.org/phpBB2/viewtopic.php?p=50761#50761

the problem here is that it duplicates an enormous
ammount of code so I've since made a second attempt
following the idea of David for the CairoGraphics2D class.

you can find attached a SwtGraphics2D class which allow
to use the chart.draw method because it extends
Graphics2D. This way, you can use JFreeChart with swt
out of the box (without _any_ change in the jfreechart
code). Please note that this is not complete yet (I'm
in holidays right now and my wife is gonna kill me if I
spend too much time on the computer).

It would be nice if someone could test under windows
because I do not have presently access to any win32
machine (tested with linux). I also could not try it
with free vm yet (planned) but I see no reason why it
should not work.

I've also started to port the ChartPanel class to swt
but it requires more work and I cannot finish it until
3 weeks for the resaons already explained. I though I
should still post the SwtGraphics2D class because it
already works. The idea here is to extends teh
Composite class rather than the JPanel and to add
support for mouse listeners foe zoom and the like.

to run:

use the MultipleAxisDemo class of David with the
following code for the main method:

public static void main( String[] args )
{
final JFreeChart chart = createChart();
final Display display = new Display();
Shell shell = new Shell( display );
shell.setLayout( new FillLayout() );
shell.setText( "Test for jfreechart running on
SWT" );
shell.setSize( 600, 300 );
final Composite frame = new Composite( shell,
SWT.NONE );
frame.setLayout( new FillLayout() );

final Canvas canvas = new Canvas( frame,
SWT.NO_BACKGROUND);
canvas.addPaintListener( new PaintListener()
{
public void paintControl( PaintEvent e )
{
canvas.setBounds( 0, 0,
frame.getBounds().width,
frame.getBounds().height );
canvas.layout();
chart.draw( e.gc, canvas.getBounds() );
}
} );
frame.pack();
shell.open();
while ( !shell.isDisposed() )
{
if ( !display.readAndDispatch() )
display.sleep();
}
}

Discussion

  • Henry Proudhon

    Henry Proudhon - 2006-06-21

    the SwtGraphics2D.java class allow to draw a jfreechart on a swt gc composite

     
  • Silent

    Silent - 2006-08-05

    Logged In: YES
    user_id=1569067

    Cheer Up~!!

     
  • Silent

    Silent - 2006-08-05

    Logged In: YES
    user_id=1569067

    SwtGraphics2D.java use gc.getDevice().
    but, In my Windows environment I cannot find getDevice()
    method.
    so I change to "null" means Device.getDevice().

    Windows XP sp2.
    SWT 3.1.2 (eclipse 3.1.2)
    JRE 1.4.2_08

     
  • Nobody/Anonymous

    Logged In: NO

    It is not a windows problem, you need SWT 3.2 available for
    download now.
    http://download.eclipse.org/eclipse/downloads/drops/R-3.2-200606291905/index.php

    so you have two solutions: install eclipse 3.2 and run the
    program as a SWT application with eclipse or just download
    the SWT 3.2 toolkit and run with something like:
    java -Djava.library.path=path\to\swt\dll MultipleAxisDemo.main

    Note that I've since hacked a complete version supporting
    SWT. I've send it to David and it will be available soon as
    experimental in JFreeChart-1.0.2

    Cheers!

     
  • Henry Proudhon

    Henry Proudhon - 2006-08-05

    Logged In: YES
    user_id=1379312

    It is not a windows problem, you need SWT 3.2 available for
    download now.
    http://download.eclipse.org/eclipse/downloads/drops/R-3.2-200606291905/index.php

    so you have two solutions: install eclipse 3.2 and run the
    program as a SWT application with eclipse or just download
    the SWT 3.2 toolkit and run with something like:
    java -Djava.library.path=path\to\swt\dll MultipleAxisDemo.main

    Note that I've since hacked a complete version supporting
    SWT. I've send it to David and it will be available soon as
    experimental in JFreeChart-1.0.2

    Cheers!

     
  • Silent

    Silent - 2006-08-07

    Logged In: YES
    user_id=1569067

    OK. It works find by using SWT 3.2 in Windows.

    but output is not good.
    I posted about this in jfreechart forum.

    I think there need to fix for Windows.

     
  • David Gilbert

    David Gilbert - 2006-08-17

    Logged In: YES
    user_id=112975

    Thanks, Henry. I'm reviewing your code at the moment and
    things seem to be working pretty well, considering the
    limitations of SWT graphics. Just one question for now: in
    the SwtCanvasCombo class, you say that you've modified the
    SWT Combo widget...if you've started with some source code
    from SWT, then we can't relicense that under the LGPL, so
    can you clarify where that has come from?

     
  • David Gilbert

    David Gilbert - 2006-08-17
    • priority: 5 --> 8
    • assigned_to: nobody --> mungady
     
  • Henry Proudhon

    Henry Proudhon - 2006-08-17

    Logged In: YES
    user_id=1379312

    I've uploaded the latest code (I though I did it before but
    apparently not). The gray label background has been fixed
    (thanks to calm1979) and I pretty much fixed the font size
    problem.
    About the SwtCanvasCombo, you're right David, so I've
    modified the header of this file for now. The plan is to
    write another class to replace this one with an arrayList of
    Canvas to draw what we've to draw (stroke, symbols...). This
    is a cheap replacement to have it working and should be gone
    in the future. Anyway Thanks to this class I now have a good
    sense on how to write your own widgets in swt.

     
  • Henry Proudhon

    Henry Proudhon - 2006-08-17

    Logged In: YES
    user_id=1379312

    David, to answer your question, I've modified the
    org.eclipse.swt.custom.CCombo class

     
  • Silent

    Silent - 2006-08-18

    Logged In: YES
    user_id=1569067

    Hi, I try to using " jfreechart-swt-support-170806.jar "
    but, there are too many errors.

    Please, notice your environment what you use.

    I used jfreechart-1.0.1, jcommon-1.0.5 and eclipse 3.1
    (swt 3.1).
    I knew "getDevice()" method problem. and I think other
    problems cause different jfree version.

     
  • Henry Proudhon

    Henry Proudhon - 2006-08-21

    Logged In: YES
    user_id=1379312

    jfreechart-1.0.1
    jcommon-1.0.5
    eclipse 3.2

    please say what errors, but it works with this configuration
    if you want to try it.
    if you want you can stick with eclipse 3.1, just install the
    SWT 3.2 and use the env variable java.library.path.

     
  • Silent

    Silent - 2006-08-21

    Logged In: YES
    user_id=1569067

    OK, I create same test environment, just differ OS (I use
    Windows XP sp2).

    anyway, I think that project for only eclipse 3.2 (means
    SWT 3.2) is not good. There are many users with eclipse
    3.0, 3.1 and maybe 2.0.

    so, I test in eclipse 3.1, too.

    BTW, I will test "jfreechart-swt-support-200806.jar"
    later. :)

    PS> I use nickname "silent" in jfree BBS.

     
  • Silent

    Silent - 2006-08-21

    Logged In: YES
    user_id=1569067

    ChartComposite.java 830 line

    ChartEditorManager.getChartEditor( canvas.getDisplay(),
    this.chart );

    but, my getChartEditor() method has just one
    argument "JfreeChart".
    so, I changed that line to
    ChartEditorManager.getChartEditor( this.chart );

    ---------
    jfreechart-1.0.1
    jcommon-1.0.5
    eclipse 3.2

     
  • Henry Proudhon

    Henry Proudhon - 2006-08-21

    Logged In: YES
    user_id=1379312

    Hi Silent,

    sorry, my mistake, I forgot to include a file I modified in
    the jfree tree in the jar (see new jar uploaded).
    Alternatively, just add the following method to the
    ChartEditorManager class (in org.jfree.chart.editor):

    public static ChartEditor getChartEditor( Display
    display, JFreeChart chart )
    {
    return new SwtChartEditor( display, chart );
    }

    I hope it was the only file missing, I must figure out a
    better way to pack the jar so I include all modified
    files... I'll write an ant script.

    Thanks for the report, concerning SWT 3.2, I already said
    that you can use whatever eclipse you like, you just have to
    download the appropriate SWT toolkit. On the other hand,
    tese class are only for testing and we can make them working
    with an earlier version of SWT (but which?).

     
  • Silent

    Silent - 2006-08-21

    Logged In: YES
    user_id=1569067

    Oh...

    when I use below code,

    private void attemptEditChartProperties()
    {
    // ChartEditor editor =
    ChartEditorManager.getChartEditor( canvas.getDisplay(),
    this.chart );

    ChartEditor editor =
    ChartEditorManager.getChartEditor( this.chart );
    ( ( SwtChartEditor ) editor ).open();
    }

    I got a ClassCastException when opening Properties dialog.
    so, I change more like below.. :|

    private void attemptEditChartProperties()
    {
    // ChartEditor editor =
    ChartEditorManager.getChartEditor( canvas.getDisplay(),
    this.chart );

    SwtChartEditor editor = new SwtChartEditor\(
    

    canvas.getDisplay(), this.chart );
    editor.open();
    }

    and I can see properties dialog well.

    but, there is some problem to use this.
    I often use null Axis label. this occured error.

    in SwtAxisEditor.java need some additional code.
    137 line : label.setText( axis.getLabel() );
    label.setText( axis.getLabel() == null ? "" : axis.getLabel
    () );

    ^^;
    Cheers!

     
  • Silent

    Silent - 2006-08-21

    Logged In: YES
    user_id=1569067

    hm..

    whatever I use other eclipse version, if I have to use SWT
    3.2 version then it works fine, anyway.
    But eclipse has it's own SWT verion. so users try to use
    default SWT that they have.

    Now, I recognize difference SWT 3.2 and earlier version
    is "getDevice()" call only.
    Font, Color, Path and etc. created with "null" device not
    ec.getDevice() is can use earlier SWT version.

    and, SwtPaintCanvas 65 line.
    e.gc.getDevice().getSystemColor( SWT.COLOR_BLACK )
    change to
    Display.getDefault().getgetSystemColor( SWT.COLOR_BLACK )

    I think this is all for earlier SWT version.

     
  • Silent

    Silent - 2006-08-21

    Logged In: YES
    user_id=1569067

    In additional.. ec.getDevice() change to null.
    SwtUtils added to follow code in toSwtFontData(), toAwtFont
    () methods.

    if ( device == null )
    {
    device = Display.getDefault();
    }

    this works fine in SWT 3.1 version.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks