Java Code Examples for org.eclipse.swt.graphics.Rectangle

The following examples show how to use org.eclipse.swt.graphics.Rectangle. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * getAboveLocation
 * 
 * @param shell
 * @param offset
 * @return Point
 */
protected Point getAboveLocation(Shell shell, int offset)
{
	Point location = fContentAssistSubjectControlAdapter.getLocationAtOffset(offset);
	location = fContentAssistSubjectControlAdapter.getControl().toDisplay(location);

	Rectangle shellBounds = shell.getBounds();
	Rectangle displayBounds = shell.getDisplay().getClientArea();

	location.y = location.y - (shellBounds.height + fContentAssistSubjectControlAdapter.getLineHeight());

	shiftHorizontalLocation(location, shellBounds, displayBounds);
	shiftVerticalLocation(location, shellBounds, displayBounds, true);

	return location;
}
 
Example 2
Source Project: ldparteditor   Source File: vboWithRGBA.java    License: MIT License 6 votes vote down vote up
@Override
public void drawScene(float mouseX, float mouseY) {
    final GLCanvas canvas = cp.getCanvas();

    if (!canvas.isCurrent()) {
        canvas.setCurrent();
        GL.setCapabilities(cp.getCapabilities());
    }
    
    GL11.glColorMask(true, true, true, true);

    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT);
    
    Rectangle bounds = cp.getBounds();
    GL11.glViewport(0, 0, bounds.width, bounds.height);
    
    shaderProgram.use();
    GL30.glBindVertexArray(VAO);
    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 3);
    GL30.glBindVertexArray(0);
    
    canvas.swapBuffers();
}
 
Example 3
Source Project: nebula   Source File: Star.java    License: Eclipse Public License 2.0 6 votes vote down vote up
void draw(final GC gc, final int x, final int y) {
	Image image;
	if (!parent.isEnabled()) {
		image = defaultImage;
	} else {
		if (marked) {
			if (hover) {
				image = selectedHoverImage;
			} else {
				image = selectedImage;
			}
		} else {
			if (hover) {
				image = hoverImage;
			} else {
				image = defaultImage;
			}
		}
	}

	gc.drawImage(image, x, y);
	bounds = new Rectangle(x, y, image.getBounds().width, image.getBounds().height);
}
 
Example 4
Source Project: elexis-3-core   Source File: DatePickerCombo.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private void popupEvent(Event event){
	switch (event.type) {
	case SWT.Paint:
		
		// draw black rectangle around dp
		Rectangle listRect = dp.getBounds();
		Color black = getDisplay().getSystemColor(SWT.COLOR_BLACK);
		event.gc.setForeground(black);
		event.gc.drawRectangle(0, 0, listRect.width + 1, listRect.height + 1);
		
		break;
	
	case SWT.Close:
		event.doit = false;
		dropDown(false);
		
		break;
	
	case SWT.Deactivate:
		dropDown(false);
		
		break;
	}
}
 
Example 5
Source Project: BiglyBT   Source File: PingGraphic.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void initialize(Canvas canvas) {
	super.initialize(canvas);

	drawCanvas.addPaintListener(new PaintListener() {
	@Override
	public void paintControl(PaintEvent e) {
		if (bufferImage != null && !bufferImage.isDisposed()) {
			Rectangle bounds = bufferImage.getBounds();
			if (bounds.width >= ( e.width + e.x ) && bounds.height >= ( e.height + e.y )) {

				e.gc.drawImage(bufferImage, e.x, e.y, e.width, e.height, e.x, e.y,
						e.width, e.height);
			}
		}
	}
});

	drawCanvas.addListener(SWT.Resize, new Listener() {
	@Override
	public void handleEvent(Event event) {
		drawChart(true);
	}
});
}
 
Example 6
Source Project: tracecompass   Source File: SWTBotSash.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Drag the sash from its middle point to the destination point
 *
 * @param dst
 *            the destination point relative to the parent
 */
public void drag(final Point dst) {
    Rectangle bounds = getBounds();
    int x = bounds.width / 2;
    int y = bounds.height / 2;
    notify(SWT.MouseEnter);
    notify(SWT.Activate);
    notify(SWT.Selection, createSelectionEvent(bounds.x + x, bounds.y + y, SWT.NONE));
    notify(SWT.MouseDown, createMouseEvent(x, y, 1, SWT.NONE, 1));
    notify(SWT.DragDetect, createMouseEvent(x, y, 0, SWT.NONE, 0));
    notify(SWT.Move);
    notify(SWT.Selection, createSelectionEvent(dst.x, dst.y, SWT.NONE));
    notify(SWT.MouseMove, createMouseEvent(x, y, 0, SWT.BUTTON1, 0));
    notify(SWT.Selection, createSelectionEvent(dst.x, dst.y, SWT.BUTTON1));
    notify(SWT.MouseUp, createMouseEvent(x, y, 1, SWT.NONE, 1));
    notify(SWT.MouseExit);
}
 
Example 7
Source Project: BiglyBT   Source File: CompositeMinSize.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected Point betterComputeSize(Composite c, Point size, int wHint, int hHint, boolean changed) {
	if (c.getChildren().length == 0 && (size.x == 64 || size.y == 64)) {
		Object ld = c.getLayoutData();
		if (ld instanceof FormData) {
			FormData fd = (FormData) ld;
			if (fd.width != 0 && fd.height != 0) {
				Rectangle trim = c.computeTrim (0, 0, fd.width, fd.height);
				return new Point(trim.width, trim.height);
			}
		}
		return new Point(1, 1);
	}
	if (size.x == 0 || size.y == 0) {
		return size;
	}
	if (minWidth > 0 && size.x < minWidth) {
		size.x = minWidth;
	}
	if (minHeight > 0 && size.y < minHeight) {
		size.y = minHeight;
	}
	return size;
}
 
Example 8
Source Project: neoscada   Source File: XAxisDynamicRenderer.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Rectangle resize ( final ResourceManager resourceManager, final Rectangle clientRectangle )
{
    final int height = this.height >= 0 ? this.height : calcHeight ( resourceManager );

    if ( this.bottom )
    {
        this.rect = new Rectangle ( clientRectangle.x, clientRectangle.y + clientRectangle.height - height, clientRectangle.width, height );
        return new Rectangle ( clientRectangle.x, clientRectangle.y, clientRectangle.width, clientRectangle.height - height );
    }
    else
    {
        this.rect = new Rectangle ( clientRectangle.x, clientRectangle.y, clientRectangle.width, height );
        return new Rectangle ( clientRectangle.x, clientRectangle.y + height, clientRectangle.width, clientRectangle.height - height );
    }
}
 
Example 9
protected void computeInformation()
{
	if (fProposal instanceof ICompletionProposalExtension3)
	{
		setCustomInformationControlCreator(((ICompletionProposalExtension3) fProposal)
				.getInformationControlCreator());
	}
	else
	{
		setCustomInformationControlCreator(null);
	}

	// compute subject area
	Point size = fProposalTable.getShell().getSize();

	// set information & subject area
	setInformation(fInformation, new Rectangle(0, 0, size.x, size.y));
}
 
Example 10
Source Project: nebula   Source File: GridColumn.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns the bounds of this column's header.
 *
 * @return bounds of the column header
 */
Rectangle getBounds() {
	Rectangle bounds = new Rectangle(0, 0, 0, 0);

	if (!isVisible()) {
		return bounds;
	}

	Point loc = parent.getOrigin(this, null);
	bounds.x = loc.x;
	bounds.y = loc.y;
	bounds.width = getWidth();
	bounds.height = parent.getHeaderHeight();
	if (getColumnGroup() != null) {
		bounds.height -= parent.getGroupHeaderHeight();
	}

	return bounds;
}
 
Example 11
Source Project: tracecompass   Source File: LineClipperTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * clip an X to a smaller X
 */
@Test
public void clipXTest() {
    Rectangle bounds = new Rectangle(0, 0, 1000, 1000);

    int x0 = -100;
    int y0 = -100;
    int x1 = 1100;
    int y1 = 1100;
    Rectangle rect = LineClipper.clip(bounds, x0, y0, x1, y1);
    assertEquals(new Rectangle(0, 0, 1000, 1000), rect);

    x0 = 1100;
    y0 = -100;
    x1 = -100;
    y1 = 1100;
    rect = LineClipper.clip(bounds, x0, y0, x1, y1);
    assertEquals(new Rectangle(1000, 0, -1000, 1000), rect);
}
 
Example 12
Source Project: ccu-historian   Source File: ChartPrintJob.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * @param printer
 * @param safetyBorder
 * @return the rectangle in pixels to print on (and which is also supported
 * by the printer hardware)
 */
private Rectangle getPrintableArea(Printer printer, double safetyBorder) {
    int safetyBorderWidth = (int) (safetyBorder * printer.getDPI().x);
    int safetyBorderHeight = (int) (safetyBorder * printer.getDPI().y);

    Rectangle trim = printer.computeTrim(0, 0, 0, 0);
    int trimLeft = -trim.x;
    int trimTop = -trim.y;
    int trimRight = trim.x + trim.width;
    int trimBottom = trim.y + trim.height;

    int marginLeft = Math.max(trimLeft, safetyBorderWidth);
    int marginRight = Math.max(trimRight, safetyBorderWidth);
    int marginTop = Math.max(trimTop, safetyBorderHeight);
    int marginBottom = Math.max(trimBottom, safetyBorderHeight);

    int availWidth = printer.getClientArea().width - marginLeft
            - marginRight;
    int availHeight = printer.getClientArea().height - marginTop
            - marginBottom;
    return new Rectangle(marginLeft, marginTop, availWidth, availHeight);
}
 
Example 13
Source Project: tmxeditor8   Source File: SelectionModel.java    License: GNU General Public License v2.0 6 votes vote down vote up
public int[] getSelectedColumns() {
	TreeSet<Integer> selectedColumns = new TreeSet<Integer>();

	selectionsLock.readLock().lock();

	try {
		for (Rectangle r : selections) {
			int startColumn = r.x;
			int numColumns = r.width;

			// Change from row < startRow to row < startRow+numRows
			for (int column = startColumn; column < startColumn + numColumns; column++) {
				selectedColumns.add(Integer.valueOf(column));
			}
		}
	} finally {
		selectionsLock.readLock().unlock();
	}

	// Convert to array
	return ObjectUtils.asIntArray(selectedColumns);
}
 
Example 14
/**
 * {@inheritDoc}
 */
public boolean isInActiveArea(IRow row, Rectangle drawingArea, int xx, int yy) {
    int offx = scaleX(_levelWidth);
    ITableNode node = (ITableNode) row;
    int level = node.getLevel();
    boolean leaf = node.getChildren().size() == 0;
    // leaves can not be toggled
    if (leaf) {
        return false;
    }

    int x = drawingArea.x + offx * level + SIZE / 2;
    int y = drawingArea.y + (drawingArea.height - SIZE) / 2;

    return x <= xx && xx <= x + SIZE && y <= yy && yy <= y + SIZE;
}
 
Example 15
Source Project: tmxeditor8   Source File: CompositeLayer.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void setChildLayer(String regionName, ILayer childLayer, final int layoutX, final int layoutY) {
	if (childLayer == null) {
		throw new IllegalArgumentException("Cannot set null child layer");
	}

	childLayerToRegionNameMap.put(childLayer, regionName);

	childLayer.addLayerListener(this);
	childLayerToLayoutCoordinateMap.put(childLayer, new LayoutCoordinate(layoutX, layoutY));
	childLayerLayout[layoutX][layoutY] = childLayer;

	childLayer.setClientAreaProvider(new IClientAreaProvider() {
		public Rectangle getClientArea() {
			return getChildClientArea(layoutX, layoutY);
		}
	});
}
 
Example 16
Source Project: nebula   Source File: AbstractCombo.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Calculates and returns the location of popup.<br>
 * Called just before than the popup is dropped.
 */
protected void setPopupLocation() {
	Display display = Display.getCurrent();
	Rectangle r = getBounds();
	Point p = display.map(this, null, 0, r.height);
	Rectangle sb = display.getBounds();
	if (p.y + popup.getSize().y > sb.height) {
		p.y -= r.height + popup.getSize().y + getBorderWidth();
	}
	int popx = popup.getSize().x;
	if (p.x + popx > sb.width) {
		p.x -= popx - r.width + getBorderWidth();
	} else if (popx < r.width) {
		p.x += r.width - popx;
	}
	popup.setLocation(p.x, p.y);
}
 
Example 17
Source Project: tmxeditor8   Source File: RowSelectionModel.java    License: GNU General Public License v2.0 6 votes vote down vote up
public List<Rectangle> getSelections() {
	List<Rectangle> selectionRectangles = new ArrayList<Rectangle>();
	
	selectionsLock.readLock().lock();
	
	try {
		int width = selectionLayer.getColumnCount();
		for (Serializable rowId : selectedRows.keySet()) {
			int rowPosition = getRowPositionById(rowId);
			selectionRectangles.add(new Rectangle(0, rowPosition, width, 1));
		}
	} finally {
		selectionsLock.readLock().unlock();
	}
	
	return selectionRectangles;
}
 
Example 18
Source Project: nebula   Source File: Win7ColumnHeaderUtil.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Based on the provided state (hover/selected) generate the appropriate column
 * header rendering.
 *
 * @param graphics
 * @param bounds
 * @param palette
 * @param hover
 *            indicates whether the mouse is hovering over the column header
 * @param selected
 *            indicates whether the column is selected (mousedown)
 * @param mousedown
 */
public static void drawColumn(GC graphics, Rectangle bounds, Win7PaletteProvider palette, boolean hover,
		boolean selected, boolean mousedown) {
	if (mousedown) {
		drawColumnHeader(graphics, bounds, palette.getPalette((Display) graphics.getDevice(),
				Win7PaletteProvider.MOUSEDOWN_GRID_COLUMN_HEADER));
		drawColumnSelectedTopShadow(graphics, bounds,
				palette.getPalette((Display) graphics.getDevice(), Win7PaletteProvider.SHADOW_GRID_COLUMN_HEADER));
	} else if (hover) {
		drawColumnHeader(graphics, bounds,
				palette.getPalette((Display) graphics.getDevice(), Win7PaletteProvider.HOVER_GRID_COLUMN_HEADER));
	} else if (selected) {
		drawColumnHeader(graphics, bounds, palette.getPalette((Display) graphics.getDevice(),
				Win7PaletteProvider.SELECTED_GRID_COLUMN_HEADER));
	} else {
		drawColumnHeader(graphics, bounds,
				palette.getPalette((Display) graphics.getDevice(), Win7PaletteProvider.NORMAL_GRID_COLUMN_HEADER));
	}
}
 
Example 19
@Override
public Collection<Rectangle> getChangedPositionRectangles() {
	Collection<Rectangle> changedPositionRectangles = new ArrayList<Rectangle>();
	
	Collection<Range> columnPositionRanges = getColumnPositionRanges();
	if (columnPositionRanges != null && columnPositionRanges.size() > 0) {
		int leftmostColumnPosition = Integer.MAX_VALUE;
		for (Range range : columnPositionRanges) {
			if (range.start < leftmostColumnPosition) {
				leftmostColumnPosition = range.start;
			}
		}
		
		int columnCount = getLayer().getColumnCount();
		int rowCount = getLayer().getRowCount();
		changedPositionRectangles.add(new Rectangle(leftmostColumnPosition, 0, columnCount - leftmostColumnPosition, rowCount));
	}
	
	return changedPositionRectangles;
}
 
Example 20
Source Project: nebula   Source File: CalendarComposite.java    License: Eclipse Public License 2.0 6 votes vote down vote up
private void drawChartOntoGC(GC gc) {
	Rectangle bounds = super.getBounds();
	gc.setBackground(mColorManager.getCalendarBackgroundColor());
	gc.fillRectangle(bounds);

	Font used = null;
	if (CalendarCombo.OS_CARBON) {
		used = mSettings.getCarbonDrawFont();
		if (used != null)
			gc.setFont(used);
	}

	// header
	drawHeader(gc);
	// day titles
	drawTitleDays(gc);
	// days
	drawDays(gc);
	// 1 pixel border
	drawBorder(gc);

	gc.dispose();
	if (used != null)
		used.dispose();
}
 
Example 21
@Override
public void paintCell(LayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
	// Save GC settings
	Color originalBackground = gc.getBackground();
	Color originalForeground = gc.getForeground();

	gc.setBackgroundPattern(new Pattern(Display.getCurrent(), bgImage));

	gc.fillRectangle(rectangle);
	gc.setBackgroundPattern(null);

	if (isNotNull(separatorColor)) {
		gc.setForeground(separatorColor);
		gc.drawLine(rectangle.x - 1, rectangle.y, rectangle.x - 1, rectangle.y + rectangle.height);
		gc.drawLine(rectangle.x - 1 + rectangle.width, rectangle.y, rectangle.x - 1 + rectangle.width, rectangle.y + rectangle.height);
	}

	// Restore original GC settings
	gc.setBackground(originalBackground);
	gc.setForeground(originalForeground);

	// Draw interior
	Rectangle interiorBounds = new Rectangle(rectangle.x + 2, rectangle.y + 2, rectangle.width - 4,	rectangle.height - 4);
	super.paintCell(cell, gc, interiorBounds, configRegistry);
}
 
Example 22
Source Project: nebula   Source File: CTreeItem.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * The Cells of a CTreeItem are considered contiguous and unified, therefore
 * the contains method is overridden
 */
public boolean contains(int x, int y) {
	Rectangle[] ba = getCellBounds();
	for(int i = 0; i < ba.length; i++) {
		if(ba[i].contains(x,y)) return true;
	}
	return false;
}
 
Example 23
Source Project: Pydev   Source File: ToolTipHandler.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Sets the location for a hovering shell
 * @param shell the object that is to hover
 * @param position the position of a widget to hover over
 * @return the top-left location for a hovering box
 */
private void setHoverLocation(Shell shell, Point position) {
    Rectangle displayBounds = shell.getDisplay().getBounds();
    Rectangle shellBounds = shell.getBounds();
    shellBounds.x = Math.max(Math.min(position.x, displayBounds.width - shellBounds.width), 0);
    shellBounds.y = Math.max(Math.min(position.y + 16, displayBounds.height - shellBounds.height), 0);
    shell.setBounds(shellBounds);
}
 
Example 24
Source Project: openstock   Source File: ChartComposite.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the data area for the chart (the area inside the axes) with the
 * current scaling applied (that is, the area as it appears on screen).
 *
 * @return The scaled data area.
 */
public Rectangle getScreenDataArea() {
    Rectangle2D dataArea = this.info.getPlotInfo().getDataArea();
    Rectangle clientArea = this.getClientArea();
    int x = (int) (dataArea.getX() * this.scaleX + clientArea.x);
    int y = (int) (dataArea.getY() * this.scaleY + clientArea.y);
    int w = (int) (dataArea.getWidth() * this.scaleX);
    int h = (int) (dataArea.getHeight() * this.scaleY);
    return new Rectangle(x, y, w, h);
}
 
Example 25
Source Project: tmxeditor8   Source File: WaitDialog.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void centerDialogOnScreen(Shell shell) {
	shell.setSize(250, 75);
	Rectangle parentSize = getParentShell().getBounds();
	Rectangle mySize = shell.getBounds();
	int locationX, locationY;
	locationX = (parentSize.width - mySize.width)/2+parentSize.x;
	locationY = (parentSize.height - mySize.height)/2+parentSize.y;
	shell.setLocation(locationX, locationY);
}
 
Example 26
protected void drawGridLines(ILayer natLayer, GC gc, Rectangle rectangle) {
	gc.setForeground(GUIHelper.COLOR_GRAY);

	drawHorizontalLines(natLayer, gc, rectangle);
	drawVerticalLines(natLayer, gc, rectangle);
	
	// paint far bottom left corner pixel
	gc.drawPoint(natLayer.getWidth() - 1, natLayer.getHeight() - 1);
}
 
Example 27
Source Project: BiglyBT   Source File: ViewUtils.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void setViewRequires( Composite genComposite, boolean one_or_more ){
	if (genComposite == null || genComposite.isDisposed()) {
		return;
	}
	Utils.disposeComposite(genComposite, false);

	Label lab = new Label(genComposite, SWT.NULL);
	
	if ( genComposite.getLayout() instanceof GridLayout ){
		GridData gridData = new GridData(SWT.CENTER, SWT.CENTER, true, true);
		gridData.verticalIndent = 10;
		lab.setLayoutData(gridData);
	}else{
		lab.setLayoutData( Utils.getFilledFormData());
	}
	Messages.setLanguageText(lab, one_or_more?"view.one.or.more.download":"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 ));
	}

}
 
Example 28
Source Project: birt   Source File: ImageViewer.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Point computeSize(int wHint, int hHint, boolean changed) {
    checkWidget();

    Image image = getCurrentImage();
    if (image != null) {
        Rectangle rect = image.getBounds();
        Rectangle trim = computeTrim(0, 0, rect.width, rect.height);
        return new Point(trim.width, trim.height);
    }

    return new Point(wHint, hHint);
}
 
Example 29
/**
 * Any selected columns will be hidden. A column is considered selected even if a cell is selected.
 */
protected boolean hideMultipleColumnPositions(MultiColumnHideCommand command) {
	for (int columnPosition : command.getColumnPositions()) {
		if (isColumnFullySelected(columnPosition)) {
			Rectangle selection = new Rectangle(columnPosition, 0, 1, getRowCount());
			clearSelection(selection);
		}
	}
	return super.doCommand(command);
}
 
Example 30
Source Project: birt   Source File: ReportGraphicsViewPainter.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public void paint( Drawable drawable, Device device, Rectangle region )
{
	ReportPrintGraphicalViewerOperation op = new ReportPrintGraphicalViewerOperation( viewer,
			drawable,
			device,
			new org.eclipse.draw2d.geometry.Rectangle( region ) );
	if (model instanceof ReportDesignHandle)
	{
		op.setOrientation( ((ReportDesignHandle)model).getBidiOrientation( ) );
	}

	op.run( "paint" ); //$NON-NLS-1$

}