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.emonic.base.editors.QuickOutlinePopupDialog.java

License:Open Source License

/**
 * @param parent/* ww w  . j  a va2  s  .co  m*/
 * @return
 */
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());
    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:org.erlide.ui.editors.erl.outline.QuickOutlinePopupDialog.java

License:Open Source License

/**
 * @param parent//ww  w  . j  ava2s  . c o  m
 * @return
 */
private void createUIWidgetFilterText(final Composite parent) {
    // Create the widget
    fFilterText = new Text(parent, SWT.NONE);
    // Set the font
    final GC gc = new GC(parent);
    gc.setFont(parent.getFont());
    final FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();
    // Create the layout
    final 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:org.gemoc.execution.concurrent.ccsljavaxdsml.ui.dashboard.form.FormHelper.java

License:Open Source License

/**
 * Force control size./* w w w.  j  a  va 2s . co  m*/
 * 
 * @param control_p
 * @param widthInChars_p
 *            The expected width, in number of chars to display.
 * @param heightInChars_p
 *            The expected height, in number of chars to display.
 */
public static void forceControlSize(Control control_p, int widthInChars_p, int heightInChars_p) {
    // Preconditions.
    if ((null == control_p) || (0 >= widthInChars_p) || (0 >= heightInChars_p)) {
        return;
    }
    // Get font metrics.
    GC gc = new GC(control_p);
    FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();
    // Get layout data.
    Object layoutData = control_p.getLayoutData();
    if (layoutData instanceof GridData) {
        GridData data = (GridData) layoutData;
        data.widthHint = Dialog.convertWidthInCharsToPixels(fontMetrics, widthInChars_p);
        data.heightHint = Dialog.convertHeightInCharsToPixels(fontMetrics, heightInChars_p);
    } else if (layoutData instanceof TableWrapData) {
        TableWrapData data = (TableWrapData) layoutData;
        data.heightHint = Dialog.convertHeightInCharsToPixels(fontMetrics, heightInChars_p);
    }
}

From source file:org.grails.ide.eclipse.ui.internal.inplace.GrailsInplaceDialog.java

License:Open Source License

private Text createCommandText(Composite parent) {
    promptLabel = new Label(parent, SWT.NONE);
    promptLabel.setText("grails> ");

    commandText = new Text(parent, SWT.NONE);

    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    GC gc = new GC(parent);
    gc.setFont(parent.getFont());/*from  w w w.j av a  2 s  .  com*/
    FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();

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

    commandText.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.character == SWT.ESC) { // ESC
                dispose();
                return;
            }

            if (e.doit && (e.keyCode == 0x0D || e.keyCode == SWT.KEYPAD_CR) && isDeactivateListenerActive) { // return
                e.doit = false;
                IProject project = getSelectedProject();
                if (!isValidProject(project)) {
                    openInformationMessage("Invalid Project ", getStatusMessage());
                } else if (explainNewWizardToUser()) {
                    return;
                } else {
                    addCommandToHistory(commandText.getText());
                    GrailsLaunchUtils.launch(JavaCore.create(getSelectedProject()), commandText.getText());
                    if (!isPinned())
                        dispose();
                }
                return;
            }

            if (e.doit && e.keyCode == SWT.ARROW_DOWN || e.keyCode == SWT.ARROW_UP) {
                e.doit = false;
                commandHistoryPopup();
                return;
            }
        }

    });

    refreshContentAssist();
    return commandText;
}

From source file:org.gw4e.eclipse.studio.editor.properties.edge.EdgeJavaScriptSection.java

License:Open Source License

public static int setHeight(FormData fd, Control control, int rowcount) {
    int height = 0;
    if (control != null && !control.isDisposed()) {
        GC gc = new GC(control);
        try {/*  w  ww .j  av a  2 s .  c o m*/
            gc.setFont(JFaceResources.getDialogFont());
            fd.height = Dialog.convertHeightInCharsToPixels(gc.getFontMetrics(), rowcount);
        } finally {
            gc.dispose();
        }
    }
    return height;
}

From source file:org.jboss.tools.central.editors.DescriptionToolTip.java

License:Open Source License

@Override
protected Composite createToolTipContentArea(Event event, Composite parent) {
    // Create the content area
    parent.setLayout(new GridLayout());
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 2;/*from w  w  w .  j  a  v a  2 s.co m*/
    layout.marginLeft = 2;
    composite.setLayout(layout);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.widthHint = 300;
    composite.setLayoutData(gd);
    composite.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
    Text text = new Text(composite, SWT.READ_ONLY | SWT.MULTI | SWT.WRAP);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    GC gc = new GC(parent);
    gd.heightHint = Dialog.convertHeightInCharsToPixels(gc.getFontMetrics(), (description.length() / 40) + 1);
    gc.dispose();
    text.setLayoutData(gd);
    text.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
    text.setText(description);

    return composite;
}

From source file:org.jboss.tools.common.jdt.debug.ui.launching.JBossConnectTab.java

License:Open Source License

public void createControl(Composite parent) {
    Font font = parent.getFont();
    Composite comp = SWTFactory.createComposite(parent, font, 1, 1, GridData.FILL_BOTH);
    GridLayout layout = new GridLayout();
    layout.verticalSpacing = 0;// w w w.ja v  a  2  s .c o m
    comp.setLayout(layout);

    createVerticalSpacer(comp, 2);
    jbossConfigurationButton = createCheckButton(comp, "JBoss Remote Configuration");
    jbossConfigurationButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            setDirty(true);
            updateLaunchConfigurationDialog();
        }

    });
    createVerticalSpacer(comp, 2);
    messageGroup = new Group(comp, SWT.NONE);
    messageGroup.setText(Messages.JavaConnectTab_Warning);
    messageGroup.setLayout(new GridLayout(3, false));
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
    messageGroup.setLayoutData(gd);

    Label noteLabel = new Label(messageGroup, SWT.NONE);
    gd = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false);
    noteLabel.setLayoutData(gd);
    Image image = JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_WARNING);
    image.setBackground(noteLabel.getBackground());
    noteLabel.setImage(image);

    Text noteText = new Text(messageGroup, SWT.WRAP | SWT.READ_ONLY);
    gd = new GridData(SWT.FILL, SWT.FILL, true, false);
    GC gc = new GC(parent);
    gd.heightHint = Dialog.convertHeightInCharsToPixels(gc.getFontMetrics(), 3);
    gc.dispose();
    noteText.setLayoutData(gd);
    noteText.setText(Messages.JavaConnectTab_JDK_Required);

    messageGroup.setVisible(!RemoteDebugActivator.getDefault().isJdk());

    Button addJDK = new Button(messageGroup, SWT.PUSH);
    addJDK.setText(Messages.JavaConnectTab_Add_JDK);
    gd = new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
    addJDK.setLayoutData(gd);
    addJDK.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            String preferenceId = "org.eclipse.jdt.debug.ui.preferences.VMPreferencePage"; //$NON-NLS-1$
            PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(getShell(), preferenceId, null,
                    null);
            dialog.open();
            updateLaunchConfigurationDialog();
            messageGroup.setVisible(!RemoteDebugActivator.getDefault().isJdk());
        }
    });

    setControl(comp);
}

From source file:org.jboss.tools.common.jdt.debug.ui.launching.xpl.JavaConnectTab.java

License:Open Source License

public void createControl(Composite parent) {
    Font font = parent.getFont();
    Composite comp = SWTFactory.createComposite(parent, font, 1, 1, GridData.FILL_BOTH);
    GridLayout layout = new GridLayout();
    layout.verticalSpacing = 0;/*from w  w w.  ja va 2  s  .co  m*/
    comp.setLayout(layout);
    createProjectEditor(comp);
    createVerticalSpacer(comp, 1);

    //connection properties
    Group group = SWTFactory.createGroup(comp, Messages.JavaConnectTab_Connection_Properties_1, 2, 1,
            GridData.FILL_HORIZONTAL);
    Composite cgroup = SWTFactory.createComposite(group, font, 2, 1, GridData.FILL_HORIZONTAL);
    fArgumentComposite = cgroup;
    updateConnector();

    createVerticalSpacer(comp, 2);
    fAllowTerminateButton = createCheckButton(comp, Messages.JavaConnectTab__Allow_termination_of_remote_VM_6);
    fAllowTerminateButton.addSelectionListener(getDefaultListener());

    createVerticalSpacer(comp, 2);
    defaultButton = createCheckButton(comp, Messages.JavaConnectTab_SetAsDefault);
    defaultButton.addSelectionListener(getDefaultListener());

    createVerticalSpacer(comp, 2);
    messageGroup = new Group(comp, SWT.NONE);
    messageGroup.setText(Messages.JavaConnectTab_Warning);
    messageGroup.setLayout(new GridLayout(3, false));
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
    messageGroup.setLayoutData(gd);

    Label noteLabel = new Label(messageGroup, SWT.NONE);
    gd = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false);
    noteLabel.setLayoutData(gd);
    Image image = JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_WARNING);
    image.setBackground(noteLabel.getBackground());
    noteLabel.setImage(image);

    Text noteText = new Text(messageGroup, SWT.WRAP | SWT.READ_ONLY);
    gd = new GridData(SWT.FILL, SWT.FILL, true, false);
    GC gc = new GC(parent);
    gd.heightHint = Dialog.convertHeightInCharsToPixels(gc.getFontMetrics(), 3);
    gc.dispose();
    noteText.setLayoutData(gd);
    noteText.setText(Messages.JavaConnectTab_JDK_Required);

    messageGroup.setVisible(!RemoteDebugActivator.getDefault().isJdk());

    Button addJDK = new Button(messageGroup, SWT.PUSH);
    addJDK.setText(Messages.JavaConnectTab_Add_JDK);
    gd = new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
    addJDK.setLayoutData(gd);
    addJDK.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            String preferenceId = "org.eclipse.jdt.debug.ui.preferences.VMPreferencePage"; //$NON-NLS-1$
            PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(getShell(), preferenceId, null,
                    null);
            dialog.open();
            refresh(hostCombo.getText(), false);
            updateLaunchConfigurationDialog();
            messageGroup.setVisible(!RemoteDebugActivator.getDefault().isJdk());
        }
    });

    setControl(comp);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(),
            IJavaDebugHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_CONNECT_TAB);
}

From source file:org.jboss.tools.common.ui.preferences.SeverityConfigurationBlock.java

License:Open Source License

private int convertHeightInCharsToPixels(Control control, int chars) {
    Font font = control.getFont();
    GC gc = new GC(font.getDevice());
    gc.setFont(font);/*w  w w.j a  va2 s  .c o  m*/
    FontMetrics fFontMetrics = gc.getFontMetrics();
    gc.dispose();
    return Dialog.convertHeightInCharsToPixels(fFontMetrics, chars);
}

From source file:org.jboss.tools.project.examples.wizard.NewProjectExamplesMainPage.java

License:Open Source License

public void createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, false));
    GridData gd = new GridData(SWT.FILL, SWT.FILL, false, false);
    composite.setLayoutData(gd);//from  w w  w  .ja  v a 2s  . com

    Composite siteComposite = new Composite(composite, SWT.NONE);
    GridLayout gridLayout = new GridLayout(2, false);
    gridLayout.marginHeight = 0;
    gridLayout.marginWidth = 0;
    siteComposite.setLayout(gridLayout);
    gd = new GridData(SWT.FILL, SWT.BEGINNING, false, false);
    siteComposite.setLayoutData(gd);

    final Button button = new Button(siteComposite, SWT.CHECK);
    gd = new GridData(SWT.FILL, SWT.BEGINNING, false, false);
    gd.horizontalSpan = 2;
    button.setLayoutData(gd);
    button.setText(Messages.ProjectExamplesPreferencePage_Show_experimental_sites);
    final IPreferenceStore store = ProjectExamplesActivator.getDefault().getPreferenceStore();
    button.setSelection(store.getBoolean(ProjectExamplesActivator.SHOW_EXPERIMENTAL_SITES));

    final Button serverButton = new Button(siteComposite, SWT.CHECK);
    gd = new GridData(SWT.FILL, SWT.BEGINNING, false, false);
    gd.horizontalSpan = 2;
    serverButton.setLayoutData(gd);
    serverButton.setText(Messages.ProjectExamplesPreferencePage_Show_runtime_sites);
    serverButton.setSelection(store.getBoolean(ProjectExamplesActivator.SHOW_RUNTIME_SITES));

    new Label(siteComposite, SWT.NONE).setText(Messages.NewProjectExamplesWizardPage_Site);
    siteCombo = new Combo(siteComposite, SWT.READ_ONLY);
    siteCombo.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));

    new Label(siteComposite, SWT.NONE).setText(Messages.NewProjectExamplesMainPage_TargetedRuntime);
    targetRuntimeTypesCombo = new Combo(siteComposite, SWT.READ_ONLY);
    targetRuntimeTypesCombo.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));

    new Label(composite, SWT.NONE).setText(Messages.NewProjectExamplesWizardPage_Projects);

    final ProjectExamplesPatternFilter filter = new ProjectExamplesPatternFilter();

    int styleBits = SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.WRAP;
    final FilteredTree filteredTree = new FilteredTree(composite, styleBits, filter, true);
    filteredTree.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    final TreeViewer viewer = filteredTree.getViewer();
    Tree tree = viewer.getTree();
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    GC gc = new GC(parent);
    gd.heightHint = Dialog.convertHeightInCharsToPixels(gc.getFontMetrics(), 9);
    gc.dispose();
    tree.setLayoutData(gd);
    tree.setFont(parent.getFont());

    viewer.setLabelProvider(new ProjectLabelProvider());
    viewer.setContentProvider(new ProjectContentProvider());

    final SiteFilter siteFilter = new SiteFilter();
    final RuntimeTypeFilter serverFilter = new RuntimeTypeFilter();

    viewer.addFilter(siteFilter);
    viewer.addFilter(serverFilter);

    Label descriptionLabel = new Label(composite, SWT.NONE);
    descriptionLabel.setText(Messages.NewProjectExamplesWizardPage_Description);
    descriptionText = new Text(composite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.READ_ONLY | SWT.BORDER | SWT.WRAP);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gc = new GC(parent);
    gd.heightHint = Dialog.convertHeightInCharsToPixels(gc.getFontMetrics(), 6);
    gc.dispose();
    descriptionText.setLayoutData(gd);

    Composite internal = new Composite(composite, SWT.NULL);
    internal.setLayout(new GridLayout(2, false));
    gd = new GridData(GridData.FILL, GridData.FILL, true, false);
    gd.widthHint = DEFAULT_WIDTH;
    internal.setLayoutData(gd);

    Label projectNameLabel = new Label(internal, SWT.NULL);
    projectNameLabel.setText(Messages.NewProjectExamplesWizardPage_Project_name);
    final Text projectName = new Text(internal, SWT.BORDER | SWT.READ_ONLY);
    projectName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    Label projectSizeLabel = new Label(internal, SWT.NULL);
    projectSizeLabel.setText(Messages.NewProjectExamplesWizardPage_Project_size);
    final Text projectSize = new Text(internal, SWT.BORDER | SWT.READ_ONLY);
    projectSize.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    Label projectURLLabel = new Label(internal, SWT.NULL);
    projectURLLabel.setText(Messages.NewProjectExamplesWizardPage_URL);
    final Text projectURL = new Text(internal, SWT.BORDER | SWT.READ_ONLY);
    projectURL.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            selection = (IStructuredSelection) event.getSelection();
            Object selected = selection.getFirstElement();
            String projectType = null;
            if (selected instanceof ProjectExample && selection.size() == 1) {
                selectedProject = (ProjectExample) selected;
                descriptionText.setText(selectedProject.getDescription());
                projectName.setText(selectedProject.getName());
                projectURL.setText(selectedProject.getUrl());
                projectSize.setText(selectedProject.getSizeAsText());
                //readyPage.setProjectExample(selectedProject);
                projectType = selectedProject.getImportType();
            } else {
                selectedProject = null;
                String description = ""; //$NON-NLS-1$
                if (selected instanceof ProjectExampleCategory) {
                    ProjectExampleCategory category = (ProjectExampleCategory) selected;
                    if (category.getDescription() != null) {
                        description = category.getDescription();
                    }
                }
                descriptionText.setText(description);
                projectName.setText(""); //$NON-NLS-1$
                projectURL.setText(""); //$NON-NLS-1$
                projectSize.setText(""); //$NON-NLS-1$
            }

            for (IWizardPage page : getWizard().getPages()) {
                if (page instanceof IProjectExamplesWizardPage) {
                    IProjectExamplesWizardPage pewp = (IProjectExamplesWizardPage) page;
                    if (projectType != null && projectType.equals(pewp.getProjectExampleType())) {
                        pewp.setProjectExample(selectedProject);
                    } else {
                        pewp.setProjectExample(null);
                    }
                }
            }

            boolean canFinish = refresh(false);
            setPageComplete(canFinish);
        }

    });

    siteCombo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            siteFilter.setSite(siteCombo.getText());
            viewer.refresh();
        }

    });

    button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            IPreferenceStore store = ProjectExamplesActivator.getDefault().getPreferenceStore();
            store.setValue(ProjectExamplesActivator.SHOW_EXPERIMENTAL_SITES, button.getSelection());

            //Store current combo selections
            String selectedRuntime = targetRuntimeTypesCombo.getText();
            String selectedSite = siteCombo.getText();

            //Rebuild the combo lists
            refresh(viewer, true);

            //Restore the combo selections with initial values if possible
            restoreCombo(targetRuntimeTypesCombo, selectedRuntime);
            restoreCombo(siteCombo, selectedSite);

            siteFilter.setSite(siteCombo.getText());
            viewer.refresh();
        }

    });

    serverButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            IPreferenceStore store = ProjectExamplesActivator.getDefault().getPreferenceStore();
            store.setValue(ProjectExamplesActivator.SHOW_RUNTIME_SITES, serverButton.getSelection());

            //Store current combo selections
            String selectedRuntime = targetRuntimeTypesCombo.getText();
            String selectedSite = siteCombo.getText();

            //Rebuild the combo lists
            refresh(viewer, true);

            //Restore the combo selections with initial values if possible
            restoreCombo(targetRuntimeTypesCombo, selectedRuntime);
            restoreCombo(siteCombo, selectedSite);

            siteFilter.setSite(siteCombo.getText());
            viewer.refresh();
        }

    });

    targetRuntimeTypesCombo.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            serverFilter.setRuntimeType(targetRuntimeTypesCombo.getText());
            viewer.refresh();
        }
    });

    setPageComplete(false);

    setControl(composite);

    refresh(viewer, true);
    siteCombo.setText(ProjectExamplesActivator.ALL_SITES);

    targetRuntimeTypesCombo.setText(ProjectExamplesActivator.ALL_RUNTIMES);

}