List of usage examples for org.eclipse.jface.dialogs Dialog convertHorizontalDLUsToPixels
public static int convertHorizontalDLUsToPixels(FontMetrics fontMetrics, int dlus)
From source file:com.microsoft.tfs.client.common.ui.prefs.BasePreferencePage.java
License:Open Source License
private void computeMetrics() { Control control = getControl(); if (control == null && Display.getCurrent() != null) { control = Display.getCurrent().getActiveShell(); }/*ww w. jav a 2s. c o m*/ 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); }
From source file:com.microsoft.tfs.client.common.ui.teambuild.editors.BuildEditorPage.java
License:Open Source License
private void createControls(final Composite composite) { final GridLayout layout = new GridLayout(1, false); layout.horizontalSpacing = 0;//from ww w. j a va2 s. c o m layout.verticalSpacing = 0; layout.marginWidth = 0; layout.marginHeight = 0; composite.setLayout(layout); final Composite header = new Composite(composite, SWT.NONE); GridDataBuilder.newInstance().hFill().hGrab().applyTo(header); /* Compute metrics in pixels */ final GC gc = new GC(header); final FontMetrics fontMetrics = gc.getFontMetrics(); gc.dispose(); final GridLayout headerLayout = new GridLayout(3, false); headerLayout.horizontalSpacing = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_SPACING); headerLayout.verticalSpacing = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_SPACING); headerLayout.marginWidth = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_MARGIN); headerLayout.marginHeight = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_MARGIN); header.setLayout(headerLayout); SWTUtil.createLabel(header, Messages.getString("BuildEditorPage.BuildDefinitionLabelText")); //$NON-NLS-1$ SWTUtil.createLabel(header, Messages.getString("BuildEditorPage.QualityFilterLabelText")); //$NON-NLS-1$ SWTUtil.createLabel(header, Messages.getString("BuildEditorPage.DateFilterLabelText")); //$NON-NLS-1$ buildDefinitionFilterCombo = new Combo(header, SWT.READ_ONLY); GridDataBuilder.newInstance().fill().hGrab().applyTo(buildDefinitionFilterCombo); qualityFilterCombo = new Combo(header, SWT.READ_ONLY); GridDataBuilder.newInstance().fill().applyTo(qualityFilterCombo); ControlSize.setCharWidthHint(qualityFilterCombo, 30); dateFilterCombo = new Combo(header, SWT.READ_ONLY); GridDataBuilder.newInstance().fill().applyTo(dateFilterCombo); ControlSize.setCharWidthHint(dateFilterCombo, 25); onlyMyBuildsCheck = new Button(header, SWT.CHECK); onlyMyBuildsCheck.setText(Messages.getString("BuildEditorPage.OnlyMyBuilds")); //$NON-NLS-1$ onlyMyBuildsCheck.setEnabled(buildServer.getBuildServerVersion().isV3OrGreater()); GridDataBuilder.newInstance().fill().hSpan(3).applyTo(onlyMyBuildsCheck); final Label separator = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL); GridDataBuilder.newInstance().hGrab().hFill().applyTo(separator); buildsTableControl = new BuildsTableControl(composite, SWT.MULTI | SWT.FULL_SELECTION | TableControl.NO_BORDER, buildServer, teamProject); GridDataBuilder.newInstance().grab().fill().applyTo(buildsTableControl); buildsTableControl.addDoubleClickListener(new IDoubleClickListener() { @Override public void doubleClick(final DoubleClickEvent event) { onDoubleClick(event); } }); buildsTableControl.getContextMenu().addMenuListener(new IMenuListener() { @Override public void menuAboutToShow(final IMenuManager manager) { fillMenu(manager); } }); // Add listener to be informed when build details are changed and our // copy might become stale. Remove the listener on dispose. BuildHelpers.getBuildManager().addBuildManagerListener(buildManagerListener); buildsTableControl.addDisposeListener(new DisposeListener() { @Override public void widgetDisposed(final DisposeEvent e) { BuildHelpers.getBuildManager().removeBuildManagerListener(buildManagerListener); } }); populateCombos(false); buildDefinitionFilterCombo.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { filterChanged(); } }); dateFilterCombo.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { filterChanged(); } }); qualityFilterCombo.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { filterChanged(); } }); onlyMyBuildsCheck.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { filterChanged(); } }); getSite().setSelectionProvider(this); if (buildServer.getBuildServerVersion().isV1()) { dateFilterCombo.setText(Messages.getString("BuildEditorPage.AnyTimeChoice")); //$NON-NLS-1$ dateFilterCombo.setEnabled(false); qualityFilterCombo.setEnabled(false); } }
From source file:com.microsoft.tfs.client.common.ui.teambuild.editors.QueueEditorPage.java
License:Open Source License
private void createControls(final Composite composite) { final GridLayout layout = new GridLayout(1, false); layout.horizontalSpacing = 0;//from w ww . j a v a2 s .c o m layout.verticalSpacing = 0; layout.marginWidth = 0; layout.marginHeight = 0; composite.setLayout(layout); final Composite header = new Composite(composite, SWT.NONE); GridDataBuilder.newInstance().hFill().hGrab().applyTo(header); /* Compute metrics in pixels */ final GC gc = new GC(header); final FontMetrics fontMetrics = gc.getFontMetrics(); gc.dispose(); final GridLayout headerLayout = new GridLayout(3, false); headerLayout.horizontalSpacing = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_SPACING); headerLayout.verticalSpacing = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_SPACING); headerLayout.marginWidth = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_MARGIN); headerLayout.marginHeight = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_MARGIN); header.setLayout(headerLayout); SWTUtil.createLabel(header, Messages.getString("QueueEditorPage.BuildDefinitionLabelText")); //$NON-NLS-1$ SWTUtil.createLabel(header, Messages.getString("QueueEditorPage.StatusFilterLabelText")); //$NON-NLS-1$ SWTUtil.createLabel(header, buildServer.getBuildServerVersion().isV3OrGreater() ? Messages.getString("QueueEditorPage.ControlFilterLabelText") //$NON-NLS-1$ : Messages.getString("QueueEditorPage.AgentFilterLabelText")); //$NON-NLS-1$ buildDefinitionFilterCombo = new Combo(header, SWT.READ_ONLY); GridDataBuilder.newInstance().fill().hGrab().applyTo(buildDefinitionFilterCombo); statusFilterCombo = new Combo(header, SWT.READ_ONLY); GridDataBuilder.newInstance().fill().applyTo(statusFilterCombo); ControlSize.setCharWidthHint(statusFilterCombo, 25); controllerFilterCombo = new Combo(header, SWT.READ_ONLY); GridDataBuilder.newInstance().fill().applyTo(controllerFilterCombo); ControlSize.setCharWidthHint(controllerFilterCombo, 30); onlyMyBuildsCheck = new Button(header, SWT.CHECK); onlyMyBuildsCheck.setText(Messages.getString("BuildEditorPage.OnlyMyBuilds")); //$NON-NLS-1$ onlyMyBuildsCheck.setEnabled(buildServer.getBuildServerVersion().isV3OrGreater()); GridDataBuilder.newInstance().fill().hSpan(3).applyTo(onlyMyBuildsCheck); final Label separator = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL); GridDataBuilder.newInstance().hGrab().hFill().applyTo(separator); queuedBuildsTable = new QueuedBuildsTableControl(composite, SWT.MULTI | SWT.FULL_SELECTION | TableControl.NO_BORDER, buildServer); GridDataBuilder.newInstance().hSpan(layout).grab().fill().applyTo(queuedBuildsTable); queuedBuildsTable.addDoubleClickListener(new IDoubleClickListener() { @Override public void doubleClick(final DoubleClickEvent event) { onDoubleClick(event); } }); queuedBuildsTable.getContextMenu().addMenuListener(new IMenuListener() { @Override public void menuAboutToShow(final IMenuManager manager) { fillMenu(manager); } }); populateCombos(false); getSite().setSelectionProvider(this); buildDefinitionFilterCombo.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { filterChanged(); } }); statusFilterCombo.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { filterChanged(); } }); controllerFilterCombo.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { filterChanged(); } }); onlyMyBuildsCheck.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { filterChanged(); } }); }
From source file:com.microsoft.tfs.client.common.ui.views.DeprecatedByTeamExplorerView.java
License:Open Source License
@Override public final void createPartControl(final Composite parent) { /* Compute metrics in pixels */ final GC gc = new GC(parent); final FontMetrics fontMetrics = gc.getFontMetrics(); gc.dispose();//from w ww .j a va 2s . co m final GridLayout layout = new GridLayout(2, false); layout.horizontalSpacing = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_SPACING) * 2; layout.verticalSpacing = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_SPACING); layout.marginWidth = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_MARGIN); layout.marginHeight = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_MARGIN); parent.setLayout(layout); final Label imageLabel = new Label(parent, SWT.NONE); imageLabel.setImage(Display.getCurrent().getSystemImage(SWT.ICON_INFORMATION)); final Link textLabel = new Link(parent, SWT.READ_ONLY | SWT.WRAP); textLabel.setText(Messages.getString("DeprecatedByTeamExplorerView.DeprecatedText")); //$NON-NLS-1$ textLabel.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { try { final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow() .getActivePage(); page.showView(TeamExplorerView.ID); } catch (final Exception f) { log.warn("Could not open Team Explorer View", f); //$NON-NLS-1$ MessageDialog.openError(getSite().getShell(), Messages.getString("DeprecatedByTeamExplorerView.OpenViewFailedTitle"), //$NON-NLS-1$ Messages.getString("DeprecatedByTeamExplorerView.OpenViewFailedMessage")); //$NON-NLS-1$ } } }); GridDataBuilder.newInstance().hGrab().hFill().applyTo(textLabel); }
From source file:com.motorola.studio.android.emulator.core.emulationui.SrcDestComposite.java
License:Apache License
/** * Defines the width hint to be used for the given label on a GridData object. * //from ww w . jav a 2s . com * @param label the label to calculate the width hint for * * @return the width hint */ private int getLabelWidthHint(Label label) { int widthHint = Dialog.convertHorizontalDLUsToPixels(fontMetrics, label.getText().length()); return Math.max(widthHint, label.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); }
From source file:com.nokia.carbide.remoteconnections.internal.ui.ClientServiceSiteUI2.java
License:Open Source License
public void createComposite(Composite parent) { initializeDialogUnits(parent);//from w ww .j a va 2 s.c o m Group group = new Group(parent, SWT.NONE); group.setText(Messages.getString("ClientServiceSiteUI2.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 String); String id = (String) element; return connectionNames.get(id); } }); 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(); String connection = (String) selection.getFirstElement(); if (connection != null && !connection.equals(ClientServiceSiteUI2.this.connection)) { ClientServiceSiteUI2.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("ClientServiceSiteUI2.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()); IConnection connection = wizard.getConnectionToEdit(); // note: refresh ASAP so the selection will be valid; but endure a listener event // which will redo this refreshUI(); setViewerInput(connection); } }); editButton = new Button(composite, SWT.PUSH); editButton.setText(Messages.getString("ClientServiceSiteUI2.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 String) { IConnection editConnection = getActualConnection((String) value); SettingsWizard wizard = new SettingsWizard(editConnection, service); wizard.open(composite.getShell()); // leave the viewer the same, callback will refresh anything needed } } }); // attach listeners RemoteConnectionsActivator.getConnectionsManager().addConnectionListener(this); RemoteConnectionsActivator.getConnectionsManager().addConnectionStoreChangedListener(this); // remove listeners on dispose group.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { RemoteConnectionsActivator.getConnectionsManager() .removeConnectionListener(ClientServiceSiteUI2.this); RemoteConnectionsActivator.getConnectionsManager() .removeConnectionStoreChangedListener(ClientServiceSiteUI2.this); } }); setViewerInput(null); }
From source file:com.nokia.carbide.remoteconnections.ui.ClientServiceSiteUI.java
License:Open Source License
public void createComposite(Composite parent) { initializeDialogUnits(parent);//ww w. j a v a 2 s .c o m 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);/*from ww w . j a v a2s . co m*/ 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:com.nokia.s60tools.imaker.PixelConverter.java
License:Open Source License
public int convertHorizontalDLUsToPixels(Control button, int dlus) { GC gc = new GC(button); gc.setFont(button.getFont());//from w ww. j a v a 2s. c o m fFontMetrics = gc.getFontMetrics(); gc.dispose(); return Dialog.convertHorizontalDLUsToPixels(fFontMetrics, dlus); }
From source file:com.salesforce.ide.ui.internal.utils.UIUtils.java
License:Open Source License
public static void setDefaultButtonLayoutData(Button button) { GC gc = new GC(button); try {//from w w w . j ava 2 s . c o m gc.setFont(button.getFont()); FontMetrics fontMetrics = gc.getFontMetrics(); 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); } finally { if (gc != null) { gc.dispose(); } } }