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:com.nokia.tools.variant.compare.ui.actions.ImportDataAction.java

License:Open Source License

public void run(IAction action) {

    final ImportDataWizard wizard;

    if (modelPart == null) {
        // no CPF is open
        wizard = new ImportDataWizard();
    } else {// w  w  w .j a  va  2  s. c om
        // Opened CPF is set as target
        wizard = new ImportDataWizard(modelPart);
        wizard.setTargetModel((ViewEditorModel) modelPart.getAdapter(ViewEditorModel.class));
    }

    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    WizardDialog dialog = new WizardDialog(window.getShell(), wizard) {
        @Override
        protected void configureShell(Shell newShell) {
            super.configureShell(newShell);
            Image image = ExtendedImageRegistry.INSTANCE
                    .getImage(ImportDataUIPlugin.INSTANCE.getImage("copyvalues_16_tlb.png"));
            newShell.setImage(image);
        }
    };
    dialog.addPageChangingListener(new IPageChangingListener() {
        public void handlePageChanging(PageChangingEvent event) {
            if (event.getCurrentPage() == wizard.getPage(ImportDataWizardPageOne.PAGE_ID)) {
                try {
                    if (!wizard.isCpfOpened()) {
                        wizard.loadSourceAndTargetModel();
                    } else {
                        wizard.loadSourceModel();
                    }
                    event.doit = true;
                } catch (Exception ex) {
                    event.doit = false;
                    ((WizardPage) event.getCurrentPage()).setErrorMessage(ex.toString());
                }
            }
        }
    });

    GC gc = new GC(window.getShell());
    FontMetrics fm = gc.getFontMetrics();
    gc.dispose();
    int minWidth = Dialog.convertWidthInCharsToPixels(fm, 35);
    int minHeight = Dialog.convertHeightInCharsToPixels(fm, 25);
    dialog.setMinimumPageSize(minWidth, minHeight);
    dialog.open();

}

From source file:com.salesforce.ide.ui.internal.utils.UIUtils.java

License:Open Source License

public static int convertHeightInCharsToPixels(Composite composite, int chars) {
    GC gc = new GC(composite.getFont().getDevice());
    gc.setFont(composite.getFont());//from w  w  w . j  av  a 2s.  c  om
    FontMetrics fFontMetrics = gc.getFontMetrics();
    gc.dispose();
    return Dialog.convertHeightInCharsToPixels(fFontMetrics, chars);
}

From source file:com.siteview.mde.internal.ui.editor.outline.QuickOutlinePopupDialog.java

License:Open Source License

private void createUIWidgetFilterText(Composite parent) {
    // Create the widget
    fFilterText = new Text(parent, SWT.NONE);
    // Set the font 
    GC gc = new GC(parent);
    gc.setFont(parent.getFont());/* w  w w .ja va2 s .com*/
    FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();
    // Create the layout
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = Dialog.convertHeightInCharsToPixels(fontMetrics, 1);
    data.horizontalAlignment = GridData.FILL;
    data.verticalAlignment = GridData.CENTER;
    fFilterText.setLayoutData(data);
}

From source file:de.byteholder.geoclipse.util.PixelConverter.java

License:Open Source License

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

From source file:de.loskutov.eclipseskins.ui.AbstractPartListControl.java

License:Open Source License

protected Text createFilterText(Composite parent) {
    Text filterText = new Text(parent, SWT.NONE);
    filterText.setToolTipText("Press <Esc> to hide tab list");
    GridData data = new GridData(GridData.FILL_HORIZONTAL);

    GC gc = new GC(parent);
    gc.setFont(parent.getFont());/* ww  w  .  j a v a2 s.c o  m*/
    FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();

    data.heightHint = Dialog.convertHeightInCharsToPixels(fontMetrics, 1);
    data.horizontalAlignment = GridData.FILL;
    data.verticalAlignment = GridData.CENTER;
    filterText.setLayoutData(data);

    filterText.addKeyListener(new KeyListener() {
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == 0x0D) {
                // return
                gotoSelectedElement();
                return;
            }
            Table table = fTableViewer.getTable();
            if (e.keyCode == SWT.ARROW_DOWN) {
                table.setFocus();
                table.setSelection(0);
            }
            if (e.keyCode == SWT.ARROW_UP) {
                table.setFocus();
                table.setSelection(table.getItemCount() - 1);
            }
            if (e.character == 0x1B) {
                // ESC
                dispose();
            }
        }

        public void keyReleased(KeyEvent e) {
            // do nothing
        }
    });
    return filterText;
}

From source file:de.walware.ecommons.ui.util.PixelConverter.java

License:Open Source License

/**
 * @see org.eclipse.jface.dialogs.DialogPage#convertHeightInCharsToPixels(int)
 *//* www  .  j  a  v a 2 s.  c om*/
public int convertHeightInCharsToPixels(final int chars) {
    return Dialog.convertHeightInCharsToPixels(fFontMetrics, chars);
}

From source file:descent.internal.ui.preferences.JavaEditorColoringConfigurationBlock.java

License:Open Source License

/**
  * Returns the number of pixels corresponding to the height of the given
  * number of characters.//from   ww w . j a  v a 2s.  c o  m
  * <p>
  * 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
  */
private int convertHeightInCharsToPixels(int chars) {
    // test for failure to initialize for backward compatibility
    if (fFontMetrics == null)
        return 0;
    return Dialog.convertHeightInCharsToPixels(fFontMetrics, chars);
}

From source file:descent.internal.ui.text.AbstractInformationControl.java

License:Open Source License

protected Text createFilterText(Composite parent) {
    fFilterText = new Text(parent, SWT.NONE);

    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    GC gc = new GC(parent);
    gc.setFont(parent.getFont());//from w  ww .  j av a2 s .c o m
    FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();

    data.heightHint = Dialog.convertHeightInCharsToPixels(fontMetrics, 1);
    data.horizontalAlignment = GridData.FILL;
    data.verticalAlignment = GridData.CENTER;
    fFilterText.setLayoutData(data);

    fFilterText.addKeyListener(new KeyListener() {
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == 0x0D) // return
                gotoSelectedElement();
            if (e.keyCode == SWT.ARROW_DOWN)
                fTreeViewer.getTree().setFocus();
            if (e.keyCode == SWT.ARROW_UP)
                fTreeViewer.getTree().setFocus();
            if (e.character == 0x1B) // ESC
                dispose();
        }

        public void keyReleased(KeyEvent e) {
            // do nothing
        }
    });

    return fFilterText;
}

From source file:gov.redhawk.ui.util.PixelConverter.java

License:Open Source License

/**
 * Convert height in chars to pixels.//from   w ww  .  j a  v a 2 s  .c o m
 * 
 * @param chars the chars
 * @return the int
 * @see DialogPage#convertHeightInCharsToPixels
 */
public int convertHeightInCharsToPixels(final int chars) {
    return Dialog.convertHeightInCharsToPixels(this.fFontMetrics, chars);
}

From source file:io.usethesource.impulse.editor.internal.AbstractInformationControl.java

License:Open Source License

protected Text createFilterText(Composite parent) {
    fFilterText = new Text(parent, SWT.NONE);
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    GC gc = new GC(parent);
    gc.setFont(parent.getFont());//from   www. jav a  2  s  . c o m
    FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();
    data.heightHint = Dialog.convertHeightInCharsToPixels(fontMetrics, 1);
    data.horizontalAlignment = GridData.FILL;
    data.verticalAlignment = GridData.CENTER;
    fFilterText.setLayoutData(data);
    fFilterText.addKeyListener(new KeyListener() {
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == 0x0D) // return
                gotoSelectedElement();
            if (e.keyCode == SWT.ARROW_DOWN)
                fTreeViewer.getTree().setFocus();
            if (e.keyCode == SWT.ARROW_UP)
                fTreeViewer.getTree().setFocus();
            if (e.character == 0x1B) // ESC
                dispose();
        }

        public void keyReleased(KeyEvent e) {
            // do nothing
        }
    });
    return fFilterText;
}