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:com.maccasoft.composer.InstrumentEditor.java

License:Open Source License

protected Control createButtonBar(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);

    GridLayout layout = new GridLayout();
    layout.numColumns = 0;/*from  ww w  .jav a 2  s . c o m*/
    layout.makeColumnsEqualWidth = false;
    layout.marginWidth = 0;
    layout.marginTop = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_MARGIN);
    layout.horizontalSpacing = Dialog.convertHorizontalDLUsToPixels(fontMetrics,
            IDialogConstants.HORIZONTAL_SPACING);
    layout.verticalSpacing = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_SPACING);
    composite.setLayout(layout);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));

    Button button = createButton(composite, -1, "Get Spin Data");
    button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            StringBuilder sb = new StringBuilder();
            sb.append("DAT\n\n");

            sb.append(name.getText().replace(' ', '_'));
            sb.append("\n");

            for (Command cmd : list) {
                if (!cmd.isDisabled()) {
                    sb.append("    " + cmd.toSpinString() + "\n");
                }
            }

            TextDialog dlg = new TextDialog(getShell());
            dlg.setString(sb.toString());
            dlg.open();
        }
    });

    button = createButton(composite, -1, "Get C Data");
    button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            StringBuilder sb = new StringBuilder();
            sb.append(String.format("uint32_t %s[] = {\n", name.getText().replace(' ', '_')));

            for (Command cmd : list) {
                if (!cmd.isDisabled()) {
                    sb.append("    " + cmd.toCString() + ",\n");
                }
            }

            sb.append("};\n");

            TextDialog dlg = new TextDialog(getShell());
            dlg.setString(sb.toString());
            dlg.open();
        }
    });

    Label label = new Label(composite, SWT.NONE);
    label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    layout.numColumns++;

    button = createButton(composite, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL);
    button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            okPressed();
            setReturnCode(OK);
            close();
        }
    });
    getShell().setDefaultButton(button);

    button = createButton(composite, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL);
    button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            close();
        }
    });

    return composite;
}

From source file:com.maccasoft.composer.InstrumentEditor.java

License:Open Source License

protected Button createButton(Composite parent, int id, String label) {
    ((GridLayout) parent.getLayout()).numColumns++;

    Button button = new Button(parent, SWT.PUSH);
    button.setText(label);/*from   w  ww  . j av a 2  s. c  o  m*/
    button.setFont(JFaceResources.getDialogFont());
    button.setData(new Integer(id));

    GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    int widthHint = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_WIDTH);
    Point minSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    data.widthHint = Math.max(widthHint, minSize.x);
    button.setLayoutData(data);

    return button;
}

From source file:com.maccasoft.composer.PianoKeyboard.java

License:Open Source License

public PianoKeyboard(Composite parent) {
    GC gc = new GC(parent);
    FontMetrics fontMetrics = gc.getFontMetrics();
    keyWidth = Dialog.convertHorizontalDLUsToPixels(fontMetrics, 10);
    diesisKeyWidth = Dialog.convertHorizontalDLUsToPixels(fontMetrics, 6);
    gc.dispose();//from w w  w . ja  v a2  s . c  om

    firstOctave = 0;
    octaves = 5;

    canvas = new Canvas(parent, SWT.NONE);
    canvas.setSize(octaves * keyWidth * 7, SWT.DEFAULT);
    canvas.addPaintListener(paintListener);
    canvas.addMouseListener(mouseListener);
    canvas.addMouseMoveListener(mouseMoveListener);
    canvas.addMouseTrackListener(mouseTrackListener);
    canvas.addKeyListener(keyListener);
}

From source file:com.microsoft.tfs.client.common.ui.controls.generic.BaseControl.java

License:Open Source License

public BaseControl(final Composite parent, final int style) {
    super(parent, style);

    /* Compute metrics in pixels */
    final GC gc = new GC(this);
    final FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();/*w w  w .  java 2  s  .  c om*/

    horizontalSpacing = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_SPACING);
    verticalSpacing = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_SPACING);

    spacing = Math.max(horizontalSpacing, verticalSpacing);

    horizontalMargin = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_MARGIN);
    verticalMargin = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_MARGIN);

    minimumMessageAreaWidth = Dialog.convertHorizontalDLUsToPixels(fontMetrics,
            IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
}

From source file:com.microsoft.tfs.client.common.ui.dialogs.vc.ApplyLabelDialog.java

License:Open Source License

private void createOkButton(final Composite parent) {
    okButton = MenuButtonFactory.getMenuButton(parent, SWT.NONE);
    okButton.setText(Messages.getString("ApplyLabelDialog.OkButtonText")); //$NON-NLS-1$

    final GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    okButton.setLayoutData(data);//from w  w  w  . j  a  v a2 s.  c  o  m

    /* Set to default size */
    final GC gc = new GC(okButton);
    final FontMetrics fm = gc.getFontMetrics();
    gc.dispose();

    final int widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH);
    final Point okSize = okButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    okSize.x = Math.max(widthHint, okSize.x);
    ControlSize.setSizeHints(okButton, okSize);

    /* Create menu */
    okButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent e) {
            editLabel = false;
            okPressed();
        }
    });

    final IAction createLabelAction = new Action() {
        @Override
        public void run() {
            editLabel = false;
            okPressed();
        }
    };
    createLabelAction.setText(Messages.getString("ApplyLabelDialog.CreateLabelActionText")); //$NON-NLS-1$

    final IAction createAndEditLabelAction = new Action() {
        @Override
        public void run() {
            editLabel = true;
            okPressed();
        }
    };
    createAndEditLabelAction.setText(Messages.getString("ApplyLabelDialog.EditLabelActionText")); //$NON-NLS-1$

    okButton.addMenuListener(new IMenuListener() {
        @Override
        public void menuAboutToShow(final IMenuManager manager) {
            manager.add(createLabelAction);
            manager.add(createAndEditLabelAction);
        }
    });

    getShell().setDefaultButton(okButton.getButton());

    validate();
}

From source file:com.microsoft.tfs.client.common.ui.editors.ConflictResolutionEditor.java

License:Open Source License

@Override
public void createPartControl(final Composite parent) {
    final Composite composite = new Composite(parent, SWT.NONE);

    /* Compute metrics in pixels */
    final GC gc = new GC(composite);
    final FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();//from  w  w  w .  j a v a 2s.c om

    Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_SPACING);
    Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_SPACING);
    final int marginWidth = Dialog.convertHorizontalDLUsToPixels(fontMetrics,
            IDialogConstants.HORIZONTAL_MARGIN);
    final int marginHeight = Dialog.convertHorizontalDLUsToPixels(fontMetrics,
            IDialogConstants.VERTICAL_MARGIN);

    final GridLayout layout = new GridLayout(1, false);
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    composite.setLayout(layout);

    final Composite summaryComposite = new Composite(composite, SWT.NONE);
    GridDataBuilder.newInstance().hGrab().hFill().applyTo(summaryComposite);

    final GridLayout summaryLayout = new GridLayout(1, false);
    summaryLayout.horizontalSpacing = 0;
    summaryLayout.verticalSpacing = 0;
    summaryLayout.marginWidth = marginWidth;
    summaryLayout.marginHeight = marginHeight;
    summaryComposite.setLayout(summaryLayout);
    summaryComposite.setBackground(getSite().getShell().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));

    summaryLabel = new Label(summaryComposite, SWT.NONE);
    summaryLabel.setBackground(getSite().getShell().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
    summaryLabel.setForeground(getSite().getShell().getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
    GridDataBuilder.newInstance().hGrab().hFill().applyTo(summaryLabel);

    final Label separatorLabel = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
    GridDataBuilder.newInstance().hGrab().hFill().applyTo(separatorLabel);

    final Composite toolbarComposite = new Composite(composite, SWT.NONE);
    GridDataBuilder.newInstance().hGrab().hFill().applyTo(toolbarComposite);

    final GridLayout toolbarCompositeLayout = new GridLayout(1, false);
    toolbarCompositeLayout.horizontalSpacing = 0;
    toolbarCompositeLayout.verticalSpacing = 0;
    toolbarCompositeLayout.marginWidth = marginWidth;
    toolbarCompositeLayout.marginHeight = 0;
    toolbarComposite.setLayout(toolbarCompositeLayout);

    toolbar = new ToolBar(toolbarComposite, SWT.HORIZONTAL | SWT.FLAT | SWT.RIGHT);
    GridDataBuilder.newInstance().hGrab().hFill().applyTo(toolbar);

    setupToolbar(toolbar);

    conflictTable = new ConflictTable(composite, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
    conflictTable.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            updateSelection();
        }
    });

    final MenuManager menuManager = new MenuManager("#popup"); //$NON-NLS-1$
    menuManager.setRemoveAllWhenShown(true);
    menuManager.addMenuListener(new IMenuListener() {
        @Override
        public void menuAboutToShow(final IMenuManager manager) {
            fillContextMenu(manager);
        }
    });
    conflictTable.setMenu(menuManager.createContextMenu(conflictTable));

    GridDataBuilder.newInstance().grab().fill().applyTo(conflictTable);

    getSite().setSelectionProvider(conflictTable);

    /*
     * Set up the resolution options control
     */

    conflictResolutionControl = new ConflictResolutionControl(composite, SWT.NONE);
    conflictResolutionControl.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(final SelectionChangedEvent e) {
            conflictTable.setSelection(e.getSelection());
        }
    });
    conflictResolutionControl.addConflictResolutionSelectionListener(new ConflictResolutionSelectionListener() {
        @Override
        public void conflictResolutionSelected(final ConflictDescription[] conflictDescriptions,
                final ConflictResolution resolution) {
            if (conflictDescriptions.length == 1) {
                resolveConflict(conflictDescriptions[0], resolution);
            } else {
                resolveConflicts(conflictDescriptions, resolution);
            }
        }
    });
    conflictResolutionControl.addConflictResolutionCancelledListener(new ConflictResolutionCancelledListener() {
        @Override
        public void conflictResolutionCancelled(final ConflictDescription conflictDescription,
                final ConflictResolution resolution) {
            resolution.removeStatusListener(ConflictResolutionEditor.this);
            resolution.cancel();
        }
    });
    GridDataBuilder.newInstance().hGrab().hFill().applyTo(conflictResolutionControl);

    setPartName(Messages.getString("ConflictResolutionEditor.PartName")); //$NON-NLS-1$

    if (needsPaint == true) {
        if (initialConflicts == null) {
            queryConflicts(null);
        } else {
            setConflictDescriptions(initialConflicts);
        }
    } else {
        updateSummary();
        updateSelection();
    }

    hasPainted = true;
}

From source file:com.microsoft.tfs.client.common.ui.editors.HistoryEditor.java

License:Open Source License

@Override
public void createPartControl(final Composite parent) {
    final Composite composite = new Composite(parent, SWT.NONE);

    /* Compute metrics in pixels */
    final GC gc = new GC(composite);
    final FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();//from   w w  w.  java 2 s .  c  om

    final int horizontalSpacing = Dialog.convertHorizontalDLUsToPixels(fontMetrics,
            IDialogConstants.HORIZONTAL_SPACING);
    final int verticalSpacing = Dialog.convertVerticalDLUsToPixels(fontMetrics,
            IDialogConstants.VERTICAL_SPACING);
    final int marginWidth = Dialog.convertHorizontalDLUsToPixels(fontMetrics,
            IDialogConstants.HORIZONTAL_MARGIN);
    final int marginHeight = Dialog.convertHorizontalDLUsToPixels(fontMetrics,
            IDialogConstants.VERTICAL_MARGIN);

    final GridLayout layout = new GridLayout(1, false);
    layout.horizontalSpacing = horizontalSpacing;
    layout.verticalSpacing = verticalSpacing;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    composite.setLayout(layout);

    final Composite locationComposite = new Composite(composite, SWT.NONE);
    GridDataBuilder.newInstance().hGrab().hFill().applyTo(locationComposite);

    final GridLayout locationLayout = new GridLayout(3, false);
    locationLayout.horizontalSpacing = horizontalSpacing;
    locationLayout.verticalSpacing = verticalSpacing;
    locationLayout.marginWidth = marginWidth;
    locationLayout.marginHeight = marginHeight;
    locationComposite.setLayout(locationLayout);

    final Label locationLabel = new Label(locationComposite, SWT.NONE);
    locationLabel.setText(Messages.getString("HistoryEditor.SourceLocationLabel")); //$NON-NLS-1$

    locationText = new Text(locationComposite, SWT.BORDER | SWT.READ_ONLY);
    GridDataBuilder.newInstance().hGrab().hFill().applyTo(locationText);

    final Button refreshButton = new Button(locationComposite, SWT.PUSH);

    /* Icons in buttons look good on Windows, strange elsewhere. */
    if (Platform.isCurrentPlatform(Platform.WINDOWS)) {
        refreshButton.setImage(
                imageHelper.getImage(TFSCommonUIImages.getImageDescriptor(TFSCommonUIImages.IMG_REFRESH)));
    }

    refreshButton.setText(Messages.getString("HistoryEditor.RefreshActionText")); //$NON-NLS-1$
    GridDataBuilder.newInstance().applyTo(refreshButton);

    historyControl = new HistoryCombinedControl(composite, SWT.FULL_SELECTION | SWT.MULTI);
    GridDataBuilder.newInstance().grab().fill().hSpan(3).applyTo(historyControl);

    historyControl.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            updateStatusLine((IStructuredSelection) event.getSelection());
        }
    });

    getSite().setSelectionProvider(historyControl);

    createActions();

    // getEditorSite().getActionBars().setGlobalActionHandler(
    // ActionFactory.COPY.getId(),
    // historyControl.getCopyAction());
    // getEditorSite().getActionBars().updateActionBars();
    refreshButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            refresh();

        }

        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
            refresh();
        }
    });

    setPartName(Messages.getString("HistoryEditor.PartName")); //$NON-NLS-1$
    contributeActions();

    TFSCommonUIClientPlugin.getDefault().getProductPlugin().getRepositoryManager()
            .addListener(repositoryManagerListener);
}

From source file:com.microsoft.tfs.client.common.ui.framework.helper.ButtonHelper.java

License:Open Source License

public static final void setButtonToButtonBarSize(final Button button) {
    final GC gc = new GC(button);
    final FontMetrics fm = gc.getFontMetrics();
    gc.dispose();//from   w w  w . jav  a 2  s .  c  om

    final int widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH);
    final Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);

    size.x = Math.max(widthHint, size.x);

    ControlSize.setSizeHints(button, size);
}

From source file:com.microsoft.tfs.client.common.ui.framework.layout.GridDataBuilder.java

License:Open Source License

public GridDataBuilder wButtonHint(final Control control) {
    final int widthHint = Dialog.convertHorizontalDLUsToPixels(ControlSize.getFontMetrics(control),
            IDialogConstants.BUTTON_WIDTH);
    final Point minSize = control.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    gridData.widthHint = Math.max(widthHint, minSize.x);

    return this;
}

From source file:com.microsoft.tfs.client.common.ui.framework.wizard.BaseWizardPage.java

License:Open Source License

private final void computeMetrics() {
    Control control = getControl();

    if (control == null && Display.getCurrent() != null) {
        control = Display.getCurrent().getActiveShell();
    }//from   w w  w. jav a 2s. c om

    if (control == null) {
        return;
    }

    /* Compute metrics in pixels */
    final GC gc = new GC(control);
    final FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();

    horizontalSpacing = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_SPACING);
    verticalSpacing = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_SPACING);

    spacing = Math.max(horizontalSpacing, verticalSpacing);

    horizontalMargin = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_MARGIN);
    verticalMargin = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_MARGIN);

    initializedMetrics = true;
}