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

📄 inputwindow.java

📁 TTreeview 的 Java实例 Eclipes环境下
💻 JAVA
字号:
package demo.pluginA.treeview.internal;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.RowLayout;

public class InputWindow extends Dialog {
	private String title;
	private String messageName;
	private String messageDescription;
	private Boolean isOptional;
	private Boolean isQuery;
	private Boolean isEditable;

	private Label labelName;
	private Label labelDiscription;
	private Text textName;
	private Text textDes;
	private Button rb;
	private Button rb2;

	/**
	 * ���캯�� ע��:�䷶Χ��protected��Ϊpublic,�����������޷�����
	 */
	//Creator for Adding 
	public InputWindow(Shell parentShell, String dialogTitle, String name,
			String desc, Boolean opt, Boolean isquery) {
		super(parentShell);
		this.title = dialogTitle;
		messageName = name;
		messageDescription = desc;
		isOptional = opt;
		isQuery = isquery;
		isEditable=true;
	}
	//Creator for Editing 
	public InputWindow(Shell parentShell, Boolean isquery, String dialogTitle, String name,
			String desc, Boolean opt) {
		super(parentShell);
		this.title = dialogTitle;
		messageName = name;
		messageDescription = desc;
		isOptional = opt;
		isQuery = isquery;//决定是否显示radiobutton
		isEditable=!isquery;
	}
	public InputWindow(Shell parentshell) {
		super(parentshell);
	}

	public String getName() {
		return this.messageName;
	}

	public String getDescription() {
		return this.messageDescription;
	}

	public Boolean getOption() {
		return this.isOptional;
	}

	/**
	 * �������ﹹ��dialog�еĽ�������
	 */

	protected Point getInitialSize() {
		return new Point(500, 300);// 300�ǿ�400�Ǹ�
	}

	protected Control createDialogArea(Composite parent) {
		getShell().setText(title); // ����dialog�ı�ͷ

		// set area layout
		Composite area = (Composite) super.createDialogArea(parent);
		GridLayout gridLayout = new GridLayout();
		gridLayout.marginWidth = 15;
		gridLayout.marginHeight = 5;
		area.setLayout(gridLayout);

		// label Name
		GridData gridDataLabel = new GridData();
		gridDataLabel.heightHint = 15;
		gridDataLabel.widthHint = 80;
		gridDataLabel.verticalIndent = 15;
		labelName = new Label(area, SWT.WRAP);
		labelName.setText("Name:");
		labelName.setLayoutData(gridDataLabel);

		// Name text area
		textName = new Text(area, SWT.SINGLE | SWT.BORDER);
		GridData gridDataText = new GridData(GridData.GRAB_HORIZONTAL
				| GridData.HORIZONTAL_ALIGN_FILL);
		gridDataText.heightHint = 15;
		gridDataText.widthHint = 450;
		textName.setLayoutData(gridDataText);
		textName.setText(messageName);

		// label description
		labelDiscription = new Label(area, SWT.WRAP);
		labelDiscription.setText("Discription:");
		labelDiscription.setLayoutData(gridDataLabel);

		// Description area
		textDes = new Text(area, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.LEFT);
		GridData gridDataText2 = new GridData(GridData.GRAB_HORIZONTAL
				| GridData.HORIZONTAL_ALIGN_FILL);
		gridDataText2.heightHint = 70;
		gridDataText2.widthHint = 450;
		textDes.setLayoutData(gridDataText2);
		textDes.setText(messageDescription);
		textDes.setEditable(isEditable);

		// radio button
		Composite composite_radioButton = new Composite(area, 1);
		RowLayout radioLayout = new RowLayout();
		radioLayout.spacing = 40;
		composite_radioButton.setLayout(radioLayout);
		rb = new Button(composite_radioButton, SWT.RADIO);
		rb2 = new Button(composite_radioButton, SWT.RADIO);
		rb.setText("Optional");
		rb2.setText("None Optional");
		if (isOptional == true) {
			rb.setSelection(true);
			rb2.setSelection(false);
		} else {
			rb2.setSelection(true);
			rb.setSelection(false);
		}
		rb.setEnabled(isEditable);
		rb2.setEnabled(isEditable);
		rb.setVisible(isQuery);
		rb2.setVisible(isQuery);
		return area;
	}

	protected void buttonPressed(int buttonId) {
		if (buttonId == IDialogConstants.OK_ID) {
			messageName = textName.getText();
			messageDescription = textDes.getText();
			if (rb.getSelection() == true) {
				isOptional = true;
			} else {
				isOptional = false;
			}
		} else {
			messageName = null;
		}
		super.buttonPressed(buttonId);
	}

	/**
	 * �����������Ըı䴰�ڵ�Ĭ��ʽ�� swt.resize�����ڿ����϶��߿�ı��С swt.max�� ���ڿ������
	 */
	protected int getshellstyle() {
		return super.getShellStyle() | SWT.Resize | SWT.MAX;
	}
}

⌨️ 快捷键说明

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