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

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

Introduction

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

Prototype

public PixelConverter(Font font) 

Source Link

Document

Create a PixelConverter which will convert device-independent units to pixels using the specified font.

Usage

From source file:ca.usask.cs.srlab.simclipse.ui.SWTUtil.java

License:Open Source License

/**
 * Returns a width hint for a button control.
 * @param button The button to calculate the width for
 * @return The width of the button//from w  ww  .  ja  v  a 2 s.co  m
 */
public static int getButtonWidthHint(Button button) {
    button.setFont(JFaceResources.getDialogFont());
    PixelConverter converter = new PixelConverter(button);
    int widthHint = converter.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
}

From source file:ch.powerunit.poweruniteclipse.helper.SWTHelper.java

License:Open Source License

public static int getButtonWidthHint(Button button) {
    PixelConverter converter = new PixelConverter(button);
    int widthHint = converter.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
}

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 ww w  .  ja  v  a  2  s .  c om
    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.preferences.AbstractFormatterSelectionBlock.java

License:Open Source License

protected static Label createLabel(Composite composite, String text, int numColumns, boolean wrap) {
    final GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = numColumns;//from  ww  w  .  j av  a2s . c o m
    if (wrap) {
        gd.heightHint = new PixelConverter(composite).convertHeightInCharsToPixels(2);
    }

    final Label label = new Label(composite, wrap ? SWT.WRAP : SWT.NONE);
    label.setFont(composite.getFont());
    label.setText(text);
    label.setLayoutData(gd);
    return label;
}

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

License:Open Source License

/**
 * Sets the <code>GridData</code> on the specified button to be one that is spaced for the current dialog page
 * units. The method <code>initializeDialogUnits</code> must be called once before calling this method for the first
 * time.//  ww  w  .  j av a  2 s .  c o m
 * 
 * @param button
 *            the button to set the <code>GridData</code>
 * @return the <code>GridData</code> set on the specified button
 */
protected GridData setButtonLayoutData(Button button) {
    GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    PixelConverter converter = new PixelConverter(button);
    int widthHint = converter.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    Point minSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    data.widthHint = Math.max(widthHint, minSize.x);
    button.setLayoutData(data);
    return data;
}

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

License:Open Source License

public Composite createContents(IFormatterControlManager manager, Composite parent) {

    final int numColumns = 4;

    if (fPixelConverter == null) {
        fPixelConverter = new PixelConverter(parent);
    }/*  w w  w  .  j a  va 2s. c  o m*/

    final SashForm sashForm = new SashForm(parent, SWT.HORIZONTAL);
    sashForm.setFont(parent.getFont());

    Composite scrollContainer = new Composite(sashForm, SWT.NONE);

    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    scrollContainer.setLayoutData(gridData);
    scrollContainer.setFont(sashForm.getFont());
    GridLayout layout = new GridLayout(2, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    scrollContainer.setLayout(layout);

    ScrolledPageContent scroll = new ScrolledPageContent(scrollContainer, SWT.V_SCROLL | SWT.H_SCROLL);
    scroll.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    final Composite settingsContainer = scroll.getBody();

    settingsContainer.setLayout(new PageLayout(scroll, 400, 400));
    settingsContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    Composite settingsPane = new Composite(settingsContainer, SWT.NONE);
    settingsPane.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    layout = new GridLayout(1, false);
    layout.verticalSpacing = (int) (1.5
            * fPixelConverter.convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING));
    layout.horizontalSpacing = fPixelConverter
            .convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
    layout.marginHeight = fPixelConverter.convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
    layout.marginWidth = fPixelConverter.convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
    settingsPane.setLayout(layout);
    createOptions(manager, settingsPane);

    settingsContainer.setSize(settingsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT));

    Label sashHandle = new Label(scrollContainer, SWT.SEPARATOR | SWT.VERTICAL);
    gridData = new GridData(SWT.RIGHT, SWT.FILL, false, true);
    sashHandle.setLayoutData(gridData);

    final Composite previewPane = new Composite(sashForm, SWT.NONE);
    previewPane.setLayout(createGridLayout(numColumns, true));
    previewPane.setFont(sashForm.getFont());
    doCreatePreviewPane(previewPane, numColumns);

    sashForm.setWeights(new int[] { 3, 3 });
    return sashForm;
}

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

License:Open Source License

protected static Label createLabel(int numColumns, Composite parent, String text, int gridDataStyle) {
    final Label label = new Label(parent, SWT.WRAP);
    label.setFont(parent.getFont());/*from  w  w  w .j  a va  2 s . c  om*/
    label.setText(text);

    PixelConverter pixelConverter = new PixelConverter(parent);
    label.setLayoutData(
            createGridData(numColumns, gridDataStyle, pixelConverter.convertHorizontalDLUsToPixels(150)));
    return label;
}

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

License:Open Source License

/**
 * @param parent/*from ww  w . j  av a  2 s .  co 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.aptana.git.ui.internal.preferences.GithubAccountPageProvider.java

License:Open Source License

private static int getButtonWidthHint(Button button) {
    PixelConverter converter = new PixelConverter(button);
    int widthHint = converter.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
}

From source file:com.aptana.ide.ui.io.dialogs.GenericConnectionPropertyDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    Composite dialogArea = (Composite) super.createDialogArea(parent);

    if (genericConnectionPoint != null) {
        setTitle(Messages.GenericConnectionPropertyDialog_EditTitle);
        getShell().setText(Messages.GenericConnectionPropertyDialog_EditText);
    } else {/*from   w w w  .  java 2  s. c  om*/
        setTitle(Messages.GenericConnectionPropertyDialog_CreateTitle);
        getShell().setText(Messages.GenericConnectionPropertyDialog_CreateText);
    }

    Composite container = new Composite(dialogArea, SWT.NONE);
    container.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    container.setLayout(GridLayoutFactory.swtDefaults()
            .margins(convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN),
                    convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN))
            .spacing(convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING),
                    convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING))
            .numColumns(2).create());

    /* row 1 */
    Label label = new Label(container, SWT.NONE);
    label.setLayoutData(GridDataFactory.swtDefaults()
            .hint(new PixelConverter(label).convertHorizontalDLUsToPixels(IDialogConstants.LABEL_WIDTH),
                    SWT.DEFAULT)
            .create());
    label.setText(StringUtil.makeFormLabel(Messages.GenericConnectionPropertyDialog_Name));

    nameText = new Text(container, SWT.SINGLE | SWT.BORDER);
    nameText.setLayoutData(GridDataFactory.fillDefaults()
            .hint(convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH), SWT.DEFAULT)
            .grab(true, false).create());

    /* row 2 */
    label = new Label(container, SWT.NONE);
    label.setLayoutData(GridDataFactory.swtDefaults()
            .hint(new PixelConverter(label).convertHorizontalDLUsToPixels(IDialogConstants.LABEL_WIDTH),
                    SWT.DEFAULT)
            .create());
    label.setText(StringUtil.makeFormLabel(Messages.GenericConnectionPropertyDialog_URI));

    uriText = new Text(container, SWT.SINGLE | SWT.BORDER);
    uriText.setLayoutData(GridDataFactory.swtDefaults()
            .hint(convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH), SWT.DEFAULT)
            .grab(true, false).create());

    /* -- */
    addListeners();

    if (genericConnectionPoint == null) {
        try {
            genericConnectionPoint = (GenericConnectionPoint) CoreIOPlugin.getConnectionPointManager()
                    .createConnectionPoint(getConnectionPointType());
            genericConnectionPoint.setName(DEFAULT_NAME);
            isNew = true;
        } catch (CoreException e) {
            IdeLog.logError(IOUIPlugin.getDefault(), Messages.GenericConnectionPropertyDialog_FailedToCreate,
                    e);
            close(); // $codepro.audit.disable closeInFinally
        }
    }
    loadPropertiesFrom(genericConnectionPoint);

    return dialogArea;
}