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

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

Introduction

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

Prototype

public static int convertVerticalDLUsToPixels(FontMetrics fontMetrics, int dlus) 

Source Link

Document

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

Usage

From source file:com.nokia.carbide.remoteconnections.ui.ClientServiceSiteUI.java

License:Open Source License

public void createComposite(Composite parent) {
    initializeDialogUnits(parent);// w  ww  .ja  va 2  s  . com
    Group group = new Group(parent, SWT.NONE);
    group.setText(Messages.getString("ClientServiceSiteUI.UseConnectionGroupLabel")); //$NON-NLS-1$
    group.setLayout(new GridLayout());
    group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    group.setData(UID, "useConnectionGroup"); //$NON-NLS-1$

    viewer = new ComboViewer(group, SWT.READ_ONLY);
    viewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            Check.checkContract(element instanceof IConnection);
            return ((IConnection) element).getDisplayName();
        }
    });
    viewer.setContentProvider(new ArrayContentProvider());
    GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
    viewer.getCombo().setLayoutData(gd);
    viewer.getControl().setData(UID, "viewer"); //$NON-NLS-1$
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            IConnection connection = (IConnection) selection.getFirstElement();
            if (!connection.equals(ClientServiceSiteUI.this.connection)) {
                ClientServiceSiteUI.this.connection = connection;
                fireConnectionSelected();
            }
        }
    });

    final Composite composite = new Composite(group, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.makeColumnsEqualWidth = true;
    layout.marginWidth = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.HORIZONTAL_MARGIN);
    layout.marginHeight = Dialog.convertVerticalDLUsToPixels(fm, IDialogConstants.VERTICAL_MARGIN);
    layout.horizontalSpacing = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.HORIZONTAL_SPACING);
    layout.verticalSpacing = Dialog.convertVerticalDLUsToPixels(fm, IDialogConstants.VERTICAL_SPACING);
    composite.setLayout(layout);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.VERTICAL_ALIGN_CENTER);
    composite.setLayoutData(gd);
    composite.setFont(parent.getFont());

    newButton = new Button(composite, SWT.PUSH);
    newButton.setText(Messages.getString("ClientServiceSiteUI.NewButtonLabel")); //$NON-NLS-1$
    newButton.setFont(JFaceResources.getDialogFont());
    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    int widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH);
    Point minSize = newButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    gd.widthHint = Math.max(widthHint, minSize.x);
    newButton.setLayoutData(gd);
    newButton.setData(UID, "newButton"); //$NON-NLS-1$
    newButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            SettingsWizard wizard = new SettingsWizard(null, service);
            wizard.open(composite.getShell());
            setViewerInput(wizard.getConnectionToEdit());
        }
    });

    editButton = new Button(composite, SWT.PUSH);
    editButton.setText(Messages.getString("ClientServiceSiteUI.EditButtonLabel")); //$NON-NLS-1$
    editButton.setFont(JFaceResources.getDialogFont());
    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH);
    minSize = editButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    gd.widthHint = Math.max(widthHint, minSize.x);
    editButton.setLayoutData(gd);
    editButton.setData(UID, "editButton"); //$NON-NLS-1$
    editButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            Object value = selection.getFirstElement();
            if (value instanceof IConnection) {
                SettingsWizard wizard = new SettingsWizard((IConnection) value, service);
                wizard.open(composite.getShell());
                setViewerInput(wizard.getConnectionToEdit());
            }
        }
    });

    setViewerInput(null);
}

From source file:com.nokia.cdt.internal.debug.launch.newwizard.ConnectToDeviceDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    initializeDialogUnits(parent);// w  w  w  .j  ava 2 s  .  com
    final Composite composite = initDialogArea(parent, Messages.getString("ConnectToDeviceDialog.Title"), //$NON-NLS-1$
            LaunchWizardHelpIds.WIZARD_DIALOG_CHANGE_CONNECTION);

    Group viewerGroup = new Group(composite, SWT.NONE);
    viewerGroup.setText(Messages.getString("ConnectToDeviceDialog.GroupLabel")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().applyTo(viewerGroup);
    GridLayoutFactory.swtDefaults().applyTo(viewerGroup);

    viewer = new ComboViewer(viewerGroup, SWT.READ_ONLY);
    viewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof IConnection)
                return ((IConnection) element).getDisplayName();

            return Messages.getString("ConnectToDeviceDialog.NoCurrentItem"); //$NON-NLS-1$
        }
    });
    viewer.setContentProvider(new ArrayContentProvider());
    Combo combo = viewer.getCombo();
    GridDataFactory.defaultsFor(combo).grab(true, false).applyTo(combo);
    viewer.getControl().setData(UID, "combo_viewer"); //$NON-NLS-1$
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            if (getDialogArea() != null)
                connectionSelected(getConnectionFromSelection(event.getSelection()));
        }
    });
    manager.addConnectionListener(this);

    parent.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent e) {
            manager.removeConnectionListener(ConnectToDeviceDialog.this);

            if (currentServiceListener != null)
                currentServiceListener.removeStatusChangedListener(ConnectToDeviceDialog.this);
        }
    });

    final Composite buttonGroup = new Composite(viewerGroup, SWT.NONE);
    int w = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.HORIZONTAL_MARGIN);
    int h = Dialog.convertVerticalDLUsToPixels(fm, IDialogConstants.VERTICAL_MARGIN);
    int hs = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.HORIZONTAL_SPACING);
    int vs = Dialog.convertVerticalDLUsToPixels(fm, IDialogConstants.VERTICAL_SPACING);
    GridLayoutFactory.swtDefaults().numColumns(2).equalWidth(true).margins(w, h).spacing(hs, vs)
            .applyTo(buttonGroup);
    GridDataFactory.swtDefaults().align(SWT.END, SWT.CENTER).applyTo(buttonGroup);
    buttonGroup.setFont(parent.getFont());

    newButton = new Button(buttonGroup, SWT.PUSH);
    newButton.setText(Messages.getString("ConnectToDeviceDialog.NewLabel")); //$NON-NLS-1$
    newButton.setFont(JFaceResources.getDialogFont());
    int widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH);
    Point minSize = newButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    widthHint = Math.max(widthHint, minSize.x);
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.TOP).hint(widthHint, SWT.DEFAULT).applyTo(newButton);
    newButton.setData(UID, "newButton"); //$NON-NLS-1$
    newButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            SettingsWizard wizard = new SettingsWizard(null, connectionData.getService());
            wizard.open(composite.getShell());
            IConnection connection = wizard.getConnectionToEdit();
            setViewerInput(connection);
        }
    });

    editButton = new Button(buttonGroup, SWT.PUSH);
    editButton.setText(Messages.getString("ConnectToDeviceDialog.EditLabel")); //$NON-NLS-1$
    editButton.setFont(JFaceResources.getDialogFont());
    widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH);
    minSize = editButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    widthHint = Math.max(widthHint, minSize.x);
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).hint(widthHint, SWT.DEFAULT).applyTo(editButton);
    editButton.setData(UID, "editButton"); //$NON-NLS-1$
    editButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            IConnection connection = getConnectionFromSelection(viewer.getSelection());
            if (connection != null) {
                SettingsWizard wizard = new SettingsWizard(connection, connectionData.getService());
                wizard.open(composite.getShell());
            }
        }
    });

    descriptionLabel = new Label(composite, SWT.WRAP);
    GridDataFactory.defaultsFor(descriptionLabel).grab(false, true).applyTo(descriptionLabel);
    composite.addControlListener(new ControlAdapter() {
        @Override
        public void controlResized(ControlEvent e) {
            descriptionLabel.pack();
        }
    });

    setViewerInput(connectionData.getConnection());

    return composite;
}

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

License:Open Source License

public int convertVerticalDLUsToPixels(final int dlus) {
    return Dialog.convertVerticalDLUsToPixels(fFontMetrics, dlus);
}

From source file:de.loskutov.eclipse.jdepend.preferences.JDependPreferencePage.java

License:Open Source License

private GridData getButtonGridData(Button button) {
    GridData gd = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING);
    GC gc = new GC(button);
    gc.setFont(button.getFont());/*from w ww . j a v a2 s  .  c om*/
    FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();
    int widthHint = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_WIDTH);
    gd.widthHint = Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);

    gd.heightHint = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_HEIGHT);
    return gd;
}

From source file:de.loskutov.eclipseskins.sessions.dialogs.ManageSessionsDialog.java

License:Open Source License

private GridData getButtonGridData(Button button) {
    GridData gd = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING);
    GC gc = new GC(button);
    gc.setFont(button.getFont());/*from  w  w w . j a va 2s. c  o m*/
    FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();
    int widthHint = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_WIDTH);
    gd.widthHint = Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);

    gd.heightHint = Dialog.convertVerticalDLUsToPixels(fontMetrics, 14 /*IDialogConstants.BUTTON_HEIGHT*/);
    return gd;
}

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

License:Open Source License

/**
 * @see org.eclipse.jface.dialogs.DialogPage#convertVerticalDLUsToPixels(int)
 *//*w  w  w. j av  a 2  s  . com*/
public int convertVerticalDLUsToPixels(final int dlus) {
    return Dialog.convertVerticalDLUsToPixels(fFontMetrics, dlus);
}

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

License:Open Source License

/**
 * Convert vertical dl us to pixels./*w w  w .  j av a 2  s .co m*/
 * 
 * @param dlus the dlus
 * @return the int
 * @see DialogPage#convertVerticalDLUsToPixels
 */
public int convertVerticalDLUsToPixels(final int dlus) {
    return Dialog.convertVerticalDLUsToPixels(this.fFontMetrics, dlus);
}

From source file:name.schedenig.eclipse.grepconsole.util.GridLayoutBuilder.java

License:Open Source License

/**
 * Initialises the layout and its margins based on the current font.
 *//* w  w  w .java 2  s . c  o  m*/
private void init() {
    layout = new GridLayout();

    if (fontMetrics != null) {
        layout.marginHeight = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_MARGIN);
        layout.marginWidth = Dialog.convertHorizontalDLUsToPixels(fontMetrics,
                IDialogConstants.HORIZONTAL_MARGIN);
        layout.verticalSpacing = Dialog.convertVerticalDLUsToPixels(fontMetrics,
                IDialogConstants.VERTICAL_SPACING);
        layout.horizontalSpacing = Dialog.convertHorizontalDLUsToPixels(fontMetrics,
                IDialogConstants.HORIZONTAL_SPACING);
    }

    layout.marginLeft = layout.marginRight = layout.marginWidth;
    layout.marginTop = layout.marginBottom = layout.marginHeight;
    layout.marginWidth = layout.marginHeight = 0;
}

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);//from   w w  w . j av  a  2s . co  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.cloudfoundry.ide.eclipse.server.ui.internal.wizards.CloudFoundryServiceWizardPage1.java

License:Open Source License

public int convertVerticalDLUsToPixels(Composite comp, int y) {
    if (fontMetrics == null) {
        initializeDialogUnits(comp);/* w  ww .j a va 2  s . c  o m*/
    }
    return Dialog.convertVerticalDLUsToPixels(fontMetrics, y);
}