Added setupPagingInformation to set default paging information

in a scrolled composite.
This commit is contained in:
Robert Greene 2004-06-10 03:30:41 +00:00
parent 4fb79dd70d
commit 35fb3535c1

View File

@ -19,6 +19,10 @@
*/ */
package com.webcodepro.applecommander.ui.swt.util; package com.webcodepro.applecommander.ui.swt.util;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.graphics.FontMetrics;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Shell;
/** /**
@ -38,4 +42,23 @@ public class SwtUtil {
(parent.getSize().y - child.getSize().y) / 2; (parent.getSize().y - child.getSize().y) / 2;
child.setLocation(x,y); child.setLocation(x,y);
} }
/**
* Setup some sensible paging information.
*/
public static void setupPagingInformation(ScrolledComposite composite) {
GC gc = new GC(composite);
FontMetrics fontMetrics = gc.getFontMetrics();
gc.dispose();
int fontHeight = fontMetrics.getHeight();
int fontWidth = fontMetrics.getAverageCharWidth();
Rectangle clientArea = composite.getClientArea();
int lines = clientArea.height / fontHeight;
int pageHeight = lines * fontHeight;
int pageWidth = clientArea.width - fontWidth;
composite.getVerticalBar().setIncrement(fontHeight);
composite.getVerticalBar().setPageIncrement(pageHeight);
composite.getHorizontalBar().setIncrement(fontWidth);
composite.getHorizontalBar().setPageIncrement(pageWidth);
}
} }