0

What is the best way to customize datebox (zk 5 or later)

asked 2011-09-19 01:33:28 +0800

mahdiiran gravatar image mahdiiran
40 3

Hi dear all

I need shamsi calendar for zkoss 5, how can i start customization of datebox? can i design new mold without recompile zk entire zul project?
What is best point to start?

Please help me!

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2011-09-19 12:14:00 +0800

mhj gravatar image mhj flag of Brazil
806 1 7

only an example, you have to do for your need:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mhj.tests;

import java.text.SimpleDateFormat;
import java.util.Date;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zul.Bandbox;
import org.zkoss.zul.Bandpopup;
import org.zkoss.zul.Button;
import org.zkoss.zul.Datebox;
import org.zkoss.zul.Div;
import org.zkoss.zul.Hbox;
import org.zkoss.zul.Vbox;

/**
 *
 * @author mhj
 */
public class DateComponent extends Bandbox {

    private SimpleDateFormat formatter;
    private Button todayBtn, clearBtn;
    private Datebox datebox;
    private Bandpopup bp;
    private Div v;
    private Hbox h1, h2;

    public DateComponent() {
        datebox = new Datebox(new Date());
        formCreate();
    }
    public DateComponent(String width) {
        datebox = new Datebox(new Date());
        this.setWidth(width);
        formCreate();
    }
    
    private void formCreate(){
        datebox.setWidth("145px");
        formatter = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        todayBtn = new Button("Today");
        clearBtn = new Button("Clear");
        todayBtn.setWidth("55px");
        clearBtn.setWidth("55px");
        
        datebox.setReadonly(true);
        datebox.setFormat("dd/MM/yyyy HH:mm:ss");
        datebox.setCols(20);
        datebox.setMaxlength(19);
        datebox.addEventListener("onChange", new EventListener() {

            @Override
            public void onEvent(Event event) throws Exception {
                onChangeDate(event);
            }
        });

        todayBtn.addEventListener("onClick", new EventListener() {

            @Override
            public void onEvent(Event event) throws Exception {
                onClickTodayBtn(event);
            }
        });

        clearBtn.addEventListener("onClick", new EventListener() {

            @Override
            public void onEvent(Event event) throws Exception {
                onClickClearBtn(event);
            }
        });
        bp = new Bandpopup();
        bp.setWidth("150px");
        v = new Div();
        v.setStyle("background-color:#cccccc;");
        v.setAlign("center");
        h1 = new Hbox();
        h2 = new Hbox();
        Div separator = new Div();
        separator.setWidth("5px");
        datebox.setParent(h1);
        todayBtn.setParent(h2);
        separator.setParent(h2);
        clearBtn.setParent(h2);
        h1.setParent(v);
        h2.setParent(v);
        v.setParent(bp);
        this.appendChild(bp);
        this.setReadonly(true);
    }

    private void onChangeDate(Event e) {
        this.setValue(formatter.format(datebox.getValue()));
        this.close();
        Events.echoEvent("onChanging", this, null);
    }

    private void onClickTodayBtn(Event e) {
        Date d = new Date();
        this.setValue(formatter.format(d));
        datebox.setValue(d);
        this.close();
        Events.echoEvent("onChanging", this, null);
    }

    private void onClickClearBtn(Event e) {
        this.setValue("");
        this.close();
        Events.echoEvent("onChanging", this, null);
    }

    public void setFormat(String formato) {
        datebox.setFormat(formato);
        formatter.applyPattern(formato);
    }

    public void setDate(Date date) {
        datebox.setValue(date);
        this.setValue(formatter.format(date));
    }

    public void setDate(Date date, String parse) {
        SimpleDateFormat auxFormat = new SimpleDateFormat(parse);
        datebox.setValue(date);
        this.setValue(auxFormat.format(date));
    }

    public void clearDate() {
        datebox.setValue(new Date());
        this.setValue("");
    }

    public Date getDate() {
        return datebox.getValue();
    }

    public void setFormatter(String format) {
        this.formatter.applyPattern(format);
    }

    public void setWidthPx(int tam) {
        datebox.setWidth(tam + "px;");
        if (tam < 110) {
            tam = 110;
        }        
        bp.setWidth((tam + 5) + "px;");
        this.invalidate();
    }
    public void setWidthPerc(int tam) {
        if (tam > 100) {
            tam = 100;
        }
        datebox.setWidth(tam + "%;");
        bp.setWidth(tam + "%;");
    }
}

link publish delete flag offensive edit

answered 2011-09-20 22:32:11 +0800

ashishd gravatar image ashishd flag of Taiwan
1972 6

Hi mahdiiran,
You can also refer to this thread where tony gives a lot of useful information in this regard

link publish delete flag offensive edit
Your reply
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

RSS

Stats

Asked: 2011-09-19 01:33:28 +0800

Seen: 545 times

Last updated: Sep 20 '11

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