org.eclipse.swt.widgets.Canvas.getSize()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(11.0k)|赞(0)|评价(0)|浏览(188)

本文整理了Java中org.eclipse.swt.widgets.Canvas.getSize()方法的一些代码示例,展示了Canvas.getSize()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Canvas.getSize()方法的具体详情如下:
包路径:org.eclipse.swt.widgets.Canvas
类名称:Canvas
方法名:getSize

Canvas.getSize介绍

暂无

代码示例

代码示例来源:origin: org.eclipse.platform/org.eclipse.swt.examples

  1. void setHeaderImageHeight (int value) {
  2. headerImageHeight = value;
  3. Point headerSize = header.getSize ();
  4. int newHeaderHeight = Math.max (fontHeight, headerImageHeight) + 2 * getHeaderPadding ();
  5. if (headerSize.y != newHeaderHeight) {
  6. header.setSize (headerSize.x, newHeaderHeight);
  7. }
  8. }
  9. /**

代码示例来源:origin: org.eclipse.platform/org.eclipse.compare

  1. private Diff handlemouseInBirdsEyeView(Canvas canvas, int my) {
  2. return fMerger.findDiff(getViewportHeight(), fSynchronizedScrolling, canvas.getSize(), my);
  3. }

代码示例来源:origin: org.eclipse.platform/org.eclipse.swt.examples

  1. /**
  2. * Returns the height of the receiver's header
  3. *
  4. * @return the height of the header or zero if the header is not visible
  5. *
  6. * @exception SWTException <ul>
  7. * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
  8. * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
  9. * </ul>
  10. *
  11. * @since 2.0
  12. */
  13. public int getHeaderHeight () {
  14. checkWidget ();
  15. if (!header.getVisible ()) return 0;
  16. return header.getSize ().y;
  17. }
  18. int getHeaderPadding () {

代码示例来源:origin: diffplug/gradle-and-eclipse-rcp

  1. private RGB posToColor(Event e) {
  2. Point size = wrapped.getSize();
  3. int cb = limitInt(e.x * _256 / size.x);
  4. int cr = limitInt(e.y * _256 / size.y);
  5. return fromYCbCr(luminance, cb, cr);
  6. }

代码示例来源:origin: BiglySoftware/BiglyBT

  1. @Override
  2. public void paintControl(PaintEvent e) {
  3. try{
  4. Rectangle clipping = e.gc.getClipping();
  5. int ofs = (labelImage.getSize().x - boundsColor.width) / 2;
  6. if (paintColorTo > 0) {
  7. e.gc.drawImage(imgSrc, 0, 0, paintColorTo, boundsColor.height, ofs, 10, paintColorTo, boundsColor.height);
  8. }
  9. if (clipping.x + clipping.width > ofs + paintColorTo && imgBounds.width - paintColorTo - 1 > 0) {
  10. e.gc.drawImage(image,
  11. paintColorTo + 1, 0, imgBounds.width - paintColorTo - 1, imgBounds.height,
  12. paintColorTo + 1 + ofs, 10, imgBounds.width - paintColorTo - 1, imgBounds.height);
  13. }
  14. }catch( Throwable f ){
  15. // seen some 'argument not valid errors spewed here, couldn't track down
  16. // the cause though :( parg.
  17. }
  18. }
  19. });

代码示例来源:origin: org.eclipse.rap/org.eclipse.rap.rwt

  1. @Override
  2. void notifyResize( Point oldSize ) {
  3. super.notifyResize( oldSize );
  4. if( !oldSize.equals( getSize() ) ) {
  5. repaint( getClientArea() );
  6. }
  7. }

代码示例来源:origin: diffplug/gradle-and-eclipse-rcp

  1. public ColorPicker(Composite parent) {
  2. super(new Canvas(parent, SWT.DOUBLE_BUFFERED));
  3. setY(128);
  4. wrapped.addListener(SWT.Paint, e -> {
  5. Point size = wrapped.getSize();
  6. Image img = getMapFor(e.display);
  7. e.gc.drawImage(img, 0, 0, _256, _256, 0, 0, size.x, size.y);
  8. });
  9. mouseDown = SwtRx.addListener(wrapped, SWT.MouseDown).map(this::posToColor);
  10. mouseMove = SwtRx.addListener(wrapped, SWT.MouseMove).map(this::posToColor);
  11. }

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jface.text

  1. private void drawRangeIndication(GC gc, Canvas canvas, Rectangle r) {
  2. final int MARGIN= 3;
  3. /* cap the height - at least on GTK, large numbers are converted to
  4. * negatives at some point */
  5. int height= Math.min(r.y + r.height - MARGIN, canvas.getSize().y);
  6. gc.setForeground(canvas.getDisplay().getSystemColor(COLOR));
  7. gc.setLineWidth(0); // NOTE: 0 means width is 1 but with optimized performance
  8. gc.drawLine(r.x + 4, r.y + 12, r.x + 4, height);
  9. gc.drawLine(r.x + 4, height, r.x + r.width - MARGIN, height);
  10. }

代码示例来源:origin: org.eclipse.platform/org.eclipse.jface.text

  1. private void drawRangeIndication(GC gc, Canvas canvas, Rectangle r) {
  2. final int MARGIN= 3;
  3. /* cap the height - at least on GTK, large numbers are converted to
  4. * negatives at some point */
  5. int height= Math.min(r.y + r.height - MARGIN, canvas.getSize().y);
  6. gc.setForeground(canvas.getDisplay().getSystemColor(COLOR));
  7. gc.setLineWidth(0); // NOTE: 0 means width is 1 but with optimized performance
  8. gc.drawLine(r.x + 4, r.y + 12, r.x + 4, height);
  9. gc.drawLine(r.x + 4, height, r.x + r.width - MARGIN, height);
  10. }

代码示例来源:origin: org.eclipse.platform/org.eclipse.jface.text

  1. /**
  2. * Marks the region covered by <code>lines</code> as needing to be redrawn.
  3. *
  4. * @param lines the lines to be redrawn in document coordinates
  5. */
  6. protected final void redraw(ILineRange lines) {
  7. if (fCanvas == null || fCanvas.isDisposed())
  8. return;
  9. int firstModelLine= lines.getStartLine();
  10. int lastModelLine= firstModelLine + lines.getNumberOfLines();
  11. int firstWidgetLine= JFaceTextUtil.modelLineToWidgetLine(fTextViewer, firstModelLine);
  12. int lastWidgetLine= JFaceTextUtil.modelLineToWidgetLine(fTextViewer, lastModelLine);
  13. int from= Math.max(0, fStyledText.getLinePixel(firstWidgetLine));
  14. // getLinePixel will return the last pixel of the last line if line == lineCount
  15. int to= Math.min(fCanvas.getSize().y, fStyledText.getLinePixel(lastWidgetLine + 1));
  16. fCanvas.redraw(0, from, fWidth, to - from, false);
  17. }

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jface.text

  1. /**
  2. * Marks the region covered by <code>lines</code> as needing to be redrawn.
  3. *
  4. * @param lines the lines to be redrawn in document coordinates
  5. */
  6. protected final void redraw(ILineRange lines) {
  7. if (fCanvas == null || fCanvas.isDisposed())
  8. return;
  9. int firstModelLine= lines.getStartLine();
  10. int lastModelLine= firstModelLine + lines.getNumberOfLines();
  11. int firstWidgetLine= JFaceTextUtil.modelLineToWidgetLine(fTextViewer, firstModelLine);
  12. int lastWidgetLine= JFaceTextUtil.modelLineToWidgetLine(fTextViewer, lastModelLine);
  13. int from= Math.max(0, fStyledText.getLinePixel(firstWidgetLine));
  14. // getLinePixel will return the last pixel of the last line if line == lineCount
  15. int to= Math.min(fCanvas.getSize().y, fStyledText.getLinePixel(lastWidgetLine + 1));
  16. fCanvas.redraw(0, from, fWidth, to - from, false);
  17. }

代码示例来源:origin: BiglySoftware/BiglyBT

  1. @Override
  2. public void runSupport() {
  3. if (image == null || image.isDisposed() || labelImage.isDisposed()) {
  4. return;
  5. }
  6. if (display.isDisposed()) {
  7. return;
  8. }
  9. paintColorTo += paintColorDir;
  10. Utils.execSWTThreadLater(7 * paintColorDir, this);
  11. int ofs = (labelImage.getSize().x - boundsColor.width) / 2;
  12. labelImage.redraw(paintColorTo - paintColorDir + ofs, 10, paintColorDir, maxY, true);
  13. if (paintColorTo >= maxX || paintColorTo <= 0) {
  14. paintColorTo = 0;
  15. //paintColorDir = (int) (Math.random() * 5) + 2;
  16. Image tmp = image;
  17. image = imgSrc;
  18. imgSrc = tmp;
  19. }
  20. }
  21. });

代码示例来源:origin: org.eclipse.platform/org.eclipse.compare

  1. @Override
  2. public void paintControl(PaintEvent e) {
  3. Point s= fSummaryHeader.getSize();
  4. if (fIndicatorColor != null) {
  5. Display d= fSummaryHeader.getDisplay();
  6. e.gc.setBackground(getColor(d, fIndicatorColor));
  7. int min= Math.min(s.x, s.y)-2*INSET;
  8. Rectangle r= new Rectangle((s.x-min)/2, (s.y-min)/2, min, min);
  9. e.gc.fillRectangle(r);
  10. if (d != null)
  11. drawBevelRect(e.gc, r.x, r.y, r.width -1, r.height -1, d.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW), d.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW));
  12. e.gc.setForeground(fSeparatorColor);
  13. e.gc.setLineWidth(0 /* 1 */);
  14. e.gc.drawLine(0+1, s.y-1, s.x-1-1, s.y-1);
  15. }
  16. }
  17. }

代码示例来源:origin: org.eclipse/org.eclipse.compare

  1. public void paintControl(PaintEvent e) {
  2. Point s= fSummaryHeader.getSize();
  3. if (fIndicatorColor != null) {
  4. Display d= fSummaryHeader.getDisplay();
  5. e.gc.setBackground(getColor(d, fIndicatorColor));
  6. int min= Math.min(s.x, s.y)-2*INSET;
  7. Rectangle r= new Rectangle((s.x-min)/2, (s.y-min)/2, min, min);
  8. e.gc.fillRectangle(r);
  9. if (d != null)
  10. drawBevelRect(e.gc, r.x, r.y, r.width -1, r.height -1, d.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW), d.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW));
  11. e.gc.setForeground(fSeparatorColor);
  12. e.gc.setLineWidth(0 /* 1 */);
  13. e.gc.drawLine(0+1, s.y-1, s.x-1-1, s.y-1);
  14. }
  15. }
  16. }

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.ui.workbench.texteditor

  1. @Override
  2. public void paint(GC gc, Canvas canvas, Rectangle bounds) {
  3. Point canvasSize= canvas.getSize();
  4. int x= 0;
  5. int y= bounds.y;
  6. int w= canvasSize.x;
  7. int h= bounds.height;
  8. int b= 1;
  9. if (y + h > canvasSize.y)
  10. h= canvasSize.y - y;
  11. if (y < 0) {
  12. h= h + y;
  13. y= 0;
  14. }
  15. if (h <= 0)
  16. return;
  17. Image image = getImage(canvas);
  18. gc.drawImage(image, 0, 0, w, h, x, y, w, h);
  19. gc.setBackground(canvas.getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION));
  20. gc.fillRectangle(x, bounds.y, w, b);
  21. gc.fillRectangle(x, bounds.y + bounds.height - b, w, b);
  22. }

代码示例来源:origin: org.eclipse/org.eclipse.ui.workbench.texteditor

  1. public void paint(GC gc, Canvas canvas, Rectangle bounds) {
  2. Point canvasSize= canvas.getSize();
  3. int x= 0;
  4. int y= bounds.y;
  5. int w= canvasSize.x;
  6. int h= bounds.height;
  7. int b= 1;
  8. if (y + h > canvasSize.y)
  9. h= canvasSize.y - y;
  10. if (y < 0) {
  11. h= h + y;
  12. y= 0;
  13. }
  14. if (h <= 0)
  15. return;
  16. Image image = getImage(canvas);
  17. gc.drawImage(image, 0, 0, w, h, x, y, w, h);
  18. gc.setBackground(canvas.getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION));
  19. gc.fillRectangle(x, bounds.y, w, b);
  20. gc.fillRectangle(x, bounds.y + bounds.height - b, w, b);
  21. }

代码示例来源:origin: org.eclipse.platform/org.eclipse.ui.workbench.texteditor

  1. @Override
  2. public void paint(GC gc, Canvas canvas, Rectangle bounds) {
  3. Point canvasSize= canvas.getSize();
  4. int x= 0;
  5. int y= bounds.y;
  6. int w= canvasSize.x;
  7. int h= bounds.height;
  8. int b= 1;
  9. if (y + h > canvasSize.y)
  10. h= canvasSize.y - y;
  11. if (y < 0) {
  12. h= h + y;
  13. y= 0;
  14. }
  15. if (h <= 0)
  16. return;
  17. Color currentRangeIndicatorColor= JFaceResources.getColorRegistry().get(RANGE_INDICATOR_COLOR);
  18. Image image= getImage(canvas, currentRangeIndicatorColor);
  19. gc.drawImage(image, 0, 0, w, h, x, y, w, h);
  20. gc.setBackground(currentRangeIndicatorColor);
  21. gc.fillRectangle(x, bounds.y, w, b);
  22. gc.fillRectangle(x, bounds.y + bounds.height - b, w, b);
  23. fLastRangeIndicatorColor= currentRangeIndicatorColor;
  24. }

代码示例来源:origin: com.diffplug.durian/durian-swt

  1. public NoBorderBtn(Composite parent) {
  2. super(new Canvas(parent, SWT.NONE));
  3. wrapped.addListener(SWT.Paint, e -> {
  4. Point size = wrapped.getSize();
  5. // fill the background based on the "enabled" status
  6. Color backgroundColor = wrapped.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
  7. e.gc.setBackground(backgroundColor);
  8. e.gc.fillRectangle(0, 0, size.x, size.y);
  9. // draw the image
  10. if (img != null) {
  11. int deltaX = size.x - imgBounds.width;
  12. int deltaY = size.y - imgBounds.height;
  13. e.gc.drawImage(img, deltaX / 2, deltaY / 2);
  14. }
  15. });
  16. // send a selection event on each click (if we aren't disabled)
  17. wrapped.addListener(SWT.MouseDown, e -> {
  18. if (enabled) {
  19. selection.onNext(this);
  20. }
  21. });
  22. // send a "completed" event when we finish
  23. wrapped.addListener(SWT.Dispose, e -> {
  24. selection.onComplete();
  25. });
  26. }

代码示例来源:origin: org.eclipse.platform/org.eclipse.jface.text

  1. /**
  2. * Double buffer drawing.
  3. *
  4. * @param dest the GC to draw into
  5. */
  6. private void doubleBufferPaint(GC dest) {
  7. Point size= fCanvas.getSize();
  8. if (size.x <= 0 || size.y <= 0)
  9. return;
  10. if (fBuffer != null) {
  11. Rectangle r= fBuffer.getBounds();
  12. if (r.width != size.x || r.height != size.y) {
  13. fBuffer.dispose();
  14. fBuffer= null;
  15. }
  16. }
  17. if (fBuffer == null)
  18. fBuffer= new Image(fCanvas.getDisplay(), size.x, size.y);
  19. GC gc= new GC(fBuffer);
  20. gc.setFont(fCanvas.getFont());
  21. try {
  22. gc.setBackground(getBackground());
  23. gc.fillRectangle(0, 0, size.x, size.y);
  24. doPaint(gc);
  25. } finally {
  26. gc.dispose();
  27. }
  28. dest.drawImage(fBuffer, 0, 0);
  29. }

代码示例来源:origin: BiglySoftware/BiglyBT

  1. @Override
  2. public void run() {
  3. if(!canvas.isDisposed() && images != null) {
  4. currentImage++;
  5. if(currentImage >= images.length) {
  6. currentImage = 0;
  7. }
  8. if(currentImage < images.length) {
  9. Image image = images[currentImage];
  10. if(image != null && !image.isDisposed()) {
  11. Rectangle imageBounds = image.getBounds();
  12. Image tempImage = new Image(canvas.getDisplay(),new Rectangle( 0, 0, imageBounds.width, imageBounds.height ));
  13. GC gcImage = new GC(tempImage);
  14. gcImage.setBackground( canvas.getBackground());
  15. gcImage.fillRectangle( new Rectangle( 0, 0, imageBounds.width, imageBounds.width ));
  16. gcImage.drawImage(image, 0, 0 );
  17. GC gc = new GC(canvas);
  18. Point canvasSize = canvas.getSize();
  19. gc.drawImage( tempImage, (canvasSize.x-imageBounds.width)/2, (canvasSize.y-imageBounds.height)/2);
  20. tempImage.dispose();
  21. gcImage.dispose();
  22. gc.dispose();
  23. }
  24. }
  25. }
  26. }
  27. });

相关文章

Canvas类方法