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

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

Introduction

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

Prototype

public static int convertHeightInCharsToPixels(FontMetrics fontMetrics, int chars) 

Source Link

Document

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

Usage

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

License:Open Source License

protected int computeHeightLimit(Control control, int nchars) {
    GC gc = new GC(control);
    gc.setFont(control.getFont());/*from   w w  w . j a v a2  s  . co  m*/
    FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();
    return Dialog.convertHeightInCharsToPixels(fontMetrics, nchars);
}

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

License:Open Source License

protected int convertHeightInCharsToPixels(int dlus) {
    return Dialog.convertHeightInCharsToPixels(fm, dlus);
}

From source file:org.eclipse.jdt.debug.ui.breakpoints.JavaBreakpointConditionEditor.java

License:Open Source License

/**
 * Creates the condition editor widgets and returns the top level
 * control.//w  ww .  j  a  v a2  s.  com
 * 
 * @param parent composite to embed the editor controls in
 * @return top level control
 */
@Override
public Control createControl(Composite parent) {
    Composite controls = SWTFactory.createComposite(parent, parent.getFont(), 2, 1, GridData.FILL_HORIZONTAL, 0,
            0);
    fConditional = SWTFactory.createCheckButton(controls,
            processMnemonics(PropertyPageMessages.JavaBreakpointConditionEditor_0), null, false, 1);
    fConditional.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    fConditional.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            boolean checked = fConditional.getSelection();
            setEnabled(checked, true);
            setDirty(PROP_CONDITION_ENABLED);
        }
    });
    Composite radios = SWTFactory.createComposite(controls, controls.getFont(), 2, 1, GridData.FILL_HORIZONTAL,
            0, 0);
    fWhenTrue = SWTFactory.createRadioButton(radios,
            processMnemonics(PropertyPageMessages.JavaBreakpointConditionEditor_1));
    fWhenTrue.setLayoutData(new GridData());
    fWhenChange = SWTFactory.createRadioButton(radios,
            processMnemonics(PropertyPageMessages.JavaBreakpointConditionEditor_2));
    fWhenChange.setLayoutData(new GridData());
    fWhenTrue.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            setDirty(PROP_CONDITION_SUSPEND_POLICY);
        }
    });
    fWhenChange.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            setDirty(PROP_CONDITION_SUSPEND_POLICY);
        }
    });

    if (fConditionHistoryDialogSettings != null) {
        fLocalConditionHistory = new HashMap<IJavaLineBreakpoint, Stack<String>>();
        fConditionHistory = SWTFactory.createCombo(parent, SWT.DROP_DOWN | SWT.READ_ONLY, 1, null);
        initializeConditionHistoryDropDown();
        fConditionHistory.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                int historyIndex = fConditionHistory.getSelectionIndex() - 1;
                if (historyIndex >= 0 && historyIndex != fSeparatorIndex)
                    fViewer.getDocument().set(getConditionHistory()[historyIndex]);
            }
        });
        GridData data = new GridData(GridData.FILL_HORIZONTAL);
        data.widthHint = 10;
        fConditionHistory.setLayoutData(data);
        fLocalConditionHistory = new HashMap<IJavaLineBreakpoint, Stack<String>>(10);
    }

    fViewer = new JDISourceViewer(parent, null, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.LEFT_TO_RIGHT);
    fViewer.setEditable(false);
    ControlDecoration decoration = new ControlDecoration(fViewer.getControl(), SWT.TOP | SWT.LEFT);
    decoration.setShowOnlyOnFocus(true);
    FieldDecoration dec = FieldDecorationRegistry.getDefault()
            .getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
    decoration.setImage(dec.getImage());
    decoration.setDescriptionText(dec.getDescription());
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    // set height/width hints based on font
    GC gc = new GC(fViewer.getTextWidget());
    gc.setFont(fViewer.getTextWidget().getFont());
    FontMetrics fontMetrics = gc.getFontMetrics();
    gd.heightHint = Dialog.convertHeightInCharsToPixels(fontMetrics, 17);
    gd.widthHint = Dialog.convertWidthInCharsToPixels(fontMetrics, 40);
    gc.dispose();
    fViewer.getControl().setLayoutData(gd);
    fContentAssistHandler = new AbstractHandler() {
        public Object execute(ExecutionEvent event) throws org.eclipse.core.commands.ExecutionException {
            fViewer.doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS);
            return null;
        }
    };
    fUndoHandler = new AbstractHandler() {
        public Object execute(ExecutionEvent event) throws org.eclipse.core.commands.ExecutionException {
            fViewer.doOperation(ITextOperationTarget.UNDO);
            return null;
        }
    };
    fRedoHandler = new AbstractHandler() {
        public Object execute(ExecutionEvent event) throws org.eclipse.core.commands.ExecutionException {
            fViewer.doOperation(ITextOperationTarget.REDO);
            return null;
        }
    };
    fHandlerService = (IHandlerService) PlatformUI.getWorkbench().getAdapter(IHandlerService.class);
    fViewer.getControl().addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            activateHandlers();
        }

        @Override
        public void focusLost(FocusEvent e) {
            deactivateHandlers();
        }
    });
    parent.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent e) {
            dispose();
        }
    });
    return parent;
}

From source file:org.eclipse.jst.jsf.ui.internal.validation.PixelConverter.java

License:Open Source License

int convertHeightInCharsToPixels(int chars) {
    return Dialog.convertHeightInCharsToPixels(fFontMetrics, chars);
}

From source file:org.eclipse.jubula.client.ui.rcp.dialogs.AUTPropertiesDialog.java

License:Open Source License

/**
 * Creates a new multiline textfield//  w w  w.ja  va2 s .co m
 * @param parent The parent composite.
 * @param labelText The m_text for the label.
 * @param lines The quantity of lines of this list.
 * @return The new multiline textfield.
 */
private List newListField(Composite parent, String labelText, int lines) {
    Label label = new Label(parent, SWT.NONE);
    label.setText(labelText);
    List listField = new List(parent, LayoutUtil.SINGLE_TEXT_STYLE | SWT.V_SCROLL | SWT.H_SCROLL);
    GridData listGridData = new GridData();
    listGridData.horizontalAlignment = GridData.FILL;
    listGridData.grabExcessHorizontalSpace = true;
    listGridData.horizontalSpan = NUM_COLUMNS_3 - 1;
    listGridData.heightHint = Dialog.convertHeightInCharsToPixels(LayoutUtil.getFontMetrics(listField), lines);
    LayoutUtil.addToolTipAndMaxWidth(listGridData, listField);
    listField.setLayoutData(listGridData);
    return listField;
}

From source file:org.eclipse.jubula.client.ui.rcp.properties.AUTPropertyPage.java

License:Open Source License

/**
 * Creates a m_text field with the AUTs of a project.
 * @param parent The parent composite.//from w w w . ja  v  a 2s . co m
 */
private void createAUTList(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout compositeLayout = new GridLayout();
    compositeLayout.numColumns = NUM_COLUMNS_1;
    composite.setLayout(compositeLayout);
    GridData data = new GridData();
    data.horizontalAlignment = SWT.FILL;
    data.grabExcessHorizontalSpace = true;
    composite.setLayoutData(data);
    newLabel(composite, Messages.AUTPropertyPageAUTList);
    m_autList = new List(composite, LayoutUtil.MULTI_TEXT_STYLE | SWT.SINGLE);
    GridData textGridData = new GridData();
    textGridData.horizontalAlignment = GridData.FILL;
    textGridData.grabExcessHorizontalSpace = true;
    textGridData.heightHint = Dialog.convertHeightInCharsToPixels(LayoutUtil.getFontMetrics(m_autList), LINES);
    LayoutUtil.addToolTipAndMaxWidth(textGridData, m_autList);
    m_autList.setLayoutData(textGridData);
}

From source file:org.eclipse.jubula.client.ui.rcp.properties.ProjectLanguagePropertyPage.java

License:Open Source License

/**
 * Resizes the two ListBoxes.//from   w w w.  java2s  .  c o m
 */
private void resizeLists() {
    ((GridData) m_projectLangList.getLayoutData()).widthHint = Dialog
            .convertHeightInCharsToPixels(LayoutUtil.getFontMetrics(m_projectLangList), 15);
    ((GridData) m_availableLangList.getLayoutData()).widthHint = Dialog
            .convertHeightInCharsToPixels(LayoutUtil.getFontMetrics(m_projectLangList), 15);
}

From source file:org.eclipse.jubula.client.ui.rcp.properties.ProjectUsedPropertyPage.java

License:Open Source License

/**
 * Resizes the two ListBoxes.//from  ww  w  . j a v a 2 s.c om
 */
private void resizeLists() {
    ((GridData) m_usedProjectsList.getLayoutData()).widthHint = Dialog
            .convertHeightInCharsToPixels(LayoutUtil.getFontMetrics(m_usedProjectsList), 15);
    ((GridData) m_availableProjectsList.getLayoutData()).widthHint = Dialog
            .convertHeightInCharsToPixels(LayoutUtil.getFontMetrics(m_usedProjectsList), 15);
}

From source file:org.eclipse.jubula.client.ui.rcp.widgets.autconfig.JavaAutConfigComponent.java

License:Open Source License

/**
 * /*from w  ww .j av  a 2 s  . co m*/
 * @param parent The parent Composite.
 */
private void initGuiEnvironmentEditor(Composite parent) {
    UIComponentHelper.createLabel(parent, "AUTConfigComponent.envVariables"); //$NON-NLS-1$ 
    m_envTextArea = new Text(parent, LayoutUtil.MULTI_TEXT | SWT.V_SCROLL);
    LayoutUtil.setMaxChar(m_envTextArea, IPersistentObject.MAX_STRING_LENGTH);
    GridData textGridData = new GridData();
    textGridData.horizontalAlignment = GridData.FILL;
    textGridData.horizontalSpan = 2;
    textGridData.grabExcessHorizontalSpace = false;
    textGridData.widthHint = COMPOSITE_WIDTH;
    textGridData.heightHint = Dialog.convertHeightInCharsToPixels(LayoutUtil.getFontMetrics(m_envTextArea), 2);
    m_envTextArea.setLayoutData(textGridData);
}

From source file:org.eclipse.jubula.client.ui.rcp.widgets.AutIdListComposite.java

License:Open Source License

/**
 * Creates the necessary components and sets their initial values.
 * /*  ww  w  .j  a  v a2  s  .c o m*/
 * @param autIdValidator The validator for the AUT ID text field.
 */
@SuppressWarnings("unchecked")
private void init(final IValidator autIdValidator) {
    GridLayout compositeLayout = new GridLayout();
    compositeLayout.numColumns = 2;
    compositeLayout.marginHeight = 0;
    compositeLayout.marginWidth = 0;
    setLayout(compositeLayout);
    Label idLabel = new Label(this, SWT.NONE);
    idLabel.setText(Messages.AUTPropertiesDialogAutId);
    ControlDecorator.createInfo(idLabel, I18n.getString("AUTPropertiesDialog.AutId.helpText"), false); //$NON-NLS-1$
    GridData data = new GridData(SWT.BEGINNING, SWT.FILL, false, false);
    data.horizontalSpan = 1;
    idLabel.setLayoutData(data);

    // Created to keep layout consistent
    new Label(this, SWT.NONE).setVisible(false);

    final WritableList idListModel = new WritableList(m_aut.getAutIds(), String.class);
    final ListViewer idListViewer = new ListViewer(this, LayoutUtil.MULTI_TEXT_STYLE);
    idListViewer.setContentProvider(new ObservableListContentProvider());
    idListViewer.setComparator(new ViewerComparator());
    idListViewer.setInput(idListModel);
    final List idList = idListViewer.getList();
    data = new GridData(SWT.FILL, SWT.FILL, true, false);
    data.verticalSpan = 3;
    data.widthHint = Dialog.convertHeightInCharsToPixels(LayoutUtil.getFontMetrics(idList), 4);
    idList.setLayoutData(data);

    createButtons(this, autIdValidator, idList, idListModel);
}