⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tdialog.java

📁 gwt 开发 界面控件的封装
💻 JAVA
字号:
/**
 * package com.mc.tables.client;
 */
package com.mc.tables.client;

/**
 * import lib
 */
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.MouseListener;
import com.google.gwt.user.client.ui.Widget;

/**
 * class TDialog extends DialogBox implements MouseListener
 * @author Administrator
 * 对话框 
 */
public class TDialog extends DialogBox implements MouseListener{

	/*
	 * contents  标题文字
	 * dgtitle   标题行
	 * dgBody    内容
	 * IcoImage  对话框图标
	 */
	
	private HTML contents =new HTML(); 
	private Grid dgtitle =new Grid(1,3); 
	private Grid dgBody =new Grid(2,1);	
	private Image IcoImage = new Image();

	/**
	 * 构造函数
	 * 对话框
	 */
	public TDialog() {	
		 super();
		  Image CloseImage = new Image("images/bg_donghua.jpg");
	      CloseImage.setSize("11px", "11px");
	      CloseImage.addClickListener(new ClickListener(){

			public void onClick(Widget sender) {
				// TODO Auto-generated method stub
				hide();
			}
	    	  
	      });
	      
	      contents.setWidth("100%");
	      
	      IcoImage.setSize("0px", "0px");
	      dgtitle.setWidget(0, 0, IcoImage);
	      dgtitle.getCellFormatter().setWidth(0, 0, "15px");
	      dgtitle.getCellFormatter().setAlignment(0, 0, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_MIDDLE);
	      
	      dgtitle.setWidget(0, 1, contents);
	      dgtitle.getCellFormatter().setAlignment(0, 1, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_MIDDLE);
	      
	      dgtitle.setWidget(0, 2, CloseImage);
	      dgtitle.getCellFormatter().setWidth(0, 2, "15px");
	      dgtitle.getCellFormatter().setAlignment(0, 2, HasHorizontalAlignment.ALIGN_RIGHT, HasVerticalAlignment.ALIGN_MIDDLE);
	    
	      dgtitle.setBorderWidth(0);
	      dgtitle.setCellPadding(0);
	      dgtitle.setCellSpacing(0);
	      dgtitle.setHeight("15px");
	      dgtitle.setWidth("100%");
	      dgtitle.setStyleName("dlg-title");
	      
	      dgBody.setWidget(0, 0, dgtitle);
	      dgBody.getCellFormatter().setAlignment(0, 0, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP);
	      dgBody.getCellFormatter().setHeight(0, 0, "15px");
	      dgBody.getCellFormatter().setWidth(0, 0, "100%");
	      
	      dgBody.getCellFormatter().setHeight(1,0,"100%");
	      dgBody.getCellFormatter().setWidth(1,0,"100%");
	      dgBody.getCellFormatter().setAlignment(1,0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE);
	      dgBody.setBorderWidth(0);
	      dgBody.setCellPadding(0);
	      dgBody.setCellSpacing(0);
	      
	      super.setWidget(dgBody);
	      
	      contents.addMouseListener(this);
	     
	    }

	/**
	 * 设置宽度
	 * width 宽度值
	 */
	public void setWidth(String width){
		super.setWidth(width);
		dgtitle.setWidth(width);
		dgBody.setWidth(width);		
	}
	
	/**
	 * 设置高度
	 * height 高度值
	 */
	public void setHeight(String height){
		super.setHeight(height);
		dgBody.getCellFormatter().setHeight(1, 0, height);
	}
	
	/**
	 * 设置宽度 和 高度
	 * width 宽度值
	 * height 高度值
	 */
	public void setSize(String width,String height){
		setWidth(width);
		setHeight(height);
	}
	
	/**
	 * 设置对话框图标
	 * @param url  图标路径
	 */
	public void setIcon(String url){
		IcoImage.setUrl(url);
		IcoImage.setSize("11px", "11px");
		dgtitle.getCellFormatter().setWidth(0, 0, "15px");
	}
	
	/**
	 * 设置标题文本
	 * @param caption 标题文本
	 */
	public void setCaption(String caption){
		
		contents.setHTML(createCaprionHTML(caption));
	}
	private String createCaprionHTML(String caption) {
	    return "<table align='left' border=0 CellPadding=0 CellSpacing=0 ><tr>" 
	      + "<td style='vertical-align:middle;white-space:nowrap'>"
	      + caption + "</td>" + "</tr></table>";
	  }
	/**
	 * 设置 内容
	 */
	public void setWidget(Widget widget){
		if(widget !=null){
			dgBody.setWidget(1, 0, widget);
		}
		
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -