Java Code Examples for org.eclipse.swt.widgets.Control#setBackground()

The following examples show how to use org.eclipse.swt.widgets.Control#setBackground() . These examples are extracted from open source projects. 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 Project: thym   File: ControlListItem.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void setBackground(Color color) {
	super.setBackground(color);
	Control[] children = getChildren();
	for (Control child : children) {
		child.setBackground(color);
	}
}
 
Example 2
Source Project: SWET   File: PopupDialog.java    License: MIT License 5 votes vote down vote up
/**
 * Set the specified background color for the specified control and all of
 * its children, except for those specified in the list of exclusions.
 * 
 * @param color
 *            the color to use as the background color
 * @param control
 *            the control whose color is to be changed
 * @param exclusions
 *            a list of controls who are to be excluded from getting their
 *            color assigned
 */
private void applyBackgroundColor(Color color, Control control,
		List<Object> exclusions) {
	if (!exclusions.contains(control)) {
		control.setBackground(color);
	}
	if (control instanceof Composite) {
		Control[] children = ((Composite) control).getChildren();
		for (int i = 0; i < children.length; i++) {
			applyBackgroundColor(color, children[i], exclusions);
		}
	}
}
 
Example 3
public void refreshAll( )
{
	// remove disposed control
	checkAll( );

	Set<String> usedColorKeys = new HashSet<String>( );
	ColorPalette colorPalette = ColorPalette.getInstance( );

	// update all text
	for ( Map.Entry<Control, IQueryExpressionManager> entry : textCollection.entrySet( ) )
	{
		Control text = entry.getKey( );
		IQueryExpressionManager iqem = entry.getValue( );
		String expr = iqem.getQuery( ).getDefinition( );
		iqem.updateText( expr );

		String name = exprCodec.getBindingName( iqem.getExpressionButton( )
				.getExpression( ) );
		if ( name != null )
		{
			colorPalette.putColor( name );
			usedColorKeys.add( name );
			text.setBackground( colorPalette.getColor( name ) );
		}
		else
		{
			text.setBackground( null );
		}
	}

	// re-organize colors
	ColorPalette.getInstance( ).updateKeys( getAllUsedBindingNames( ) );
}
 
Example 4
@Override
public void updateEntityColor(final Object entity, final Color color) {
  for (Control control : contentComposite.getChildren()) {
    if (!entity.equals(control.getData())) continue;

    if (control instanceof ChatLineSeparator || control instanceof ChatLinePartnerChangeSeparator)
      control.setBackground(color);
  }
}
 
Example 5
@Override
public void setBackgroundColor(Color background) {
    super.setBackgroundColor(background);
    Control[] children= fParent.getChildren();
    for (Control element : children) {
        element.setBackground(background);
    }
}
 
Example 6
private void setColorAndFont(Control control, Color foreground, Color background, Font font) {
    control.setForeground(foreground);
    control.setBackground(background);
    control.setFont(font);
    
    if (control instanceof Composite) {
        Control[] children= ((Composite) control).getChildren();
        for (Control element : children) {
            setColorAndFont(element, foreground, background, font);
        }
    }
}
 
Example 7
protected void configureBackground(Control control) {
    final Color backgroundColor = control.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
    final Color whiteColor = control.getDisplay().getSystemColor(SWT.COLOR_WHITE);
    if (toolkit.isPresent()) {
        if (control instanceof Composite) {
            toolkit.get().adapt((Composite) control);
        } else {
            toolkit.get().adapt(control, true, true);
        }
    }
    control.setBackground(readOnly ? backgroundColor : whiteColor);
    control.setEnabled(!readOnly);
}
 
Example 8
Source Project: typescript.java   File: RenameInformationPopup.java    License: MIT License 5 votes vote down vote up
private static void recursiveSetBackgroundColor(Control control, Color color) {
	control.setBackground(color);
	if (control instanceof Composite) {
		Control[] children= ((Composite) control).getChildren();
		for (int i= 0; i < children.length; i++) {
			recursiveSetBackgroundColor(children[i], color);
		}
	}
}
 
Example 9
Source Project: birt   File: ChartUIUtil.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public static void setBackgroundColor( Control control, boolean selected,
		Color color )
{
	if ( control != null && !control.isDisposed( ) )
	{
		if ( selected )
		{
			control.setBackground( color );
		}
		else
		{
			control.setBackground( null );
		}
	}
}
 
Example 10
private void updateBackground(Composite composite, Color background) {
  composite.setBackground(background);

  for (Control control : composite.getChildren()) {
    if (control instanceof Composite) {
      updateBackground((Composite) control, background);
    } else {
      control.setBackground(background);
    }
  }
}
 
Example 11
Source Project: Pydev   File: SharedUiPlugin.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public static void fixSelectionStatusDialogStatusLineColor(Object dialog, Color color) {
    //TODO: Hack: remove when MessageLine is styleable.
    try {
        Field field = org.eclipse.ui.dialogs.SelectionStatusDialog.class
                .getDeclaredField("fStatusLine");
        field.setAccessible(true);
        Control messageLine = (Control) field.get(dialog);
        messageLine.setBackground(color);
    } catch (Exception e) {
        Log.log(e);
    }
}
 
Example 12
Source Project: gama   File: EditorsDialog.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Method createContents()
 *
 * @see org.eclipse.jface.dialogs.Dialog#createContents(org.eclipse.swt.widgets.Composite)
 */
@Override
protected Control createContents(final Composite parent) {
	final Control composite = super.createContents(parent);
	composite.setBackground(IGamaColors.WHITE.color());
	return composite;
}
 
Example 13
private static void recursiveSetBackgroundColor(Control control, Color color) {
	control.setBackground(color);
	if (control instanceof Composite) {
		Control[] children= ((Composite) control).getChildren();
		for (int i= 0; i < children.length; i++) {
			recursiveSetBackgroundColor(children[i], color);
		}
	}
}
 
Example 14
Source Project: gama   File: SliderEditor.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Composite createToolbar2() {
	final Composite t = super.createToolbar2();
	t.setBackground(getNormalBackground());
	for (final Control c : t.getChildren()) {
		c.setBackground(getNormalBackground());
	}
	return t;
}
 
Example 15
Source Project: hop   File: PropsUi.java    License: Apache License 2.0 4 votes vote down vote up
public void setLook( final Control control, int style ) {
  if ( this.isOSLookShown() && style != WIDGET_STYLE_FIXED ) {
    return;
  }

  final GuiResource gui = GuiResource.getInstance();
  Font font = null;
  Color background = null;

  switch ( style ) {
    case WIDGET_STYLE_DEFAULT:
      background = gui.getColorBackground();
      if ( control instanceof Group && OS.indexOf( "mac" ) > -1 ) {
        control.addPaintListener( paintEvent -> {
          paintEvent.gc.setBackground( gui.getColorBackground() );
          paintEvent.gc.fillRectangle( 2, 0, control.getBounds().width - 8, control.getBounds().height - 20 );
        } );
      }
      font = null; // GuiResource.getInstance().getFontDefault();
      break;
    case WIDGET_STYLE_FIXED:
      if ( !this.isOSLookShown() ) {
        background = gui.getColorBackground();
      }
      font = gui.getFontFixed();
      break;
    case WIDGET_STYLE_TABLE:
      background = gui.getColorBackground();
      font = null; // gui.getFontGrid();
      break;
    case WIDGET_STYLE_NOTEPAD:
      background = gui.getColorBackground();
      font = gui.getFontNote();
      break;
    case WIDGET_STYLE_GRAPH:
      background = gui.getColorBackground();
      font = gui.getFontGraph();
      break;
    case WIDGET_STYLE_TOOLBAR:
      background = GuiResource.getInstance().getColorDemoGray();
      break;
    case WIDGET_STYLE_TAB:
      background = GuiResource.getInstance().getColorWhite();
      CTabFolder tabFolder = (CTabFolder) control;
      tabFolder.setSimple( false );
      tabFolder.setBorderVisible( true );
      // need to make a copy of the tab selection background color to get around PDI-13940
      Color c = GuiResource.getInstance().getColorTab();
      Color tabColor = new Color( c.getDevice(), c.getRed(), c.getGreen(), c.getBlue() );
      tabFolder.setSelectionBackground( tabColor );
      break;
    default:
      background = gui.getColorBackground();
      font = null; // gui.getFontDefault();
      break;
  }

  if ( font != null && !font.isDisposed() ) {
    control.setFont( font );
  }

  if ( background != null && !background.isDisposed() ) {
    if ( control instanceof Button ) {
      Button b = (Button) control;
      if ( ( b.getStyle() & SWT.PUSH ) != 0 ) {
        return;
      }
    }
    control.setBackground( background );
  }
}
 
Example 16
Source Project: nebula   File: PageContainer.java    License: Eclipse Public License 2.0 4 votes vote down vote up
public void adapt(Control control) {
	control.setBackground(getDisplay().getSystemColor(SWT.COLOR_WHITE));
}
 
Example 17
Source Project: pentaho-kettle   File: PropsUI.java    License: Apache License 2.0 4 votes vote down vote up
public void setLook( final Control control, int style ) {
  if ( this.isOSLookShown() && style != WIDGET_STYLE_FIXED ) {
    return;
  }

  final GUIResource gui = GUIResource.getInstance();
  Font font = null;
  Color background = null;

  switch ( style ) {
    case WIDGET_STYLE_DEFAULT:
      background = gui.getColorBackground();
      if ( control instanceof Group && OS.indexOf( "mac" ) > -1 ) {
        control.addPaintListener( new PaintListener() {
          @Override
          public void paintControl( PaintEvent paintEvent ) {
            paintEvent.gc.setBackground( gui.getColorBackground() );
            paintEvent.gc.fillRectangle( 2, 0, control.getBounds().width - 8, control.getBounds().height - 20 );
          }
        } );
      }
      font = null; // GUIResource.getInstance().getFontDefault();
      break;
    case WIDGET_STYLE_FIXED:
      if ( !this.isOSLookShown() ) {
        background = gui.getColorBackground();
      }
      font = gui.getFontFixed();
      break;
    case WIDGET_STYLE_TABLE:
      background = gui.getColorBackground();
      font = null; // gui.getFontGrid();
      break;
    case WIDGET_STYLE_NOTEPAD:
      background = gui.getColorBackground();
      font = gui.getFontNote();
      break;
    case WIDGET_STYLE_GRAPH:
      background = gui.getColorBackground();
      font = gui.getFontGraph();
      break;
    case WIDGET_STYLE_TOOLBAR:
      background = GUIResource.getInstance().getColorDemoGray();
      break;
    case WIDGET_STYLE_TAB:
      background = GUIResource.getInstance().getColorWhite();
      CTabFolder tabFolder = (CTabFolder) control;
      tabFolder.setSimple( false );
      tabFolder.setBorderVisible( true );
      // need to make a copy of the tab selection background color to get around PDI-13940
      Color c = GUIResource.getInstance().getColorTab();
      Color tabColor = new Color( c.getDevice(), c.getRed(), c.getGreen(), c.getBlue() );
      tabFolder.setSelectionBackground( tabColor );
      break;
    default:
      background = gui.getColorBackground();
      font = null; // gui.getFontDefault();
      break;
  }

  if ( font != null && !font.isDisposed() ) {
    control.setFont( font );
  }

  if ( background != null && !background.isDisposed() ) {
    if ( control instanceof Button ) {
      Button b = (Button) control;
      if ( ( b.getStyle() & SWT.PUSH ) != 0 ) {
        return;
      }
    }
    control.setBackground( background );
  }
}
 
Example 18
default void setupControl(Control control) {
    control.setForeground(control.getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND));
    control.setBackground(control.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
}
 
Example 19
Source Project: gama   File: EditorsDialog.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
protected Control createButtonBar(final Composite parent) {
	final Control composite = super.createButtonBar(parent);
	composite.setBackground(IGamaColors.WHITE.color());
	return composite;
}
 
Example 20
/**
 * Utility to set the foreground and the background color of the given control
 * 
 * @param control
 *            the control to modify
 * @param foreground
 *            the color to use for the foreground
 * @param background
 *            the color to use for the background
 */
private static void setColor(Control control, Color foreground, Color background)
{
	control.setForeground(foreground);
	control.setBackground(background);
}