org.eclipse.swt.graphics.Rectangle类的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(11.5k)|赞(0)|评价(0)|浏览(144)

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

Rectangle介绍

[英]Instances of this class represent rectangular areas in an (x, y) coordinate system. The top left corner of the rectangle is specified by its x and y values, and the extent of the rectangle is specified by its width and height.

The coordinate space for rectangles and points is considered to have increasing values downward and to the right from its origin making this the normal, computer graphics oriented notion of (x, y) coordinates rather than the strict mathematical one.

The hashCode() method in this class uses the values of the public fields to compute the hash value. When storing instances of the class in hashed collections, do not modify these fields after the object has been inserted.

Application code does not need to explicitly release the resources managed by each instance when those instances are no longer required, and thus no dispose() method is provided.
[中]此类的实例表示(x,y)坐标系中的矩形区域。矩形的左上角由其x和y值指定,矩形的范围由其宽度和高度指定。
矩形和点的坐标空间被认为从原点向下和向右具有递增的值,这使得这是正常的、面向计算机图形学的(x,y)坐标概念,而不是严格的数学概念。
此类中的hashCode()方法使用公共字段的值来计算哈希值。在散列集合中存储类的实例时,不要在插入对象后修改这些字段。
当不再需要每个实例时,应用程序代码需要显式释放这些实例管理的资源,因此不提供dispose()方法。

代码示例

代码示例来源:origin: pentaho/pentaho-kettle

public void paintControl( final PaintEvent event ) {
  if ( transGraph.trans != null && transGraph.trans.isFinished() ) {
   refreshImage( event.gc );
   if ( image != null && !image.isDisposed() ) {
    event.gc.drawImage( image, 0, 0 );
   }
  } else {
   Rectangle bounds = canvas.getBounds();
   if ( bounds.width <= 0 || bounds.height <= 0 ) {
    return;
   }
   event.gc.setForeground( GUIResource.getInstance().getColorWhite() );
   event.gc.setBackground( GUIResource.getInstance().getColorWhite() );
   event.gc.fillRectangle( new Rectangle( 0, 0, bounds.width, bounds.height ) );
   event.gc.setForeground( GUIResource.getInstance().getColorBlack() );
   String metricsMessage =
    BaseMessages.getString( PKG, "TransMetricsDelegate.TransformationIsNotRunning.Message" );
   org.eclipse.swt.graphics.Point extent = event.gc.textExtent( metricsMessage );
   event.gc.drawText( metricsMessage, ( bounds.width - extent.x ) / 2, ( bounds.height - extent.y ) / 2 );
  }
 }
} );

代码示例来源:origin: pentaho/pentaho-kettle

private boolean isInAdd( Point screen ) {
 if ( size_add == null || screen == null ) {
  return false;
 }
 return size_add.contains( screen );
}

代码示例来源:origin: caoxinyu/RedisClient

@Override
public void handleEvent(Event event) {
    Rectangle clientArea = table.getClientArea();
    Point pt = new Point(event.x, event.y);
    int index = table.getTopIndex();
    int count = table.getItemCount();
    while (index < count) {
      boolean visible = false;
      TableItem item = table.getItem(index);
      
      for (int i = 0; i < table.getColumnCount(); i++) {
        Rectangle rect = item.getBounds(i);
        if (rect.contains(pt)) {
          beforeEdit();
          clickRow(item, i);
          return;
        }
        if (!visible && rect.intersects(clientArea)) {
          visible = true;
        }
      }
      if (!visible)
        return;
      index++;
    }
}
protected void beforeEdit() {

代码示例来源:origin: org.eclipse.swt.cocoa.macosx/x86_64

Image createButtonImage(Display display, int button) {
  GC tempGC = new GC (this);
  Point size = renderer.computeSize(button, SWT.NONE, tempGC, SWT.DEFAULT, SWT.DEFAULT);
  tempGC.dispose();
  Rectangle trim = renderer.computeTrim(button, SWT.NONE, 0, 0, 0, 0);
  Image image = new Image (display, size.x - trim.width, size.y - trim.height);
  GC gc = new GC (image);
  RGB transparent;
  if (button == CTabFolderRenderer.PART_CHEVRON_BUTTON) {
    transparent = new RGB(0xFF, 0xFF, 0xFF);
  } else {
    transparent = new RGB(0xFD, 0, 0);
  }
  Color transColor = new Color(display, transparent);
  gc.setBackground(transColor);
  gc.fillRectangle(image.getBounds());
  renderer.draw(button, SWT.NONE, new Rectangle(trim.x, trim.y, size.x, size.y), gc);
  gc.dispose ();
  transColor.dispose();
  ImageData imageData = image.getImageData();
  imageData.transparentPixel = imageData.palette.getPixel(transparent);
  image.dispose();
  image = new Image(display, imageData);
  return image;
}
void createItem (CTabItem item, int index) {

代码示例来源:origin: pentaho/pentaho-kettle

shell.setMaximized( maximized );
shell.setBounds( rectangle );
 Rectangle bounds = shell.getBounds();
 if ( bounds.width < minWidth ) {
  bounds.width = minWidth;
shell.setBounds( shellSize );
Rectangle entireClientArea = shell.getDisplay().getClientArea();
Rectangle resizedRect = Geometry.copy( shellSize );
constrainRectangleToContainer( resizedRect, entireClientArea );
if ( !resizedRect.equals( shellSize ) || isClippedByUnalignedMonitors( resizedRect, shell.getDisplay() ) ) {
 Monitor monitor = shell.getDisplay().getPrimaryMonitor();
 if ( shell.getParent() != null ) {
  monitor = shell.getParent().getMonitor();

代码示例来源:origin: pentaho/pentaho-kettle

public static void setSize( Shell shell, int prefWidth, int prefHeight ) {
 PropsUI props = PropsUI.getInstance();
 WindowProperty winprop = props.getScreen( shell.getText() );
 if ( winprop != null ) {
  winprop.setShell( shell, prefWidth, prefHeight );
 } else {
  shell.layout();
  winprop = new WindowProperty( shell.getText(), false, new Rectangle( 0, 0, prefWidth, prefHeight ) );
  winprop.setShell( shell );
  // Now, as this is the first time it gets opened, try to put it in the middle of the screen...
  Rectangle shellBounds = shell.getBounds();
  Monitor monitor = shell.getDisplay().getPrimaryMonitor();
  if ( shell.getParent() != null ) {
   monitor = shell.getParent().getMonitor();
  }
  Rectangle monitorClientArea = monitor.getClientArea();
  int middleX = monitorClientArea.x + ( monitorClientArea.width - shellBounds.width ) / 2;
  int middleY = monitorClientArea.y + ( monitorClientArea.height - shellBounds.height ) / 2;
  shell.setLocation( middleX, middleY );
 }
}

代码示例来源:origin: org.eclipse.e4.ui.workbench.renderers/swt

void createShadow(final Display display) {
  if (shadowImage != null) {
    shadowImage.dispose();
    shadowImage = null;
  }
  ImageData data = new ImageData(60, 60, 32, new PaletteData(0xFF0000,
      0xFF00, 0xFF));
  Image tmpImage = shadowImage = new Image(display, data);
  GC gc = new GC(tmpImage);
  if (shadowColor == null)
    shadowColor = gc.getDevice().getSystemColor(SWT.COLOR_GRAY);
  gc.setBackground(shadowColor);
  drawTabBody(gc, new Rectangle(0, 0, 60, 60), SWT.None);
  ImageData blured = blur(tmpImage, 5, 25);
  shadowImage = new Image(display, blured);
  tmpImage.dispose();
}

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

private void updateButtonColor(final Display display, final int rV, final int gV, final int bV) {
 Image oldImg = img;
 img = new Image(display,25,10);
 GC gc = new GC(img);
 if ( r >= 0 && g >= 0 && b >= 0 ){
   Color color = ColorCache.getColor(display, rV, gV, bV);
   gc.setBackground(color);
     gc.fillRectangle(0,0,25,10);
  }else{
   Color color = colorChooser.getBackground();
   gc.setBackground(color);
     gc.fillRectangle(0,0,25,10);
     new GCStringPrinter( gc, "-", new Rectangle( 0, 0, 25, 10 ), 0, SWT.CENTER ).printString();
 }
 gc.dispose();
 colorChooser.setImage(img);
 if(oldImg != null && ! oldImg.isDisposed())
  oldImg.dispose();
}

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

@Override
public Image getBackgroundImage() {
  if (bounds == null || bounds.isEmpty()) {
    return null;
  }
  Image image = new Image(Display.getDefault(), bounds.width
      - (marginWidth * 2), bounds.height - (marginHeight * 2));
  GC gc = new GC(image);
  gc.setForeground(getBackgroundSWT());
  gc.setBackground(getBackgroundSWT());
  gc.fillRectangle(0, 0, bounds.width, bounds.height);
  gc.dispose();
  return image;
}

代码示例来源:origin: pentaho/pentaho-kettle

String operator = condition.getOperatorDesc();
 size_oper[nr] = new Rectangle( opx, opy, opw, oph );
 if ( nr == hover_operator ) {
  gc.setBackground( gray );
  gc.fillRectangle( Real2Screen( size_oper[nr] ) );
  gc.drawRectangle( Real2Screen( size_oper[nr] ) );
  gc.setBackground( bg );
size_cond[nr] = new Rectangle( cx, cy, cw, ch );

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

/**
 * @param image
 * @param bounds
 * @param text
 */
public static void obfuscateArea(Image image, Rectangle bounds, String text) {
  if (bounds.isEmpty())
    return;
  if (text == null || text.length() == 0) {
    obfuscateArea(image, bounds);
    return;
  }
  GC gc = new GC(image);
  try {
    Device device = image.getDevice();
    gc.setBackground(Colors.getSystemColor(device, SWT.COLOR_WHITE));
    gc.setForeground(Colors.getSystemColor(device, SWT.COLOR_RED));
    gc.fillRectangle(bounds);
    gc.drawRectangle(bounds);
    Utils.setClipping(gc, bounds);
    gc.drawText(text, bounds.x + 2, bounds.y + 1);
  } finally {
    gc.dispose();
  }
}

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

protected Point getStackedLocation(Shell shell, Shell parent) {
  Point p= parent.getLocation();
  Point size= parent.getSize();
  p.x += size.x / 4;
  p.y += size.y;
  p= parent.toDisplay(p);
  Point shellSize= shell.getSize();
  Monitor monitor= getClosestMonitor(parent.getDisplay(), new Rectangle(p.x, p.y, 0, 0));
  Rectangle displayBounds= monitor.getClientArea();
  constrainLocation(p, shellSize, displayBounds);
  return p;
}

代码示例来源:origin: org.xworker/xworker_swt

public void paintControl(PaintEvent event) {
  Control control = (Control) event.widget;
  Rectangle rect = new Rectangle(0, 0,
      control.getSize().x, control.getSize().y);
  
  GC gc = event.gc;
  //System.out.println(event.count);
  Color color = gc.getForeground();
  gc.setForeground(event.display.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW));
  gc.drawLine(rect.x, rect.y, rect.width, rect.y);
  gc.drawLine(rect.x, rect.y, rect.x, rect.height);
  gc.setForeground(event.display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));
  gc.drawLine(rect.x, rect.height-1, rect.width, rect.height-1);
  gc.drawLine(rect.width-1, rect.y, rect.width-1, rect.height);
  gc.setForeground(color);
}

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

private Rectangle computeShellBounds() {
 Rectangle result = new Rectangle( 0, 0, 0, 0 );
 Point preferredSize = shell.computeSize( SWT.DEFAULT, SWT.DEFAULT );
 Rectangle displaySize = parent.getDisplay().getBounds();
 result.x = ( displaySize.width - preferredSize.x ) / 2 + displaySize.x;
 result.y = ( displaySize.height - preferredSize.y ) / 2 + displaySize.y;
 result.width = Math.min( preferredSize.x, MAX_WIDTH );
 result.height = preferredSize.y;
 return result;
}

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

private void layoutBullet(GC gc, Locator loc, int lineHeight,
    Hashtable<String, Object> resourceTable) {
  int x = loc.x - getIndent() + getBulletIndent();
  int rowHeight = loc.heights.get(0)[0];
  if (style == CIRCLE) {
    int y = loc.y + rowHeight / 2 - CIRCLE_DIAM / 2;
    bbounds = new Rectangle(x, y, CIRCLE_DIAM, CIRCLE_DIAM);
  } else if (style == TEXT && text != null) {
    //int height = gc.getFontMetrics().getHeight();
    Point textSize = gc.textExtent(text);
    bbounds = new Rectangle(x, loc.y, textSize.x, textSize.y);
  } else if (style == IMAGE && text != null) {
    Image image = (Image) resourceTable.get(text);
    if (image != null) {
      Rectangle ibounds = image.getBounds();
      int y = loc.y + rowHeight / 2 - ibounds.height / 2;
      bbounds = new Rectangle(x, y, ibounds.width, ibounds.height);
    }
  }
}

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

/**
 * Constrain the shell size to be no larger than the display bounds.
 *
 * @since 2.0
 */
protected void constrainShellSize() {
  // limit the shell size to the display size
  Rectangle bounds = shell.getBounds();
  Rectangle constrained = getConstrainedShellBounds(bounds);
  if (!bounds.equals(constrained)) {
    shell.setBounds(constrained);
  }
}

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

@Override
public void mouseExit(MouseEvent e) {
  if (fComposite == null)
      return;
  Control[] children= fComposite.getChildren();
  Rectangle bounds= null;
  for (int i= 0; i < children.length; i++) {
    if (bounds == null)
      bounds= children[i].getBounds();
    else
      bounds.add(children[i].getBounds());
    if (bounds.contains(e.x, e.y))
      return;
  }
  // if none of the children contains the event, we leave the popup
  dispose();
}

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

@Override
  public void paintControl(PaintEvent e) {
    GC gc = e.gc;
    gc.setForeground( Colors.grey);
    Point size = engine_comp.getSize();
    gc.drawRectangle( new Rectangle( 0,  0, size.x-1, size.y-1 ));
  }
});

代码示例来源:origin: pentaho/pentaho-kettle

private Rectangle getAndNotSize( GC gc ) {
 Point p = gc.textExtent( Condition.operators[Condition.OPERATOR_AND_NOT] );
 return new Rectangle( 0, 0, p.x, p.y );
}

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

@Override
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));
}

相关文章