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

The following examples show how to use org.eclipse.swt.widgets.Label#getFont() . 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: SWTUtils.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Update the width of the label to take into account the error font. Only works for labels in a grid layout
 * 
 * @param label
 * @param errorFont
 */
public static void updateErrorLabelWidth(Label label, Font errorFont)
{
	Object layoutData = label.getLayoutData();
	if (layoutData instanceof GridData)
	{
		Font currentFont = label.getFont();
		label.setFont(errorFont);
		((GridData) layoutData).widthHint = label.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
		label.setFont(currentFont);
	}
}
 
Example 2
Source File: TaskSelectionPage.java    From CogniCrypt with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void createControl(final Composite parent) {
	final List<Task> tasks = TaskJSONReader.getTasks();

	final ScrolledComposite sc = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
	sc.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

	this.container = new Composite(sc, SWT.NONE);
	this.container.setBounds(10, 10, 450, 200);

	//To display the Help view after clicking the help icon
	PlatformUI.getWorkbench().getHelpSystem().setHelp(sc, "de.cognicrypt.codegenerator.TaskSelectionHelp");

	final GridLayout gl = new GridLayout(2, false);
	gl.verticalSpacing = -6;
	this.container.setLayout(gl);

	new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1);
	new Label(this.container, SWT.NONE);
	final Label useCaseDescriptionLabel = new Label(this.container, SWT.WRAP);
	final GridData gd_selectProjectLabel = new GridData(SWT.FILL, SWT.FILL, false, false, 1, tasks.size() + 1);
	gd_selectProjectLabel.heightHint = 200;
	gd_selectProjectLabel.widthHint = 600;
	useCaseDescriptionLabel.setLayoutData(gd_selectProjectLabel);
	Font a = useCaseDescriptionLabel.getFont();
	useCaseDescriptionLabel.setFont(new Font(useCaseDescriptionLabel.getDisplay(), new FontData(a.getFontData()[0].getName(), 12, SWT.None)));

	final List<Button> buttons = new ArrayList<Button>();
	final List<Image> unclickedImages = new ArrayList<Image>();
	new Label(this.container, SWT.NONE);
	for (Task ccTask : tasks) {
		final Image taskImage = loadImage(ccTask.getImage());
		unclickedImages.add(taskImage);

		final Button taskButton = createImageButton(this.container, taskImage, ccTask.getDescription());
		buttons.add(taskButton);
	}
	buttons.stream().forEach(e -> e.addListener(SWT.Selection, new SelectionButtonListener(buttons, unclickedImages, tasks, useCaseDescriptionLabel)));
	buttons.get(0).notifyListeners(SWT.Selection, new Event());

	setControl(this.container);
	new Label(this.container, SWT.NONE);
	new Label(this.container, SWT.NONE);

	sc.setContent(this.container);
	sc.setExpandHorizontal(true);
	sc.setExpandVertical(true);
	sc.setMinSize(this.container.computeSize(SWT.DEFAULT, SWT.DEFAULT));
	setControl(sc);
}
 
Example 3
Source File: MigrationTaskView.java    From depan with Apache License 2.0 4 votes vote down vote up
/**
 * Construct the GUI under the given parent.
 *
 * @param parent the parent Composite.
 * @return the top level widget.
 */
private Composite setupComposite(Composite parent) {
  // widgets
  Composite topLevel = new Composite(parent, SWT.NONE);

  Label labelId = new Label(topLevel, SWT.NONE);
  id = new Label(topLevel, SWT.NONE);
  Label labelName = new Label(topLevel, SWT.NONE);
  name = new Label(topLevel, SWT.NONE);
  Label labelDescription = new Label(topLevel, SWT.NONE);
  description = new Label(topLevel, SWT.NONE);
  Label labelQuarter = new Label(topLevel, SWT.NONE);
  quarter = new Label(topLevel, SWT.NONE);
  Label labelUpdatedBy = new Label(topLevel, SWT.NONE);
  updatedBy = new Label(topLevel, SWT.NONE);

  // content
  labelId.setText("ID");
  labelName.setText("Name");
  labelDescription.setText("Description");
  labelQuarter.setText("Quarter");
  labelUpdatedBy.setText("Updated by");

  // layout
  GridLayout layout = new GridLayout(2, false);
  layout.horizontalSpacing = 22;
  layout.verticalSpacing = 9;
  topLevel.setLayout(layout);
  id.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
  name.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
  description.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
  quarter.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
  updatedBy.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

  Font font = name.getFont();
  FontDescriptor bold = FontDescriptor.createFrom(font);
  bold = bold.setStyle(SWT.BOLD);
  FontDescriptor big = bold.setHeight(18);
  Font boldFont = bold.createFont(font.getDevice());

  name.setFont(big.createFont(font.getDevice()));
  id.setFont(boldFont);
  description.setFont(boldFont);
  quarter.setFont(boldFont);
  updatedBy.setFont(boldFont);

  return topLevel;
}