com.google.gwt.user.client.ui.Panel.add()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(10.4k)|赞(0)|评价(0)|浏览(121)

本文整理了Java中com.google.gwt.user.client.ui.Panel.add()方法的一些代码示例,展示了Panel.add()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Panel.add()方法的具体详情如下:
包路径:com.google.gwt.user.client.ui.Panel
类名称:Panel
方法名:add

Panel.add介绍

[英]Adds a child widget.

How to Override this Method

There are several important things that must take place in the correct order to properly add or insert a Widget to a Panel. Not all of these steps will be relevant to every Panel, but all of the steps must be considered.

  1. Validate: Perform any sanity checks to ensure the Panel can accept a new Widget. Examples: checking for a valid index on insertion; checking that the Panel is not full if there is a max capacity.
  2. Adjust for Reinsertion: Some Panels need to handle the case where the Widget is already a child of this Panel. Example: when performing a reinsert, the index might need to be adjusted to account for the Widget's removal. See ComplexPanel#adjustIndex(Widget,int).
  3. Detach Child: Remove the Widget from its existing parent, if any. Most Panels will simply call Widget#removeFromParent() on the Widget.
  4. Logical Attach: Any state variables of the Panel should be updated to reflect the addition of the new Widget. Example: the Widget is added to the Panel's WidgetCollection at the appropriate index.
  5. Physical Attach: The Widget's Element must be physically attached to the Panel's Element, either directly or indirectly.
  6. Adopt: Call #adopt(Widget) to finalize the add as the very last step.
    [中]添加一个子部件。
    如何覆盖此方法
    要正确地将小部件添加或插入到面板中,必须按照正确的顺序进行几件重要的事情。并非所有这些步骤都与每个面板相关,但必须考虑所有步骤。
    1.验证:执行任何健全性检查,以确保面板可以接受新的小部件。示例:插入时检查有效索引;如果有最大容量,检查面板是否未满。
    1.调整重新插入:一些面板需要处理小部件已经是该面板子部件的情况。示例:在执行重新插入时,可能需要调整索引以考虑小部件的删除。请参阅ComplexPanel#adjustIndex(小部件,int)。
    1.分离子部件:从现有的父部件(如果有的话)中删除小部件。大多数面板只会在小部件上调用小部件#removeFromParent()。
    1.逻辑附加:应更新面板的任何状态变量,以反映新部件的添加。示例:小部件被添加到面板的WidgetCollection的适当索引处。
    1.物理连接:小部件的元素必须直接或间接地物理连接到面板的元素。
    1.采用:调用#采用(Widget)完成添加,作为最后一步。

代码示例

代码示例来源:origin: libgdx/libgdx

public PreloaderCallback getPreloaderCallback () {
  final Panel preloaderPanel = new VerticalPanel();
  preloaderPanel.setStyleName("gdx-preloader");
  final Image logo = new Image(GWT.getModuleBaseURL() + "logo.png");
  logo.setStyleName("logo");		
  preloaderPanel.add(logo);
  final Panel meterPanel = new SimplePanel();
  meterPanel.setStyleName("gdx-meter");
  meterPanel.addStyleName("red");
  final InlineHTML meter = new InlineHTML();
  final Style meterStyle = meter.getElement().getStyle();
  meterStyle.setWidth(0, Unit.PCT);
  meterPanel.add(meter);
  preloaderPanel.add(meterPanel);
  getRootPanel().add(preloaderPanel);
  return new PreloaderCallback() {
    @Override
    public void error (String file) {
      System.out.println("error: " + file);
    }
    
    @Override
    public void update (PreloaderState state) {
      meterStyle.setWidth(100f * state.getProgress(), Unit.PCT);
    }            
    
  };
}

代码示例来源:origin: libgdx/libgdx

private void checkLogLabel () {
  if (log == null) {
    ((GwtApplication)Gdx.app).log = log = new TextArea();
    // It's possible that log functions are called
    // before the app is initialized. E.g. SoundManager can call log functions before the app is initialized.
    // Since graphics is null, we're getting errors. The log size will be updated later, in case graphics was null
    if (Gdx.graphics != null) {
      log.setSize(Gdx.graphics.getWidth() + "px", "200px");
    } else {
      log.setSize("400px", "200px"); // Dummy value
    }
    log.setReadOnly(true);
    ((GwtApplication)Gdx.app).getRootPanel().add(log);
  }
}

代码示例来源:origin: libgdx/libgdx

private void checkLogLabel () {
  if (log == null) {
    ((GwtApplication)Gdx.app).log = log = new TextArea();
    // It's possible that log functions are called
    // before the app is initialized. E.g. SoundManager can call log functions before the app is initialized.
    // Since graphics is null, we're getting errors. The log size will be updated later, in case graphics was null
    if (Gdx.graphics != null) {
      log.setSize(Gdx.graphics.getWidth() + "px", "200px");
    } else {
      log.setSize("400px", "200px"); // Dummy value
    }
    log.setReadOnly(true);
    ((GwtApplication)Gdx.app).getRootPanel().add(log);
  }
}

代码示例来源:origin: libgdx/libgdx

public PreloaderCallback getPreloaderCallback () {
  final Panel preloaderPanel = new VerticalPanel();
  preloaderPanel.setStyleName("gdx-preloader");
  final Image logo = new Image(GWT.getModuleBaseURL() + "logo.png");
  logo.setStyleName("logo");		
  preloaderPanel.add(logo);
  final Panel meterPanel = new SimplePanel();
  meterPanel.setStyleName("gdx-meter");
  meterPanel.addStyleName("red");
  final InlineHTML meter = new InlineHTML();
  final Style meterStyle = meter.getElement().getStyle();
  meterStyle.setWidth(0, Unit.PCT);
  meterPanel.add(meter);
  preloaderPanel.add(meterPanel);
  getRootPanel().add(preloaderPanel);
  return new PreloaderCallback() {
    @Override
    public void error (String file) {
      System.out.println("error: " + file);
    }
    
    @Override
    public void update (PreloaderState state) {
      meterStyle.setWidth(100f * state.getProgress(), Unit.PCT);
    }            
    
  };
}

代码示例来源:origin: libgdx/libgdx

} catch (Throwable e) {
  root.clear();
  root.add(getNoWebGLSupportWidget());
  return;

代码示例来源:origin: libgdx/libgdx

} catch (Throwable e) {
  root.clear();
  root.add(getNoWebGLSupportWidget());
  return;

代码示例来源:origin: libgdx/libgdx

public GwtGraphics (Panel root, GwtApplicationConfiguration config) {
  Canvas canvasWidget = Canvas.createIfSupported();
  if (canvasWidget == null) throw new GdxRuntimeException("Canvas not supported");
  canvas = canvasWidget.getCanvasElement();
  root.add(canvasWidget);
  canvas.setWidth(config.width);
  canvas.setHeight(config.height);
  this.config = config;
  WebGLContextAttributes attributes = WebGLContextAttributes.create();
  attributes.setAntialias(config.antialiasing);
  attributes.setStencil(config.stencil);
  attributes.setAlpha(config.alpha);
  attributes.setPremultipliedAlpha(config.premultipliedAlpha);
  attributes.setPreserveDrawingBuffer(config.preserveDrawingBuffer);
  context = WebGLRenderingContext.getContext(canvas, attributes);
  context.viewport(0, 0, config.width, config.height);
  this.gl = config.useDebugGL ? new GwtGL20Debug(context) : new GwtGL20(context);
  String versionString = gl.glGetString(GL20.GL_VERSION);
  String vendorString = gl.glGetString(GL20.GL_VENDOR);
  String rendererString = gl.glGetString(GL20.GL_RENDERER);
  glVersion = new GLVersion(Application.ApplicationType.WebGL, versionString, vendorString, rendererString);
}

代码示例来源:origin: libgdx/libgdx

public GwtGraphics (Panel root, GwtApplicationConfiguration config) {
  Canvas canvasWidget = Canvas.createIfSupported();
  if (canvasWidget == null) throw new GdxRuntimeException("Canvas not supported");
  canvas = canvasWidget.getCanvasElement();
  root.add(canvasWidget);
  canvas.setWidth(config.width);
  canvas.setHeight(config.height);
  this.config = config;
  WebGLContextAttributes attributes = WebGLContextAttributes.create();
  attributes.setAntialias(config.antialiasing);
  attributes.setStencil(config.stencil);
  attributes.setAlpha(config.alpha);
  attributes.setPremultipliedAlpha(config.premultipliedAlpha);
  attributes.setPreserveDrawingBuffer(config.preserveDrawingBuffer);
  context = WebGLRenderingContext.getContext(canvas, attributes);
  context.viewport(0, 0, config.width, config.height);
  this.gl = config.useDebugGL ? new GwtGL20Debug(context) : new GwtGL20(context);
  String versionString = gl.glGetString(GL20.GL_VERSION);
  String vendorString = gl.glGetString(GL20.GL_VENDOR);
  String rendererString = gl.glGetString(GL20.GL_RENDERER);
  glVersion = new GLVersion(Application.ApplicationType.WebGL, versionString, vendorString, rendererString);
}

代码示例来源:origin: com.google.gwt/gwt-servlet

public void add(IsWidget child) {
 this.add(asWidgetOrNull(child));
}

代码示例来源:origin: org.jboss.errai/errai-bus

public void addError(final String message, final String additionalDetails, final Throwable e) {
 if (!showErrors)
  return;
 contentPanel.add(new HTML("<strong style='background:red;color:white;'>" + message + "</strong>"));
 final StringBuilder buildTrace = new StringBuilder("<tt style=\"font-size:11px;\"><pre>");
 if (e != null) {
  e.printStackTrace();
  buildTrace.append(e.getClass().getName()).append(": ").append(e.getMessage()).append("<br/>");
  for (final StackTraceElement ste : e.getStackTrace()) {
   buildTrace.append("  ").append(ste.toString()).append("<br/>");
  }
 }
 buildTrace.append("</pre>");
 contentPanel.add(new HTML(buildTrace.toString() + "<br/><strong>Additional Details:</strong>" + additionalDetails
   + "</tt>"));
 if (!isShowing()) {
  resize();
  show();
  center();
 }
}

代码示例来源:origin: com.googlecode.gwtupload/gwtupload

protected void addElementsToPanel() {
 panel.add(cancelLabel);
 panel.add(fileNameLabel);
 panel.add(statusLabel);
}

代码示例来源:origin: org.dashbuilder/dashbuilder-displayer-client

@Override
public void addFilterConfigWidget(IsWidget widget) {
  filterDetailsPanel.add(widget);
  filterExpandIcon.setVisible(true);
}

代码示例来源:origin: net.sf.advanced-gwt/advanced-gwt

/**
 * This method initializes a toolbar with common values.
 *
 * @param toolbar is a toolbar to be initialized.
 * @param panel   is a top or bottom panel.
 * @return an initialized toolbar.
 */
protected GridToolbar prepareToolbar(GridToolbar toolbar, Panel panel) {
  toolbar.setGridPanel(this);
  panel.add(toolbar);
  return toolbar;
}

代码示例来源:origin: org.kie.workbench.stunner/kie-wb-common-stunner-widgets

protected void setWidgetForPanel(final Panel panel,
                 final IsWidget widget) {
  panel.clear();
  panel.add(widget);
}

代码示例来源:origin: org.codehaus.sonar/sonar-gwt-api

protected void addBigCell(Panel panel, String html) {
  HTML htmlDiv = new HTML(html);
  htmlDiv.setStyleName("big");
  panel.add(htmlDiv);
 }
}

代码示例来源:origin: com.vaadin/mpr-core

private void attachWidget(Widget widget, String appId, int nodeId) {
  Element wrapperElement = getWrapperElement(appId, nodeId);
  Panel wrapper = new AbsolutePanel(wrapperElement) {
    {
      onAttach();
    }
  };
  wrapper.add(widget);
}

代码示例来源:origin: org.kie.guvnor/guvnor-test-scenario-editor-client

private void addFieldSelectorWidget() {
  helper.setParentIsAList(true);
  valueEditorWidget = new FieldSelectorWidget(field,
      helper,
      this);
  panel.add(valueEditorWidget);
}

代码示例来源:origin: org.dashbuilder/dashbuilder-renderer-lienzo

@Override
public void addFilterReset() {
  Anchor anchor = new Anchor(LienzoDisplayerConstants.INSTANCE.resetAnchor());
  filterPanel.add(anchor);
  anchor.addClickHandler(new ClickHandler() {
    public void onClick(ClickEvent event) {
      getPresenter().onFilterResetClicked();
    }
  });
}

代码示例来源:origin: org.metawidget.modules/metawidget-all

public void startContainerLayout( Panel container, GwtMetawidget metawidget ) {
  State state = getState( container, metawidget );
  FlexTable flexTable = new FlexTable();
  flexTable.setStyleName( mTableStyleName );
  container.add( flexTable );
  state.formatter = flexTable.getFlexCellFormatter();
}

代码示例来源:origin: org.uberfire/uberfire-runtime-plugins-client

@Override
public void onOpen() {
  LayoutInstance layoutInstance = layoutGenerator.build(layoutTemplate);
  mainPanel.clear();
  mainPanel.getElement().addClassName("uf-perspective-component");
  mainPanel.add(ElementWrapperWidget.getWidget(layoutInstance.getElement()));
}

相关文章