Java Code Examples for com.google.gwt.user.client.ui.Panel#add()

The following examples show how to use com.google.gwt.user.client.ui.Panel#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GalleryPage.java    From appinventor-extensions with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method called by constructor to initialize the app's title section
 * @param container   The container that title resides
 */
private void initAppTitle(Panel container) {
  if (newOrUpdateApp()) {
    // GUI for editable title container
    if (editStatus==NEWAPP) {
      // If it's new app, give a textual hint telling user this is title
      titleText.setText(app.getTitle());
    } else if (editStatus==UPDATEAPP) {
      // If it's not new, just set whatever's in the data field already
      titleText.setText(app.getTitle());
    }
    titleText.addValueChangeHandler(new ValueChangeHandler<String>() {
      @Override
      public void onValueChange(ValueChangeEvent<String> event) {
        app.setTitle(titleText.getText());
      }
    });
    titleText.addStyleName("app-desc-textarea");
    container.add(titleText);
    container.addStyleName("app-title-container");
  } else {
    Label title = new Label(app.getTitle());
    title.addStyleName("app-title");
    container.add(title);
  }
}
 
Example 2
Source File: GalleryPage.java    From appinventor-extensions with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method called by constructor to initialize the app's description
 * @param c1   The container that description resides (editable state)
 * @param c2   The container that description resides (public state)
 */
private void initAppDesc(Panel c1, Panel c2) {
  desc.getElement().setPropertyString("placeholder", MESSAGES.galleryDescriptionHint());
  if (newOrUpdateApp()) {
    desc.addValueChangeHandler(new ValueChangeHandler<String>() {
      @Override
      public void onValueChange(ValueChangeEvent<String> event) {
        app.setDescription(desc.getText());
      }
    });
    if(editStatus==UPDATEAPP){
      desc.setText(app.getDescription());
    }
    desc.addStyleName("app-desc-textarea");
    c1.add(desc);
  } else {
    Label description = new Label(app.getDescription());
    c2.add(description);
    c2.addStyleName("app-description");
  }
}
 
Example 3
Source File: GalleryPage.java    From appinventor-extensions with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method called by constructor to initialize the salvage section
 * @param container   The container that salvage label reside
 */
private void initSalvageSection(Panel container) { //TODO: Update the location of this button
  if (!canSalvage()) {                              // Permitted to salvage?
    return;
  }

  final Label salvagePrompt = new Label("salvage");
  salvagePrompt.addStyleName("primary-link");
  container.add(salvagePrompt);

  salvagePrompt.addClickHandler(new ClickHandler() {
    public void onClick(ClickEvent event) {
      final OdeAsyncCallback<Void> callback = new OdeAsyncCallback<Void>(
          // failure message
          MESSAGES.galleryError()) {
            @Override
            public void onSuccess(Void bool) {
              salvagePrompt.setText("done");
            }
        };
      Ode.getInstance().getGalleryService().salvageGalleryApp(app.getGalleryAppId(), callback);
    }
  });
}
 
Example 4
Source File: GalleryPage.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to update the app image
 * @param url  The URL of the image to show
 * @param container  The container that image widget resides
 */
private void updateAppImage(String url, final Panel container) {
    image = new Image();
    image.addStyleName("app-image");
    image.setUrl(url);
    // if the user has provided a gallery app image, we'll load it. But if not
    // the error will occur and we'll load default image
    image.addErrorHandler(new ErrorHandler() {
      public void onError(ErrorEvent event) {
        image.setResource(GalleryImages.get().genericApp());
      }
    });
    container.add(image);

    if(gallery.getSystemEnvironment() != null &&
        gallery.getSystemEnvironment().toString().equals("Development")){
      final OdeAsyncCallback<String> callback = new OdeAsyncCallback<String>(
        // failure message
        MESSAGES.galleryError()) {
          @Override
          public void onSuccess(String newUrl) {
            if (newUrl != null) {
              image.setUrl(newUrl + "?" + System.currentTimeMillis());
            }
          }
        };
      Ode.getInstance().getGalleryService().getBlobServingUrl(url, callback);
    }
}
 
Example 5
Source File: GalleryPage.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method called by constructor to initialize the app's stats fields
 * @param container   The container that stats fields reside
 */
private void initAppStats(Panel container) {
  // Images for stats data
  Image numDownloads = new Image();
  numDownloads.setUrl(DOWNLOAD_ICON_URL);
  Image numLikes = new Image();
  numLikes.setUrl(HOLLOW_HEART_ICON_URL);

  // Add stats data
  container.addStyleName("app-stats");
  container.add(numDownloads);
  container.add(new Label(Integer.toString(app.getDownloads())));
  // Adds dynamic like
  initLikeSection(container);
  // Adds dynamic feature
  initFeatureSection(container);
  // Adds dynamic tutorial
  initTutorialSection(container);
  // Adds dynamic salvage
  initSalvageSection(container);

  // We are not using views and comments at initial launch
  /*
  Image numViews = new Image();
  numViews.setUrl(NUM_VIEW_ICON_URL);
  Image numComments = new Image();
  numComments.setUrl(NUM_COMMENT_ICON_URL);
  container.add(numViews);
  container.add(new Label(Integer.toString(app.getViews())));
  container.add(numComments);
  container.add(new Label(Integer.toString(app.getComments())));
  */
}
 
Example 6
Source File: ProfilePage.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to update the user's image
 * @param url  The URL of the image to show
 * @param container  The container that image widget resides
 */
private void updateUserImage(final String url, Panel container) {
  userAvatar = new Image();
  //setUrl if the new URL is the same one as it was before; an easy workaround is
  //to make the URL unique so it forces the browser to reload
  userAvatar.setUrl(url + "?" + System.currentTimeMillis());
  userAvatar.addStyleName("app-image");
  if (profileStatus == PRIVATE) {
    //userAvatar.addStyleName("status-updating");
  }
  // if the user has provided a gallery app image, we'll load it. But if not
  // the error will occur and we'll load default image
  userAvatar.addErrorHandler(new ErrorHandler() {
    public void onError(ErrorEvent event) {
      userAvatar.setResource(GalleryImages.get().androidIcon());
    }
  });
  container.add(userAvatar);

  if(gallery.getSystemEnvironment() != null &&
      gallery.getSystemEnvironment().toString().equals("Development")){
    final OdeAsyncCallback<String> callback = new OdeAsyncCallback<String>(
      // failure message
      MESSAGES.galleryError()) {
        @Override
        public void onSuccess(String newUrl) {
          if (userAvatar != null) {
            userAvatar.setUrl(newUrl + "?" + System.currentTimeMillis());
          }
        }
      };
    Ode.getInstance().getGalleryService().getBlobServingUrl(url, callback);
  }
}
 
Example 7
Source File: ErrorIndicatorPresenter.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an error indicator.
 *
 * @param container panel to which this widget is to be attached
 */
public static ErrorIndicatorPresenter create(Panel container) {
  ErrorIndicatorWidget ui = ErrorIndicatorWidget.create();
  ErrorIndicatorPresenter presenter = new ErrorIndicatorPresenter(ui);
  ui.init(presenter);
  container.add(ui);
  return presenter;
}
 
Example 8
Source File: DebugOptions.java    From swellrt with Apache License 2.0 5 votes vote down vote up
private void addCheckBox(Panel panel, String caption, boolean initValue,
    ValueChangeHandler<Boolean> handler) {
  CheckBox box = new CheckBox(caption);
  box.setValue(initValue);
  box.addValueChangeHandler(handler);
  panel.add(box);
}
 
Example 9
Source File: SingleListBoxDemo.java    From gwt-traction with Apache License 2.0 5 votes vote down vote up
@Override
public void onModuleLoad() {

    eventListBox = new ListBox(true);
    eventListBox.setVisibleItemCount(20);
    RootPanel.get("eventlog").add(eventListBox);

    singleListBox = new SingleListBox();
    singleListBox.addItem("Apples");
    singleListBox.addItem("Bananas");
    singleListBox.addItem("Oranges");
    singleListBox.addItem("Pears");
    singleListBox.addValueChangeHandler(new ValueChangeHandler<String>() {
        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            addEvent("ValueChangeEvent: " + event.getValue());
        }
    });
    Panel select = RootPanel.get("select");
    select.add(singleListBox);

    Panel toggle = RootPanel.get("toggle");
    toggle.add(createSetAddMissingValue(true));
    toggle.add(createSetAddMissingValue(false));

    Panel controls1 = RootPanel.get("controls1");
    controls1.add(createSelectButton("Bananas"));
    controls1.add(createSelectButton("Pears"));

    Panel controls2 = RootPanel.get("controls2");
    controls2.add(createSelectButton("Kiwis"));
    controls2.add(createSelectButton("Watermelons"));
}
 
Example 10
Source File: OpacityDemo.java    From gwt-traction with Apache License 2.0 5 votes vote down vote up
@Override
   public void onModuleLoad() {

Panel controls = RootPanel.get("controls");

startOpacity = createTextBox("1.0");
endOpacity = createTextBox("0.1");
duration = createTextBox("5000");

addTextBox(controls, "Start Opacity", startOpacity);
addTextBox(controls, "End Opacity", endOpacity);
addTextBox(controls, "Duration", duration);

Button start = new Button("Start");
start.addClickHandler(new ClickHandler() {
    @Override
           public void onClick(ClickEvent event) {
        OpacityAnimation animation = new OpacityAnimation(new Element[] {
							      Document.get().getElementById("box1"),
							      Document.get().getElementById("box2"),
							      Document.get().getElementById("box3")
							  },
							  Float.parseFloat(startOpacity.getText()),
							  Float.parseFloat(endOpacity.getText()));
        animation.run(Integer.parseInt(duration.getText()));
    }
});

controls.add(start);
   }
 
Example 11
Source File: GroupedListBoxDemo.java    From gwt-traction with Apache License 2.0 5 votes vote down vote up
@Override
   public void onModuleLoad() {

groupedListBox1 = new GroupedListBox(false);
groupedListBox2 = new GroupedListBox(true);
RootPanel.get("select1").add(groupedListBox1);
RootPanel.get("select2").add(groupedListBox2);

addItem("Fruits|Apples");
addItem("Fruits|Bananas");
addItem("Fruits|Oranges");
addItem("Fruits|Pears");	
addItem("Vegetables|Tomatoes");	
addItem("Vegetables|Carrots");		

Panel controls = RootPanel.get("controls");
controls.add(createAddButton("Fruits|Blueberries"));
controls.add(createAddButton("Vegetables|Broccoli"));
controls.add(createAddButton("Meats|Chicken"));
controls.add(createAddButton("Meats|Turkey"));

Button remove = new Button("Remove Selected");
remove.addClickHandler(new ClickHandler() {
           
           @Override
           public void onClick(ClickEvent event) {
               removeSelected();
           }
       });

controls.add(remove);
   }
 
Example 12
Source File: ColorDemo.java    From gwt-traction with Apache License 2.0 5 votes vote down vote up
@Override
   public void onModuleLoad() {

Panel controls = RootPanel.get("controls");

startColor = createTextBox("rgba(255,255,0,1)");
endColor = createTextBox("rgba(255,0,255,0)");
duration = createTextBox("5000");

addTextBox(controls, "Start Color", startColor);
addTextBox(controls, "End Color", endColor);
addTextBox(controls, "Duration", duration);

Button start = new Button("Start");
start.addClickHandler(new ClickHandler() {
    @Override
    public void onClick(ClickEvent event) {
        ColorAnimation animation = new ColorAnimation(new Element[] {
							      Document.get().getElementById("box1"),
							      Document.get().getElementById("box2"),
							      Document.get().getElementById("box3")
							  },
							  "backgroundColor",
							  RgbaColor.from(startColor.getText()),
							  RgbaColor.from(endColor.getText()));
        animation.run(Integer.parseInt(duration.getText()));
    }
});

controls.add(start);
   }
 
Example 13
Source File: ErrorIndicatorPresenter.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an error indicator.
 *
 * @param container panel to which this widget is to be attached
 */
public static ErrorIndicatorPresenter create(Panel container) {
  ErrorIndicatorWidget ui = ErrorIndicatorWidget.create();
  ErrorIndicatorPresenter presenter = new ErrorIndicatorPresenter(ui);
  ui.init(presenter);
  container.add(ui);
  return presenter;
}
 
Example 14
Source File: DebugOptions.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
private void addCheckBox(Panel panel, String caption, boolean initValue,
    ValueChangeHandler<Boolean> handler) {
  CheckBox box = new CheckBox(caption);
  box.setValue(initValue);
  box.addValueChangeHandler(handler);
  panel.add(box);
}
 
Example 15
Source File: OpacityDemo.java    From gwt-traction with Apache License 2.0 4 votes vote down vote up
private static final void addTextBox(Panel panel, String label, TextBox box) {
panel.add(new Label(label));
panel.add(box);
   }
 
Example 16
Source File: ColorDemo.java    From gwt-traction with Apache License 2.0 4 votes vote down vote up
private static final void addTextBox(Panel panel, String label, TextBox box) {
panel.add(new Label(label));
panel.add(box);
   }