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

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

Introduction

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

Prototype

public static int convertHorizontalDLUsToPixels(FontMetrics fontMetrics, int dlus) 

Source Link

Document

Returns the number of pixels corresponding to the given number of horizontal dialog units.

Usage

From source file:net.sf.jmoney.views.feedback.FeedbackHistorySelectionDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite container) {
    Composite ancestor = (Composite) super.createDialogArea(container);

    createMessageArea(ancestor);//from   w  w  w.  j  a  v a 2  s.co  m

    Composite parent = new Composite(ancestor, SWT.NONE);

    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    parent.setLayout(layout);
    parent.setLayoutData(new GridData(GridData.FILL_BOTH));

    fViewer = new TableViewer(parent,
            SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    fViewer.setContentProvider(new ArrayContentProvider());

    final Table table = fViewer.getTable();
    table.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseDoubleClick(MouseEvent e) {
            okPressed();
        }
    });
    fViewer.setLabelProvider(new FeedbackLabelProvider());
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = convertHeightInCharsToPixels(15);
    gd.widthHint = convertWidthInCharsToPixels(WIDTH_IN_CHARACTERS);
    table.setLayoutData(gd);

    fRemoveButton = new Button(parent, SWT.PUSH);
    fRemoveButton.setText("&Remove");
    fRemoveButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent event) {
            buttonPressed(REMOVE_ID);
        }
    });
    GridData removeButtonLayoutData = new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false);
    fRemoveButton.setFont(JFaceResources.getDialogFont());
    GC gc = new GC(fRemoveButton);
    gc.setFont(fRemoveButton.getFont());
    FontMetrics fFontMetrics = gc.getFontMetrics();
    gc.dispose();
    int widthHint = Dialog.convertHorizontalDLUsToPixels(fFontMetrics, IDialogConstants.BUTTON_WIDTH);
    removeButtonLayoutData.widthHint = Math.max(widthHint,
            fRemoveButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    removeButtonLayoutData.horizontalAlignment = GridData.FILL;
    fRemoveButton.setLayoutData(removeButtonLayoutData);

    fViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            validateDialogState();
        }
    });

    Label fLink = new Label(parent, SWT.NONE);
    fLink.setText(MessageFormat.format("History limited to {0} result sets not shown in views.",
            new Integer(historyLimit)));
    fLink.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));

    applyDialogFont(ancestor);

    // set input & selections last, so all the widgets are created.
    fViewer.setInput(fInput);
    fViewer.getTable().setFocus();
    return ancestor;
}

From source file:net.sourceforge.eclipseccase.ui.DialogArea.java

License:Open Source License

protected Button createButton(Composite parent, String label, int style) {
    Button button = new Button(parent, SWT.PUSH);
    button.setText(label);/*  w  w  w . j av a 2s  .  c o m*/
    // we need to explicitly set the font to the parent's font for dialogs
    button.setFont(parent.getFont());
    GridData data = new GridData(style);
    data.heightHint = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_HEIGHT);
    int widthHint = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_WIDTH);
    data.widthHint = Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    button.setLayoutData(data);
    return button;
}

From source file:org.apache.directory.studio.aciitemeditor.Activator.java

License:Apache License

/**
 * Returns the button with respect to the font metrics.
 *
 * @param control a control//from ww w.  j av  a 2 s. c o  m
 * @return the button width
 */
public static int getButtonWidth(Control control) {
    GC gc = new GC(control);

    try {
        gc.setFont(JFaceResources.getDialogFont());
        FontMetrics fontMetrics = gc.getFontMetrics();

        int width = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_WIDTH);

        return width;
    } finally {
        gc.dispose();
    }
}

From source file:org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils.java

License:Apache License

/**
 * Creates a button under the given parent. 
 * The button width is set to the default width.
 *
 * @param parent the parent//from  w  ww . java2s. c  om
 * @param text the label of the button 
 * @param span the horizontal span
 * @return the created button
 */
public static Button createButton(Composite parent, String text, int span) {
    GC gc = new GC(parent);

    try {
        gc.setFont(JFaceResources.getDialogFont());
        FontMetrics fontMetrics = gc.getFontMetrics();
        Button button = new Button(parent, SWT.PUSH);
        GridData gridData = new GridData();
        gridData.widthHint = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_WIDTH);
        gridData.horizontalSpan = span;
        button.setLayoutData(gridData);
        button.setText(text);

        return button;
    } finally {
        gc.dispose();
    }

}

From source file:org.cloudfoundry.ide.eclipse.server.ui.internal.wizards.CloudFoundryServiceWizardPage1.java

License:Open Source License

public int convertHorizontalDLUsToPixels(Composite comp, int x) {
    if (fontMetrics == null) {
        initializeDialogUnits(comp);/*w  w  w. ja  va  2 s .c  om*/
    }
    return Dialog.convertHorizontalDLUsToPixels(fontMetrics, x);
}

From source file:org.ebayopensource.turmeric.eclipse.utils.ui.UIUtil.java

License:Open Source License

/**
 * Returns a width hint for a button control.
 * /*w w w  . j av  a 2s . c  o m*/
 * @param button
 *            the button
 * @return the width hint
 */
public static int getButtonWidthHint(Button button) {
    button.setFont(JFaceResources.getDialogFont());
    Font font = button.getFont();
    GC gc = new GC(font.getDevice());
    gc.setFont(font);
    int widthHint = Dialog.convertHorizontalDLUsToPixels(gc.getFontMetrics(), IDialogConstants.BUTTON_WIDTH);
    gc.dispose();
    return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
}

From source file:org.eclipse.acceleo.ui.interpreter.internal.view.wizards.NewVariableWizardPage.java

License:Open Source License

/**
 * Returns a width hint for a button control.
 * /* w  w  w .  j  a  v  a  2  s.co m*/
 * @param button
 *            the button
 * @return the width hint
 */
public static int getButtonWidthHint(Button button) {
    Font font = JFaceResources.getDialogFont();
    button.setFont(font);
    GC gc = new GC(font.getDevice());
    gc.setFont(font);
    FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();
    int widthHint = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_WIDTH);
    return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
}

From source file:org.eclipse.birt.report.designer.ui.preferences.SelectionButtonDialogField.java

License:Open Source License

public Control[] doFillIntoGrid(Composite parent, int nColumns) {
    assertEnoughColumns(nColumns);/*from  ww w  .  j a v  a2  s.c  o  m*/

    Button button = getSelectionButton(parent);
    GridData gd = new GridData();
    gd.horizontalSpan = nColumns;
    gd.horizontalAlignment = GridData.FILL;
    if (fButtonStyle == SWT.PUSH) {
        GC gc = new GC(button.getFont().getDevice());
        gc.setFont(button.getFont());
        FontMetrics fFontMetrics = gc.getFontMetrics();
        gc.dispose();
        int widthHint = Dialog.convertHorizontalDLUsToPixels(fFontMetrics, IDialogConstants.BUTTON_WIDTH);
        gd.widthHint = Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    }

    button.setLayoutData(gd);

    return new Control[] { button };
}

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

License:Open Source License

/**
 * @see org.eclipse.jface.dialogs.DialogPage#convertHorizontalDLUsToPixels(int)
 *//*from   w w w  .  jav  a  2 s. co  m*/
public int convertHorizontalDLUsToPixels(int dlus) {
    return Dialog.convertHorizontalDLUsToPixels(getFontMetrics(), dlus);
}

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

License:Open Source License

private GridData getButtonGridData(Button button, FontMetrics fontMetrics) {
    GridData gd = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING);
    int widthHint = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_WIDTH);
    gd.widthHint = Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    return gd;//  w  w  w. ja v a2  s. com
}