Пример #1
0
  public void Configure_start_time() {

    final DialogBox dialogBox = new DialogBox();
    dialogBox.addStyleName("g-DialogBox");
    DOM.setStyleAttribute(dialogBox.getElement(), "border", "0px");
    dialogBox.setText("Set Time");
    dialogBox.setSize("294", "207");

    final AbsolutePanel absolutePanel = new AbsolutePanel();
    dialogBox.setWidget(absolutePanel);
    absolutePanel.setSize("294px", "187px");

    // 自定义datebox的输出格式,在这里采用了简洁的输出格式"M/d/yy H:mm"
    final DateBox dateBox = new DateBox();
    DateTimeFormat dateTimeFormat =
        DateTimeFormat.getFormat(
            "M/d/yy H:mm"); // DateTimeFormat只能通过函数getFormat来生成满足特定pattern的对象,因为其构造函数为protected
    DateBox.DefaultFormat defaultFormat = new DateBox.DefaultFormat(dateTimeFormat);
    dateBox.setFormat(defaultFormat);
    absolutePanel.add(dateBox, 109, 35);
    dateBox.setWidth("150px");

    final Label dateLabel = new Label("Date:");
    absolutePanel.add(dateLabel, 36, 35);
    dateLabel.setSize("38px", "18px");

    final Label dateLabel_1 = new Label("Time:");
    absolutePanel.add(dateLabel_1, 36, 80);
    dateLabel_1.setSize("38px", "18px");

    final ListBox listBox = new ListBox();
    absolutePanel.add(listBox, 109, 77);
    listBox.setSize("150px", "21px");
    String[] minutes = {"00", "15", "30", "45"};
    String[] hours = {
      "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16",
      "17", "18", "19", "20", "21", "22", "23"
    };
    String[] times = new String[96];
    // System.out.println(minutes.length+"  "+hours.length+"  "+times.length);
    for (int i = 0; i < 24; i++) {
      for (int j = 0; j < 4; j++) {
        times[4 * i + j] = hours[i] + ":" + minutes[j];
      }
    }
    for (int i = 0; i < 96; i++) {
      listBox.addItem(times[i]);
    }

    final Button okButton = new Button();
    DOM.setStyleAttribute(okButton.getElement(), "fontSize", "10pt");
    okButton.removeStyleName("gwt-Button");
    okButton.addClickHandler(
        new ClickHandler() {

          public void onClick(ClickEvent event) {
            // TODO Auto-generated method stub
            TextBox inner_textBox = dateBox.getTextBox();
            if (inner_textBox.getText() == null || inner_textBox.getText().equals("")) {
              dateBox.addStyleName("dateBoxFormatError"); // 如果用户没编辑日期,则datebox框变红,等待用户更正
            } else {
              String dateString = inner_textBox.getText();
              int index = listBox.getSelectedIndex();
              String timeString = listBox.getValue(index);
              if (timeString != null) {
                String[] date_and_time = dateString.split(" ");
                date_and_time[1] = timeString;
                dateString = date_and_time[0] + " " + date_and_time[1];
                start_time = dateString;
              }
              dialogBox.hide();
            }
            System.out.println(start_time);
          }
        });

    absolutePanel.add(okButton, 93, 129);
    okButton.setSize("105px", "21px");
    okButton.setText("OK");

    dialogBox.center();
  }
Пример #2
0
  public DialogCarma(KarmaHome home, KarmaUser user) {
    super(false, true);
    this.homeParent = home;
    this.user = user;

    setHTML(CONSTANTS.this_html());

    VerticalPanel verticalPanel = new VerticalPanel();
    verticalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    setWidget(verticalPanel);
    verticalPanel.setWidth("100%");

    HorizontalPanel horizontalPanel = new HorizontalPanel();
    horizontalPanel.setSpacing(5);
    verticalPanel.add(horizontalPanel);
    horizontalPanel.setWidth("100%");

    VerticalPanel verticalPanel_2 = new VerticalPanel();
    horizontalPanel.add(verticalPanel_2);
    verticalPanel_2.setSize("260", "110");

    Grid grid_1 = new Grid(3, 2);
    verticalPanel_2.add(grid_1);
    grid_1.setSize("", "100");

    Label label_10 = new Label(CONSTANTS.label_10_text());
    grid_1.setWidget(0, 0, label_10);
    grid_1.getCellFormatter().setWidth(0, 0, "100");

    listTypes = new ListBox();
    grid_1.setWidget(0, 1, listTypes);
    grid_1.getCellFormatter().setWidth(0, 1, "150");
    listTypes.setWidth("100%");
    ClientUtils.fillTypes(listTypes);

    Label label_11 = new Label(CONSTANTS.label_11_text());
    grid_1.setWidget(1, 0, label_11);

    tbPlate = new TextBox();
    tbPlate.setVisibleLength(10);
    grid_1.setWidget(1, 1, tbPlate);
    tbPlate.setWidth("100%");

    cbxForeign = new CheckBox(CONSTANTS.cbxForeign_text());
    grid_1.setWidget(2, 0, cbxForeign);
    cbxForeign.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            showCountries();
          }
        });

    listCountry = new ListBox();
    grid_1.setWidget(2, 1, listCountry);
    listCountry.setWidth("100%");
    listCountry.setVisible(false);
    ClientUtils.fillCountries(listCountry);

    VerticalPanel verticalPanel_6 = new VerticalPanel();
    horizontalPanel.add(verticalPanel_6);
    verticalPanel_6.setSize("260", "110");

    Grid grid_2 = new Grid(3, 2);
    verticalPanel_6.add(grid_2);
    grid_2.setSize("", "100");

    Label label_15 = new Label(CONSTANTS.label_15_text());
    grid_2.setWidget(0, 0, label_15);
    grid_2.getCellFormatter().setWidth(0, 0, "50");

    date = new DateBox();
    date.setFormat(new DefaultFormat(DateTimeFormat.getFormat("yyyy-MM-dd HH:mm")));
    grid_2.setWidget(0, 1, date);
    grid_2.getCellFormatter().setWidth(0, 1, "200");
    date.setWidth("100%");
    date.addValueChangeHandler(
        new ValueChangeHandler<Date>() {
          @Override
          public void onValueChange(ValueChangeEvent<Date> event) {
            Date d = event.getValue();
            if (d.after(new Date())
                || d.before(new Date(System.currentTimeMillis() - 31536000000L))) {
              date.setValue(new Date());
              MsgMan.getInstance().showError(CONSTANTS.error_date1(), date);
            }
          }
        });

    Label label_16 = new Label(CONSTANTS.label_16_text());
    grid_2.setWidget(1, 0, label_16);

    taNotes = new TextArea();
    taNotes.addKeyPressHandler(
        new KeyPressHandler() {
          public void onKeyPress(KeyPressEvent event) {
            updateCounter();
          }
        });
    taNotes.setSize("100%", "50");
    grid_2.setWidget(1, 1, taNotes);

    lblCounter = new Label("New label");
    lblCounter.addStyleName("counter");
    grid_2.setWidget(2, 1, lblCounter);
    grid_2.getCellFormatter().setHorizontalAlignment(2, 1, HasHorizontalAlignment.ALIGN_RIGHT);

    HorizontalPanel horizontalPanel_3 = new HorizontalPanel();
    horizontalPanel_3.setSpacing(5);
    horizontalPanel_3.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
    verticalPanel.add(horizontalPanel_3);
    verticalPanel.setCellHorizontalAlignment(
        horizontalPanel_3, HasHorizontalAlignment.ALIGN_CENTER);

    btnPuntuar = new Button("New button");
    horizontalPanel_3.add(btnPuntuar);
    btnPuntuar.setText(CONSTANTS.btnPuntuar_text());
    btnPuntuar.setWidth("100");

    Button btnCancel = new Button("New button");
    horizontalPanel_3.add(btnCancel);
    btnCancel.setText(CONSTANTS.btnCancel_text());
    btnCancel.setWidth("100");
    btnPuntuar.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            makeKarma();
          }
        });
    btnCancel.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            DialogCarma.this.hide();
          }
        });

    updateCounter();
  }