示例#1
0
  protected void createContents() {
    VGridLayout layout = new VGridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    setLayout(layout);

    if (cdt.builder.hasHeader()) {
      createHeader();
      //			if (cdt.field.length > 1
      //					|| (cdt.getCalendarField(cdt.field[0]) != Calendar.MONTH
      //							&& cdt.getCalendarField(cdt.field[0]) != Calendar.YEAR)) {
      //				createHeader();
      //			}
    }

    if (cdt.builder.hasHeader() && (cdt.builder.hasBody() || cdt.builder.hasFooter())) {
      VLabel separator = new VLabel(this, SWT.HORIZONTAL | SWT.SEPARATOR);
      separator.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    }

    if (cdt.builder.hasBody()) {
      createBody();
    }

    if ((cdt.builder.hasHeader() || cdt.builder.hasBody()) && cdt.builder.hasFooter()) {
      VLabel sep = new VLabel(this, SWT.HORIZONTAL | SWT.SEPARATOR);
      sep.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    }

    if (cdt.builder.hasFooter()) {
      createFooter();
    }
  }
示例#2
0
  /** create the Calendar's body, which contains the dayLabels and dayButtons */
  private void createBody() {
    body = new VPanel(this, SWT.NONE);
    body.setData(CDT.PickerPart, PickerPart.BodyPanel);
    body.setPainter(cdt.getPainter());
    cdt.getPainter().update(body);
    VGridLayout layout = new VGridLayout(1, false);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.horizontalSpacing = 0;
    body.setLayout(layout);
    body.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    addBodyPanel();

    for (Iterator<Body> iter = cdt.builder.getBodies().iterator(); iter.hasNext(); ) {
      Body b = iter.next();
      if (b.newColumn) {
        VLabel sep = new VLabel(body, SWT.SEPARATOR | SWT.VERTICAL);
        sep.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
        body.getLayout(VGridLayout.class).numColumns++;
        addBodyPanel();
      }
      switch (b.type) {
        case Body.DAYS:
          createDays(b);
          break;
        case Body.MONTHS:
          createMonths(b);
          break;
        case Body.TIME:
          createTime(b);
          break;
        case Body.YEARS:
          createYears(b);
          break;
      }
    }

    for (VPanel bodyPanel : bodyPanels) {
      bodyPanel.getLayout(VStackLayout.class).setTopControl(null);
    }
  }
示例#3
0
  private void createDays(Body b) {
    VPanel bodyPanel = bodyPanels[bodyPanels.length - 1];

    dayPanel = new VPanel(bodyPanel, SWT.NO_FOCUS);
    dayPanel.setData(CDT.PickerPart, PickerPart.DayPanel);
    dayPanel.setPainter(cdt.getPainter());
    cdt.getPainter().update(dayPanel);
    VGridLayout layout = new VGridLayout(7, true);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.horizontalSpacing = b.spacing;
    layout.verticalSpacing = b.spacing;
    dayPanel.setLayout(layout);

    bodyPanel.getLayout(VStackLayout.class).setDefault(dayPanel, false);

    addListener(
        SWT.MouseWheel,
        new Listener() {
          public void handleEvent(Event event) {
            scrollCalendar((event.count > 0) ? SWT.ARROW_UP : SWT.ARROW_DOWN);
          }
        });

    Menu bodyMenu = dayPanel.createMenu();

    todayMenuItem = new MenuItem(bodyMenu, SWT.NONE);
    todayMenuItem.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            cdt.setSelection(new Date());
          }
        });

    showSelMenuItem = new MenuItem(bodyMenu, SWT.NONE);
    showSelMenuItem.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            cdt.showSelection();
          }
        });

    dayListener =
        new Listener() {
          public void handleEvent(Event event) {
            switch (event.type) {
              case SWT.KeyDown:
                if (event.stateMask == 0) {
                  if (event.keyCode == SWT.KEYPAD_CR
                      || event.character == SWT.CR
                      || event.character == ' ') {
                    setSelectionFromFocusButton(event);
                  } else if (event.keyCode == SWT.HOME
                      || event.keyCode == SWT.END
                      || event.keyCode == SWT.PAGE_DOWN
                      || event.keyCode == SWT.PAGE_UP) {
                    scrollCalendar(event.keyCode);
                    setSelectionFromFocusButton(event);
                  }
                }
                break;
              case SWT.MouseDown:
                if (event.button == 3) {
                  dayPanel.getMenu().setVisible(true);
                }
                break;
              case SWT.MouseWheel:
                scrollCalendar((event.count > 0) ? SWT.ARROW_UP : SWT.ARROW_DOWN);
                break;
              case SWT.Selection:
                if (event.widget == null) {
                  VButton button = (VButton) event.data;
                  int stateMask = event.stateMask;
                  setSelectionFromButton(button, stateMask);
                  if (cdt.field.length == 1
                      && cdt.getCalendarField(cdt.field[0]) == Calendar.DATE) {
                    cdt.fireSelectionChanged(true);
                  } else {
                    cdt.fireSelectionChanged();
                  }
                }
                break;
              case SWT.Traverse:
                if (event.detail == SWT.TRAVERSE_RETURN) {
                  setSelectionFromFocusButton(event);
                } else {
                  traverseSelection(event.keyCode);
                  setSelectionFromFocusButton(event);
                }
                break;
            }
          }
        };

    dayLabels = new VLabel[DAYS_IN_WEEK];
    for (int day = 0; day < dayLabels.length; day++) {
      dayLabels[day] = new VLabel(dayPanel, SWT.CENTER);
      dayLabels[day].setData(CDT.PickerPart, PickerPart.DayOfWeekLabel);
      dayLabels[day].setData(CDT.Key.Compact, b.compact);
      dayLabels[day].setData(CDT.Key.Index, day);
      dayLabels[day].setPainter(cdt.getPainter());
      cdt.getPainter().update(dayLabels[day]);
      dayLabels[day].setMargins(1, 1);
      dayLabels[day].setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    }

    VLabel sep = new VLabel(dayPanel, SWT.HORIZONTAL | SWT.SEPARATOR);
    sep.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 7, 1));

    dayButtons = new VButton[DAYS_IN_WEEK * NUM_ROWS];
    for (int day = 0; day < dayButtons.length; day++) {
      dayButtons[day] = new VButton(dayPanel, SWT.TOGGLE);
      dayButtons[day].setData(CDT.PickerPart, PickerPart.DayButton);
      dayButtons[day].setData(CDT.Key.Index, day);
      dayButtons[day].setPainter(cdt.getPainter());
      cdt.getPainter().update(dayButtons[day]);
      dayButtons[day].setSquare(true);
      dayButtons[day].setMargins(4, 4);
      dayButtons[day].setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
      dayButtons[day].addListener(SWT.KeyDown, dayListener);
      dayButtons[day].addListener(SWT.MouseDown, dayListener);
      dayButtons[day].addListener(SWT.MouseWheel, dayListener);
      dayButtons[day].addListener(SWT.Selection, dayListener);
      dayButtons[day].addListener(SWT.Traverse, dayListener);
    }
  }