1 11 package org.eclipse.ltk.internal.ui.refactoring.util; 12 13 import org.eclipse.core.runtime.Assert; 14 15 import org.eclipse.swt.SWT; 16 import org.eclipse.swt.layout.GridData; 17 import org.eclipse.swt.widgets.Button; 18 19 import org.eclipse.jface.dialogs.IDialogConstants; 20 import org.eclipse.jface.resource.JFaceResources; 21 22 27 public final class SWTUtil { 28 29 public static int getButtonWidthHint(Button button) { 30 button.setFont(JFaceResources.getDialogFont()); 31 return Math.max(new PixelConverter(button).convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH), button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); 32 } 33 34 public static void setButtonDimensionHint(Button button) { 35 Assert.isNotNull(button); 36 Object data= button.getLayoutData(); 37 if (data instanceof GridData) { 38 ((GridData) data).widthHint= getButtonWidthHint(button); 39 ((GridData) data).horizontalAlignment= GridData.FILL; 40 } 41 } 42 43 private SWTUtil() { 44 } 46 } 47 | Popular Tags |