本文整理汇总了Java中org.eclipse.swt.graphics.Rectangle类的典型用法代码示例。如果您正苦于以下问题:Java Rectangle类的具体用法?Java Rectangle怎么用?Java Rectangle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Rectangle类属于org.eclipse.swt.graphics包,在下文中一共展示了Rectangle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInitialLocation
import org.eclipse.swt.graphics.Rectangle; //导入依赖的package包/类
/**
* Returns the initial location to use for the shell based upon the current selection in the viewer. Bottom is
* preferred to top, and right is preferred to left, therefore if possible the popup will be located below and to
* the right of the selection.
*
* @param initialSize
* the initial size of the shell, as returned by {@code getInitialSize}.
* @return the initial location of the shell
*/
@Override
protected Point getInitialLocation(final Point initialSize) {
if (null == anchor) {
return super.getInitialLocation(initialSize);
}
final Point point = anchor;
final Rectangle monitor = getShell().getMonitor().getClientArea();
if (monitor.width < point.x + initialSize.x) {
point.x = max(0, point.x - initialSize.x);
}
if (monitor.height < point.y + initialSize.y) {
point.y = max(0, point.y - initialSize.y);
}
return point;
}
示例2: getConstrainedShellBounds
import org.eclipse.swt.graphics.Rectangle; //导入依赖的package包/类
/**
* Given the desired position of the shell, this method returns an adjusted position such that the window is no
* larger than its monitor, and does not extend beyond the edge of the monitor. This is used for computing the
* initial window position via the parent shell, clients can use this as a utility method if they want to limit the
* region in which the window may be moved.
*
* @param shell
* the shell which shell bounds is being calculated.
* @param preferredSize
* the preferred position of the window.
* @return a rectangle as close as possible to preferredSize that does not extend outside the monitor.
*/
public static Rectangle getConstrainedShellBounds(final Shell shell, final Point preferredSize) {
final Point location = getInitialLocation(shell, preferredSize);
final Rectangle result = new Rectangle(location.x, location.y, preferredSize.x, preferredSize.y);
final Monitor monitor = getClosestMonitor(shell.getDisplay(), Geometry.centerPoint(result));
final Rectangle bounds = monitor.getClientArea();
if (result.height > bounds.height) {
result.height = bounds.height;
}
if (result.width > bounds.width) {
result.width = bounds.width;
}
result.x = Math.max(bounds.x, Math.min(result.x, bounds.x
+ bounds.width - result.width));
result.y = Math.max(bounds.y, Math.min(result.y, bounds.y
+ bounds.height - result.height));
return result;
}
示例3: getClosestMonitor
import org.eclipse.swt.graphics.Rectangle; //导入依赖的package包/类
/**
* Returns the monitor whose client area contains the given point. If no monitor contains the point, returns the
* monitor that is closest to the point.
*
* @param toSearch
* point to find (display coordinates).
* @param toFind
* point to find (display coordinates).
* @return the monitor closest to the given point.
*/
private static Monitor getClosestMonitor(final Display toSearch, final Point toFind) {
int closest = Integer.MAX_VALUE;
final Monitor[] monitors = toSearch.getMonitors();
Monitor result = monitors[0];
for (int index = 0; index < monitors.length; index++) {
final Monitor current = monitors[index];
final Rectangle clientArea = current.getClientArea();
if (clientArea.contains(toFind)) {
return current;
}
final int distance = Geometry.distanceSquared(Geometry.centerPoint(clientArea), toFind);
if (distance < closest) {
closest = distance;
result = current;
}
}
return result;
}
示例4: getScreenDataArea
import org.eclipse.swt.graphics.Rectangle; //导入依赖的package包/类
/**
* Returns the data area (the area inside the axes) for the plot or subplot,
* with the current scaling applied.
*
* @param x the x-coordinate (for subplot selection).
* @param y the y-coordinate (for subplot selection).
*
* @return The scaled data area.
*/
public Rectangle getScreenDataArea(int x, int y) {
PlotRenderingInfo plotInfo = this.info.getPlotInfo();
Rectangle result;
if (plotInfo.getSubplotCount() == 0)
result = getScreenDataArea();
else {
// get the origin of the zoom selection in the Java2D space used for
// drawing the chart (that is, before any scaling to fit the panel)
Point2D selectOrigin = translateScreenToJava2D(new Point(x, y));
int subplotIndex = plotInfo.getSubplotIndex(selectOrigin);
if (subplotIndex == -1) {
return null;
}
result = scale(plotInfo.getSubplotInfo(subplotIndex).getDataArea());
}
return result;
}
示例5: setViewRequiresOneDownload
import org.eclipse.swt.graphics.Rectangle; //导入依赖的package包/类
public static void setViewRequiresOneDownload(Composite genComposite) {
if (genComposite == null || genComposite.isDisposed()) {
return;
}
Utils.disposeComposite(genComposite, false);
Label lab = new Label(genComposite, SWT.NULL);
GridData gridData = new GridData(SWT.CENTER, SWT.CENTER, true, true);
gridData.verticalIndent = 10;
lab.setLayoutData(gridData);
Messages.setLanguageText(lab, "view.one.download.only");
genComposite.layout(true);
Composite parent = genComposite.getParent();
if (parent instanceof ScrolledComposite) {
ScrolledComposite scrolled_comp = (ScrolledComposite) parent;
Rectangle r = scrolled_comp.getClientArea();
scrolled_comp.setMinSize(genComposite.computeSize(r.width, SWT.DEFAULT ));
}
}
示例6: cellMouseTrigger
import org.eclipse.swt.graphics.Rectangle; //导入依赖的package包/类
@Override
public void cellMouseTrigger(TableCellMouseEvent event) {
if (event.eventType == TableCellMouseEvent.EVENT_MOUSEMOVE
|| event.eventType == TableRowMouseEvent.EVENT_MOUSEDOWN) {
TableRow row = event.cell.getTableRow();
if (row == null) {
return;
}
Object data = row.getData(ID_EXPANDOHITAREA);
if (data instanceof Rectangle) {
Rectangle hitArea = (Rectangle) data;
boolean inExpando = hitArea.contains(event.x, event.y);
if (event.eventType == TableCellMouseEvent.EVENT_MOUSEMOVE) {
((TableCellCore) event.cell).setCursorID(inExpando ? SWT.CURSOR_HAND
: SWT.CURSOR_ARROW);
} else if (inExpando) { // mousedown
if (row instanceof TableRowCore) {
TableRowCore rowCore = (TableRowCore) row;
rowCore.setExpanded(!rowCore.isExpanded());
}
}
}
}
}
示例7: handleEvent
import org.eclipse.swt.graphics.Rectangle; //导入依赖的package包/类
public static void handleEvent(Event event) {
Table table = (Table) event.widget;
int columnCount = table.getColumnCount();
if (columnCount == 0)
return;
Rectangle area = table.getClientArea();
int totalAreaWdith = area.width;
int lineWidth = table.getGridLineWidth();
int totalGridLineWidth = (columnCount - 1) * lineWidth;
int totalColumnWidth = 0;
for (TableColumn column : table.getColumns()) {
totalColumnWidth = totalColumnWidth + column.getWidth();
}
int diff = totalAreaWdith - (totalColumnWidth + totalGridLineWidth);
TableColumn lastCol = table.getColumns()[columnCount - 1];
lastCol.setWidth(diff + lastCol.getWidth());
}
示例8: translateToPoint
import org.eclipse.swt.graphics.Rectangle; //导入依赖的package包/类
protected static boolean translateToPoint ( final Rectangle clientRect, final XAxis x, final YAxis y, final DataPoint point, final DataEntry entry )
{
// we always need X
point.x = clientRect.x + x.translateToClient ( clientRect.width, entry.getTimestamp () );
final Double value = entry.getValue ();
if ( value == null || Double.isNaN ( value ) || Double.isInfinite ( value ) )
{
return false;
}
// we only provide Y if we really have a value
point.y = clientRect.y + y.translateToClient ( clientRect.height, value );
return true;
}
示例9: MainAvoCADoShell
import org.eclipse.swt.graphics.Rectangle; //导入依赖的package包/类
/**
* create the main avoCADo shell and display it
* @param display
*/
public MainAvoCADoShell(Display display){
shell = new Shell(display);
setupShell(); // place components in the main avoCADo shell
shell.setText("avoCADo");
shell.setSize(800, 600); //TODO: set intial size to last known size
shell.setMinimumSize(640, 480);
Rectangle b = display.getBounds();
int xPos = Math.max(0, (b.width-800)/2);
int yPos = Math.max(0, (b.height-600)/2);
shell.setLocation(xPos, yPos);
shell.setImage(ImageUtils.getIcon("./avoCADo.png", 32, 32));
shell.open();
AvoGlobal.intializeNewAvoCADoProject(); // initialize app to starting model/view.
StartupSplashShell.closeSplash();
// handle events while the shell is not disposed
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
示例10: SWTStrokeCanvas
import org.eclipse.swt.graphics.Rectangle; //导入依赖的package包/类
/**
* Creates a new instance.
*
* @param parent the parent.
* @param style the style.
*/
public SWTStrokeCanvas(Composite parent, int style) {
super(parent, style);
addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
BasicStroke stroke = (BasicStroke) getStroke();
if (stroke != null) {
int x, y;
Rectangle rect = getClientArea();
x = (rect.width - 100) / 2;
y = (rect.height - 16) / 2;
Transform swtTransform = new Transform(e.gc.getDevice());
e.gc.getTransform(swtTransform);
swtTransform.translate(x, y);
e.gc.setTransform(swtTransform);
swtTransform.dispose();
e.gc.setBackground(getDisplay().getSystemColor(
SWT.COLOR_BLACK));
e.gc.setLineWidth((int) stroke.getLineWidth());
e.gc.drawLine(10, 8, 90, 8);
}
}
});
}
示例11: render
import org.eclipse.swt.graphics.Rectangle; //导入依赖的package包/类
@Override
public void render ( final Graphics g, final Rectangle clientRectangle )
{
if ( this.title == null || this.title.isEmpty () )
{
return;
}
g.setClipping ( this.rect );
g.setFont ( createFont ( g.getResourceManager () ) );
final Point size = g.textExtent ( this.title );
final int x = this.rect.width / 2 - size.x / 2;
final int y = this.padding;
g.drawText ( this.title, this.rect.x + x, this.rect.y + y, null );
g.setClipping ( clientRectangle );
}
示例12: resize
import org.eclipse.swt.graphics.Rectangle; //导入依赖的package包/类
@Override
public Rectangle resize ( final ResourceManager resourceManager, final Rectangle clientRectangle )
{
if ( this.title == null || this.title.isEmpty () )
{
return null;
}
final GC gc = new GC ( resourceManager.getDevice () );
gc.setFont ( createFont ( resourceManager ) );
try
{
final Point size = gc.textExtent ( this.title );
this.rect = new Rectangle ( clientRectangle.x, clientRectangle.y, clientRectangle.width, size.y + this.padding * 2 );
return new Rectangle ( clientRectangle.x, this.rect.y + this.rect.height, clientRectangle.width, clientRectangle.height - this.rect.height );
}
finally
{
gc.dispose ();
}
}
示例13: cellPaint
import org.eclipse.swt.graphics.Rectangle; //导入依赖的package包/类
@Override
public void cellPaint(GC gc, TableCellSWT cell) {
Rectangle bounds = cell.getBounds();
ImageLoader imageLoader = ImageLoader.getInstance();
Image viewImage = imageLoader.getImage("ic_view");
if(imageWidth == -1 || imageHeight == -1) {
imageWidth = viewImage.getBounds().width;
imageHeight = viewImage.getBounds().height;
}
bounds.width -= (imageWidth + 5);
GCStringPrinter.printString(gc, cell.getSortValue().toString(), bounds,true,false,SWT.LEFT);
Subscription sub = (Subscription) cell.getDataSource();
if ( sub != null && !sub.isSearchTemplate()){
gc.drawImage(viewImage, bounds.x + bounds.width, bounds.y + bounds.height / 2 - imageHeight / 2);
}
imageLoader.releaseImage("ic_view");
//gc.drawText(cell.getText(), bounds.x,bounds.y);
}
示例14: setupPagingInformation
import org.eclipse.swt.graphics.Rectangle; //导入依赖的package包/类
/**
* 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);
}
示例15: paint
import org.eclipse.swt.graphics.Rectangle; //导入依赖的package包/类
void paint(GC gc) {
if (fImage != null) {
Rectangle bounds = fImage.getBounds();
Rectangle clientArea = getClientArea();
int x;
if (bounds.width < clientArea.width)
x = (clientArea.width - bounds.width) / 2;
else
x = -getHorizontalBar().getSelection();
int y;
if (bounds.height < clientArea.height)
y = (clientArea.height - bounds.height) / 2;
else
y = -getVerticalBar().getSelection();
gc.drawImage(fImage, x, y);
}
}