Java Code Examples for org.eclipse.swt.widgets.Label#setForeground()

The following examples show how to use org.eclipse.swt.widgets.Label#setForeground() . 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: FindReplaceDialog.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates the status and close section of the dialog.
 * @param parent
 *            the parent composite
 * @return the status and close button
 */
private Composite createStatusAndCloseButton(Composite parent) {
	statusLabel = new Label(parent, SWT.LEFT);
	statusLabel.setForeground(statusLabel.getDisplay().getSystemColor(SWT.COLOR_RED));
	GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(statusLabel);

	Composite panel = new Composite(parent, SWT.NULL);
	GridLayout layout = new GridLayout(0, false);
	layout.marginWidth = 0;
	layout.marginHeight = 0;
	panel.setLayout(layout);
	panel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

	Button closeButton = createButton(panel, IDialogConstants.CLOSE_ID, IDialogConstants.CLOSE_LABEL, false);
	GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.BOTTOM).grab(true, false).hint(90, SWT.DEFAULT)
			.applyTo(closeButton);

	return parent;
}
 
Example 2
Source File: SWTUtil.java    From eclipse-cs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * @see org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent)
 */
@Override
public void mouseDown(MouseEvent e) {
  Control theControl = (Control) e.widget;

  Display display = theControl.getDisplay();
  Shell tip = new Shell(theControl.getShell(), SWT.ON_TOP | SWT.TOOL);
  tip.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
  FillLayout layout = new FillLayout();
  layout.marginHeight = 1;
  layout.marginWidth = 2;
  tip.setLayout(layout);
  Label label = new Label(tip, SWT.NONE);
  label.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
  label.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));

  label.setText(theControl.getToolTipText());
  label.addMouseTrackListener(this);
  Point size = tip.computeSize(SWT.DEFAULT, SWT.DEFAULT);
  Rectangle rect = theControl.getBounds();
  Point pt = theControl.getParent().toDisplay(rect.x, rect.y);
  tip.setBounds(pt.x, pt.y, size.x, size.y);
  tip.setVisible(true);
}
 
Example 3
Source File: N4JSNewProjectWizardCreationPage.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private Composite initTestProjectUI(DataBindingContext dbc, Composite parent) {
	// Additional test project options
	final Group testProjectOptionsGroup = new Group(parent, NONE);
	testProjectOptionsGroup.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).create());

	final Button createTestGreeterFileButton = new Button(testProjectOptionsGroup, CHECK);
	createTestGreeterFileButton.setText("Create a test project greeter file");

	final Button addNormalSourceFolderButton = new Button(testProjectOptionsGroup, CHECK);
	addNormalSourceFolderButton.setText("Also create a non-test source folder");

	Label nextPageHint = new Label(testProjectOptionsGroup, NONE);
	nextPageHint.setText("The projects which should be tested can be selected on the next page");
	nextPageHint.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_FOREGROUND));

	initTestProjectBinding(dbc, addNormalSourceFolderButton, createTestGreeterFileButton);

	return testProjectOptionsGroup;
}
 
Example 4
Source File: ReportDocumentEditor.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private Label createLabel( Composite parent, String text )
{
	Label label = new Label( parent, SWT.WRAP );
	if ( text != null )
		label.setText( text );
	label.setBackground( fBackgroundColor );
	label.setForeground( fForegroundColor );
	GridData gd = new GridData( SWT.FILL, SWT.FILL, true, false );
	label.setLayoutData( gd );
	return label;
}
 
Example 5
Source File: DisplayOverlay.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
private Label label(final Composite c, final int horizontalAlign) {
	final Label l = new Label(c, SWT.None);
	l.setForeground(IGamaColors.WHITE.color());
	l.setBackground(IGamaColors.BLACK.color());
	l.setText(" ");
	l.setLayoutData(infoData(horizontalAlign));
	l.addMouseListener(toggleListener);
	return l;
}
 
Example 6
Source File: ToolkitControl.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private void initControl() {
  GridLayoutFactory.fillDefaults().numColumns(3).spacing(3, 2).applyTo(this);
  GridLayout layout = (GridLayout) this.getLayout();
  layout.marginLeft = 7;
  layout.marginTop = 2;
  layout.marginBottom = 2;

  Label iconLabel = new Label(this, SWT.NULL);
  iconLabel.setBackground(getBackground());
  GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.BEGINNING).span(1, 2).applyTo(
      iconLabel);
  listenTo(iconLabel);

  Link nameLabel = new Link(this, SWT.NONE);
  nameLabel.setText(wbToolkit.getName());
  nameLabel.setBackground(getBackground());
  nameLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  nameLabel.setFont(getBoldFont(getFont()));
  listenTo(nameLabel);

  Label providerLabel = new Label(this, SWT.NONE);
  providerLabel.setText(wbToolkit.getProviderDescription());
  providerLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
  providerLabel.setBackground(getBackground());
  providerLabel.setForeground(Display.getDefault().getSystemColor(
      SWT.COLOR_GRAY));
  listenTo(providerLabel);

  Label summaryLabel = new Label(this, SWT.WRAP);
  String description = stripCRLF(wbToolkit.getDescription());
  summaryLabel.setText(description);
  summaryLabel.setBackground(getBackground());
  GridDataFactory.fillDefaults().grab(true, false).span(2, 1).hint(100,
      SWT.DEFAULT).applyTo(summaryLabel);
  listenTo(summaryLabel);

  listenTo(this);
}
 
Example 7
Source File: ComponentTitledSeparator.java    From arx with Apache License 2.0 5 votes vote down vote up
/**
 * @return a SWT label
 */
private Label createLabel() {
        final Label label = new Label(this, SWT.NONE);
        label.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false));
        label.setFont(getFont());
        label.setForeground(getForeground());
        label.setBackground(getBackground());
        return label;
}
 
Example 8
Source File: LinkLabel.java    From BiglyBT with GNU General Public License v2.0 5 votes vote down vote up
public static void removeLinkedLabel(Label label ) {
	label.setCursor(null );
    label.setForeground(null);
    label.setData( null );
    MouseAdapter ml = (MouseAdapter)label.getData( MOUSE_LISTENER_KEY );
    if ( ml != null ){
    	label.removeMouseListener(ml);
    }
    ClipboardCopy.removeCopyToClipMenu( label );
}
 
Example 9
Source File: BonitaPreferenceDialog.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private void disableAllItems() {
    for (final ToolItem item : itemPerPreferenceNode.values()) {
        item.setEnabled(false);
    }

    for (final Label l : labelPerPreferenceNode.values()) {
        l.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_GRAY));
        l.setFont(BonitaStudioFontRegistry.getNormalFont());
    }
}
 
Example 10
Source File: BonitaPreferenceDialog.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected void cleanHighlights() {
    for (final ToolItem item : itemPerPreferenceNode.values()) {
        item.setEnabled(true);
    }
    for (final Label l : labelPerPreferenceNode.values()) {
        l.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
        l.setFont(BonitaStudioFontRegistry.getNormalFont());
    }
}
 
Example 11
Source File: ClassFileEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private Label createHeadingLabel(Composite parent, String text) {
	Label label = new Label(parent, SWT.NONE);
	if (text != null)
		label.setText(text);
	label.setBackground(fBackgroundColor);
	label.setForeground(fForegroundColor);
	label.setFont(JFaceResources.getBannerFont());
	fBannerLabels.add(label);
	return label;
}
 
Example 12
Source File: XCheckFilteredTreeDialog.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected Control createCustomArea(Composite parent) {

   statusLabel = new Label(parent, SWT.NONE);
   statusLabel.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
   updateStatusLabel();

   createPreCustomArea(parent);

   Composite aiComp = new Composite(parent, SWT.NONE);
   aiComp.setLayout(XViewerLib.getZeroMarginLayout());
   aiComp.setLayoutData(new GridData(GridData.FILL_BOTH));

   treeViewer =
      new XCheckedFilteredTree(aiComp,
         SWT.MULTI | SWT.CHECK | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, patternFilter);
   treeViewer.getViewer().getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
   treeViewer.getViewer().setContentProvider(contentProvider);
   treeViewer.getViewer().setLabelProvider(labelProvider);
   treeViewer.getViewer().setSorter(viewerSorter);
   GridData gd = new GridData(GridData.FILL_BOTH);
   gd.heightHint = 400;
   treeViewer.getViewer().getTree().setLayoutData(gd);
   treeViewer.getViewer().addSelectionChangedListener(event -> updateStatusLabel());
   if (input != null) {
      treeViewer.getViewer().setInput(input);
   }
   if (initialSelections != null) {
      treeViewer.setInitalChecked(initialSelections);
   }
   return parent;
}
 
Example 13
Source File: ReportDocumentEditor.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private Label createScriptgLabel( Composite parent, String text )
{
	Label label = new Label( parent, SWT.NONE );
	if ( text != null )
		label.setText( text );
	label.setBackground( fBackgroundColor );
	label.setForeground( fForegroundColor );
	// label.setFont(JFaceResources.getBannerFont());

	return label;
}
 
Example 14
Source File: SearchDialog.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
private Composite createButtonSection(Composite composite) {

		Composite panel = new Composite(composite, SWT.NONE);
		GridLayout layout= new GridLayout(1,false);
		panel.setLayout(layout);
		
		statusLabel = new Label(panel, SWT.LEFT);
		statusLabel.setForeground(statusLabel.getDisplay().getSystemColor(SWT.COLOR_RED));
		GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(statusLabel);
		
		findButton = createButton(panel, IDialogConstants.CLIENT_ID, "&Find", false);
		GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.BOTTOM).grab(false, false).hint(52, SWT.DEFAULT).applyTo(findButton);
		
		findButton.setEnabled(false);
		getShell().setDefaultButton(findButton);
		
		findButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				doFind();
			}
		});
 		
		Button closeButton = createButton(panel, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
		GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.BOTTOM).grab(false, false).hint(52, SWT.DEFAULT).applyTo(closeButton);
		
		return panel;
	}
 
Example 15
Source File: ClassFileEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private Label createLabel(Composite parent, String text) {
	Label label= new Label(parent, SWT.WRAP);
	if (text != null)
		label.setText(text);
	label.setBackground(fBackgroundColor);
	label.setForeground(fForegroundColor);
	GridData gd= new GridData(SWT.FILL, SWT.FILL, true, false);
	label.setLayoutData(gd);
	return label;
}
 
Example 16
Source File: IndexEditionControl.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private void createLabels() {
    formPage.getToolkit()
            .createLabel(this, Messages.selectIndexFieldsMessages, SWT.WRAP)
            .setLayoutData(GridDataFactory.fillDefaults().create());
    formPage.getToolkit()
            .createLabel(this, Messages.warningTextIndex, SWT.WRAP)
            .setLayoutData(GridDataFactory.fillDefaults().create());

    Label validationLabel = formPage.getToolkit().createLabel(this, "", SWT.WRAP);
    validationLabel.setLayoutData(GridDataFactory.fillDefaults().create());
    validationLabel.setForeground(errorColor);

    indexedFieldNameObservable.addChangeListener(e -> {
        if (selectedIndexObservable.getValue() != null) {
            if (!selectedIndexObservable.getValue().getFieldNames().isEmpty()) {
                validationLabel.setVisible(false);
                ((GridData) validationLabel.getLayoutData()).exclude = true;
            } else {
                validationLabel.setVisible(true);
                ((GridData) validationLabel.getLayoutData()).exclude = false;
                validationLabel.setText(
                        String.format(Messages.indexFieldEmptiness, selectedIndexObservable.getValue().getName()));
            }
            layout();
        }
    });
}
 
Example 17
Source File: ChoiceWidget.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Build the instruction
 */
private void buildInstruction() {
	final Color color = new Color(Display.getCurrent(), 35, 107, 178);
	SWTGraphicUtil.addDisposer(this, color);

	instruction = new Label(this, SWT.NONE);
	instruction.setForeground(color);
	instruction.setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false));
}
 
Example 18
Source File: SpinnerTime.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
private void initComponents( )
{
	hour = new SpinnerTimeText( this,
			SWT.NONE,
			24,
			IPropertyEventConstants.HOUR_CHANGE_EVENT );
	firstLabel = new Label( this, SWT.NONE );
	min = new SpinnerTimeText( this,
			SWT.NONE,
			60,
			IPropertyEventConstants.MIN_CHANGE_EVENT );
	lastLabel = new Label( this, SWT.NONE );
	sec = new SpinnerTimeText( this,
			SWT.NONE,
			60,
			IPropertyEventConstants.SECOND_CHANGE_EVENT );

	//		Font font = new Font( Display.getCurrent( ), "Dialog", 10, SWT.BOLD
	// ); //$NON-NLS-1$
	Font font = FontManager.getFont( "Dialog", 10, SWT.BOLD ); //$NON-NLS-1$

	firstLabel.setBackground( Display.getCurrent( )
			.getSystemColor( SWT.COLOR_WHITE ) );
	lastLabel.setBackground( Display.getCurrent( )
			.getSystemColor( SWT.COLOR_WHITE ) );
	firstLabel.setFont( font );
	lastLabel.setFont( font );

	firstLabel.setForeground( Display.getCurrent( )
			.getSystemColor( SWT.COLOR_BLACK ) );
	lastLabel.setForeground( Display.getCurrent( )
			.getSystemColor( SWT.COLOR_BLACK ) );

	firstLabel.setText( ":" ); //$NON-NLS-1$
	lastLabel.setText( ":" ); //$NON-NLS-1$

	up = new Button( this, SWT.ARROW | SWT.UP );
	down = new Button( this, SWT.ARROW | SWT.DOWN );
	label = new Label( this, SWT.NONE );

	label.setBackground( Display.getCurrent( )
			.getSystemColor( SWT.COLOR_WHITE ) );

	//added by gao 2004.07.08
	//font.dispose( );
}
 
Example 19
Source File: SimpleRoundedComposite.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Clears all existing child elements and adds the provided text to the composite by an implicit
 * creation of {@link Label}s.
 *
 * <p>The added text gets layed out adequately by centering all but the first and last created
 * {@link Label}s.<br>
 * The first one becomes left wheras the last one becomes right aligned.
 *
 * @param texts
 */
public void setTexts(String[] texts) {
  disposeChildren();

  if (texts == null || texts.length == 0) return;

  /*
   * Sets layout Because the number of grid columns depends on the number
   * of text to display, each time you set the texts the layout needs to
   * be recreated.
   */
  GridLayout gridLayout = new GridLayout(texts.length, false);
  gridLayout.horizontalSpacing = 10;
  gridLayout.verticalSpacing = 0;
  gridLayout.marginWidth = MARGIN_WIDTH;
  gridLayout.marginHeight = MARGIN_HEIGHT;
  super.setLayout(gridLayout);

  textLabels = new Label[texts.length];

  // Places the labels
  for (int i = 0; i < texts.length; i++) {
    String text = texts[i];

    // Calculate layout

    int horizontalAlignment = SWT.CENTER;
    if (texts.length > 1 && i == 0) horizontalAlignment = SWT.LEFT;
    else if (texts.length > 1 && i == (texts.length - 1)) horizontalAlignment = SWT.RIGHT;
    boolean grabExcessHorizontalSpace = (i == (texts.length - 1));

    Label label = new Label(this, SWT.WRAP | horizontalAlignment);
    textLabels[i] = label;

    label.setForeground(getForeground());
    label.setBackground(getBackground());
    label.setText(text);

    FontUtils.changeFontSizeBy(label, -1);
    FontUtils.makeBold(label);

    label.setLayoutData(
        new GridData(horizontalAlignment, SWT.BEGINNING, grabExcessHorizontalSpace, false));
  }

  // Explicitly request layout in case the label(s) changed
  layout();
}
 
Example 20
Source File: JsonImportDialog.java    From olca-app with Mozilla Public License 2.0 4 votes vote down vote up
@Override
protected Control createDialogArea(Composite parent) {
	Composite root = (Composite) super.createDialogArea(parent);
	UI.gridLayout(root, 1, 10, 10);

	Composite comp = new Composite(root, SWT.NONE);
	UI.gridLayout(comp, 2, 10, 0);
	UI.formLabel(comp, M.File);
	String fileText = Strings.cut(provider.file.getParent(), 50)
			+ File.separator
			+ Strings.cut(provider.file.getName(), 50);
	Label label = UI.formLabel(comp, fileText);
	label.setForeground(Colors.linkBlue());

	Button openCheck = new Button(root, SWT.RADIO);
	openCheck.setText("Open mapping definition");
	Combo combo = new Combo(root, SWT.READ_ONLY);
	Controls.onSelect(combo, e -> {
		selectedMap = flowMaps.get(combo.getSelectionIndex());
	});
	UI.gridData(combo, true, false);
	Controls.onSelect(openCheck, e -> {
		selectedMap = flowMaps.get(combo.getSelectionIndex());
		combo.setEnabled(true);
	});

	Button genCheck = new Button(root, SWT.RADIO);
	genCheck.setText("Generate mapping based on flow attributes");
	Controls.onSelect(genCheck, e -> {
		selectedMap = null;
		combo.setEnabled(false);
	});

	if (flowMaps.isEmpty()) {
		genCheck.setSelection(true);
		openCheck.setSelection(false);
		combo.setEnabled(false);
		openCheck.setEnabled(false);
	} else {
		openCheck.setSelection(true);
		genCheck.setSelection(false);
		String[] items = this.flowMaps
				.stream()
				.map(m -> m.name)
				.toArray(len -> new String[len]);
		combo.setItems(items);
		combo.select(0);
		selectedMap = flowMaps.get(0);
	}
	return root;
}