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

The following examples show how to use org.eclipse.swt.widgets.Label#setData() . 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: ValidPreferenceCheckedTreeViewer.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Adds a line of information to <code>parent</code>. If <code>icon</code> is not <code>null</code>, an icon is placed on
 * the left, and then a label with <code>text</code>.
 *
 * @param parent
 *          the composite to add the entry to
 * @param icon
 *          the icon to place next to the text. <code>null</code> for none.
 * @param text
 *          the text to display
 * @return the created label
 */
protected Label createEntry(final Composite parent, final Image icon, final String text) {
  if (icon != null) {
    final Label iconLabel = new Label(parent, SWT.NONE);
    iconLabel.setImage(icon);
    iconLabel.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
    iconLabel.setData(new GridData());
  }

  final Label textLabel = new Label(parent, SWT.WRAP);

  if (icon == null) {
    GridDataFactory.generate(textLabel, 2, 1);
  } else {
    GridDataFactory.generate(textLabel, 1, 1);
  }

  textLabel.setText(text);
  textLabel.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
  return textLabel;
}
 
Example 2
Source File: OptionsConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected void highlight(final Composite parent, final Label labelControl, final Combo comboBox, final int color) {
	Object data= labelControl.getData();
	if (data == null) {
		if (color != HIGHLIGHT_NONE) {
			PaintListener painter= new HighlightPainter(parent, labelControl, comboBox, color);
			parent.addPaintListener(painter);
			labelControl.setData(painter);
		} else {
			return;
		}
	} else {
		if (color == HIGHLIGHT_NONE) {
			parent.removePaintListener((PaintListener) data);
			labelControl.setData(null);
		} else if (color != ((HighlightPainter) data).fColor){
			((HighlightPainter) data).fColor= color;
		} else {
			return;
		}
	}
	
	parent.redraw();
}
 
Example 3
Source File: CustomPreviewTable.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private void addHeaderSplitter( )
{
	Label splitter = new Label( cmpHeaders, SWT.NONE );
	FormData fd = new FormData( );
	fd.top = new FormAttachment( 2 );
	int i = btnHeaders.size( );
	if ( i == 0 )
	{
		fd.left = new FormAttachment( 0 );
	}
	else
	{
		Button btnNeighbor = btnHeaders.get( i - 1 );
		fd.left = new FormAttachment( btnNeighbor );
	}
	fd.width = SPLITTER_WIDTH;
	splitter.setLayoutData( fd );
	splitter.setData( Integer.valueOf( i - 1 ) );
	splitter.addMouseListener( this );
	splitter.addMouseMoveListener( this );
}
 
Example 4
Source File: MainPage.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void createContent ( final Composite parent )
{
    parent.setLayout ( new GridLayout ( 1, false ) );

    final Label label = new Label ( parent, SWT.NONE );
    label.setText ( System.getProperty ( Properties.MAIN_PAGE_TEXT, "Administration Console" ) );
    label.setData ( RWT.CUSTOM_VARIANT, "mainLabel" );

    final GridData gd = new GridData ( SWT.CENTER, SWT.BEGINNING, true, true );
    gd.verticalIndent = 20;
    label.setLayoutData ( gd );
}
 
Example 5
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 6
Source File: DateChooser.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
Cell(Composite parent, int idx) {
	label = new Label(parent, SWT.CENTER);
	index = idx;
	label.addListener(SWT.MouseDown, listener);
	label.setData(this);
}
 
Example 7
Source File: LinkSwtParameter.java    From BiglyBT with GNU General Public License v2.0 4 votes vote down vote up
public LinkSwtParameter(Composite composite, String name_resource,
		String labelKey, String url) {
	super(name_resource);

	if (labelKey != null) {
		Label label = new Label(composite, SWT.NONE);
		Messages.setLanguageText(label, labelKey);
		setRelatedControl(label);
	}

	link_label = new Label(composite, SWT.WRAP);
	setMainControl(link_label);
	this.url = url;
	Messages.setLanguageText(link_label, name_resource);
	Display display = link_label.getDisplay();
	link_label.setCursor(display.getSystemCursor(SWT.CURSOR_HAND));
	link_label.setForeground(display.getSystemColor(SWT.COLOR_LINK_FOREGROUND));
	link_label.addListener(SWT.MouseUp, e -> {
		if (e.button == 1) {
			triggerChangeListeners(false);
		} else {
			e.doit = true;
		}
	});
	link_label.addListener(SWT.MouseDoubleClick,
			e -> triggerChangeListeners(false));
	link_label.setData(url);
	ClipboardCopy.addCopyToClipMenu(link_label);

	if (doGridData(composite) && labelKey == null) {
		GridLayout parentLayout = (GridLayout) composite.getLayout();
		if (parentLayout.numColumns >= 2) {
			GridData gridData = Utils.getWrappableLabelGridData(2,
					GridData.FILL_HORIZONTAL);
			link_label.setLayoutData(gridData);
		} else {
			link_label.setLayoutData(new GridData());
		}
	}

	if (url != null) {
		Utils.setTT(link_label, url);
	}
}
 
Example 8
Source File: LinkLabel.java    From BiglyBT with GNU General Public License v2.0 4 votes vote down vote up
public static void updateLinkedLabel(Label label, String hyperlink) {
	label.setData(hyperlink);
	Utils.setTT(label,hyperlink);
}
 
Example 9
Source File: DecoratedStringChooser.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
public DecoratedStringChooser(Composite parent, final Settings cfg,
	final DecoratedString[] strings){
	super(parent, SWT.BORDER);
	
	int num = strings.length;
	int typRows = ((int) Math.sqrt(num));
	int typCols = typRows + (num - (typRows * typRows));
	if (typCols < 4) {
		typCols = 4;
	}
	setLayout(new GridLayout(typCols, true));
	Label expl = new Label(this, SWT.WRAP);
	expl.setText(Messages.DecoratedStringChooser_howToChange); //$NON-NLS-1$
	expl.setLayoutData(SWTHelper.getFillGridData(typCols, false, 1, false));
	for (int i = 0; i < num; i++) {
		Label lab = new Label(this, SWT.NONE);
		lab.setText(strings[i].getText());
		lab.setData(strings[i].getValue());
		
		String coldesc;
		if(strings[i].getValue() != null) {
			coldesc = cfg.get(strings[i].getValue(), "FFFFFF"); //$NON-NLS-1$
		} else {
			coldesc = cfg.get(strings[i].getText(), "FFFFFF"); //$NON-NLS-1$
		}

		Color background = UiDesk.getColorFromRGB(coldesc);
		lab.setBackground(background);
		GridData gd = new GridData(GridData.FILL_BOTH);
		lab.setLayoutData(gd);
		lab.addMouseListener(new MouseAdapter() {
			
			@Override
			public void mouseDoubleClick(MouseEvent e){
				ColorDialog cd = new ColorDialog(getShell());
				Label l = (Label) e.getSource();
				RGB selected = cd.open();
				if (selected != null) {
					String symbolic = UiDesk.createColor(selected);
					l.setBackground(UiDesk.getColorFromRGB(symbolic));
					if(l.getData() != null) {
						cfg.set((String) l.getData(), symbolic);
					} else {
						cfg.set(l.getText(), symbolic);
					}
				}
			}
			
		});
	}
}