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

The following examples show how to use org.eclipse.swt.widgets.Button#computeSize() . 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: XYGraphConfigDialog.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
@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);
	}
}
 
Example 2
Source File: ColumnMappingDialog.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private void createButtonArea( Composite right )
{
	Composite composite = new Composite( right, SWT.NONE );
	GridLayout layout = new GridLayout( 1, false );
	composite.setLayout( layout );
	composite.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );

	editBtn = new Button( composite, SWT.PUSH );
	editBtn.setText( Messages.getString( "ColumnMappingDialog.button.edit" ) ); //$NON-NLS-1$
	GridData gd = new GridData( );
	gd.horizontalAlignment = SWT.END;
	gd.grabExcessHorizontalSpace = true;
	gd.widthHint = editBtn.computeSize( -1, -1 ).x
			- editBtn.getBorderWidth( ) + 20;
	editBtn.setLayoutData( gd );
	editBtn.setEnabled( false );
	editBtn.addSelectionListener( new SelectionAdapter( ) {

		public void widgetSelected( SelectionEvent e )
		{
			doEditPrameter( );
		}
	} );

}
 
Example 3
Source File: JframeApp.java    From jframe with Apache License 2.0 6 votes vote down vote up
/**
 * 
 */
protected void createToolBar() {
    CoolBar bar = new CoolBar(shell, SWT.FLAT);
    bar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    bar.setLayout(new RowLayout());

    CoolItem item = new CoolItem(bar, SWT.NONE);
    Button button = new Button(bar, SWT.FLAT);
    // button.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, true));
    button.setText("Button");
    Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    item.setPreferredSize(item.computeSize(size.x, size.y));
    item.setControl(button);

    Rectangle clientArea = shell.getClientArea();
    bar.setLocation(clientArea.x, clientArea.y);
    bar.pack();
}
 
Example 4
Source File: ExtractInterfaceWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void addInstanceofCheckbox(Composite result, int margin) {
	String title= RefactoringMessages.ExtractInterfaceWizard_use_supertype;
	fInstanceofCheckbox= new Button(result, SWT.CHECK);
	fInstanceofCheckbox.setSelection(false);
	GridData gd= new GridData();
	gd.horizontalIndent= (margin + fInstanceofCheckbox.computeSize(SWT.DEFAULT, SWT.DEFAULT).x);
	gd.horizontalSpan= 2;
	fInstanceofCheckbox.setLayoutData(gd);
	fInstanceofCheckbox.setText(title);
	fProcessor.setInstanceOf(fInstanceofCheckbox.getSelection());
	fInstanceofCheckbox.addSelectionListener(new SelectionAdapter(){
		@Override
		public void widgetSelected(SelectionEvent e) {
			fProcessor.setInstanceOf(fInstanceofCheckbox.getSelection());
		}
	});
}
 
Example 5
Source File: UIUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Convenient method to setup button to invoke expression builder
 */
public static void setExpressionButtonImage( Button button )
{
	String imageName;
	if ( button.isEnabled( ) )
	{
		imageName = IReportGraphicConstants.ICON_ENABLE_EXPRESSION_BUILDERS;
	}
	else
	{
		imageName = IReportGraphicConstants.ICON_DISABLE_EXPRESSION_BUILDERS;
	}
	Image image = ReportPlatformUIImages.getImage( imageName );

	GridData gd = new GridData( );
	if ( Platform.getOS( ).equals( Platform.OS_WIN32 ) )
	{
		gd.widthHint = 20;
		gd.heightHint = 20;
	}
	else
	{
		gd.widthHint = button.computeSize( SWT.DEFAULT, SWT.DEFAULT ).y;
	}

	button.setLayoutData( gd );

	button.setImage( image );
	if ( button.getImage( ) != null )
	{
		button.getImage( ).setBackground( button.getBackground( ) );
	}
	button.setToolTipText( Messages.getString( "ExpressionBuilder.ToolTip" ) ); //$NON-NLS-1$

}
 
Example 6
Source File: CrosstabFilterConditionBuilder.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Set the layout data of the button to a GridData with appropriate heights
 * and widths.
 * 
 * @param button
 */
protected void setButtonCGridLayoutData( Button button )
{
	int widthHint = convertHorizontalDLUsToPixels( IDialogConstants.BUTTON_WIDTH );
	Point minSize = button.computeSize( SWT.DEFAULT, SWT.DEFAULT, true );
	button.setLayoutData( GridDataFactory.swtDefaults( )
			.hint( Math.max( widthHint, minSize.x ), SWT.DEFAULT )
			.create( ) );
}
 
Example 7
Source File: TSWizardDialog.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
protected void setButtonLayoutData(Button button) {
	GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
	int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);

	// On large fonts this can make this dialog huge
	widthHint = Math.min(widthHint,
			button.getDisplay().getBounds().width / 5);
	Point minSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
	data.widthHint = Math.max(widthHint, minSize.x);

	button.setLayoutData(data);
}
 
Example 8
Source File: NewReportPageSupport.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected GridData setButtonLayoutData( Button button )
{
	GridData data = new GridData( GridData.HORIZONTAL_ALIGN_FILL );
	// TODO replace DialogPage's implementation
	// int widthHint =
	// convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
	Point minSize = button.computeSize( SWT.DEFAULT, SWT.DEFAULT, true );
	data.widthHint = minSize.x;// Math.max(widthHint, minSize.x);
	button.setLayoutData( data );
	return data;
}
 
Example 9
Source File: TSWizardDialog.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
protected void setButtonLayoutData(Button button) {
	GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
	int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);

	// On large fonts this can make this dialog huge
	widthHint = Math.min(widthHint,
			button.getDisplay().getBounds().width / 5);
	Point minSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
	data.widthHint = Math.max(widthHint, minSize.x);

	button.setLayoutData(data);
}
 
Example 10
Source File: ReorgMoveWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void addUpdateQualifiedNameComponent(Composite parent, int marginWidth) {
	final JavaMoveProcessor processor= getJavaMoveProcessor();
	if (!processor.canEnableQualifiedNameUpdating() || !processor.canUpdateQualifiedNames())
		return;
	fQualifiedNameCheckbox= new Button(parent, SWT.CHECK);
	int indent= marginWidth + fQualifiedNameCheckbox.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
	fQualifiedNameCheckbox.setText(RefactoringMessages.RenameInputWizardPage_update_qualified_names);
	fQualifiedNameCheckbox.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
	fQualifiedNameCheckbox.setSelection(processor.getUpdateQualifiedNames());

	fQualifiedNameComponent= new QualifiedNameComponent(parent, SWT.NONE, processor, getRefactoringSettings());
	fQualifiedNameComponent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
	GridData gd= (GridData)fQualifiedNameComponent.getLayoutData();
	gd.horizontalAlignment= GridData.FILL;
	gd.horizontalIndent= indent;
	updateQualifiedNameUpdating(processor, processor.getUpdateQualifiedNames());

	fQualifiedNameCheckbox.addSelectionListener(new SelectionAdapter() {
		@Override
		public void widgetSelected(SelectionEvent e) {
			boolean enabled= ((Button)e.widget).getSelection();
			updateQualifiedNameUpdating(processor, enabled);
		}
	});
	fQualifiedNameCheckbox.setSelection(getRefactoringSettings().getBoolean(UPDATE_QUALIFIED_NAMES));
	updateQualifiedNameUpdating(processor, fQualifiedNameCheckbox.getSelection());
}
 
Example 11
Source File: AddRemoveList.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the <code>GridData</code> on the specified button to be one that is spaced for the current dialog page
 * units. The method <code>initializeDialogUnits</code> must be called once before calling this method for the first
 * time.
 * 
 * @param button
 *            the button to set the <code>GridData</code>
 * @return the <code>GridData</code> set on the specified button
 */
protected GridData setButtonLayoutData(Button button)
{
	GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
	PixelConverter converter = new PixelConverter(button);
	int widthHint = converter.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
	Point minSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
	data.widthHint = Math.max(widthHint, minSize.x);
	button.setLayoutData(data);
	return data;
}
 
Example 12
Source File: ExtClassPathPreferencePage.java    From ermasterr with Apache License 2.0 5 votes vote down vote up
private Button createButton(final Composite parent, final String label) {
    final int widthHint = convertHorizontalDLUsToPixels(61);

    final Button button = new Button(parent, 8);
    button.setText(label);

    Dialog.applyDialogFont(button);
    final GridData data = new GridData(256);
    final Point minButtonSize = button.computeSize(-1, -1, true);
    data.widthHint = Math.max(widthHint, minButtonSize.x);
    button.setLayoutData(data);

    return button;
}
 
Example 13
Source File: EmulatedNativeCheckBoxLabelProvider.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
private Image makeShot(Control control, boolean type) {
    /* Hopefully no platform uses exactly this color because we'll make
       it transparent in the image.*/
    Color greenScreen = new Color(control.getDisplay(), 222, 223, 224);

    shell = new Shell(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
            SWT.NO_TRIM | SWT.NO_BACKGROUND);

    // otherwise we have a default gray color
    shell.setBackground(greenScreen);

    Button button = new Button(shell, SWT.CHECK | SWT.NO_BACKGROUND);
    button.setBackground(greenScreen);
    button.setSelection(type);

    // otherwise an image is located in a corner
    button.setLocation(1, 1);
    Point bsize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);

    // otherwise an image is stretched by width
    bsize.x = Math.max(bsize.x - 1, bsize.y - 1);
    bsize.y = Math.max(bsize.x - 1, bsize.y - 1);
    button.setSize(bsize);

    GC gc = new GC(shell);
    Point shellSize = new Point(32, 32);
    shell.setSize(shellSize);
    shell.open();

    Image image = new Image(control.getDisplay(), bsize.x, bsize.y);
    gc.copyArea(image, 0, 0);
    gc.dispose();
    shell.close();

    ImageData imageData = image.getImageData();
    imageData.transparentPixel = imageData.palette.getPixel(greenScreen
            .getRGB());

    Image img = new Image(control.getDisplay(), imageData);
    image.dispose();

    return img;
}
 
Example 14
Source File: RouteResourceController.java    From tesb-studio-se with Apache License 2.0 4 votes vote down vote up
@Override
public Control createControl(final Composite subComposite, final IElementParameter param, final int numInRow,
        final int nbInRow, final int top, final Control lastControl) {
    this.curParameter = param;
    this.paramFieldType = param.getFieldType();
    FormData data;

    final DecoratedField dField = new DecoratedField(subComposite, SWT.BORDER | SWT.READ_ONLY,
            new SelectAllTextControlCreator());
    if (param.isRequired()) {
        FieldDecoration decoration = FieldDecorationRegistry.getDefault().getFieldDecoration(
                FieldDecorationRegistry.DEC_REQUIRED);
        dField.addFieldDecoration(decoration, SWT.RIGHT | SWT.TOP, false);
    }
    Control cLayout = dField.getLayoutControl();

    labelText = (Text) dField.getControl();

    labelText.setData(PARAMETER_NAME, param.getName());

    cLayout.setBackground(subComposite.getBackground());
    labelText.setEditable(false);
    if (elem instanceof Node) {
        labelText.setToolTipText(VARIABLE_TOOLTIP + param.getVariableName());
    }

    addDragAndDropTarget(labelText);

    CLabel labelLabel = getWidgetFactory().createCLabel(subComposite, param.getDisplayName());
    data = new FormData();
    if (lastControl != null) {
        data.left = new FormAttachment(lastControl, 0);
    } else {
        data.left = new FormAttachment(((numInRow - 1) * MAX_PERCENT) / (nbInRow + 1), 0);
    }
    data.top = new FormAttachment(0, top);
    labelLabel.setLayoutData(data);
    if (numInRow != 1) {
        labelLabel.setAlignment(SWT.RIGHT);
    }

    data = new FormData();
    int currentLabelWidth = STANDARD_LABEL_WIDTH;
    GC gc = new GC(labelLabel);
    Point labelSize = gc.stringExtent(param.getDisplayName());
    gc.dispose();
    if ((labelSize.x + ITabbedPropertyConstants.HSPACE) > currentLabelWidth) {
        currentLabelWidth = labelSize.x + ITabbedPropertyConstants.HSPACE;
    }

    if (numInRow == 1) {
        if (lastControl != null) {
            data.left = new FormAttachment(lastControl, currentLabelWidth);
        } else {
            data.left = new FormAttachment(0, currentLabelWidth);
        }

    } else {
        data.left = new FormAttachment(labelLabel, 0, SWT.RIGHT);
    }
    data.right = new FormAttachment((numInRow * MAX_PERCENT) / (nbInRow + 1), 0);
    data.top = new FormAttachment(0, top);
    cLayout.setLayoutData(data);

    Button btn;
    Point btnSize;

    btn = getWidgetFactory().createButton(subComposite, "", SWT.PUSH); //$NON-NLS-1$
    btnSize = btn.computeSize(SWT.DEFAULT, SWT.DEFAULT);

    btn.setImage(ImageProvider.getImage(CoreUIPlugin.getImageDescriptor(DOTS_BUTTON)));

    btn.addSelectionListener(listenerSelection);
    btn.setData(PARAMETER_NAME, param.getName());
    btn.setEnabled(!param.isReadOnly());
    data = new FormData();
    data.left = new FormAttachment(cLayout, 0);
    data.right = new FormAttachment(cLayout, STANDARD_BUTTON_WIDTH, SWT.RIGHT);
    data.top = new FormAttachment(0, top);
    data.height = STANDARD_HEIGHT - 2;
    btn.setLayoutData(data);

    hashCurControls.put(param.getName(), labelText);
    Point initialSize = dField.getLayoutControl().computeSize(SWT.DEFAULT, SWT.DEFAULT);
    Control lastControlUsed = btn;
    lastControlUsed = addVersionCombo(subComposite,
            param.getChildParameters().get(EParameterName.ROUTE_RESOURCE_TYPE_VERSION.getName()), lastControlUsed,
            numInRow + 1, nbInRow, top);
    dynamicProperty.setCurRowSize(Math.max(initialSize.y, btnSize.y) + ITabbedPropertyConstants.VSPACE);
    return btn;
}
 
Example 15
Source File: CleanupPreferencePage.java    From eclipse-extras with Eclipse Public License 1.0 4 votes vote down vote up
private static int computePreferredButtonWidth( Button button ) {
  int defaultButtonWidth = getDefaultButtonWidth();
  Point minSize = button.computeSize( SWT.DEFAULT, SWT.DEFAULT, true );
  return Math.max( defaultButtonWidth, minSize.x );
}
 
Example 16
Source File: Buttons.java    From eclipse-extras with Eclipse Public License 1.0 4 votes vote down vote up
static int computePreferredButtonWidth( Button button ) {
  int defaultButtonWidth = getDefaultButtonWidth();
  Point minSize = button.computeSize( SWT.DEFAULT, SWT.DEFAULT, true );
  return Math.max( defaultButtonWidth, minSize.x );
}
 
Example 17
Source File: CheckboxCellContentProvider.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * If the enabled/disabled checked/unchecked checkbox <code>Image</code>s
 * have not already been created and added to the JFace
 * <code>ImageRegistry</code>, this method generates and registers them.
 * This produces platform-specific images at run-time.
 * 
 * @param display
 *            The <code>Display</code> shared with the underlying
 *            <code>ColumnViewer</code>.
 * @param background
 *            The background of the <code>ColumnViewer</code>'s cells.
 */
private static void registerImages(final Display display, Color background) {

	if (display != null && IMAGES_REGISTERED.compareAndSet(false, true)) {

		// Get the ImageRegistry for JFace images. We will load up images
		// for each combination of checkbox enabled/disabled and
		// checked/unchecked.
		ImageRegistry jfaceImages = JFaceResources.getImageRegistry();

		// Create a temporary shell and checkbox Button to generate
		// platform-specific images of checkboxes.
		Shell shell = new Shell(display, SWT.NO_TRIM);
		Button checkbox = new Button(shell, SWT.CHECK);

		// Set the widget's background to the viewer's cell background.
		checkbox.setBackground(background);

		// Reduce the size of the shell to a square (checkboxes are supposed
		// to be square!!!).
		Point size = checkbox.computeSize(SWT.DEFAULT, SWT.DEFAULT);
		// int width = Math.min(size.x, size.y);
		checkbox.setSize(size);
		// checkbox.setLocation(width - size.x, width - size.y);
		// shell.setSize(width, width);
		shell.setSize(size);

		// Open the shell to enable widget drawing.
		shell.open();

		// Create the enabled/unchecked image.
		jfaceImages.put(ENABLED_UNCHECKED, createImage(checkbox));
		// Create the enabled/checked image.
		checkbox.setSelection(true);
		jfaceImages.put(ENABLED_CHECKED, createImage(checkbox));
		// Create the disabled/checked image.
		checkbox.setEnabled(false);
		jfaceImages.put(DISABLED_CHECKED, createImage(checkbox));
		// Create the disabled/unchecked image.
		checkbox.setSelection(false);
		jfaceImages.put(DISABLED_UNCHECKED, createImage(checkbox));

		// Release any remaining resources.
		// gc.dispose();
		shell.close();
	}

	return;
}
 
Example 18
Source File: MenuButton.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public Point computeSize( int wHint, int hHint, boolean changed )
{

	int width;
	int height;

	Button tmp = new Button( this, button.getStyle( ) );
	if ( text != null )
	{
		tmp.setText( text );
		height = tmp.computeSize( SWT.DEFAULT, SWT.DEFAULT ).y;
	}
	else
	{
		tmp.setText( "" ); //$NON-NLS-1$
		height = tmp.computeSize( SWT.DEFAULT, SWT.DEFAULT ).y;
	}
	if ( image != null )
		tmp.setImage( image );
	Point size = tmp.computeSize( SWT.DEFAULT, SWT.DEFAULT );
	tmp.dispose( );

	if ( menu != null )
	{
		width = size.x + WIDTH_MORE;
	}
	else
		width = size.x;

	if ( isFixed && image != null )
	{
		int imageWidth = image.getImageData( ).width;
		if ( imageWidth > IMAGE_WIDTH )
			width -= ( imageWidth - IMAGE_WIDTH );

	}
	if ( !isFixed )
		height = size.y;
	defaultSize = new Point( width, height );
	if ( wHint != SWT.DEFAULT )
		width = wHint;
	if ( hHint != SWT.DEFAULT )
		height = hHint;

	return new Point( width, height );
}
 
Example 19
Source File: ColumnMappingWizardPage.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
private int computeMaxWidth( Button btn, int maxWidth )
{
	int widthHint = btn.computeSize( -1, -1 ).x
			- btn.getBorderWidth( );
	return widthHint > maxWidth ? widthHint : maxWidth;
}
 
Example 20
Source File: MenuButton.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public Point computeSize( int wHint, int hHint, boolean changed )
{

	int width;
	int height;

	Button tmp = new Button( this, button.getStyle( ) );
	if ( text != null )
	{
		tmp.setText( text );
		height = tmp.computeSize( SWT.DEFAULT, SWT.DEFAULT ).y;
	}
	else
	{
		tmp.setText( "" ); //$NON-NLS-1$
		height = tmp.computeSize( SWT.DEFAULT, SWT.DEFAULT ).y;
	}
	if ( image != null )
		tmp.setImage( image );
	Point size = tmp.computeSize( SWT.DEFAULT, SWT.DEFAULT );
	tmp.dispose( );

	if ( menu != null )
	{
		width = size.x + WIDTH_MORE;
	}
	else
		width = size.x;

	if ( isFixed && image != null )
	{
		int imageWidth = image.getImageData( ).width;
		if ( imageWidth > IMAGE_WIDTH )
			width -= ( imageWidth - IMAGE_WIDTH );

	}
	if ( !isFixed )
		height = size.y;
	defaultSize = new Point( width, height );
	if ( wHint != SWT.DEFAULT )
		width = wHint;
	if ( hHint != SWT.DEFAULT )
		height = hHint;

	return new Point( width, height );
}