mirror of
https://github.com/AppleCommander/AppleCommander.git
synced 2024-12-22 23:29:34 +00:00
Added setupPagingInformation to set default paging information
in a scrolled composite.
This commit is contained in:
parent
4fb79dd70d
commit
35fb3535c1
@ -19,6 +19,10 @@
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -38,4 +42,23 @@ public class SwtUtil {
|
||||
(parent.getSize().y - child.getSize().y) / 2;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user