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

The following examples show how to use org.eclipse.swt.widgets.Button#getBounds() . 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: PWColorChooser.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @param button button on which we draw the rectangle
 */
protected void drawButton(final Button button) {
	final int height = (int) button.getFont().getFontData()[0].height;
	final int width = button.getBounds().width - 16;

	final Image newImage = new Image(button.getDisplay(), Math.max(1, width), Math.max(1, height));

	final GC gc = new GC(newImage);
	gc.setBackground(PWColorChooser.this.color);
	gc.fillRectangle(0, 0, width, height);

	gc.setForeground(button.getDisplay().getSystemColor(SWT.COLOR_BLACK));
	gc.drawRectangle(0, 0, width - 1, height - 1);

	gc.dispose();

	button.setImage(newImage);
}
 
Example 2
Source File: SimpleMessageDialog.java    From hop with Apache License 2.0 5 votes vote down vote up
/**
 * Overridden to give the button the desired width.
 */
@Override
public void create() {
  super.create();
  final Button button = getButton( 0 );
  final int newX = button.getBounds().x + button.getBounds().width - buttonWidth;
  button.setBounds( newX, button.getBounds().y, buttonWidth, button.getBounds().height );
}
 
Example 3
Source File: SimpleMessageDialog.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Overridden to give the button the desired width.
 */
@Override
public void create() {
  super.create();
  final Button button = getButton( 0 );
  final int newX = button.getBounds().x + button.getBounds().width - buttonWidth;
  button.setBounds( newX, button.getBounds().y, buttonWidth, button.getBounds().height );
}
 
Example 4
Source File: CheckBoxToolTip.java    From hop with Apache License 2.0 4 votes vote down vote up
protected Composite createToolTipContentArea( Event event, Composite parent ) {
  Composite composite = new Composite( parent, SWT.NONE );
  FormLayout compLayout = new FormLayout();
  compLayout.marginHeight = 5;
  compLayout.marginWidth = 5;
  composite.setLayout( compLayout );

  composite.setBackground( display.getSystemColor( SWT.COLOR_INFO_BACKGROUND ) );

  Label imageLabel = new Label( composite, SWT.NONE );
  imageLabel.setImage( image );
  imageLabel.setBackground( display.getSystemColor( SWT.COLOR_INFO_BACKGROUND ) );
  FormData fdImageLabel = new FormData();
  fdImageLabel.left = new FormAttachment( 0, 0 );
  fdImageLabel.top = new FormAttachment( 0, 0 );
  imageLabel.setLayoutData( fdImageLabel );

  Label titleLabel = new Label( composite, SWT.LEFT );
  titleLabel.setText( title );
  titleLabel.setBackground( display.getSystemColor( SWT.COLOR_INFO_BACKGROUND ) );
  titleLabel.setFont( GuiResource.getInstance().getFontBold() );
  FormData fdTitleLabel = new FormData();
  fdTitleLabel.left = new FormAttachment( imageLabel, 20 );
  fdTitleLabel.top = new FormAttachment( 0, 0 );
  titleLabel.setLayoutData( fdTitleLabel );

  Label line = new Label( composite, SWT.SEPARATOR | SWT.HORIZONTAL );
  line.setBackground( display.getSystemColor( SWT.COLOR_INFO_BACKGROUND ) );
  FormData fdLine = new FormData();
  fdLine.left = new FormAttachment( imageLabel, 5 );
  fdLine.right = new FormAttachment( 100, -5 );
  fdLine.top = new FormAttachment( titleLabel, 5 );
  line.setLayoutData( fdLine );

  // Text messageLabel = new Text(composite, SWT.LEFT | ( showingScrollBars ? SWT.H_SCROLL | SWT.V_SCROLL : SWT.NONE )
  // );
  /*
   * Text messageLabel = new Text(composite, SWT.SINGLE | SWT.LEFT); messageLabel.setText(message);
   * messageLabel.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); FormData fdMessageLabel = new
   * FormData(); fdMessageLabel.left = new FormAttachment(imageLabel, 20); fdMessageLabel.top = new
   * FormAttachment(line, 5); if (showingScrollBars) { fdMessageLabel.right = new FormAttachment(imageLabel, 500);
   * fdMessageLabel.bottom= new FormAttachment(line, 400); } messageLabel.setLayoutData(fdMessageLabel);
   */
  Label messageLabel = new Label( composite, SWT.LEFT );
  messageLabel.setText( message );
  messageLabel.setBackground( display.getSystemColor( SWT.COLOR_INFO_BACKGROUND ) );
  FormData fdMessageLabel = new FormData();
  fdMessageLabel.left = new FormAttachment( imageLabel, 20 );
  fdMessageLabel.top = new FormAttachment( line, 5 );
  messageLabel.setLayoutData( fdMessageLabel );

  final Button disable = new Button( composite, SWT.CHECK );
  disable.setText( checkBoxMessage );
  disable.setBackground( display.getSystemColor( SWT.COLOR_INFO_BACKGROUND ) );
  disable.setSelection( false );
  FormData fdDisable = new FormData();
  fdDisable.left = new FormAttachment( 0, 0 );
  fdDisable.top = new FormAttachment( messageLabel, 20 );
  fdDisable.bottom = new FormAttachment( 100, 0 );
  disable.setLayoutData( fdDisable );
  disable.addSelectionListener( new SelectionAdapter() {

    public void widgetSelected( SelectionEvent e ) {
      for ( ICheckBoxToolTipListener listener : listeners ) {
        listener.checkBoxSelected( false );
      }
      hide();
    }

  } );
  disable.addPaintListener( new PaintListener() {

    public void paintControl( PaintEvent arg0 ) {
      checkBoxBounds = disable.getBounds();
    }

  } );

  composite.layout();
  checkBoxBounds = disable.getBounds();

  return composite;
}
 
Example 5
Source File: ForkedColorsAndFontsPropertySection.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @param event -
 *            selection event
 * @param button -
 *            event source
 * @param propertyId -
 *            id of the property
 * @param commandName -
 *            name of the command
 * @param imageDescriptor -
 *            the image to draw overlay on the button after the new color is
 *            set
 * @return - new RGB color, or null if none selected
 */
protected RGB changeColor(SelectionEvent event, Button button,
        final String propertyId, String commandName,
        ImageDescriptor imageDescriptor) {

	CustomColorPalettePopup popup = new CustomColorPalettePopup(button.getParent()
        .getShell(), IDialogConstants.BUTTON_BAR_HEIGHT);        
    popup.setPreviousColor(previousColor);
    Rectangle r = button.getBounds();
    Point location = button.getParent().toDisplay(r.x, r.y);
    popup.open(new Point(location.x, location.y + r.height));        
    if (popup.getSelectedColor() == null && !popup.useDefaultColor()) {
        return null;
    }        
    // selectedColor should be null if we are to use the default color
    final RGB selectedColor = popup.getSelectedColor();

    final EStructuralFeature feature = (EStructuralFeature) PackageUtil
        .getElement(propertyId);

    // Update model in response to user

    List commands = new ArrayList();
    Iterator it = getInputIterator();

    RGB colorToReturn = selectedColor;
    RGB color = selectedColor;
    while (it.hasNext()) {
        final IGraphicalEditPart ep = (IGraphicalEditPart) it.next();

        color = selectedColor;
        if (popup.useDefaultColor()) {
            Object preferredValue = ep.getPreferredValue(feature);
            if (preferredValue instanceof Integer) {
                color = FigureUtilities
                    .integerToRGB((Integer) preferredValue);
            }
        }
            
        // If we are using default colors, we want to return the color of the first selected element to be consistent
        if (colorToReturn == null) {
            colorToReturn = color;
        }

        if (color != null) {
            final RGB finalColor = color; // need a final variable
           commands.add(createCommand(commandName, ((View) ep.getModel())
                .eResource(), new Runnable() {

                public void run() {
                    ENamedElement element = PackageUtil
                        .getElement(propertyId);
                    if (element instanceof EStructuralFeature)
                        ep.setStructuralFeatureValue(feature,
                            FigureUtilities.RGBToInteger(finalColor));
                }
            }));
        }
    }
    if (!commands.isEmpty()){
     executeAsCompositeCommand(commandName, commands);
	    Image overlyedImage = new ColorOverlayImageDescriptor(
        imageDescriptor.getImageData(), color).createImage();
    	disposeImage(button.getImage());
     button.setImage(overlyedImage);
 }
    return colorToReturn;
}
 
Example 6
Source File: CheckBoxToolTip.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
protected Composite createToolTipContentArea( Event event, Composite parent ) {
  Composite composite = new Composite( parent, SWT.NONE );
  FormLayout compLayout = new FormLayout();
  compLayout.marginHeight = 5;
  compLayout.marginWidth = 5;
  composite.setLayout( compLayout );

  composite.setBackground( display.getSystemColor( SWT.COLOR_INFO_BACKGROUND ) );

  Label imageLabel = new Label( composite, SWT.NONE );
  imageLabel.setImage( image );
  imageLabel.setBackground( display.getSystemColor( SWT.COLOR_INFO_BACKGROUND ) );
  FormData fdImageLabel = new FormData();
  fdImageLabel.left = new FormAttachment( 0, 0 );
  fdImageLabel.top = new FormAttachment( 0, 0 );
  imageLabel.setLayoutData( fdImageLabel );

  Label titleLabel = new Label( composite, SWT.LEFT );
  titleLabel.setText( title );
  titleLabel.setBackground( display.getSystemColor( SWT.COLOR_INFO_BACKGROUND ) );
  titleLabel.setFont( GUIResource.getInstance().getFontBold() );
  FormData fdTitleLabel = new FormData();
  fdTitleLabel.left = new FormAttachment( imageLabel, 20 );
  fdTitleLabel.top = new FormAttachment( 0, 0 );
  titleLabel.setLayoutData( fdTitleLabel );

  Label line = new Label( composite, SWT.SEPARATOR | SWT.HORIZONTAL );
  line.setBackground( display.getSystemColor( SWT.COLOR_INFO_BACKGROUND ) );
  FormData fdLine = new FormData();
  fdLine.left = new FormAttachment( imageLabel, 5 );
  fdLine.right = new FormAttachment( 100, -5 );
  fdLine.top = new FormAttachment( titleLabel, 5 );
  line.setLayoutData( fdLine );

  // Text messageLabel = new Text(composite, SWT.LEFT | ( showingScrollBars ? SWT.H_SCROLL | SWT.V_SCROLL : SWT.NONE )
  // );
  /*
   * Text messageLabel = new Text(composite, SWT.SINGLE | SWT.LEFT); messageLabel.setText(message);
   * messageLabel.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); FormData fdMessageLabel = new
   * FormData(); fdMessageLabel.left = new FormAttachment(imageLabel, 20); fdMessageLabel.top = new
   * FormAttachment(line, 5); if (showingScrollBars) { fdMessageLabel.right = new FormAttachment(imageLabel, 500);
   * fdMessageLabel.bottom= new FormAttachment(line, 400); } messageLabel.setLayoutData(fdMessageLabel);
   */
  Label messageLabel = new Label( composite, SWT.LEFT );
  messageLabel.setText( message );
  messageLabel.setBackground( display.getSystemColor( SWT.COLOR_INFO_BACKGROUND ) );
  FormData fdMessageLabel = new FormData();
  fdMessageLabel.left = new FormAttachment( imageLabel, 20 );
  fdMessageLabel.top = new FormAttachment( line, 5 );
  messageLabel.setLayoutData( fdMessageLabel );

  final Button disable = new Button( composite, SWT.CHECK );
  disable.setText( checkBoxMessage );
  disable.setBackground( display.getSystemColor( SWT.COLOR_INFO_BACKGROUND ) );
  disable.setSelection( false );
  FormData fdDisable = new FormData();
  fdDisable.left = new FormAttachment( 0, 0 );
  fdDisable.top = new FormAttachment( messageLabel, 20 );
  fdDisable.bottom = new FormAttachment( 100, 0 );
  disable.setLayoutData( fdDisable );
  disable.addSelectionListener( new SelectionAdapter() {

    public void widgetSelected( SelectionEvent e ) {
      for ( CheckBoxToolTipListener listener : listeners ) {
        listener.checkBoxSelected( false );
      }
      hide();
    }

  } );
  disable.addPaintListener( new PaintListener() {

    public void paintControl( PaintEvent arg0 ) {
      checkBoxBounds = disable.getBounds();
    }

  } );

  composite.layout();
  checkBoxBounds = disable.getBounds();

  return composite;
}