`
mic_scofield
  • 浏览: 9895 次
  • 性别: Icon_minigender_1
  • 来自: 成都
文章分类
社区版块
存档分类
最新评论

SWT

阅读更多
 * @author mic_scofield
package com.mic_scofield.cn;

import java.io.File;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

public class AboutDialog extends TitleAreaDialog {
	
	private String versionStr;
	
	private final static String VERSION_CONFIG_DLL_PATH = "config/Version.xml";
	
	/**
	 * Create the dialog.
	 * @param parentShell
	 */
	public AboutDialog(Shell parentShell) {
		super(parentShell);
	}

	/**
	 * Create contents of the dialog.
	 * @param parent
	 */
	@Override
	protected Control createDialogArea(Composite parent) {
		this.getShell().setText("\u5173\u4e8e...");
		setTitle("\u5173\u4E8E\u5BF9\u8BDD\u6846\u63D0\u793A\u4FE1\u606F\uFF0C\u53EF\u4EE5\u662F\u516C\u53F8\u6807\u5FD7\u6216\u8005\u5168\u79F0");
		Composite area = (Composite) super.createDialogArea(parent);
		Composite container = new Composite(area, SWT.NONE);
		container.setLayoutData(new GridData(GridData.FILL_BOTH));
		{
            GridData gridData = new GridData(GridData.FILL_BOTH);
            gridData.heightHint = 366;
            gridData.grabExcessVerticalSpace = false;
            container.setLayoutData(gridData);
        }
        {
            Label lblVersionTitle = new Label(container, SWT.NONE);
            lblVersionTitle.setBounds(20, 10, 221, 19);
            //TODO
            lblVersionTitle.setText("\u7248\u672c:");
        }
        {
            Label lblVersionValue = new Label(container, SWT.NONE);
            lblVersionValue.setBounds(66, 35, 468, 29);
            versionStr = readVersionInfo();
            lblVersionValue.setText(versionStr);
        }
        {
            Label lblWorkingDirectoryTitle = new Label(container, SWT.NONE);
            lblWorkingDirectoryTitle.setBounds(20, 70, 221, 19);
            //TODO
            lblWorkingDirectoryTitle.setText("\u8fd0\u884c\u8def\u5f84:");
        }
        {
            Label lblWorkingDirectoryValue = new Label(container, SWT.NONE);
            lblWorkingDirectoryValue.setBounds(66, 95, 468, 45);
            lblWorkingDirectoryValue.setText(System.getProperty("user.dir")); //$NON-NLS-1$
        }
		return area;
	}

	/**
	 * Create contents of the button bar.
	 * @param parent
	 */
	@Override
	protected void createButtonsForButtonBar(Composite parent) {
		createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
				true);
		createButton(parent, IDialogConstants.CANCEL_ID,
				IDialogConstants.CANCEL_LABEL, false);
	}

	/**
	 * Return the initial size of the dialog.
	 */
	@Override
	protected Point getInitialSize() {
		return new Point(450, 300);
	}
	
	 private String readVersionInfo()
	    {
	        SAXReader saxReader = new SAXReader();
	        Document doc = null;
	        StringBuffer valueStr;
	        
	        File file = new File(VERSION_CONFIG_DLL_PATH);
	        try
	        {
	            doc = saxReader.read(file);
	            Element eleCmd = (Element)doc.selectSingleNode("version"); //$NON-NLS-1$
	            valueStr = new StringBuffer(eleCmd.attributeValue("value")); //$NON-NLS-1$
	            String dateStr = eleCmd.attributeValue("date"); //$NON-NLS-1$
	            valueStr.append("   "); //$NON-NLS-1$
	            valueStr.append(dateStr);
	        }
	        catch (DocumentException e1)
	        {
	        	//TODO log
	            return null;
	        }
	        
	        return valueStr.toString();
	    }

}



Version.xml

<?xml version="1.0" encoding="UTF-8"?>
<version value="V01B001C0001" date="2010-5-31"/>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics