1 11 package org.eclipse.ui.internal.texteditor; 12 13 import org.eclipse.swt.SWT; 14 import org.eclipse.swt.layout.GridData; 15 import org.eclipse.swt.widgets.Button; 16 17 import org.eclipse.core.runtime.Assert; 18 19 import org.eclipse.jface.dialogs.IDialogConstants; 20 import org.eclipse.jface.resource.JFaceResources; 21 22 23 28 public class SWTUtil { 29 30 36 public static int getButtonWidthHint(Button button) { 37 button.setFont(JFaceResources.getDialogFont()); 38 PixelConverter converter= new PixelConverter(button); 39 int widthHint= converter.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); 40 return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); 41 } 42 43 50 public static void setButtonDimensionHint(Button button) { 51 Assert.isNotNull(button); 52 Object gd= button.getLayoutData(); 53 if (gd instanceof GridData) { 54 ((GridData)gd).widthHint= getButtonWidthHint(button); 55 ((GridData)gd).horizontalAlignment = GridData.FILL; 56 } 57 } 58 } 59 | Popular Tags |