KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ltk > internal > ui > refactoring > util > SWTUtil


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
23  * Utility class for swt-related functions.
24  *
25  * @since 3.2
26  */

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 JavaDoc 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         // Not for instantiation
45
}
46 }
47
Popular Tags