SWT ChartComposite vs. ChartCanvas

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
pcentgraf
Posts: 2
Joined: Tue Oct 02, 2007 10:06 pm

SWT ChartComposite vs. ChartCanvas

Post by pcentgraf » Tue Oct 02, 2007 10:16 pm

First, thanks for going to the effort to port JFreeChart to SWT. It has greatly simplified things for my project. However....

The SWT-based ChartComposite class extends the SWT Composite class, but it immediately creates an SWT Canvas and expands it to fill the entire area of the ChartComposite. The net effect is that standard SWT methods often do not work, since they affect the ChartComposite and not the embedded Canvas. For example, addMouseMoveListener() has no effect, since the Canvas completely obscures the ChartComposite.

Why don't you simply make a ChartCanvas class that directly extends SWT Canvas? This would be much simpler and more in the spirit of SWT design. All of the basic SWT methods inherited from Control etc. would work as expected. I believe that this could be achieved with a simple refactoring, so that all references to the "canvas" field are replaced by "this", with no other modifications.

Or, am I missing some reason that this was not done from the beginning?

--
Peter

heprom
Posts: 91
Joined: Sat May 27, 2006 4:25 am
Location: Paris

Post by heprom » Mon Oct 15, 2007 7:52 pm

Hi Peter,

I realized this some time ago when people started to report problem like mouse listener not working and I had to pass the events from the composite onto the canvas. The reason for this is mainly historical, back then I did not know much about SWT, and it sounded just logical since ChartPanel extends JPanel and the equivalent of JPanel in SWT in the Composite class. I'll review the pro/cons of this approach and see if it's worth refactoring.

Btw, this kind of request is better issued by posting a feature request on sourceforge, I'm not browsing the forum everyday.

Regards
/heprom

Locked