Example usage for org.eclipse.jface.dialogs Dialog convertWidthInCharsToPixels

List of usage examples for org.eclipse.jface.dialogs Dialog convertWidthInCharsToPixels

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs Dialog convertWidthInCharsToPixels.

Prototype

public static int convertWidthInCharsToPixels(FontMetrics fontMetrics, int chars) 

Source Link

Document

Returns the number of pixels corresponding to the width of the given number of characters.

Usage

From source file:net.bpelunit.toolsupport.editors.wizards.components.OperationDataComponent.java

License:Open Source License

@Override
public Composite createControls(Composite composite, int nColumns) {

    String niceName = ActivityUtil.getNiceName(this.fActivity) + " operation";
    Group operationGroup = this.createGroup(composite, niceName, nColumns,
            new GridData(SWT.FILL, SWT.BEGINNING, true, false));

    this.fServiceDialogField.doFillIntoGrid(operationGroup, nColumns);
    Text text0 = this.fServiceDialogField.getTextControl(null);
    LayoutUtil.setWidthHint(text0, this.getMaxFieldWidth());
    LayoutUtil.setHorizontalGrabbing(text0);

    this.fPortDialogField.doFillIntoGrid(operationGroup, nColumns);
    Text text1 = this.fPortDialogField.getTextControl(null);
    LayoutUtil.setWidthHint(text1, Dialog.convertWidthInCharsToPixels(this.getFontMetrics(), 30));

    this.fOperationDialogField.doFillIntoGrid(operationGroup, nColumns);
    Text text2 = this.fOperationDialogField.getTextControl(null);
    LayoutUtil.setWidthHint(text2, Dialog.convertWidthInCharsToPixels(this.getFontMetrics(), 30));

    if (ActivityUtil.isReceiveFirstActivity(this.fActivity)) {
        this.fReceiveFaultField.doFillIntoGrid(operationGroup, nColumns);
    } else {//w  w w .j  ava  2  s.c  om
        this.fOutputDialogField.doFillIntoGrid(operationGroup, nColumns);
    }

    if (ActivityUtil.isTwoWayActivity(this.fActivity)) {
        if (ActivityUtil.isReceiveFirstActivity(this.fActivity)) {
            this.fOutputDialogField.doFillIntoGrid(operationGroup, nColumns);
        } else {
            this.fReceiveFaultField.doFillIntoGrid(operationGroup, nColumns);
        }
    }

    return operationGroup;
}

From source file:net.certiv.fluentmark.preferences.AbstractConfigurationBlock.java

License:Open Source License

/**
 * Returns the number of pixels corresponding to the width of the given number of characters.
 * <p>/*from  w w w . j a  va  2s .c  om*/
 * This method may only be called after <code>initializeDialogUnits</code> has been called.
 * </p>
 * <p>
 * Clients may call this framework method, but should not override it.
 * </p>
 *
 * @param chars the number of characters
 * @return the number of pixels
 */
protected int convertWidthInCharsToPixels(int chars) {
    if (fFontMetrics == null)
        return 0;
    return Dialog.convertWidthInCharsToPixels(fFontMetrics, chars);
}

From source file:net.refractions.udig.style.sld.AbstractSimpleConfigurator.java

License:Open Source License

/**
 * Construct a subpart labeled with the provided tag.
 * <p>/*from  w w  w  .j  ava 2 s  .c o m*/
 * Creates a composite with a grid layout of the specifed columns,
 * and a label with text from label.
 * </p>
 * @param parent
 * @param label
 * @return Composite with one label 
 */
public static Composite subpart(Composite parent, String label) {
    Composite subpart = new Composite(parent, SWT.NONE);
    RowLayout across = new RowLayout();
    across.type = SWT.HORIZONTAL;
    across.wrap = true;
    across.pack = true;
    across.fill = true;
    across.marginBottom = 1;
    across.marginRight = 2;

    subpart.setLayout(across);

    Label labell = new Label(subpart, SWT.LEFT);
    labell.setText(label);

    RowData data = new RowData();
    data.width = 40;
    //check to see if width is not enough space
    GC gc = new GC(parent.getParent());
    gc.setFont(parent.getParent().getFont());
    FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();
    int labelWidth = Dialog.convertWidthInCharsToPixels(fontMetrics, labell.getText().length() + 1);
    if (labelWidth > data.width) {
        data.width = labelWidth;
    }
    // TODO: adjust the methods that call this one to keep a consistent
    // width (otherwise they're misaligned)
    data.height = 10;
    labell.setLayoutData(data);

    return subpart;
}

From source file:org.codehaus.groovy.eclipse.dsl.inferencing.suggestions.ui.AbstractDialogue.java

License:Apache License

protected Point getOffsetLabelLocation(String[] labels) {

    int length = SWT.DEFAULT;
    int charLength = 0;

    for (String label : labels) {
        int nameLength = label.length();
        if (nameLength > charLength) {
            charLength = nameLength;/*from   ww  w .ja v a 2s  .co m*/
        }
    }
    if (charLength > 0) {
        Control control = getShell();
        GC gc = new GC(control);
        Font requiredLabelFont = getRequiredParameterFont();
        gc.setFont(requiredLabelFont != null ? requiredLabelFont : control.getFont());
        FontMetrics fontMetrics = gc.getFontMetrics();
        length = Dialog.convertWidthInCharsToPixels(fontMetrics, charLength);
        gc.dispose();
    }
    Point longestLabelWidth = new Point(length, -1);
    longestLabelWidth.x += getLabelNameSeparatorOffset();
    return longestLabelWidth;
}

From source file:org.cs3.prolog.ui.util.OptionEditor.java

License:Open Source License

protected int convertWidthInCharsToPixels(int chars) {
    GC gc = new GC(parent);
    int c = Dialog.convertWidthInCharsToPixels(gc.getFontMetrics(), chars);
    gc.dispose();/*from  ww w .j a va 2  s.  co  m*/
    return c;

}

From source file:org.eclipse.cdt.debug.internal.ui.PixelConverter.java

License:Open Source License

/**
 * @see org.eclipse.jface.dialogs.DialogPage#convertWidthInCharsToPixels(int)
 *///from  www. j  av a2  s.  c o  m
public int convertWidthInCharsToPixels(int chars) {
    return Dialog.convertWidthInCharsToPixels(getFontMetrics(), chars);
}

From source file:org.eclipse.cdt.internal.autotools.ui.properties.AutotoolsToolPropertyOptionPage.java

License:Open Source License

protected void createFieldEditors() {
    super.createFieldEditors();
    // Add a string editor to edit the tool command
    Composite parent = getFieldEditorParent();
    FontMetrics fm = AbstractCPropertyTab.getFontMetrics(parent);
    commandStringField = new StringFieldEditor(toolName, ConfigureMessages.getString(COMMAND), parent);
    commandStringField.setEmptyStringAllowed(false);
    GridData gd = ((GridData) commandStringField.getTextControl(parent).getLayoutData());
    gd.grabExcessHorizontalSpace = true;
    gd.minimumWidth = Dialog.convertWidthInCharsToPixels(fm, 3);
    addField(commandStringField);//  ww  w  .  j  a  va 2  s  .  com
    // Add a field editor that displays overall build options
    Composite par = getFieldEditorParent();
    allOptionFieldEditor = new MultiLineTextFieldEditor(AutotoolsConfigurePrefStore.ALL_OPTIONS_ID,
            ConfigureMessages.getString(ALL_OPTIONS), par);
    allOptionFieldEditor.getTextControl(par).setEditable(false);
    //      gd = ((GridData)allOptionFieldEditor.getTextControl().getLayoutData());
    gd.grabExcessHorizontalSpace = true;
    gd.minimumWidth = Dialog.convertWidthInCharsToPixels(fm, 20);
    addField(allOptionFieldEditor);
}

From source file:org.eclipse.cdt.managedbuilder.ui.properties.BuildToolSettingUI.java

License:Open Source License

@Override
protected void createFieldEditors() {

    // Load up the preference store
    super.createFieldEditors();
    // Add a string editor to edit the tool command
    Composite parent = getFieldEditorParent();
    FontMetrics fm = AbstractCPropertyTab.getFontMetrics(parent);
    commandStringField = new StringFieldEditor(fTool.getId(), Messages.BuildToolSettingsPage_tool_command,
            parent);/*  w w  w.ja  v a 2  s .  c o m*/
    commandStringField.setEmptyStringAllowed(false);
    GridData gd = ((GridData) commandStringField.getTextControl(parent).getLayoutData());
    gd.grabExcessHorizontalSpace = true;
    gd.minimumWidth = Dialog.convertWidthInCharsToPixels(fm, 3);
    addField(commandStringField);
    // Add a field editor that displays overall build options
    Composite par = getFieldEditorParent();
    allOptionFieldEditor = new MultiLineTextFieldEditor(ToolSettingsPrefStore.ALL_OPTIONS_ID, ALL_OPTIONS, par);
    allOptionFieldEditor.getTextControl(par).setEditable(false);
    //      gd = ((GridData)allOptionFieldEditor.getTextControl().getLayoutData());
    gd.grabExcessHorizontalSpace = true;
    gd.minimumWidth = Dialog.convertWidthInCharsToPixels(fm, 20);
    addField(allOptionFieldEditor);

    addField(createLabelEditor(getFieldEditorParent(), WHITESPACE));
    addField(createLabelEditor(getFieldEditorParent(), Messages.BuildToolSettingsPage_tool_advancedSettings));

    // Add a string editor to edit the tool command line pattern
    parent = getFieldEditorParent();
    commandLinePatternField = new StringFieldEditor(fTool.getId() + ToolSettingsPrefStore.COMMAND_LINE_SUFFIX,
            Messages.BuildToolSettingsPage_tool_commandLinePattern, parent);
    gd = ((GridData) commandLinePatternField.getTextControl(parent).getLayoutData());
    gd.grabExcessHorizontalSpace = true;
    gd.widthHint = Dialog.convertWidthInCharsToPixels(fm, 30);
    gd.minimumWidth = Dialog.convertWidthInCharsToPixels(fm, 20);
    addField(commandLinePatternField);
}

From source file:org.eclipse.emf.compare.ui.viewer.content.part.property.ModelContentMergePropertyTab.java

License:Open Source License

/**
 * Creates a table viewer on a newly-created table control under the given parent. The table control is
 * created using the given style bits./*from  ww  w  . j  a  va2 s  .  c  om*/
 * 
 * @param parentComposite
 *            the parent control.
 * @param side
 *            Side of this viewer part.
 * @param parentFolder
 *            Parent folder of this tab.
 */
public ModelContentMergePropertyTab(Composite parentComposite, int side,
        ModelContentMergeTabFolder parentFolder) {
    super(parentComposite, SWT.NONE);
    partSide = side;
    parent = parentFolder;

    setContentProvider(new PropertyContentProvider());
    setLabelProvider(new PropertyLabelProvider(AdapterUtils.getAdapterFactory()));
    getTable().addPaintListener(new PropertyPaintListener());

    setUseHashlookup(true);
    getTable().setLinesVisible(true);
    getTable().setHeaderVisible(true);

    final GC gc = new GC(getTable());
    gc.setFont(getTable().getFont());
    final FontMetrics metrics = gc.getFontMetrics();
    gc.dispose();

    final TableColumn nameColumn = new TableColumn(getTable(), SWT.LEFT);
    nameColumn.setText(EMFCompareUIMessages.getString("ModelContentMergePropertyPart.column1.name")); //$NON-NLS-1$
    nameColumn.setWidth(Dialog.convertWidthInCharsToPixels(metrics, nameColumn.getText().length() * 3));
    final TableColumn weightsColumn = new TableColumn(getTable(), SWT.RIGHT);
    weightsColumn.setText(EMFCompareUIMessages.getString("ModelContentMergePropertyPart.column2.name")); //$NON-NLS-1$
    weightsColumn.setWidth(Dialog.convertWidthInCharsToPixels(metrics, weightsColumn.getText().length() * 3));

    mapDifferences();
}

From source file:org.eclipse.equinox.internal.p2.ui.dialogs.IUPropertyPage.java

License:Open Source License

protected int computeWidthLimit(Control control, int nchars) {
    GC gc = new GC(control);
    gc.setFont(control.getFont());//from  ww  w .  java2 s .com
    FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();
    return Dialog.convertWidthInCharsToPixels(fontMetrics, nchars);
}