Java Code Examples for org.eclipse.swt.widgets.Button#setFont()

The following examples show how to use org.eclipse.swt.widgets.Button#setFont() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WizardExportResourcesPage2.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source File: RemoveLinkedFolderDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected Control createCustomArea(final Composite parent) {

	final Composite composite= new Composite(parent, SWT.NONE);
	composite.setLayout(new GridLayout());

	fRemoveBuildPathAndFolder= new Button(composite, SWT.RADIO);
	fRemoveBuildPathAndFolder.addSelectionListener(selectionListener);

	fRemoveBuildPathAndFolder.setText(NewWizardMessages.ClasspathModifierQueries_delete_linked_folder);
	fRemoveBuildPathAndFolder.setFont(parent.getFont());

	fRemoveBuildPath= new Button(composite, SWT.RADIO);
	fRemoveBuildPath.addSelectionListener(selectionListener);

	fRemoveBuildPath.setText(NewWizardMessages.ClasspathModifierQueries_do_not_delete_linked_folder);
	fRemoveBuildPath.setFont(parent.getFont());

	fRemoveBuildPathAndFolder.setSelection(fRemoveStatus == IRemoveLinkedFolderQuery.REMOVE_BUILD_PATH_AND_FOLDER);
	fRemoveBuildPath.setSelection(fRemoveStatus == IRemoveLinkedFolderQuery.REMOVE_BUILD_PATH);

	return composite;
}
 
Example 3
Source File: ScriptSWTFactory.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Create the push button
 * 
 * @param parent
 * @param label
 * @param image
 * @return
 */
public static Button createPushButton( Composite parent, String label,
		Image image )
{
	Button button = new Button( parent, SWT.PUSH );
	button.setFont( parent.getFont( ) );
	if ( image != null )
	{
		button.setImage( image );
	}
	if ( label != null )
	{
		button.setText( label );
	}

	GridData gd = new GridData( );
	button.setLayoutData( gd );
	setButtonDimensionHint( button );
	return button;
}
 
Example 4
Source File: MenuPage.java    From EasyShell with Eclipse Public License 2.0 5 votes vote down vote up
private void createEditButton(Font font, GridData gridData, Composite groupComponent) {
    editButton = new Button(groupComponent, SWT.PUSH);
    editButton.setText(Activator.getResourceString("easyshell.menu.page.button.text.edit"));
    editButton.setToolTipText(Activator.getResourceString("easyshell.menu.page.button.tooltip.edit"));
    editButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent event) {
            editDialog();
        }
    });
    editButton.setLayoutData(gridData);
    editButton.setFont(font);
    setButtonLayoutData(editButton);
}
 
Example 5
Source File: CommandPage.java    From EasyShell with Eclipse Public License 2.0 5 votes vote down vote up
private void createCopyButton(Font font, GridData gridData, Composite groupComponent) {
    addCopyButton = new Button(groupComponent, SWT.PUSH);
    addCopyButton.setText(Activator.getResourceString("easyshell.command.page.button.text.copy"));
    addCopyButton.setToolTipText(Activator.getResourceString("easyshell.command.page.button.tooltip.copy"));
    addCopyButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent event) {
            addCopyDialog();
        }
    });
    addCopyButton.setLayoutData(gridData);
    addCopyButton.setFont(font);
    setButtonLayoutData(addCopyButton);
}
 
Example 6
Source File: ScopedPreferencesFieldEditor.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns this field editor's link component.
 * <p>
 * The link is created if it does not already exist
 * </p>
 *
 * @param parent the parent
 * @return the label control
 */
private Button getButtonControl(Composite parent, String text) {
    Button button = new Button(parent, SWT.PUSH);
    button.setText(text);
    button.setFont(parent.getFont());

    GridData gd = createFillGridData();
    button.setLayoutData(gd);
    return button;
}
 
Example 7
Source File: WizardFileSystemResourceExportPage2.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create the export destination specification widgets
 * @param parent
 *            org.eclipse.swt.widgets.Composite
 */
protected void createDestinationGroup(Composite parent) {

	Font font = parent.getFont();
	// destination specification group
	Composite destinationSelectionGroup = new Composite(parent, SWT.NONE);
	GridLayout layout = new GridLayout();
	layout.numColumns = 3;
	destinationSelectionGroup.setLayout(layout);
	destinationSelectionGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL
			| GridData.VERTICAL_ALIGN_FILL));
	destinationSelectionGroup.setFont(font);

	Label destinationLabel = new Label(destinationSelectionGroup, SWT.NONE);
	destinationLabel.setText(getDestinationLabel());
	destinationLabel.setFont(font);

	// destination name entry field
	destinationNameField = new Text(destinationSelectionGroup, SWT.BORDER);
	destinationNameField.addListener(SWT.Modify, this);
	destinationNameField.addListener(SWT.Selection, this);
	GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
	data.widthHint = SIZING_TEXT_FIELD_WIDTH;
	destinationNameField.setLayoutData(data);
	destinationNameField.setFont(font);

	// destination browse button
	destinationBrowseButton = new Button(destinationSelectionGroup, SWT.PUSH);
	destinationBrowseButton.setText(DataTransferMessages.DataTransfer_browse);
	destinationBrowseButton.addListener(SWT.Selection, this);
	destinationBrowseButton.setFont(font);
	setButtonLayoutData(destinationBrowseButton);

	new Label(parent, SWT.NONE); // vertical spacer
}
 
Example 8
Source File: WizardFileSystemResourceExportPage2.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create the button for checking if we should ask if we are going to overwrite existing files.
 * @param optionsGroup
 * @param font
 */
protected void createOverwriteExisting(Group optionsGroup, Font font) {
	// overwrite... checkbox
	overwriteExistingFilesCheckbox = new Button(optionsGroup, SWT.CHECK | SWT.LEFT);
	overwriteExistingFilesCheckbox.setText(DataTransferMessages.ExportFile_overwriteExisting);
	overwriteExistingFilesCheckbox.setFont(font);
}
 
Example 9
Source File: AbstractInterpreterEditor.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Helper method to create a push button.
 *
 * @param parent the parent control
 * @param key the resource name used to supply the button's label text
 * @param listenerToAdd
 * @return Button
 */
/*default*/public static Button createBt(Composite parent, String key, SelectionListener listenerToAdd) {
    Button button = new Button(parent, SWT.PUSH);
    button.setText(JFaceResources.getString(key));
    button.setFont(parent.getFont());
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    //        data.heightHint = convertVerticalDLUsToPixels(button, IDialogConstants.BUTTON_HEIGHT);
    int widthHint = convertHorizontalDLUsToPixelsStatic(button, IDialogConstants.BUTTON_WIDTH);
    data.widthHint = Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    button.setLayoutData(data);
    button.addSelectionListener(listenerToAdd);
    return button;
}
 
Example 10
Source File: TreeListDialogField.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected Button createButton(Composite parent, String label, SelectionListener listener) {
	Button button= new Button(parent, SWT.PUSH);
	button.setFont(parent.getFont());
	button.setText(label);
	button.addSelectionListener(listener);
	GridData gd= new GridData();
	gd.horizontalAlignment= GridData.FILL;
	gd.grabExcessHorizontalSpace= true;
	gd.verticalAlignment= GridData.BEGINNING;
	gd.widthHint= getButtonWidthHint(button);

	button.setLayoutData(gd);
	return button;
}
 
Example 11
Source File: SWTUtil.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates and returns a new radio button with the given label.
 * 
 * @param parent
 *            parent control
 * @param label
 *            button label or <code>null</code>
 * @return a new radio button
 */
public static Button createRadioButton(Composite parent, String label)
{
	Button button = new Button(parent, SWT.RADIO);
	button.setFont(parent.getFont());
	if (label != null)
	{
		button.setText(label);
	}
	GridData gd = new GridData();
	button.setLayoutData(gd);
	SWTUtil.setButtonDimensionHint(button);
	return button;
}
 
Example 12
Source File: MenuPage.java    From EasyShell with Eclipse Public License 2.0 5 votes vote down vote up
private void createNewButton(Font font, GridData gridData, Composite groupComponent) {
    addNewButton = new Button(groupComponent, SWT.PUSH);
    addNewButton.setText(Activator.getResourceString("easyshell.menu.page.button.text.new"));
    addNewButton.setToolTipText(Activator.getResourceString("easyshell.menu.page.button.tooltip.new"));
    addNewButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent event) {
            addNewDialog();
        }
    });
    addNewButton.setLayoutData(gridData);
    addNewButton.setFont(font);
    setButtonLayoutData(addNewButton);
}
 
Example 13
Source File: SWTUtil.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns a width hint for a button control.
 */
public static int getButtonWidthHint(Button button)
{
	button.setFont(JFaceResources.getDialogFont());
	PixelConverter converter = new PixelConverter(button);
	int widthHint = converter.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
	return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
}
 
Example 14
Source File: OptionsConfigurationBlock.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected Button addCheckboxWithData(Composite parent, String label, ControlData data, GridData gd) {
	Button checkBox = new Button(parent, SWT.CHECK);
	checkBox.setFont(JFaceResources.getDialogFont());
	checkBox.setText(label);
	checkBox.setData(data);
	checkBox.setLayoutData(gd);
	checkBox.addSelectionListener(getSelectionListener());
	makeScrollableCompositeAware(checkBox);
	updateCheckBox(checkBox);
	checkBoxes.add(checkBox);
	return checkBox;
}
 
Example 15
Source File: ProfileConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static Button createButton(Composite composite, String text, final int style) {
	final Button button= new Button(composite, SWT.PUSH);
	button.setFont(composite.getFont());
	button.setText(text);

	final GridData gd= new GridData(style);
	gd.widthHint= SWTUtil.getButtonWidthHint(button);
	button.setLayoutData(gd);
	return button;
}
 
Example 16
Source File: PythonBreakpointPage.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a fully configured check button with the given text.
 * @param parent the parent composite
 * @param text the label of the returned check button
 * @return a fully configured check button
 */
protected Button createCheckButton(Composite parent, String text) {
    Button button = new Button(parent, SWT.CHECK | SWT.LEFT);
    button.setText(text);
    button.setFont(parent.getFont());
    button.setLayoutData(new GridData());
    return button;
}
 
Example 17
Source File: TableEditor.java    From cppcheclipse with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to create a push button.
 * 
 * @param parent
 *            the parent control
 * @param key
 *            the resource name used to supply the button's label text
 * @return Button
 */
protected Button createPushButton(Composite parent, String key,
		SelectionListener listener) {
	Button button = new Button(parent, SWT.PUSH);
	button.setText(JFaceResources.getString(key));
	button.setFont(parent.getFont());
	GridData data = new GridData(GridData.FILL_HORIZONTAL);
	int widthHint = convertHorizontalDLUsToPixels(button,
			IDialogConstants.BUTTON_WIDTH);
	data.widthHint = Math.max(widthHint,
			button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
	button.setLayoutData(data);
	button.addSelectionListener(listener);
	return button;
}
 
Example 18
Source File: NewReportPageSupport.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates the project location specification controls.
 * 
 * @param group
 *            the parent composite
 * @param enabled
 *            the initial enabled state of the widgets created
 */
private void createUserSpecifiedProjectLocationGroup( Composite group,
		boolean enabled )
{
	Font font = group.getFont( );

	// location label
	locationLabel = new Label( group, SWT.NONE );
	locationLabel.setText( LABEL_DIRECTORY );
	locationLabel.setEnabled( enabled );
	locationLabel.setFont( font );

	// file location entry field
	locationPathField = new Text( group, SWT.BORDER );
	GridData data = new GridData( GridData.FILL_HORIZONTAL );
	data.widthHint = 250;
	locationPathField.setLayoutData( data );
	locationPathField.setEnabled( enabled );
	locationPathField.setFont( font );

	// browse button
	browseButton = new Button( group, SWT.PUSH );
	browseButton.setText( LABEL_BROWSE );
	browseButton.addSelectionListener( new SelectionAdapter( ) {

		public void widgetSelected( SelectionEvent event )
		{
			handleLocationBrowseButtonPressed( );
		}
	} );

	browseButton.setEnabled( enabled );
	browseButton.setFont( font );
	setButtonLayoutData( browseButton );

	if ( defaultFileLocation != null )
	{
		locationPathField.setText( defaultFileLocation );
	}
	else
	{
		locationPathField.setText( "" );//$NON-NLS-1$
	}
}
 
Example 19
Source File: FolderSelectionGroup.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Create group
 * 
 * @param parent
 */
public void create( Composite parent )
{
	// get font
	Font font = parent.getFont( );

	// label control
	Label label = new Label( parent, SWT.LEFT );
	label.setFont( font );
	label.setText( this.labelText );

	Composite composite = new Composite( parent, SWT.NULL );
	GridLayout layout = new GridLayout( );
	layout.marginWidth = 0;
	layout.marginHeight = 0;
	layout.numColumns = 2;
	composite.setLayout( layout );

	GridData data = new GridData( GridData.FILL_HORIZONTAL );
	composite.setLayoutData( data );

	// text control
	text = new Text( composite, SWT.BORDER );
	text.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
	text.setFont( font );
	text.setText( this.textValue );
	text.addVerifyListener( new VerifyListener( ) {

		public void verifyText( VerifyEvent e )
		{
			e.doit = e.text.indexOf( DELIMITER ) < 0;
		}
	} );

	// directory selection button
	button = new Button( composite, SWT.PUSH );
	button.setFont( font );
	button.setText( this.buttonText );
	button.addSelectionListener( new SelectionAdapter( ) {

		public void widgetSelected( SelectionEvent event )
		{
			dialog = new DirectoryDialog( PlatformUI.getWorkbench( )
					.getDisplay( ).getActiveShell( ) );

			dialog.setText( dialogTitle );
			dialog.setMessage( dialogMessage );
			dialog.setFilterPath( dialogFilterPath );
			String folderName = dialog.open( );
			if ( folderName == null )
			{
				return;
			}
			text.setText( folderName );
		}
	} );
}
 
Example 20
Source File: MultiChoice.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Create the popup that contains all checkboxes
 */
private void createPopup() {
	this.popup = new Shell(getShell(), SWT.NO_TRIM | SWT.ON_TOP);
	this.popup.setLayout(new FillLayout());

	final int[] popupEvents = { SWT.Close, SWT.Deactivate, SWT.Dispose };
	for (final int popupEvent : popupEvents) {
		this.popup.addListener(popupEvent, this.listener);
	}

	if (this.elements == null) {
		return;
	}

	this.scrolledComposite = new ScrolledComposite(this.popup, SWT.BORDER | SWT.V_SCROLL);
	final Composite content = new Composite(this.scrolledComposite, SWT.NONE);
	content.setLayout(new GridLayout(this.numberOfColumns, true));

	this.checkboxes = new ArrayList<>(this.elements.size());
	for (final T o : this.elements) {
		final Button checkBoxButton = new Button(content, SWT.CHECK);

		if (this.font != null) {
			checkBoxButton.setFont(this.font);
		}
		if (this.foreground != null) {
			checkBoxButton.setForeground(this.foreground);
		}
		if (this.background != null) {
			checkBoxButton.setBackground(this.background);
		}
		checkBoxButton.setEnabled(text.getEditable());

		checkBoxButton.setData(o);
		checkBoxButton.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false));
		checkBoxButton.setText(this.labelProvider.getText(o));
		checkBoxButton.addListener(SWT.Selection, e -> {
			if (checkBoxButton.getSelection()) {
				MultiChoice.this.selection.add(o);
			} else {
				MultiChoice.this.selection.remove(o);
			}
			MultiChoice.this.lastModified = o;
			setLabel();
		});

		if (this.selectionListener != null) {
			checkBoxButton.addSelectionListener(this.selectionListener);
		}

		checkBoxButton.setSelection(this.selection.contains(o));
		this.checkboxes.add(checkBoxButton);
	}

	this.scrolledComposite.setContent(content);
	this.scrolledComposite.setExpandHorizontal(false);
	this.scrolledComposite.setExpandVertical(true);
	content.pack();
	this.preferredHeightOfPopup = content.getSize().y;
}