Blog do projektu Open Source JavaHotel

niedziela, 25 marca 2012

Simple calendar

I extracted simple "calendar" component from JavaHotel application. It is nothing more than several controls allowing user to navigate through period of time. It does not make a lot of sense to run it as a stand-alone but can be used as a part of larger application.

Demo version is available (click on ScrollControll).
http://javahoteltest.appspot.com/

The source code for this demo :

  private class DrawClass implements IDrawPartSeason {

        @Override
        public void setW(IGWidget w) {
            hP.add(w.getGWidget());
            hP.add(vP);
            vP.setBorderWidth(1);
            vP.setSpacing(15);
        }

        @Override
        public void refresh(IDrawPartSeasonContext sData) {
            int no = sData.getLastD() - sData.getFirstD() + 1;
            if (vP.getWidgetCount() != no) {
                vP.clear();
                for (int i = 0; i < no; i++) {
                    vP.add(new Label(""));
                }
            }
            for (int i = 0; i < no; i++) {
                Date d = sData.getD(sData.getFirstD() + i);
                String s = DateFormatUtil.toS(d);
                Label l = (Label) vP.getWidget(i);
                l.setText(s);
            }

        }

    }
Callback function should implement two methods. The first (launched only once at the beginning) delivers widget containing the controls which should be placed somewhere in the display.
The second responds to the user movement through the period of time. In this example simply refresh the cells.
The source code : interfaces and implementation.

Brak komentarzy:

Prześlij komentarz