Java Code Examples for com.google.gwt.user.client.DOM#setStyleAttribute()

The following examples show how to use com.google.gwt.user.client.DOM#setStyleAttribute() . 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: MockComponentsUtil.java    From appinventor-extensions with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the text alignment for the given widget.
 *
 * @param widget  widget to change text alignment for
 * @param align  one of "0" for left, "1" for center or "2" for right
 */
static void setWidgetTextAlign(Widget widget, String align) {
  switch (Integer.parseInt(align)) {
    default:
      // This should never happen
      throw new IllegalArgumentException("align:" + align);

    case 0:
      align = "left";
      break;

    case 1:
      align = "center";
      break;

    case 2:
      align = "right";
      break;
  }
  DOM.setStyleAttribute(widget.getElement(), "textAlign", align);
}
 
Example 2
Source File: MockComponentsUtil.java    From appinventor-extensions with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the font typeface for the given widget.
 *
 * @param widget  widget to change font typeface for
 * @param typeface  "0" for normal, "1" for sans serif, "2" for serif and
 *                  "3" for monospace
 */
static void setWidgetFontTypeface(Widget widget, String typeface) {
  switch (Integer.parseInt(typeface)) {
    default:
      // This should never happen
      throw new IllegalArgumentException("Typeface:" + typeface);

    case 0:
    case 1:
      typeface = "sans-serif";
      break;

    case 2:
      typeface = "serif";
      break;

    case 3:
      typeface = "monospace";
      break;
  }
  DOM.setStyleAttribute(widget.getElement(), "fontFamily", typeface);
}
 
Example 3
Source File: DiagramTab.java    From SensorWebClient with GNU General Public License v2.0 6 votes vote down vote up
private Viewport getMainChartViewport() {
    Image mainChartImage = new Image("img/blank.gif");

    Viewport mainchart = new Viewport("100%", "100%");
    mainchart.setEnableZoomWhenShiftkeyPressed(true);
    mainchart.add(mainChartImage);

    // as it is focusable, we do not want to see an outline
    DOM.setStyleAttribute(mainchart.getElement(), "outline", "none");
    DOM.setStyleAttribute(mainchart.getElement(), "overflow", "visible");
    ImageViewImpl imageView = new ImageViewImpl(mainChartImage);

    new ImagePresenter(this.mainChartEventBus, imageView);
    new DragImageControl(this.mainChartEventBus);
    new MouseWheelControl(this.mainChartEventBus);

    return mainchart;
}
 
Example 4
Source File: MockCanvas.java    From appinventor-extensions with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the canvas's BackgroundImage property to a new value.
 */
private void setBackgroundImageProperty(String text) {
  String url = convertImagePropertyValueToUrl(text);

  // We tell the layout (which is a MockCanvasLayout) that there is (or is not) a background
  // image so it can adjust the "layout width/height". The "layout width/height" is used when the
  // preferred width/height of a MockContainer is requested. See MockContainer.getPreferredWidth
  // and getPreferredHeight, as well as MockLayout.getPreferredWidth and getPreferredHeight.
  if (url == null) {
    // text was not recognized as an asset.
    ((MockCanvasLayout) layout).setBackgroundImageUrl("");
    url = "static/images/canvas.png";
    // We set the background image of the canvasWidget so it displays the image. We do it inside
    // the if because we need to override the background-size property only for this case
    MockComponentsUtil.setWidgetBackgroundImage(this, canvasWidget, url);
    DOM.setStyleAttribute(canvasWidget.getElement(), "backgroundSize", "");
  } else {
    ((MockCanvasLayout) layout).setBackgroundImageUrl(url);
    // We set the background image of the canvasWidget so it displays the image.
    MockComponentsUtil.setWidgetBackgroundImage(this, canvasWidget, url);
  }
}
 
Example 5
Source File: ReplaysPage.java    From sc2gears with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the label style of a label widget.
 * @param labelWidget label widget to style
 * @param label       label whose style to set
 */
private void setLabelStyle( final Widget labelWidget, final int label ) {
	if ( label < userInfo.getLabelColors  ().length )
		DOM.setStyleAttribute( labelWidget.getElement(), "color"     , '#' + userInfo.getLabelColors  ()[ label ] );
	if ( label < userInfo.getLabelBgColors().length )
		DOM.setStyleAttribute( labelWidget.getElement(), "background", '#' + userInfo.getLabelBgColors()[ label ] );
}
 
Example 6
Source File: MockComponentsUtil.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
static void restoreSizeStyle(Element element, String[] style) {
  if (style[0] != null) {
    DOM.setStyleAttribute(element, "width", style[0]);
  }
  if (style[1] != null) {
    DOM.setStyleAttribute(element, "height", style[1]);
  }
  if (style[2] != null) {
    DOM.setStyleAttribute(element, "lineHeight", style[2]);
  }
}
 
Example 7
Source File: MockComponentsUtil.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
static String[] clearSizeStyle(Element element) {
  String widthStyle = DOM.getStyleAttribute(element, "width");
  String heightStyle = DOM.getStyleAttribute(element, "height");
  String lineHeightStyle = DOM.getStyleAttribute(element, "lineHeight");
  if (widthStyle != null) {
    DOM.setStyleAttribute(element, "width", null);
  }
  if (heightStyle != null) {
    DOM.setStyleAttribute(element, "height", null);
  }
  if (lineHeightStyle != null) {
    DOM.setStyleAttribute(element, "lineHeight", "initial");
  }
  return new String[] { widthStyle, heightStyle, lineHeightStyle };
}
 
Example 8
Source File: Admin.java    From sc2gears with Apache License 2.0 5 votes vote down vote up
@Override
public void onModuleLoad() {
	mainPanel.setWidth( "100%" );
	DOM.setStyleAttribute( mainPanel.getElement(), "marginBottom", "10px" );
	mainPanel.setHorizontalAlignment( HasHorizontalAlignment.ALIGN_CENTER );
	mainPanel.add( ClientUtils.styledWidget( new Label( "Sc2gears™ Database Admin Page" ), "h1" ) );
	menuPanel.add( ClientUtils.createCheckingUserWidget() );
	mainPanel.add( menuPanel );
	RootPanel.get().add( mainPanel );
	
	SERVICE_ASYNC.getUserInfo( new AsyncCallback< RpcResult< UserInfo > >() {
		@Override
		public void onSuccess( final RpcResult< UserInfo > rpcResult ) {
			Admin.userInfo = rpcResult.getValue();
			menuPanel.clear();
			if ( userInfo.getUserName() == null )
				menuPanel.add( new HTML( "You are not logged in. You can login <a href=\"" + userInfo.getLoginUrl() + "\">here</a>." ) );
			else if ( !userInfo.isAdmin() )
				menuPanel.add( new HTML( "You are not authorized to view this page. You can logout <a href=\"" + userInfo.getLogoutUrl() + "\">here</a>." ) );
			else {
				ClientUtils.createAndSetupLogoutLink( "Logout " + userInfo.getUserName(), userInfo.getLogoutUrl() );
				final MenuItem[] MENU_ITEMS = MenuItem.values();
				menu = new Menu( MENU_ITEMS, mainPanel );
				// Too many menu items, menu is too big, make it smaller:
				for ( int i = 0; i < MENU_ITEMS.length; i++ )
					menu.setTabHTML( i, "<span style='font-size:80%'>" + MENU_ITEMS[ i ].label + "</span>" );
				menuPanel.add( menu );
				// Go to home page
				menu.setPage( new HomePage() );
			}
		}
		@Override
		public void onFailure( final Throwable caught ) {
			menuPanel.clear();
			menuPanel.add( new Label( "Failed to reach the server. Try refreshing the page." ) );
		}
	} );
}
 
Example 9
Source File: MockHVLayoutBase.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
private void ensureDividerInited() {
  if (dividerElement == null) {
    dividerElement = DOM.createDiv();
    DOM.setStyleAttribute(dividerElement, "backgroundColor", DIVIDER_COLOR);
    setDividerVisible(false);
    DOM.appendChild(container.getRootPanel().getElement(), dividerElement);
  }
}
 
Example 10
Source File: MiniProgressBar.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Create a progress bar within the given range starting at the specified
 * progress amount.
 *
 * @param minProgress the minimum progress
 * @param maxProgress the maximum progress
 * @param curProgress the current progress
 * @param textFormatter the text formatter
 */
public MiniProgressBar(double minProgress, double maxProgress,
  double curProgress, TextFormatter textFormatter) {
  this.minProgress = minProgress;
  this.maxProgress = maxProgress;
  this.curProgress = curProgress;
  setTextFormatter(textFormatter);

  // Create the outer shell
  setElement(DOM.createDiv());
  DOM.setStyleAttribute(getElement(), "position", "relative");
  setStyleName("gwt-ProgressBar-shell");

  // Create the bar element
  barElement = DOM.createDiv();
  DOM.appendChild(getElement(), barElement);
  DOM.setStyleAttribute(barElement, "height", "100%");
  setBarStyleName("gwt-ProgressBar-bar");

  // Create the text element
  textElement = DOM.createDiv();
  DOM.appendChild(getElement(), textElement);
  DOM.setStyleAttribute(textElement, "position", "absolute");
  DOM.setStyleAttribute(textElement, "top", "0px");

  //Set the current progress
  setProgress(curProgress);
}
 
Example 11
Source File: ImageThumbnailWidget.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
private void setImageSize() {
  int width = isFullSize?attachmentWidth:thumbnailWidth;
  int height = isFullSize?attachmentHeight:thumbnailHeight;
  image.setPixelSize(width, height);
  //TODO(user,danilatos): Whinge about how declarative UI doesn't let us avoid this hack:
  Style pstyle = image.getElement().getParentElement().getParentElement().getStyle();
  if (width == 0) {
    image.setWidth("");
    pstyle.clearWidth();
  } else {
    pstyle.setWidth(width, Unit.PX);
  }
  if (height == 0) {
    image.setHeight("");
    pstyle.clearHeight();
  } else {
    pstyle.setHeight(height, Unit.PX);
  }

  String url = isFullSize?attachmentUrl:thumbnailUrl;
  if (url != null) {
    if (doubleBufferLoader == null) {
      doubleBufferLoader = new DoubleBufferImage(spin, errorLabel, image);
    }
    doubleBufferLoader.loadImage(url);
    DOM.setStyleAttribute(image.getElement(), "visibility", "");
  }

  // NOTE(user): IE requires that the imageCaptionContainer element has a width
  //   in order to correctly center the caption.
  if (DO_FRAME_WIDTH_UPDATE) {
    captionPanel.getElement().getStyle().setWidth(width, Unit.PX);
  }
}
 
Example 12
Source File: DiagramTab.java    From SensorWebClient with GNU General Public License v2.0 5 votes vote down vote up
public void onSetDomainBounds(SetDomainBoundsEvent event) {
    if ( !TimeseriesDataStore.getTimeSeriesDataStore().getDataItems().isEmpty()) {
        String[] widthHeight = getBoundValues(event);

        Element mousePointerElement = DiagramTab.this.getMousePointerLineElement();
        DOM.setStyleAttribute(mousePointerElement, "width", widthHeight[0]);
        DOM.setStyleAttribute(mousePointerElement, "height", widthHeight[1]);

        setTooltipsOnTop(event);
    }
}
 
Example 13
Source File: MockSwitch.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Set thumb color for switch in checked state
 * Thumb color is the color the color of the button that toggles back and forth
 *
 */
private void setThumbColorActiveProperty(String text) {
  thumbColorActive = MockComponentsUtil.getColor(text).toString();
  if (checked) {
    DOM.setStyleAttribute(toggleWidget.getWidget(1).getElement().getFirstChildElement().getNextSiblingElement(),
            "fill", thumbColorActive);
  }
}
 
Example 14
Source File: ClientUtils.java    From sc2gears with Apache License 2.0 5 votes vote down vote up
/**
 * Creates and adds a logout link to the Root panel, at the top right absolute position.
 * @param text      text of the logout link
 * @param logoutUrl logout URL
 * @return the logout link
 */
public static Anchor createAndSetupLogoutLink( final String text, final String logoutUrl ) {
	final Anchor logoutLink = new Anchor( text, logoutUrl );
	
	// Absolute position to the top right
	DOM.setStyleAttribute( logoutLink.getElement(), "position", "absolute" );
	DOM.setStyleAttribute( logoutLink.getElement(), "top"     , "2px"      );
	DOM.setStyleAttribute( logoutLink.getElement(), "right"   , "4px"      );
	
	RootPanel.get().add( logoutLink );
	
	return logoutLink;
}
 
Example 15
Source File: MockSwitch.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Set thumb color for switch in UNhecked state
 * Thumb color is the color the color of the button that toggles back and forth
 *
 */
private void setThumbColorInactiveProperty(String text) {
  thumbColorInactive = MockComponentsUtil.getColor(text).toString();
  if (!checked) {
    DOM.setStyleAttribute(toggleWidget.getWidget(1).getElement().getFirstChildElement().getNextSiblingElement(),
            "fill", thumbColorInactive);
  }
}
 
Example 16
Source File: MiniProgressBar.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Set the current progress.
 *
 * @param curProgress the current progress
 */
public void setProgress(double curProgress) {
  this.curProgress = Math.max(minProgress, Math.min(maxProgress, curProgress));

  // Calculate percent complete
  int percent = (int) (100 * getPercent());
  DOM.setStyleAttribute(barElement, "width", percent + "%");
  DOM.setElementProperty(textElement, "innerHTML", generateText(curProgress));
  updateTextStyle(percent);

  // Realign the text
  redraw();
}
 
Example 17
Source File: MockSwitch.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Set track color for switch in checked state
 * Track color is the color of the track that the toggle button slides back and forth along
 *
 */
private void setTrackColorActiveProperty(String text) {
  trackColorActive = MockComponentsUtil.getColor(text).toString();
  if (checked) {
    DOM.setStyleAttribute(toggleWidget.getWidget(1).getElement().getFirstChildElement(), "fill",
            trackColorActive);
  }
}
 
Example 18
Source File: IframeCoverUtility.java    From cuba with Apache License 2.0 4 votes vote down vote up
/**
 * Adds an iframe cover over an Embedded component
 * 
 * @param iframe
 *            The iframe element
 * @return The element which covers the iframe
 */
private static Element addIframeCover(Element iframe) {
    if (iframeCoverMap.containsKey(iframe)) {
        return iframeCoverMap.get(iframe);
    }

    // Get dimensions
    String iframeWidth = iframe.getAttribute("width");
    String iframeHeight = iframe.getAttribute("height");

    Style iframeStyle = iframe.getStyle();

    if (!iframeWidth.equals("") && !iframeHeight.equals("")) {
        iframeStyle.setPosition(Position.ABSOLUTE);
        iframeStyle.setTop(0, Unit.PX);
        iframeStyle.setLeft(0, Unit.PX);
    }

    // Create the cover element
    Element coverContainer = DOM.createDiv();
    DOM.setStyleAttribute(coverContainer, "width", iframeWidth);
    DOM.setStyleAttribute(coverContainer, "height", iframeHeight);

    coverContainer.setClassName("v-dragdrop-iframe-container");
    coverContainer.getStyle().setPosition(Position.RELATIVE);
    iframe.getParentElement().appendChild(coverContainer);

    // Move iframe to cover container
    iframe.getParentElement().replaceChild(coverContainer, iframe);
    coverContainer.appendChild(iframe);

    // Style the cover
    Element cover = DOM.createDiv();
    cover.setClassName(SHIM_STYLENAME);
    Style coverStyle = cover.getStyle();
    coverStyle.setPosition(Position.ABSOLUTE);
    coverStyle.setWidth(100, Unit.PCT);
    coverStyle.setHeight(100, Unit.PCT);
    coverStyle.setTop(0, Unit.PX);
    coverStyle.setLeft(0, Unit.PX);

    coverContainer.appendChild(cover);

    iframeCoverMap.put(iframe, coverContainer);

    return coverContainer;
}
 
Example 19
Source File: ImageButton.java    From sc2gears with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the image of this image button.
 * @param imageName name of the button image file, relative to the <code>/images/fugue/</code> folder, example: <code>"arrow.png"</code>
 */
public void setImage( final String imageName ) {
	DOM.setStyleAttribute( getElement(), "background", "transparent url('/images/fugue/" + imageName + "')" );
}
 
Example 20
Source File: ClientUtils.java    From sc2gears with Apache License 2.0 2 votes vote down vote up
/**
 * Sets common style for the specified button to be <i>small<i>.
 * @param button button to be styled
 */
public static void styleSmallButton( final Button button ) {
	DOM.setStyleAttribute( button.getElement(), "fontSize", "85%" );
}