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

The following examples show how to use org.eclipse.swt.widgets.Label#computeSize() . 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: ActiveControl.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * create a new field
 * 
 * @param parent
 *            the parent Composite
 * @param show
 *            ho to display the label
 */
public ActiveControl(Composite parent, int displayBits, String displayName){
	super(parent, SWT.NONE);
	if ((displayBits & (DISPLAY_HORIZONTAL | HIDE_LABEL)) == DISPLAY_HORIZONTAL) {
		setLayout(new GridLayout(3, false));
	} else {
		setLayout(new GridLayout(2, false));
	}
	flags = displayBits;
	labelContents = displayName == null ? "" : displayName;
	if ((displayBits & HIDE_LABEL) == 0) {
		lbl = new Label(this, SWT.NONE);
		lbl.setText(displayName);
		
		setData(PROP_DISPLAYNAME, displayName);
		controllers = new Composite(this, SWT.NONE);
		// controllers.setBackground(Desk.getColor(Desk.COL_GREEN));
		GridData gd = new GridData(SWT.RIGHT, SWT.BOTTOM, false, false);
		Point size = lbl.computeSize(SWT.DEFAULT, SWT.DEFAULT);
		gd.heightHint = size.y;
		controllers.setLayoutData(gd);
		controllers.setLayout(new FillLayout());
		lbl.setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));
	}
}
 
Example 2
Source File: Day.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private void initialize() {
	GridData gd = new GridData();
	gd.horizontalSpan = 2;
	gd.verticalAlignment = GridData.FILL;
	gd.grabExcessVerticalSpace = true;
	gd.grabExcessHorizontalSpace = true;
	gd.horizontalAlignment = GridData.FILL;
	GridData gridData = new GridData();
	gridData.horizontalAlignment = GridData.FILL;
	gridData.grabExcessHorizontalSpace = true;
	gridData.verticalAlignment = GridData.CENTER;
	spacer = new Label(this, SWT.NONE);
	spacer.setLayoutData(gridData);
	spacer.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
	GridLayout gridLayout = new GridLayout();
	gridLayout.numColumns = 2;
	gridLayout.verticalSpacing = 0;
	dayNumber = new Label(this, SWT.NONE);
	dayNumber.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
	dayNumber.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_SELECTION));
	dayNumber.setText("31");
	textBounds = dayNumber.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
	this.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
	this.setLayout(gridLayout);
	setSize(new org.eclipse.swt.graphics.Point(106, 101));
	setBackground(CELL_BACKGROUND_LIGHT);
}
 
Example 3
Source File: AccountsPanel.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
void createAccountsPane(Composite accountArea) {
  for (Account account : loginService.getAccounts()) {
    Composite accountRow = new Composite(accountArea, SWT.NONE);
    Label avatar = new Label(accountRow, SWT.NONE);
    Composite secondColumn = new Composite(accountRow, SWT.NONE);
    Label name = new Label(secondColumn, SWT.LEAD);
    Label email = new Label(secondColumn, SWT.LEAD);
    Label separator = new Label(accountArea, SWT.HORIZONTAL | SWT.SEPARATOR);
    separator.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));

    // <Avatar size> = 3 * <email label height>
    Point emailSize = email.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    int avatarSize = emailSize.y * 3;

    GridDataFactory.swtDefaults().hint(avatarSize, avatarSize).applyTo(avatar);
    GridLayoutFactory.fillDefaults().numColumns(2).applyTo(accountRow);
    GridLayoutFactory.fillDefaults().generateLayout(secondColumn);

    if (account.getName() != null) {
      name.setText(account.getName());
    }
    email.setText(account.getEmail());  // email is never null.

    if (account.getAvatarUrl() != null) {
      try {
        imageLoader.loadImage(account.getAvatarUrl() + "=s" + avatarSize, avatar);
      } catch (MalformedURLException ex) {
        logger.log(Level.WARNING, "malformed avatar image URL", ex);
      }
    }
  }
}
 
Example 4
Source File: TimeGraphFindDialog.java    From tracecompass with Eclipse Public License 2.0 5 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) {

    Composite panel = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    panel.setLayout(layout);

    fStatusLabel = new Label(panel, SWT.LEFT);
    fStatusLabel.setText(Messages.TimeGraphFindDialog_StatusWrappedLabel);
    setGridData(fStatusLabel, SWT.FILL, true, SWT.CENTER, false);
    GridData gd = (GridData) fStatusLabel.getLayoutData();
    gd.widthHint = fStatusLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
    fStatusLabel.setText("");  //$NON-NLS-1$

    Composite buttonSection = new Composite(panel, SWT.NULL);
    GridLayout buttonLayout = new GridLayout();
    buttonLayout.numColumns = 2;
    buttonSection.setLayout(buttonLayout);

    String label = Messages.TimeGraphFindDialog_CloseButtonLabel;
    Button closeButton = createButton(buttonSection, 101, label, false);
    setGridData(closeButton, SWT.RIGHT, false, SWT.BOTTOM, false);

    fFindNextButton = makeButton(buttonSection, Messages.TimeGraphFindDialog_FindNextButtonLabel, 102, true, new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            performSearch(((e.stateMask & SWT.SHIFT) != 0) ^ isForwardSearch());
            updateFindHistory();
        }
    });
    setGridData(fFindNextButton, SWT.FILL, true, SWT.FILL, false);

    return panel;
}
 
Example 5
Source File: TmfAbstractToolTipHandler.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Point create() {
    Composite parent = getParent();
    Table<ToolTipString, ToolTipString, ToolTipString> model = getModel();
    if (parent == null || model.size() == 0) {
        // avoid displaying empty tool tips.
        return null;
    }
    setupControl(parent);
    ScrolledComposite scrolledComposite = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
    scrolledComposite.setExpandVertical(true);
    scrolledComposite.setExpandHorizontal(true);
    setupControl(scrolledComposite);

    Composite composite = new Composite(scrolledComposite, SWT.NONE);
    fComposite = composite;
    composite.setLayout(new GridLayout(3, false));
    setupControl(composite);
    Set<ToolTipString> rowKeySet = model.rowKeySet();
    for (ToolTipString row : rowKeySet) {
        Set<Entry<ToolTipString, ToolTipString>> entrySet = model.row(row).entrySet();
        for (Entry<ToolTipString, ToolTipString> entry : entrySet) {
            Label nameLabel = new Label(composite, SWT.NO_FOCUS);
            nameLabel.setText(entry.getKey().toString());
            setupControl(nameLabel);
            Label separator = new Label(composite, SWT.NO_FOCUS | SWT.SEPARATOR | SWT.VERTICAL);
            GridData gd = new GridData(SWT.CENTER, SWT.CENTER, false, false);
            gd.heightHint = nameLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
            separator.setLayoutData(gd);
            setupControl(separator);
            Label valueLabel = new Label(composite, SWT.NO_FOCUS);
            valueLabel.setText(entry.getValue().toString());
            setupControl(valueLabel);
        }
    }
    scrolledComposite.setContent(composite);
    Point preferredSize = computePreferredSize();
    scrolledComposite.setMinSize(preferredSize.x, preferredSize.y);
    return preferredSize;
}
 
Example 6
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 7
Source File: MessageModal.java    From Universal-FE-Randomizer with MIT License 4 votes vote down vote up
public MessageModal(Shell parent, String title, String message) {
	display = Display.getDefault();
	yuneImage = new Image(display, Main.class.getClassLoader().getResourceAsStream("YuneIcon_100x100.png"));
	
	dialogShell = new Shell(parent, SWT.PRIMARY_MODAL | SWT.DIALOG_TRIM);
	dialogShell.setText(title);
	dialogShell.setImage(yuneImage);
	
	dialogShell.addListener(SWT.CLOSE, new Listener() {

		@Override
		public void handleEvent(Event event) {
			event.doit = false;
		}
		
	});
	
	FormLayout mainLayout = new FormLayout();
	mainLayout.marginWidth = 5;
	mainLayout.marginHeight = 5;
	dialogShell.setLayout(mainLayout);
	
	imageLabel = new Label(dialogShell, SWT.NONE);
	imageLabel.setImage(yuneImage);
	
	FormData imageData = new FormData(100, 100);
	imageData.left = new FormAttachment(0, 10);
	imageData.top = new FormAttachment(0, 10);
	imageLabel.setLayoutData(imageData);
	
	contentGroup = new Composite(dialogShell, SWT.NONE);
	FormLayout contentLayout = new FormLayout();
	contentLayout.marginTop = 5;
	contentLayout.marginLeft = 5;
	contentLayout.marginBottom = 5;
	contentLayout.marginRight = 5;
	contentGroup.setLayout(contentLayout);
	
	titleLabel = new Label(contentGroup, SWT.LEFT);
	titleLabel.setText(title);
	FontData normalFont = titleLabel.getFont().getFontData()[0];
	Font boldFont = new Font(display, normalFont.getName(), normalFont.getHeight(), SWT.BOLD);
	titleLabel.setFont(boldFont);
	
	FormData titleData = new FormData();
	titleData.top = new FormAttachment(0, 0);
	titleData.left = new FormAttachment(0, 0);
	titleData.right = new FormAttachment(100, 0);
	titleLabel.setLayoutData(titleData);
	
	descriptionLabel = new Label(contentGroup, SWT.LEFT | SWT.WRAP);
	descriptionLabel.setText(message);
	
	FormData descriptionData = new FormData();
	descriptionData.left = new FormAttachment(titleLabel, 0, SWT.LEFT);
	descriptionData.right = new FormAttachment(titleLabel, 0, SWT.RIGHT);
	descriptionData.top = new FormAttachment(titleLabel, 10);
	descriptionData.bottom = new FormAttachment(100, -5);
	Point expectedSize = descriptionLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT);
	descriptionData.width = Math.max(200, expectedSize.x);
	descriptionData.height = Math.max(60, expectedSize.y);
	descriptionLabel.setLayoutData(descriptionData);
	
	FormData groupData = new FormData();
	groupData.left = new FormAttachment(imageLabel, 10);
	groupData.top = new FormAttachment(imageLabel, 0, SWT.TOP);
	groupData.right = new FormAttachment(100, -10);
	contentGroup.setLayoutData(groupData);
	
	layoutSize();
	Rectangle parentBounds = parent.getBounds();
	Rectangle dialogBounds = dialogShell.getBounds();
	
	dialogShell.setLocation(parentBounds.x + (parentBounds.width - dialogBounds.width) / 2, parentBounds.y + (parentBounds.height - dialogBounds.height) / 2);
}
 
Example 8
Source File: DataSetComputedColumnsPage.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
private int computeMaxWidth( Label label )
{
	int widthHint = label.computeSize( -1, -1 ).x
			- label.getBorderWidth( );
	return widthHint > this.maxWidth ? widthHint : this.maxWidth;
}
 
Example 9
Source File: MeasureDialog.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
private void createArgumentUI( )
{
    IAggrFunction function = getSelectedFunction( );
    if ( function != null )
    {
        IParameterDefn[] params = function.getParameterDefn( );
        if ( params != null && params.length > 0 )
        {

            ( (GridData) paramsComposite.getLayoutData( ) ).exclude = false;
            ( (GridData) paramsComposite.getLayoutData( ) ).heightHint = SWT.DEFAULT;

            int width = getMaxLabelWidth( parent );

            for ( final IParameterDefn param : params )
            {
                String paramName =      DataAdapterUtil.adaptArgumentName(param.getName( ) );
                //Expression is handled as measureExpression 
                if ( ARGUMENT_EXPRESSION.equals( paramName ) )
                {
                    continue;
                }
                        
                Label lblParam = new Label( paramsComposite, SWT.NONE );
                lblParam.setText(
                        param.getDisplayName( ) + Messages.getString( "MeasureDialog.Text.Colon" ) ); //$NON-NLS-1$
                GridData gd = new GridData( );
                gd.widthHint = lblParam.computeSize( SWT.DEFAULT, SWT.DEFAULT ).x;
                if ( gd.widthHint < width )
                    gd.widthHint = width;
                lblParam.setLayoutData( gd );

                if ( param.isDataField( ) )
                {
                    createComboControl( paramsComposite, param );
                }

                else
                {
                    createTextControl( paramsComposite, param );
                }
            }
        }
    }
}