org.eclipse.swt.widgets.Shell#setDefaultButton ( )源码实例Demo

下面列出了org.eclipse.swt.widgets.Shell#setDefaultButton ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: nebula   文件: XYGraphConfigDialog.java
@Override
protected void createButtonsForButtonBar(Composite parent) {
	((GridLayout) parent.getLayout()).numColumns++;
	Button button = new Button(parent, SWT.PUSH);
	button.setText("Apply");
	GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
	int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
	Point minSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
	data.widthHint = Math.max(widthHint, minSize.x);
	button.setLayoutData(data);
	button.addSelectionListener(new SelectionAdapter() {
		@Override
		public void widgetSelected(SelectionEvent e) {
			applyChanges();
		}
	});
	super.createButtonsForButtonBar(parent);
	Shell shell = parent.getShell();
	if (shell != null) {
		shell.setDefaultButton(button);
	}
}
 
源代码2 项目: tlaplus   文件: ExecutionStatisticsDialog.java
protected Button createButton(Composite parent, int id, String label, boolean defaultButton) {
	// increment the number of columns in the button bar
	((GridLayout) parent.getLayout()).numColumns++;
	Button button = new Button(parent, SWT.PUSH | SWT.WRAP); // Need wrap here contrary to Dialog#createButton to wrap button label on Windows and macOS(?).
	button.setText(label);
	button.setFont(JFaceResources.getDialogFont());
	button.setData(Integer.valueOf(id));
	button.addSelectionListener(widgetSelectedAdapter(event -> buttonPressed(((Integer) event.widget.getData()).intValue())));
	if (defaultButton) {
		Shell shell = parent.getShell();
		if (shell != null) {
			shell.setDefaultButton(button);
		}
	}
	setButtonLayoutData(button);
	return button;
}
 
/**
 * Creates a new button with the given id.
 * <p>
 * The <code>Dialog</code> implementation of this framework method creates a standard push button, registers for
 * selection events including button presses and registers default buttons with its shell. The button id is stored
 * as the buttons client data. Note that the parent's layout is assumed to be a GridLayout and the number of columns
 * in this layout is incremented. Subclasses may override.
 * </p>
 * @param parent
 *            the parent composite
 * @param id
 *            the id of the button (see <code>IDialogConstants.*_ID</code> constants for standard dialog button ids)
 * @param label
 *            the label from the button
 * @param defaultButton
 *            <code>true</code> if the button is to be the default button, and <code>false</code> otherwise
 */
protected Button createButton(Composite parent, int id, String label, boolean defaultButton) {
	// increment the number of columns in the button bar
	((GridLayout) parent.getLayout()).numColumns++;

	Button button = new Button(parent, SWT.PUSH);

	GridData buttonData = new GridData(GridData.FILL_HORIZONTAL);
	button.setLayoutData(buttonData);

	button.setData(new Integer(id));
	button.setText(label);
	button.setFont(parent.getFont());

	if (defaultButton) {
		Shell shell = parent.getShell();
		if (shell != null) {
			shell.setDefaultButton(button);
		}
		button.setFocus();
	}
	button.setFont(parent.getFont());
	setButtonLayoutData(button);
	return button;
}
 
源代码4 项目: tmxeditor8   文件: WizardExportResourcesPage2.java
/**
 * Creates a new button with the given id.
 * <p>
 * The <code>Dialog</code> implementation of this framework method creates a standard push button, registers for
 * selection events including button presses and registers default buttons with its shell. The button id is stored
 * as the buttons client data. Note that the parent's layout is assumed to be a GridLayout and the number of columns
 * in this layout is incremented. Subclasses may override.
 * </p>
 * @param parent
 *            the parent composite
 * @param id
 *            the id of the button (see <code>IDialogConstants.*_ID</code> constants for standard dialog button ids)
 * @param label
 *            the label from the button
 * @param defaultButton
 *            <code>true</code> if the button is to be the default button, and <code>false</code> otherwise
 */
protected Button createButton(Composite parent, int id, String label, boolean defaultButton) {
	// increment the number of columns in the button bar
	((GridLayout) parent.getLayout()).numColumns++;

	Button button = new Button(parent, SWT.PUSH);

	GridData buttonData = new GridData(GridData.FILL_HORIZONTAL);
	button.setLayoutData(buttonData);

	button.setData(new Integer(id));
	button.setText(label);
	button.setFont(parent.getFont());

	if (defaultButton) {
		Shell shell = parent.getShell();
		if (shell != null) {
			shell.setDefaultButton(button);
		}
		button.setFocus();
	}
	button.setFont(parent.getFont());
	setButtonLayoutData(button);
	return button;
}
 
源代码5 项目: JAADAS   文件: SootConfigManagerDialog.java
protected Button createSpecialButton(
	Composite parent,
	int id,
	String label,
	boolean defaultButton, boolean enabled) {


	Button button = new Button(parent, SWT.PUSH);
	button.setText(label);

	button.setData(new Integer(id));
	button.addSelectionListener(new SelectionAdapter() {
	public void widgetSelected(SelectionEvent event) {
		buttonPressed(((Integer) event.widget.getData()).intValue());
	}
	});
	if (defaultButton) {
		Shell shell = parent.getShell();
		if (shell != null) {
			shell.setDefaultButton(button);
		}
	}
	button.setFont(parent.getFont());
	if (!enabled){
		button.setEnabled(false);
	}

	setButtonLayoutData(button);
	specialButtonList.add(button);
	return button;
}
 
源代码6 项目: uima-uimaj   文件: INSDComponentPage.java
/**
 * Creates a new button
 * <p>
 * The <code>Dialog</code> implementation of this framework method creates a standard push
 * button, registers for selection events including button presses and registers default buttons
 * with its shell. The button id is stored as the buttons client data. Note that the parent's
 * layout is assumed to be a GridLayout and the number of columns in this layout is incremented.
 * Subclasses may override.
 * </p>
 *
 * @param parent          the parent composite
 * @param label          the label from the button
 * @param defaultButton          <code>true</code> if the button is to be the default button, and <code>false</code>
 *          otherwise
 * @param text the text
 * @return the button
 */
protected Button addButton(Composite parent, String label, boolean defaultButton, final Text text) {

  Button button = new Button(parent, SWT.PUSH);
  button.setText(label);

  if (defaultButton) {
    Shell shell = parent.getShell();
    if (shell != null) {
      shell.setDefaultButton(button);
    }
    button.setFocus();
  }
  button.setFont(parent.getFont());

  SelectionListener listener = new SelectionAdapter() {
    @Override
    public void widgetSelected(SelectionEvent e) {

      ResourceSelectionDialog dialog = new ResourceSelectionDialog(getShell(), currentContainer,
              "Selection Dialog");
      dialog.setTitle("Selection Dialog");
      dialog.setMessage("Please select a file:");
      dialog.open();
      Object[] result = dialog.getResult();
      if (result[0] != null) {
        IResource res = (IResource) result[0];
        text.setText(res.getProjectRelativePath().toOSString());
      }

    }
  };
  button.addSelectionListener(listener);

  return button;
}
 
源代码7 项目: nebula   文件: PTWindowEditor.java
/**
 * @see org.eclipse.nebula.widgets.opal.propertytable.editor.PTChooserEditor#openWindow(org.eclipse.nebula.widgets.opal.propertytable.PTWidget,
 *      org.eclipse.swt.widgets.Item, org.eclipse.nebula.widgets.opal.propertytable.PTProperty)
 */
@Override
protected void openWindow(final PTWidget widget, final Item item, final PTProperty property) {
	final Shell shell = new Shell(widget.getWidget().getShell(), SWT.DIALOG_TRIM);
	shell.setLayout(new GridLayout(2, false));
	shell.setText(ResourceManager.getLabel(ResourceManager.EDIT_PROPERTY));

	final Label title = new Label(shell, SWT.NONE);
	final GridData titleLayoutData = new GridData(GridData.BEGINNING, GridData.BEGINNING, true, false, 2, 1);
	titleLayoutData.widthHint = 400;
	title.setLayoutData(titleLayoutData);
	final Font font = SWTGraphicUtil.buildFontFrom(title, SWT.BOLD, 16);
	title.setFont(font);
	title.setText(ResourceManager.getLabel(ResourceManager.EDIT_PROPERTY));
	SWTGraphicUtil.addDisposer(title, font);

	createContent(shell, property);

	final Composite composite = new Composite(shell, SWT.NONE);
	composite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false, 2, 1));

	final GridLayout gridLayout = new GridLayout(2, false);
	gridLayout.horizontalSpacing = gridLayout.verticalSpacing = 0;
	composite.setLayout(gridLayout);

	final Button ok = new Button(composite, SWT.PUSH);
	final GridData okLayoutData = new GridData(GridData.END, GridData.BEGINNING, true, false);
	okLayoutData.widthHint = 150;
	ok.setLayoutData(okLayoutData);
	ok.setText(ResourceManager.getLabel(ResourceManager.OK));
	ok.addListener(SWT.Selection, event -> {
		fillProperty(item, property);
		shell.dispose();
	});

	final Button cancel = new Button(composite, SWT.PUSH);
	final GridData cancelLayoutData = new GridData(GridData.END, GridData.BEGINNING, false, false);
	cancelLayoutData.widthHint = 150;
	cancel.setLayoutData(cancelLayoutData);
	cancel.setText(ResourceManager.getLabel(ResourceManager.CANCEL));
	cancel.addListener(SWT.Selection, event -> {
		shell.dispose();
	});

	shell.setDefaultButton(ok);
	shell.pack();
	SWTGraphicUtil.centerShell(shell);
	shell.open();
}
 
源代码8 项目: Rel   文件: RemoteDatabaseDialog.java
/**
 * Create contents of the dialog.
 */
private void createContents() {
	shlOpenRemoteDatabase = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.RESIZE);
	shlOpenRemoteDatabase.setSize(450, 112);
	shlOpenRemoteDatabase.setText("Open Remote Database");
	shlOpenRemoteDatabase.setLayout(new FormLayout());

	Label lblDomain = new Label(shlOpenRemoteDatabase, SWT.NONE);
	FormData fd_lblDomain = new FormData();
	fd_lblDomain.top = new FormAttachment(0, 10);
	fd_lblDomain.left = new FormAttachment(0, 10);
	lblDomain.setLayoutData(fd_lblDomain);
	lblDomain.setText("Domain name or IP address:");

	Label lblPort = new Label(shlOpenRemoteDatabase, SWT.NONE);
	FormData fd_lblPort = new FormData();
	fd_lblPort.left = new FormAttachment(0, 10);
	lblPort.setLayoutData(fd_lblPort);
	lblPort.setText("Port:");

	domain = new Text(shlOpenRemoteDatabase, SWT.BORDER);
	FormData fd_domain = new FormData();
	fd_domain.right = new FormAttachment(100, -10);
	fd_domain.left = new FormAttachment(lblDomain, 6);
	fd_domain.top = new FormAttachment(0, 5);
	domain.setLayoutData(fd_domain);

	port = new Text(shlOpenRemoteDatabase, SWT.BORDER);
	fd_lblPort.top = new FormAttachment(port, 6, SWT.TOP);
	FormData fd_port = new FormData();
	fd_port.top = new FormAttachment(lblDomain, 6);
	fd_port.left = new FormAttachment(0, 48);
	port.setLayoutData(fd_port);
	port.setText(String.valueOf(defaultPort));

	Button btnCancel = new Button(shlOpenRemoteDatabase, SWT.NONE);
	FormData fd_btnCancel = new FormData();
	fd_btnCancel.bottom = new FormAttachment(100, -10);
	fd_btnCancel.right = new FormAttachment(domain, 0, SWT.RIGHT);
	fd_btnCancel.left = new FormAttachment(100, -79);
	btnCancel.setLayoutData(fd_btnCancel);
	btnCancel.setText("Cancel");
	btnCancel.addListener(SWT.Selection, e -> shlOpenRemoteDatabase.dispose());

	Button btnOk = new Button(shlOpenRemoteDatabase, SWT.NONE);
	btnOk.setSelection(true);
	FormData fd_btnOk = new FormData();
	fd_btnOk.left = new FormAttachment(btnCancel, -73, SWT.LEFT);
	fd_btnOk.top = new FormAttachment(btnCancel, 0, SWT.TOP);
	fd_btnOk.right = new FormAttachment(btnCancel, -6);
	btnOk.setLayoutData(fd_btnOk);
	btnOk.setText("Ok");
	btnOk.addListener(SWT.Selection, e -> {
		String errStr = "";
		if (domain.getText().trim().length() == 0) {
			errStr += ((errStr.length() > 0) ? "\n" : "") + "You must specify a domain name or IP address.";
		}
		int portValue = 0;
		if (port.getText().trim().length() == 0) {
			errStr += ((errStr.length() > 0) ? "\n" : "") + "You must specify a port between 0 and 65535.";
		} else {
			try {
				portValue = Integer.parseInt(port.getText());
				if (portValue < 0)
					errStr += ((errStr.length() > 0) ? "\n" : "")
							+ "The port must be an integer between 0 and 65535.";
			} catch (NumberFormatException nfe) {
				errStr += ((errStr.length() > 0) ? "\n" : "") + "The port you entered, '" + port.getText()
						+ "' should be an integer between 0 and 65535.";
			}
		}
		if (errStr.length() > 0) {
			MessageDialog.openError(shlOpenRemoteDatabase, "Error", errStr);
		} else {
			result = new RemoteDatabaseDialogResponse(domain.getText(), portValue);
			shlOpenRemoteDatabase.dispose();
		}
	});
	shlOpenRemoteDatabase.setDefaultButton(btnOk);
}
 
源代码9 项目: RepDev   文件: FailedLogonShell.java
private void create() {
	failShell = new Shell(SWT.APPLICATION_MODAL | SWT.TITLE | SWT.CLOSE);
	failShell.setText("Invalid Password");
	failShell.setImage(RepDevMain.smallSymAddImage);
	
	FormLayout layout = new FormLayout();
	layout.marginTop = 5;
	layout.marginBottom = 5;
	layout.marginLeft = 5;
	layout.marginRight = 5;
	layout.spacing = 5;
	failShell.setLayout(layout);
	
	FailText = new Label(failShell, SWT.NONE);
	FailText.setText("Please retype your userID:");
	
	pass = new Text(failShell, SWT.SINGLE | SWT.BORDER | SWT.PASSWORD);	
	
	Button ok = new Button(failShell, SWT.PUSH);
	ok.setText("Submit");
	ok.addSelectionListener(new SelectionAdapter() {
		public void widgetSelected(SelectionEvent e) {	
			newPass = pass.getText();
			failShell.close();
		}
	});
	
	FormData data = new FormData();
	
	data = new FormData();
	data.left = new FormAttachment(0);
	//data.right = new FormAttachment(100);
	data.top = new FormAttachment(0);
	//data.bottom = new FormAttachment();
	FailText.setLayoutData(data);
	
	data = new FormData();
	data.left = new FormAttachment(0);
	data.right = new FormAttachment(100);
	data.top = new FormAttachment(FailText);
	//data.bottom = new FormAttachment(ok);
	pass.setLayoutData(data);
	
	data = new FormData();
	data.left = new FormAttachment(0);
	//data.right = new FormAttachment(100);
	data.top = new FormAttachment(pass);
	data.bottom = new FormAttachment(100);
	ok.setLayoutData(data);
	
	failShell.setDefaultButton(ok);
	
	failShell.pack();
	failShell.open();
	
	while (!failShell.isDisposed()) {
		if (!failShell.getDisplay().readAndDispatch())
			failShell.getDisplay().sleep();
	}
}
 
源代码10 项目: RepDev   文件: GotoLineShell.java
private void create(Shell parent, StyledText txt) {
	display = parent.getDisplay();
	
	this.txt = txt;
	
	shell = new Shell( parent, SWT.APPLICATION_MODAL | SWT.CLOSE | SWT.TITLE );
	shell.setText("Goto Line");
	
	FormLayout layout = new FormLayout();
	layout.marginTop = 10;
	layout.marginBottom = 10;
	layout.marginLeft = 10;
	layout.marginRight = 10;
	layout.spacing = 5;
	
	shell.setLayout(layout);
			
	final Label gotoLabel = new Label( shell, SWT.None );
	gotoLabel.setText("Enter Line Number (1..." + txt.getLineCount() + ")");
	
	final Text gotoText = new Text(shell, SWT.BORDER | SWT.SINGLE );
	
	final Button go = new Button(shell, SWT.PUSH );
	go.setText("Goto Line");
	
	FormData data = new FormData();
	data.top = new FormAttachment(0);
	data.left = new FormAttachment(0);
	gotoLabel.setLayoutData(data);
	
	data = new FormData();
	data.top = new FormAttachment(gotoLabel);
	data.left = new FormAttachment(0);
	data.right = new FormAttachment(100);
	gotoText.setLayoutData(data);
	
	data = new FormData();
	data.top = new FormAttachment(gotoText);
	data.left = new FormAttachment(0);
	data.right = new FormAttachment(100);
	data.bottom = new FormAttachment(100);
	go.setLayoutData(data);
	
	go.addSelectionListener(new SelectionAdapter() {
		public void widgetSelected(SelectionEvent e) {
			try {
				setLine(Integer.parseInt(gotoText.getText()));
				shell.dispose();
			} catch (Exception ex) {
				// System.err.println(ex.getMessage());
			}
		}			
	});
	
	shell.setDefaultButton(go);
	shell.pack();
	shell.open();
			
}