-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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!
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 + "%;"); } }
Asked: 2011-09-19 01:33:28 +0800
Seen: 545 times
Last updated: Sep 20 '11