0

Canvas not draw after dofinnally

asked 2015-07-16 15:23:59 +0800

adolfoleonardi gravatar image adolfoleonardi
1 1

Hi I use the library canvas4z to draw a simple circle, but the browser show the circle only after ad event (eg button click). I'd like to see the circle after the dofinnally method!

Where is my error?


Adolfo Leonardi

zul page: <zk> <window title="pippo" border="normal" apply="PippoController" &gt;="" <canvas="" id="canvas" width="50px" height="50px"/> <button id="refresh" label="refresh"></button> </window> </zk>

and PippoController.java

import java.awt.geom.Arc2D;
import org.zkforge.canvas.Canvas;
import org.zkforge.canvas.Drawable;
import org.zkforge.canvas.Path;
import org.zkoss.zk.ui.Component;
import org.zkoss.zul.Button;
import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zk.ui.select.annotation.Listen;
import org.zkoss.zk.ui.select.annotation.VariableResolver;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zkplus.spring.DelegatingVariableResolver;

@VariableResolver(DelegatingVariableResolver.class)
public class PippoController extends SelectorComposer<Component> {
    private static final long serialVersionUID = 6468999863309679635L;
    @Wire Button refresh;
    @Wire   Canvas canvas; 
    Path circlegreeen = new Path(new Arc2D.Double(5,5, 40, 40, 0, 360,  Arc2D.CHORD));
    @Override
    public void doAfterCompose(Component comp) throws Exception {
        super.doAfterCompose(comp);
        circlegreeen.setStrokeStyle("#00FF00");
        circlegreeen.setFillStyle("#00FF00");
        circlegreeen.setLineWidth(5);
        circlegreeen.setDrawingType(Drawable.DrawingType.STROKE);

    }

    @Listen("onClick=#refresh")
    public void onClick_refresh() throws Throwable{
        canvas.add(circlegreeen);   
    }
    @Override
    public void doFinally() throws Exception {
        canvas.add(circlegreeen);
    }
}
delete flag offensive retag edit

4 Answers

Sort by ยป oldest newest most voted
0

answered 2015-07-20 08:54:38 +0800

Darksu gravatar image Darksu
1991 1 4

Hello adolfoleonardi,

The doFinally is called after the component has been composed completely.

The doAfterCompose invokes after ZK loader creates this component, initializes it and composes all its children, if any.

Best Regards,

Darksu

link publish delete flag offensive edit
0

answered 2015-07-20 09:37:25 +0800

adolfoleonardi gravatar image adolfoleonardi
1 1

Hi Darksu, i tried to insert the " canvas.add(circlegreeen);" in doFinally and in then doAfterCompose, but the browse doesn't draw the circle. The circle is showed only the onclick event, why?


Adolfo Leonardi

link publish delete flag offensive edit
0

answered 2015-07-27 09:38:15 +0800

adolfoleonardi gravatar image adolfoleonardi
1 1

any suggestions?

link publish delete flag offensive edit
0

answered 2015-07-31 10:55:51 +0800

adolfoleonardi gravatar image adolfoleonardi
1 1

SOLVED:

@Wire Window win;

@Override
public void doFinally() throws Exception {
    Clients.showBusy("waiting...");
    Events.echoEvent("onLater", win, null); //echo an event back 
}//doFinally
@Listen("onLater=#win")
public void onLater_win() throws Throwable{     
    //Draw my cancas
     Clients.clearBusy();
}
link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2015-07-16 15:23:59 +0800

Seen: 33 times

Last updated: Jul 31 '15

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More