Example usage for org.eclipse.jface.layout PixelConverter convertWidthInCharsToPixels

List of usage examples for org.eclipse.jface.layout PixelConverter convertWidthInCharsToPixels

Introduction

In this page you can find the example usage for org.eclipse.jface.layout PixelConverter convertWidthInCharsToPixels.

Prototype

public int convertWidthInCharsToPixels(int chars) 

Source Link

Document

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

Usage

From source file:com.aptana.formatter.ui.preferences.AbstractFormatterSelectionBlock.java

License:Open Source License

protected Composite createSelectorBlock(Composite parent) {
    final int numColumns = 5;

    PixelConverter fPixConv = new PixelConverter(parent);
    fComposite = createComposite(parent, numColumns);

    Label profileLabel = new Label(fComposite, SWT.NONE);
    profileLabel.setText(FormatterMessages.AbstractFormatterSelectionBlock_activeProfile);
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
    data.horizontalSpan = numColumns;/*from w w w  .java  2 s.  co m*/
    profileLabel.setLayoutData(data);

    fProfileCombo = createProfileCombo(fComposite, 1, fPixConv.convertWidthInCharsToPixels(20));
    updateComboFromProfiles();
    fProfileCombo.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            updateSelection();
        }
    });

    fNewButton = createButton(fComposite, GridData.HORIZONTAL_ALIGN_BEGINNING);
    fNewButton.setImage(SWTUtils.getImage(UIPlugin.getDefault(), "/icons/add.gif")); //$NON-NLS-1$
    fNewButton.setToolTipText(FormatterMessages.AbstractFormatterSelectionBlock_newProfile);
    fNewButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            createNewProfile(fComposite.getShell());
        }
    });

    fDeleteButton = createButton(fComposite, GridData.HORIZONTAL_ALIGN_BEGINNING);
    fDeleteButton.setImage(SWTUtils.getImage(UIPlugin.getDefault(), "/icons/delete.gif")); //$NON-NLS-1$
    fDeleteButton.setToolTipText(FormatterMessages.AbstractFormatterSelectionBlock_removeProfile);
    fDeleteButton.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            doDelete();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            doDelete();
        }

        protected void doDelete() {
            IProfileManager profileManager = getProfileManager();
            IProfile selected = profileManager.getSelected(fProject);
            if (MessageDialog.openQuestion(fComposite.getShell(),
                    FormatterMessages.AbstractFormatterSelectionBlock_confirmRemoveLabel,
                    NLS.bind(FormatterMessages.AbstractFormatterSelectionBlock_confirmRemoveMessage,
                            selected.getName()))) {
                profileManager.deleteProfile(selected);
                updateComboFromProfiles();
                updateSelection();
            }
        }
    });

    // add a filler

    fLoadButton = createButton(fComposite, GridData.HORIZONTAL_ALIGN_BEGINNING);
    fLoadButton.setImage(SWTUtils.getImage(UIPlugin.getDefault(), "/icons/import.gif")); //$NON-NLS-1$
    fLoadButton.setToolTipText(FormatterMessages.AbstractFormatterSelectionBlock_importProfile);
    fLoadButton.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            doImport(fComposite);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            doImport(fComposite);
        }

    });

    fSaveButton = createButton(fComposite, GridData.HORIZONTAL_ALIGN_BEGINNING);
    fSaveButton.setImage(SWTUtils.getImage(UIPlugin.getDefault(), "/icons/export.gif")); //$NON-NLS-1$
    fSaveButton.setToolTipText(FormatterMessages.FormatterModifyDialog_export);
    fSaveButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            doExport();
        }
    });

    createLabel(fComposite, "", 3); //$NON-NLS-1$

    // Edit
    fEditButton = createButton(fComposite, GridData.HORIZONTAL_ALIGN_BEGINNING);
    fEditButton.setImage(SWTUtils.getImage(UIPlugin.getDefault(), "/icons/pencil.gif")); //$NON-NLS-1$
    fEditButton.setToolTipText(FormatterMessages.AbstractFormatterSelectionBlock_edit);
    fEditButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            editButtonPressed();
        }
    });

    // Restore Defaults
    fDefaultButton = createButton(fComposite, GridData.HORIZONTAL_ALIGN_BEGINNING);
    fDefaultButton.setImage(SWTUtils.getImage(UIPlugin.getDefault(), "/icons/arrow_undo.png")); //$NON-NLS-1$
    fDefaultButton.setToolTipText(FormatterMessages.AbstractFormatterSelectionBlock_defaults);
    fDefaultButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            IScriptFormatterFactory formatter = getSelectedFormatter();
            if (formatter == null) {
                return;
            }
            PreferenceKey[] preferenceKeys = formatter.getPreferenceKeys();
            IProfileManager manager = getProfileManager();
            if (!MessageDialog.openQuestion(fDefaultButton.getShell(),
                    FormatterMessages.AbstractFormatterSelectionBlock_confirmDefaultsTitle,
                    NLS.bind(FormatterMessages.AbstractFormatterSelectionBlock_confirmDefaultsMessage,
                            formatter.getName()))) {
                return;
            }
            List<IProfile> builtInProfiles = manager.getBuiltInProfiles();
            String defaultProfileId = manager.getDefaultProfileID();
            IProfile defaultProfile = null;
            for (IProfile profile : builtInProfiles) {
                if (profile.getID().equals(defaultProfileId)) {
                    defaultProfile = profile;
                    break;
                }
            }
            if (defaultProfile != null) {
                Map<String, String> defaultSettings = defaultProfile.getSettings();
                Map<String, String> activeSettings = manager.getSelected(fProject).getSettings();
                IScopeContext context = EclipseUtil.instanceScope();
                for (PreferenceKey key : preferenceKeys) {
                    String name = key.getName();
                    if (defaultSettings.containsKey(name)) {
                        String value = defaultSettings.get(name);
                        activeSettings.put(name, value);
                        key.setStoredValue(context, value);
                    } else {
                        activeSettings.remove(name);
                    }
                }
                manager.getSelected(fProject).setSettings(activeSettings);
                manager.markDirty();
                // Apply the preferences. This will update the preview as well.
                applyPreferences();
            }
        }
    });
    IProfileManager profileManager = getProfileManager();
    fDefaultButton.setEnabled(!profileManager.getSelected(fProject).isBuiltInProfile());

    configurePreview(fComposite, numColumns);
    updateButtons();
    applyPreferences(true);

    return fComposite;
}

From source file:com.aptana.formatter.ui.util.SWTFactory.java

License:Open Source License

/**
 * @param parent/*  ww  w.  j a v  a2 s  .c o m*/
 * @param min
 * @param max
 * @param hspan
 * @param style
 * @return
 */
public static Spinner createSpinner(Composite parent, int min, int max, int hspan, int style) {
    Spinner spinner = new Spinner(parent, SWT.BORDER | style);
    spinner.setMinimum(min);
    spinner.setMaximum(max);

    GridData gd = new GridData(SWT.CENTER, SWT.CENTER, false, false, hspan, 1);
    PixelConverter pc = new PixelConverter(spinner);
    // See http://jira.appcelerator.org/browse/APSTUD-3215
    // We need to add some extra spacing to the MacOSX spinner in order to adjust the size to the way Mac draws
    // spinners.
    int extraWidth = Platform.OS_MACOSX.equals(Platform.getOS()) ? 25 : 0;
    gd.widthHint = pc.convertWidthInCharsToPixels(2) + extraWidth;
    spinner.setLayoutData(gd);
    return spinner;
}

From source file:com.cisco.yangide.editor.preferences.AbstractConfigurationBlock.java

License:Open Source License

/**
 * Returns an array of size 2: - first element is of type <code>Label</code> - second element is
 * of type <code>Text</code> Use <code>getLabelControl</code> and <code>getTextControl</code> to
 * get the 2 controls.//  w w  w  .j  a  v  a2  s .  c  o m
 */
protected Control[] addLabelledTextField(Composite composite, String label, String key, int textLimit,
        int indentation, boolean isNumber) {

    PixelConverter pixelConverter = new PixelConverter(composite);

    Label labelControl = new Label(composite, SWT.NONE);
    labelControl.setText(label);
    GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.horizontalIndent = indentation;
    labelControl.setLayoutData(gd);

    Text textControl = new Text(composite, SWT.BORDER | SWT.SINGLE);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.widthHint = pixelConverter.convertWidthInCharsToPixels(textLimit + 1);
    textControl.setLayoutData(gd);
    textControl.setTextLimit(textLimit);
    fTextFields.put(textControl, key);
    if (isNumber) {
        fNumberFields.add(textControl);
        textControl.addModifyListener(fNumberFieldListener);
    } else {
        textControl.addModifyListener(fTextFieldListener);
    }

    return new Control[] { labelControl, textControl };
}

From source file:com.google.dart.tools.ui.actions.AbstractOpenWizardAction.java

License:Open Source License

@Override
public void run() {
    EmitInstrumentationCommand();/* w  ww  . j a  va 2 s.  co m*/
    Shell shell = getShell();
    try {
        INewWizard wizard = createWizard();
        wizard.init(PlatformUI.getWorkbench(), getSelection());

        WizardDialog dialog = new WizardDialog(shell, wizard);
        PixelConverter converter = new PixelConverter(JFaceResources.getDialogFont());
        dialog.setMinimumPageSize(converter.convertWidthInCharsToPixels(70),
                converter.convertHeightInCharsToPixels(20));
        dialog.create();
        int res = dialog.open();
        notifyResult(res == Window.OK);
    } catch (CoreException e) {
        String title = ActionMessages.AbstractOpenWizardAction_createerror_title;
        String message = ActionMessages.AbstractOpenWizardAction_createerror_message;
        ExceptionHandler.handle(e, shell, title, message);
    }
}

From source file:com.google.dart.tools.ui.internal.refactoring.ExtractMethodInputPage.java

License:Open Source License

private void createSignaturePreview(Composite composite, RowLayouter layouter) {
    Label previewLabel = new Label(composite, SWT.NONE);
    previewLabel.setText(RefactoringMessages.ExtractMethodInputPage_signature_preview);
    layouter.perform(previewLabel);/*from  w  ww. j ava2s.  c om*/

    IPreferenceStore store = DartToolsPlugin.getDefault().getCombinedPreferenceStore();
    fSignaturePreview = new DartSourceViewer(composite, null, null, false,
            SWT.READ_ONLY | SWT.V_SCROLL | SWT.WRAP /*| SWT.BORDER*/, store);
    fSignaturePreview.configure(new DartSourceViewerConfiguration(
            DartToolsPlugin.getDefault().getDartTextTools().getColorManager(), store, null, null));
    fSignaturePreview.getTextWidget().setFont(JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT));
    fSignaturePreview.adaptBackgroundColor(composite);
    fSignaturePreview.setDocument(fSignaturePreviewDocument);
    fSignaturePreview.setEditable(false);

    Control signaturePreviewControl = fSignaturePreview.getControl();
    PixelConverter pixelConverter = new PixelConverter(signaturePreviewControl);
    GridData gdata = new GridData(GridData.FILL_BOTH);
    gdata.widthHint = pixelConverter.convertWidthInCharsToPixels(50);
    gdata.heightHint = pixelConverter.convertHeightInCharsToPixels(2);
    signaturePreviewControl.setLayoutData(gdata);
    layouter.perform(signaturePreviewControl);
}

From source file:com.liferay.ide.project.ui.action.NewWizardAction.java

License:Open Source License

public void run() {
    Shell shell = getShell();/*from  w ww  .j a  va2 s . c  o m*/
    try {
        INewWizard wizard = createWizard();

        wizard.init(PlatformUI.getWorkbench(), getSelection());

        WizardDialog dialog = new WizardDialog(shell, wizard);

        PixelConverter converter = new PixelConverter(JFaceResources.getDialogFont());

        dialog.setMinimumPageSize(converter.convertWidthInCharsToPixels(70),
                converter.convertHeightInCharsToPixels(20));

        dialog.create();

        int res = dialog.open();

        notifyResult(res == Window.OK);
    } catch (CoreException e) {
    }
}

From source file:com.redhat.ceylon.eclipse.code.preferences.ResourceContainerWorkbookPage.java

License:Open Source License

@Override
public Control getControl(Composite parent) {
    PixelConverter converter = new PixelConverter(parent);
    Composite composite = new Composite(parent, SWT.NONE);

    LayoutUtil.doDefaultLayout(composite, new DialogField[] { fFoldersList, fJavaOutputLocationField }, true,
            SWT.DEFAULT, SWT.DEFAULT);/*from  w w  w. jav a2  s .  c  o  m*/
    LayoutUtil.setHorizontalGrabbing(fFoldersList.getTreeControl(null));

    int buttonBarWidth = converter.convertWidthInCharsToPixels(24);
    fFoldersList.setButtonsMinWidth(buttonBarWidth);

    fSWTControl = composite;

    // expand
    //        List<CPListElement> elements= fFoldersList.getElements();
    //        for (int i= 0; i < elements.size(); i++) {
    //            CPListElement elem= elements.get(i);
    //            IPath[] exclusionPatterns= (IPath[]) elem.getAttribute(CPListElement.EXCLUSION);
    //            IPath[] inclusionPatterns= (IPath[]) elem.getAttribute(CPListElement.INCLUSION);
    //            IPath output= (IPath) elem.getAttribute(CPListElement.OUTPUT);
    //            if (exclusionPatterns.length > 0 || inclusionPatterns.length > 0 || output != null) {
    //                fFoldersList.expandElement(elem, 3);
    //            }
    //        }
    return composite;
}

From source file:com.redhat.ceylon.eclipse.code.preferences.SourceContainerWorkbookPage.java

License:Open Source License

@Override
public Control getControl(Composite parent) {
    PixelConverter converter = new PixelConverter(parent);
    Composite composite = new Composite(parent, SWT.NONE);

    LayoutUtil.doDefaultLayout(composite,
            new DialogField[] { fFoldersList, /*fUseFolderOutputs,*/ fJavaOutputLocationField }, true,
            SWT.DEFAULT, SWT.DEFAULT);//from  w ww  .ja v  a  2  s.c o m
    LayoutUtil.setHorizontalGrabbing(fFoldersList.getTreeControl(null));

    int buttonBarWidth = converter.convertWidthInCharsToPixels(24);
    fFoldersList.setButtonsMinWidth(buttonBarWidth);

    fSWTControl = composite;

    // expand
    //        List<CPListElement> elements= fFoldersList.getElements();
    //        for (int i= 0; i < elements.size(); i++) {
    //            CPListElement elem= elements.get(i);
    //            IPath[] exclusionPatterns= (IPath[]) elem.getAttribute(CPListElement.EXCLUSION);
    //            IPath[] inclusionPatterns= (IPath[]) elem.getAttribute(CPListElement.INCLUSION);
    //            IPath output= (IPath) elem.getAttribute(CPListElement.OUTPUT);
    //            if (exclusionPatterns.length > 0 || inclusionPatterns.length > 0 || output != null) {
    //                fFoldersList.expandElement(elem, 3);
    //            }
    //        }
    return composite;
}

From source file:com.redhat.ceylon.eclipse.code.wizard.SourceContainerWorkbookPage.java

License:Open Source License

@Override
public Control getControl(Composite parent) {
    PixelConverter converter = new PixelConverter(parent);
    Composite composite = new Composite(parent, SWT.NONE);

    LayoutUtil.doDefaultLayout(composite,
            new DialogField[] { fFoldersList, fUseFolderOutputs, fJavaOutputLocationField }, true, SWT.DEFAULT,
            SWT.DEFAULT);/*  w w w.  j a  v  a2s.c om*/
    LayoutUtil.setHorizontalGrabbing(fFoldersList.getTreeControl(null));

    int buttonBarWidth = converter.convertWidthInCharsToPixels(24);
    fFoldersList.setButtonsMinWidth(buttonBarWidth);

    fSWTControl = composite;

    // expand
    List<CPListElement> elements = fFoldersList.getElements();
    for (int i = 0; i < elements.size(); i++) {
        CPListElement elem = elements.get(i);
        IPath[] exclusionPatterns = (IPath[]) elem.getAttribute(CPListElement.EXCLUSION);
        IPath[] inclusionPatterns = (IPath[]) elem.getAttribute(CPListElement.INCLUSION);
        IPath output = (IPath) elem.getAttribute(CPListElement.OUTPUT);
        if (exclusionPatterns.length > 0 || inclusionPatterns.length > 0 || output != null) {
            fFoldersList.expandElement(elem, 3);
        }
    }
    return composite;
}

From source file:de.byteholder.geoclipse.map.DialogManageOfflineImages.java

License:Open Source License

private void createUI10LeftPart(final Composite parent) {

    Label label;/*from ww w .j a v a  2s  .  c om*/
    final PixelConverter pc = new PixelConverter(parent);

    final Composite container = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(container);
    GridLayoutFactory.fillDefaults().numColumns(2).applyTo(container);
    //      container.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_GREEN));
    {
        /*
         * target zoom level
         */
        label = new Label(container, SWT.NONE);
        label.setText(Messages.Dialog_OfflineArea_Label_ZoomLevel);

        // combo: zoom level
        _comboTargetZoom = new Combo(container, SWT.READ_ONLY);
        _comboTargetZoom.setVisibleItemCount(20);
        _comboTargetZoom.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(final SelectionEvent e) {

                getOfflineImageState();

                // focus was disabled, reset focus
                _comboTargetZoom.setFocus();
            }
        });

        /*
         * map provider
         */
        label = new Label(container, SWT.NONE);
        label.setText(Messages.Dialog_OfflineArea_Label_MapProvider);

        // combo: zoom level
        _comboMapProvider = new Combo(container, SWT.READ_ONLY);
        GridDataFactory.fillDefaults()//
                .hint(pc.convertWidthInCharsToPixels(60), SWT.DEFAULT).applyTo(_comboMapProvider);
        _comboMapProvider.setVisibleItemCount(30);
        _comboMapProvider.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(final SelectionEvent e) {
                onSelectMapProvider();
            }
        });

        /*
         * profile parts
         */
        label = new Label(container, SWT.NONE);
        label.setText(Messages.Dialog_OfflineArea_Label_ProfileParts);
        GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.FILL).applyTo(label);

        createUI20PartViewer(container);

        /*
         * queue
         */
        label = new Label(container, SWT.NONE);
        label.setText(Messages.Dialog_OfflineArea_Label_Queue);

        final Composite progContainer = new Composite(container, SWT.NONE);
        GridDataFactory.fillDefaults().grab(true, false).applyTo(progContainer);
        GridLayoutFactory.fillDefaults().numColumns(2).applyTo(progContainer);
        //         progContainer.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));
        {
            /*
             * progress bar
             */
            _progbarQueue = new ProgressBar(progContainer, SWT.HORIZONTAL | SWT.SMOOTH);
            GridDataFactory.fillDefaults().grab(true, false).applyTo(_progbarQueue);

            /*
             * text: queue
             */
            _txtQueue = new Text(progContainer, SWT.READ_ONLY | SWT.TRAIL | SWT.BORDER);
            GridDataFactory.fillDefaults()//
                    .align(SWT.END, SWT.FILL).hint(pc.convertWidthInCharsToPixels(20), SWT.DEFAULT)
                    .applyTo(_txtQueue);
            _txtQueue.setBackground(_display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
        }
    }
}