Package com.google.wave.api

Examples of com.google.wave.api.TextView


  /**
   * Creates the AdminPane from an empty blip.
   */
  public void create() {
    TextView textView = blip.getDocument();

    // Set the 'effective' author to be Polly.
    textView.setAuthor(AdminWavelet.POLLY);
   
    textView.append("\n\n");

    textView.appendElement(new FormElement(ElementType.LABEL, TITLE_LABEL,
        "Enter the title of your poll here:"));

    textView.appendElement(new FormElement(ElementType.INPUT, TITLE_INPUT,
        metadata.getTitle()));
   
    textView.append("\n");

    textView.appendElement(new FormElement(ElementType.LABEL, QUESTION_LABEL,
        "Question: Enter the text of your question here:"));

    textView.appendElement(new FormElement(ElementType.INPUT, QUESTION_INPUT,
        metadata.getQuestion()));
   
    textView.append("\n");
   
    textView.appendElement(new FormElement(ElementType.LABEL, CHOICES_LABEL,
        "Choices:"));
   
    FormElement textArea = new FormElement(ElementType.TEXTAREA, CHOICES_INPUT);
    textView.appendElement(textArea);
   
    // Style the textarea to initially be bulleted.
    int textAreaPosition = textView.getPosition(textArea);
    textView.setStyle(new Range(textAreaPosition, textAreaPosition + 1), StyleType.BULLETED);
   
    textView.append("\n");

    textView.appendElement(new FormElement(ElementType.LABEL, RECIPIENTS_LABEL,
        "Recipients (comma separated list of participants):"));

    textView.appendElement(new FormElement(ElementType.INPUT, RECIPIENTS_INPUT,
        metadata.getRecipients()));
   
    textView.append("\n");

    textView.appendElement(new FormElement(ElementType.BUTTON, DISTRIBUTE_POLL_BUTTON,
        "Distribute Poll"));

    // Create an annotation over the document so that we can recognize it. No
    // value is set since we are only concerned with the existence of the
    // annotation.
    textView.setAnnotation("poll-admin", "");
   
    // Parse the form to retrieve the inital values.
    parseBlip();
  }
View Full Code Here


   *
   * @param asPreview whether or not the PreviewPane is used in a preview or as
   *     the actual poll.
   */
  public void create(boolean asPreview) {
    TextView textView = blip.getDocument();

    // If being used as a preview, create a sub-heading for the pane.
    if (asPreview) {
      textView.append("\n");
      textView.appendStyledText(new StyledText("Preview", StyleType.HEADING2));
    }

    textView.append("\n\n");

    textView.appendElement(new FormElement(ElementType.LABEL, PREV_QUESTION_LABEL,
        metadata.getQuestion()));
    textView.append("\n\n");
   
    textView.appendElement(new FormElement(ElementType.RADIO_BUTTON_GROUP,
        PREV_CHOICES_RADIOGROUP));
   
    for (int i = 0; i < metadata.getChoices().size(); ++i) {
      textView.appendElement(new FormElement(
          ElementType.RADIO_BUTTON,
          PREV_CHOICES_RADIOGROUP,
          PREV_CHOICE_PREFIX + String.valueOf(i) + PREV_CHOICE_RADIO_SUFFIX));
      textView.appendElement(new FormElement(
          ElementType.LABEL,
          PREV_CHOICE_PREFIX + String.valueOf(i) + PREV_CHOICE_LABEL_SUFFIX,
          metadata.getChoices().get(i)));
      textView.append("\n");
    }
   
    textView.append("\n\n");
   
    textView.appendElement(new FormElement(ElementType.BUTTON, PREV_SUBMIT_POLL_BUTTON,
        "Submit Poll"));
  }
View Full Code Here

   * handled appropriately.
   *
   * @param choices the new list of choices.
   */
  public void setChoices(List<String> choices) {
    TextView textView = blip.getDocument();
    FormView formView = textView.getFormView();
   
    // Count existing choice elements
    int existingCount = 0;
    for (FormElement formElement : formView.getFormElements()) {
      if (formElement.getType() == ElementType.LABEL &&
          formElement.getName().startsWith(PREV_CHOICE_PREFIX) &&
          formElement.getName().endsWith(PREV_CHOICE_LABEL_SUFFIX)) {
        ++existingCount;
      }
    }
   
    // Prune extra choices
    if (existingCount > choices.size()) {
      for (int i = existingCount - 1; i >= choices.size(); --i) {
        String choiceLabel = PREV_CHOICE_PREFIX + String.valueOf(i) + PREV_CHOICE_LABEL_SUFFIX;
        int position = textView.getPosition(formView.getFormElement(choiceLabel));

        // Delete the carriage return following the label.
        textView.delete(new Range(position + 1, position + 2));
        // Delete the label.
        formView.delete(choiceLabel);
        // Delete the radio button.
        formView.delete(PREV_CHOICE_PREFIX + String.valueOf(i) + PREV_CHOICE_RADIO_SUFFIX);
      }
      existingCount = choices.size();
    }
   
    // Replace existing labels.
    for (int i = 0; i < existingCount; ++i) {
      String choiceLabel = PREV_CHOICE_PREFIX + String.valueOf(i) + PREV_CHOICE_LABEL_SUFFIX;
      FormElement label = formView.getFormElement(choiceLabel);
      if (!choices.get(i).equals(metadata.getChoices().get(i))) {
        label.setValue(choices.get(i));
        formView.replace(label);
      }
    }
   
    // Add new labels.
    if (existingCount < choices.size()) {
      // Get the position of the last label.
      int lastLabelPosition;
      if (existingCount == 0) {
        lastLabelPosition = textView.getPosition(formView.getFormElement(PREV_CHOICES_RADIOGROUP));
      } else {
        String choiceLabel = PREV_CHOICE_PREFIX + String.valueOf(existingCount - 1) +
            PREV_CHOICE_LABEL_SUFFIX;
        lastLabelPosition = textView.getPosition(formView.getFormElement(choiceLabel)) + 1;
      }
     
      for (int i = existingCount; i < choices.size(); ++i) {
        FormElement radioButton = new FormElement(
            ElementType.RADIO_BUTTON,
            PREV_CHOICES_RADIOGROUP,
            PREV_CHOICE_PREFIX + String.valueOf(i) + PREV_CHOICE_RADIO_SUFFIX);
        FormElement label = new FormElement(
            ElementType.LABEL,
            PREV_CHOICE_PREFIX + String.valueOf(i) + PREV_CHOICE_LABEL_SUFFIX,
            choices.get(i));
        textView.insertElement(lastLabelPosition + 1, radioButton);
        textView.insertElement(lastLabelPosition + 2, label);
        textView.insert(lastLabelPosition + 3, "\n");
        lastLabelPosition = lastLabelPosition + 3;
      }
    }
  }
View Full Code Here

  /**
   * Creates the ResultsPane by appending it to the end of a blip.
   */
  public void create() {
    TextView textView = blip.getDocument();

    textView.append("\n");

    textView.appendStyledText(new StyledText("Results", StyleType.HEADING2));

    textView.append("\n\n");
   
    textView.appendElement(new Image(getParticipationChartUrl(),
        PARTICIPATION_WIDTH, PARTICIPATION_HEIGHT, ""));
   
    textView.appendElement(new Image(getDistrtibutionChartUrl(),
        DISTRIBUTION_WIDTH, DISTRIBUTION_HEIGHT, ""));

    textView.append("\n");
  }
View Full Code Here

    Image distributionChart = new Image(getDistrtibutionChartUrl(),
        DISTRIBUTION_WIDTH, DISTRIBUTION_HEIGHT, "");
    Image participationChart = new Image(getParticipationChartUrl(),
        PARTICIPATION_WIDTH, PARTICIPATION_HEIGHT, "");
   
    TextView textView = blip.getDocument();
    for (Element element : textView.getElements(ElementType.IMAGE)) {
      Image image = (Image)element;
      if (image.getUrl().contains("Poll%20Distribution")) {
        textView.replaceElement(textView.getPosition(image), distributionChart);
      } else if (image.getUrl().contains("Poll%20Participation")) {
        textView.replaceElement(textView.getPosition(image), participationChart);
      }
    }
  }
View Full Code Here

  }

  @Override
  public void renderForm() {
    // Clear out everything.
    TextView document = blip.getDocument();
    document.delete();

    // TODO: Decide if want to use former code and, if so, how to get username.
//    // Former code:
//    String username = twitterWave.getUsername();
//    blip.getWavelet().setTitle(
//        new StyledText((username + (username.endsWith("s") ? "'" : "'s") + " Twitter Search"),
//            StyleType.HEADING3));
   
    // Set the new title.
    blip.getWavelet().setTitle(new StyledText("Twitter Search", StyleType.HEADING3));

    // Insert the search input box.
    document.append("\n");
    document.appendElement(new FormElement(
        ElementType.INPUT,
        SEARCH_INPUT_ID,
        twitterWave.getSearchQuery()));

    // Append the search button.
    document.append("\n");
    document.appendElement(new FormElement(
        ElementType.BUTTON,
        SEARCH_BUTTON_ID,
        SEARCH_BUTTON_CAPTION));
  }
View Full Code Here

  }

  @Override
  public void renderForm() {
    // Clear out everything.
    TextView document = blip.getDocument();
    document.delete();

    // TODO: Decide if want to user former code and, if so, and how to get username.
//  // Former code:
//  blip.getWavelet().setTitle(
//      new StyledText("What are you doing " + twitterWave.getUsername() + "?",
//          StyleType.HEADING3));
   
    // Set the title.
    blip.getWavelet().setTitle(
        new StyledText("What are you doing ?",
            StyleType.HEADING3));

    // Insert the update form.
    document.append("\n");
    document.appendElement(new FormElement(
        ElementType.INPUT,
        UPDATE_INPUT_ID,
        ""));

    // Insert the update button.
    document.append("\n");
    document.appendElement(new FormElement(
        ElementType.BUTTON,
        UPDATE_BUTTON_ID,
        "Update"));
  }
View Full Code Here

   * @param wavelet The {@link Wavelet} to append the tweet to.
   * @param tweet The tweet to be appended.
   */
  private void appendTweet(Wavelet wavelet, Tweet tweet) {
    // Set the metadata: author, creation time, and tweet id annotation.
    TextView textView = wavelet.appendBlip().getDocument();
    textView.setAuthor(tweet.getAuthor() + "@" + getRobotAddress());
    textView.setCreationTime(tweet.getTime());
    textView.setAnnotation(TWEET_ID_ANNOTATION_KEY, tweet.getId());

    String content = tweet.getText();
    textView.insert(0, content);

    // Linkify the content.
    Matcher matcher = Pattern.compile(URL_REGEX).matcher(content);
    while (matcher.find()) {
      textView.setAnnotation(new Range(matcher.start(), matcher.end()), LINK_ANNOTATION_KEY,
          matcher.group());
    }
  }
View Full Code Here

      // When user logs in via the popup, finish OAuth by exchanging
      // request token for an access token.
      for (Event event : robotMessageBundle.getEvents()) {
        if (event.getType() == EventType.DOCUMENT_CHANGED) {
          // Get all the gadgets in the wave (typically only be one).
          TextView document = wavelet.getRootBlip().getDocument();
          GadgetView gadgetView = document.getGadgetView();
          for (Gadget gadget : gadgetView.getGadgets()) {
            if ((gadget != null) && ("true".equals(gadget.getField(GADGET_STATE)))) {
              if (twitterService.checkAuthorization(wavelet, loginForm)) {
                FetchController controller =
                    twitterWave.isInSearchMode() ? new SearchController(twitterService, rootBlip,
View Full Code Here

    setWaveId(wavelet.getWaveId());
    setWaveletId(wavelet.getWaveletId());
   
    // Setup wavelet.
    wavelet.setTitle(CONTENTS_TITLE);
    TextView contentsDocument = wavelet.getRootBlip().getDocument();
    contentsDocument.append("\n\n(Write Introduction Here)");
   
    // Create New Post button in new blip.
    Blip blip = wavelet.appendBlip();
    contentsDocument = blip.getDocument();
    contentsDocument.appendElement(new FormElement(ElementType.BUTTON, LOGIN_BUTTON_ID,
        LOGIN_BUTTON_CAPTION));
   
    // Create new blip for TOC and save blip ID.
    String blipKey = String.valueOf(Math.random());
    blip = wavelet.appendBlip(blipKey);
View Full Code Here

TOP

Related Classes of com.google.wave.api.TextView

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.