SCViewer/com.minres.scviewer.e4.appl.../src/com/minres/scviewer/e4/application/internal/TrimUtil.java

43 lines
1.3 KiB
Java

package com.minres.scviewer.e4.application.internal;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
/**
* Simple class to provide some common internal Trim support.
*
* @since 3.2
*
*/
public class TrimUtil {
/**
* Default height for workbench trim.
*/
public static final int TRIM_DEFAULT_HEIGHT;
static {
Shell s = new Shell(Display.getCurrent(), SWT.NONE);
s.setLayout(new GridLayout());
ToolBar t = new ToolBar(s, SWT.NONE);
t.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
ToolItem ti = new ToolItem(t, SWT.PUSH);
ti.setImage(JFaceResources.getImageRegistry().get(Dialog.DLG_IMG_MESSAGE_INFO));
s.layout();
int toolItemHeight = t.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
GC gc = new GC(s);
Point fontSize = gc.textExtent("Wg"); //$NON-NLS-1$
gc.dispose();
TRIM_DEFAULT_HEIGHT = Math.max(toolItemHeight, fontSize.y);
s.dispose();
}
}