Java Code Examples for com.google.gwt.user.client.ui.Image#setUrl()

The following examples show how to use com.google.gwt.user.client.ui.Image#setUrl() . 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: TableImages.java    From document-management-system with GNU General Public License v2.0 6 votes vote down vote up
@Override
public AbstractImagePrototype scrollTableAscending() {
	return new AbstractImagePrototype() {
		public void applyTo(Image image) {
			image.setUrl("img/sort_asc.gif");
		}

		public Image createImage() {
			return new Image("img/sort_asc.gif");
		}

		public String getHTML() {
			return "<img border=\"0\" src=\"img/sort_asc.gif\"/>";
		}
	};
}
 
Example 2
Source File: TableImages.java    From document-management-system with GNU General Public License v2.0 6 votes vote down vote up
@Override
public AbstractImagePrototype scrollTableDescending() {
	return new AbstractImagePrototype() {
		public void applyTo(Image image) {
			image.setUrl("img/sort_desc.gif");
		}

		public Image createImage() {
			return new Image("img/sort_desc.gif");
		}

		public String getHTML() {
			return "<img border=\"0\" src=\"img/sort_desc.gif\"/>";
		}
	};
}
 
Example 3
Source File: TableImages.java    From document-management-system with GNU General Public License v2.0 6 votes vote down vote up
@Override
public AbstractImagePrototype scrollTableFillWidth() {
	return new AbstractImagePrototype() {
		public void applyTo(Image image) {
			image.setUrl("img/fill_width.gif");
		}

		public Image createImage() {
			return new Image("img/fill_width.gif");
		}

		public String getHTML() {
			return "<img border=\"0\" src=\"img/fill_width.gif\"/>";
		}
	};
}
 
Example 4
Source File: DigitalObjectPreview.java    From proarc with GNU General Public License v3.0 6 votes vote down vote up
/**
         * Shows a resource as the {@code <img>} element.
         */
        public void loadImage(String url) {
            ClientUtils.setMembers(display, imgContainer);
            image = new Image();
            image.addLoadHandler(this);
            image.addErrorHandler(this);
            image.setUrl(url);
            drawHandler = imgContainer.addDrawHandler(this);
            resizedHandler = imgContainer.addResizedHandler(this);
            ClientUtils.fine(LOG, "loadImage url: %s, width: %s", url, image.getWidth());
            if (image.getWidth() == 0) {
                WidgetCanvas widgetCanvas = new WidgetCanvas(image);
                widgetCanvas.setVisible(false);
                widgetCanvas.setWidth(1);
                widgetCanvas.setHeight(1);
                widgetCanvas.draw();
                Img loadingImg = new Img("[SKIN]/loadingSmall.gif", 16, 16);
//                Img loadingImg = new Img("[SKIN]/shared/progressCursorTracker.gif", 16, 16);
                loadingImg.setAltText(i18n.ImportBatchDataSource_State_LOADING());
                loadingImg.setPrompt(i18n.ImportBatchDataSource_State_LOADING());
                loadingImg.setLayoutAlign(Alignment.CENTER);
                imgContainer.setMembers(loadingImg, widgetCanvas);
            }
            scheduleForRender();
        }
 
Example 5
Source File: DataStore.java    From djvu-html5 with GNU General Public License v2.0 6 votes vote down vote up
private CanvasElement prepareMissingTileImage() {
	int tileSize = DjvuContext.getTileSize();
	CanvasElement canvas = createImage(tileSize, tileSize);
	Context2d context2d = canvas.getContext2d();
	context2d.setFillStyle("white");
	context2d.fillRect(0, 0, canvas.getWidth(), canvas.getHeight());
	Image image = new Image();
	final ImageElement imageElement = image.getElement().cast();
	imageElement.getStyle().setProperty("visibility", "hidden");
	Event.setEventListener(imageElement, event -> {
		if (Event.ONLOAD == event.getTypeInt()) {
			missingTileImage.getContext2d().drawImage(imageElement, 0, 0);
			RootPanel.get().getElement().removeChild(imageElement);
		}
	});
	RootPanel.get().getElement().appendChild(imageElement);
	image.setUrl(getBlankImageUrl());
	return canvas;
}
 
Example 6
Source File: ImageHelper.java    From gdx-fireapp with Apache License 2.0 5 votes vote down vote up
/**
 * Creates texture region from byte[].
 * <p>
 * GWT platform requires additional step (as far as i know) to deal with Pixmap. It is need to load Image element
 * and wait until it is loaded.
 *
 * @param bytes    Image byte[] representation, not null
 * @param consumer Consumer where you should deal with region, not null
 */
public static void createTextureFromBytes(byte[] bytes, final Consumer<TextureRegion> consumer) {
    String base64 = "data:image/png;base64," + new String(Base64Coder.encode(bytes));
    final Image image = new Image();
    image.setVisible(false);
    image.addLoadHandler(new LoadHandler() {
        @Override
        public void onLoad(LoadEvent event) {
            ImageElement imageElement = image.getElement().cast();
            Pixmap pixmap = new Pixmap(imageElement);
            GdxFIRLogger.log("Image loaded");
            final int orgWidth = pixmap.getWidth();
            final int orgHeight = pixmap.getHeight();
            int width = MathUtils.nextPowerOfTwo(orgWidth);
            int height = MathUtils.nextPowerOfTwo(orgHeight);
            final Pixmap potPixmap = new Pixmap(width, height, pixmap.getFormat());
            potPixmap.drawPixmap(pixmap, 0, 0, 0, 0, pixmap.getWidth(), pixmap.getHeight());
            pixmap.dispose();
            TextureRegion region = new TextureRegion(new Texture(potPixmap), 0, 0, orgWidth, orgHeight);
            potPixmap.dispose();
            RootPanel.get().remove(image);
            consumer.accept(region);
        }
    });
    image.setUrl(base64);
    RootPanel.get().add(image);
}
 
Example 7
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 8
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 9
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 10
Source File: GalleryGuiFactory.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
private GalleryAppWidget(final GalleryApp app) {
  nameLabel = new Label(app.getTitle());
  authorLabel = new Label(app.getDeveloperName());
  numDownloadsLabel = new Label(Integer.toString(app.getDownloads()));
  numLikesLabel = new Label(Integer.toString(app.getLikes()));
  numViewsLabel = new Label(Integer.toString(app.getViews()));
  numCommentsLabel = new Label(Integer.toString(app.getComments()));
  image = new Image();
  image.addErrorHandler(new ErrorHandler() {
    public void onError(ErrorEvent event) {
      image.setResource(GalleryImages.get().genericApp());
    }
  });
  String url = gallery.getCloudImageURL(app.getGalleryAppId());
  image.setUrl(url);

  if(gallery.getSystemEnvironment() != null &&
      gallery.getSystemEnvironment().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 11
Source File: MaterialWebpImage.java    From gwt-material-addins with Apache License 2.0 5 votes vote down vote up
public void checkWebpSupport() {
    Image image = new Image();
    image.setUrl("data:image/webp;base64,UklGRjoAAABXRUJQVlA4IC4AAACyAgCdASoCAAIALmk0mk0iIiIiIgBoSygABc6WWgAA/veff/0PP8bA//LwYAAA");
    image.addLoadHandler(loadEvent -> {
        setUrl(getUrl());
    });
    image.addErrorHandler(errorEvent -> {
        setUrl(getFallbackUrl());
    });
    add(image);
}
 
Example 12
Source File: DjVuPage.java    From djvu-html5 with GNU General Public License v2.0 5 votes vote down vote up
private GPixmap decodeJPEG(CachedInputStream iff) throws IOException {
	final GPixmap result = new GPixmap();

	final Image image = new Image();
	final ImageElement imageElement = image.getElement().cast();
	imageElement.getStyle().setProperty("visibility", "hidden");
	Event.setEventListener(imageElement, new EventListener() {
		@Override
		public void onBrowserEvent(Event event) {
			if (Event.ONLOAD == event.getTypeInt()) {
				final int w = imageElement.getWidth(), h = imageElement.getHeight();
				final Canvas canvas = Canvas.createIfSupported();
				canvas.setWidth(w + "px");
				canvas.setCoordinateSpaceWidth(w);
				canvas.setHeight(h + "px");
				canvas.setCoordinateSpaceHeight(h);
				canvas.getContext2d().drawImage(imageElement, 0, 0);

				result.init(h, w, null);
				//TODO result.setImageData(canvas.getContext2d().getImageData(0, 0, w, h));
			}
		}
	});
	
	StringBuilder data = new StringBuilder();
	int b;
	while ((b = iff.read()) != -1) {
		data.append((char) b);
	}
	String dataURL = "data:image/jpeg;base64," + btoa(data.toString());
	image.setUrl(dataURL);

	return result;
}
 
Example 13
Source File: Header.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Widget getProductSection() {

        final HorizontalPanel panel = new HorizontalPanel();
        panel.getElement().setAttribute("role", "presentation");
        panel.getElement().setAttribute("aria-hidden", "true");

        final Image logo = new Image();
        logo.getElement().setAttribute("style", "cursor:pointer");
        logo.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent clickEvent) {
                toggleNavigation(false);
                placeManager.revealPlace(new PlaceRequest(NameTokens.HomepagePresenter));
            }
        });
        logo.setStyleName("logo");
        panel.add(logo);

        if (ProductConfig.Profile.PRODUCT.equals(productConfig.getProfile())) {
            logo.addErrorHandler(new ErrorHandler() {
                @Override
                public void onError(ErrorEvent event) {
                    panel.remove(logo);
                    Label productName = new Label(productConfig.getProductName());
                    productName.setStyleName("header-product-name");
                    panel.insert(productName, 0);
                }
            });
            logo.setUrl("images/logo/" + logoName(productConfig.getProductName()) + ".png");
            logo.setAltText(productConfig.getProductName());
        } else {
            logo.setUrl("images/logo/community_title.png");
            logo.setAltText("Wildlfy Application Server");
        }

        return panel;
    }
 
Example 14
Source File: GalleryGuiFactory.java    From appinventor-extensions with Apache License 2.0 4 votes vote down vote up
/**
 * Creates list of comments in the app page.
 * @param comments: list of returned gallery comments from callback.
 * @param container: the GUI panel where comments will reside.
 */
public void generateAppPageComments(List<GalleryComment> comments, FlowPanel container) {
  container.clear();  // so don't show previous listing
  if (comments == null) {
    Label noComments = new Label("This app does not have any comments yet.");
    noComments.addStyleName("comment-nope");
    container.add(noComments);
    return;
  }

  for ( GalleryComment c : comments) {
    FlowPanel commentItem = new FlowPanel();
    FlowPanel commentPerson = new FlowPanel();
    FlowPanel commentMeta = new FlowPanel();
    FlowPanel commentContent = new FlowPanel();

    // Add commentPerson, default avatar for now
    Image cPerson = new Image();
    cPerson.setUrl(PERSON_URL);
    commentPerson.add(cPerson);
    commentPerson.addStyleName("comment-person");
    commentItem.add(commentPerson);

    // Add commentContent
    Label cAuthor = new Label(c.getUserName());
    cAuthor.addStyleName("comment-author");
    commentMeta.add(cAuthor);

    Date commentDate = new Date(c.getTimeStamp());
    DateTimeFormat dateFormat = DateTimeFormat.getFormat("yyyy/MM/dd hh:mm:ss a");
    Label cDate = new Label(" on " + dateFormat.format(commentDate));
    cDate.addStyleName("comment-date");
    commentMeta.add(cDate);

    commentMeta.addStyleName("comment-meta");
    commentContent.add(commentMeta);

    Label cText = new Label(c.getComment());
    cText.addStyleName("comment-text");
    commentContent.add(cText);

    commentContent.addStyleName("comment-content");
    commentItem.add(commentContent);

    commentItem.addStyleName("comment-item");
    commentItem.addStyleName("clearfix");
    container.add(commentItem);
  }
}