tags:

views:

155

answers:

0

Recently, I had use JXLayer, to overlay two moving yellow message boxes, on the top of JFreeChart

http://yccheok.blogspot.com/2010/02/investment-flow-chart.html

I was wondering, had anyone experience using JXLayer + JHotdraw, to overlay all sorts of figures (Re-sizable text box, straight line, circle...), on the top of JFreeChart.

I just would like to add drawing capability, without changing the JFreeChart source code. So that, JStock's user may draw trending lines, annotation text on their favorite stock charting.

The code skeleton is as follow :

// this.chartPanel is JFreeChartPanel
final org.jdesktop.jxlayer.JXLayer<ChartPanel> layer = new org.jdesktop.jxlayer.JXLayer<ChartPanel>(this.chartPanel);
this.myUI = new MyUI<ChartPanel>(this);
layer.setUI(this.myUI);

public class MyUI<V extends javax.swing.JComponent> extends AbstractLayerUI<V> {
    @Override
    protected void paintLayer(Graphics2D g2, JXLayer<? extends V> layer) {
        // Previous, I am using my own hand-coded, to draw the yellow box
        //
        // Now, How can I make use of JHotDraw at here, to draw various type of
        // figures?
    }

    @Override
    protected void processMouseEvent(MouseEvent e, JXLayer<? extends V> layer) {
        // How can I make use of JHotDraw at here?
    }

    @Override
    protected void processMouseMotionEvent(MouseEvent e, JXLayer<? extends V> layer) {
        // How can I make use of JHotDraw at here?
    }
}

As you see, I already got Graphics2D g2 from paintLayer method. How is it possible that I can pass the Graphics2D object to JHotDraw, and let JHotDraw handles all the drawing.

My experience in using JHotDraw are with

org.jhotdraw.draw.DefaultDrawingView org.jhotdraw.draw.DefaultDrawingEditor

I am able to use them to draw various figures, by clicking on the toolbar and click on drawing area.

How is it possible I can use DefaultDrawingView and DefaultDrawingEditor within MyUI's paintLayer?

Also, shall I let MyUI handles the mouse event, or JHotDraw?

Sorry, I start getting confused.