Ejemplo n.º 1
0
 private int getTextWidth(final int index) {
   int result = 0;
   String text = getText(index);
   if (text.length() > 0) {
     result = Graphics.stringExtent(parent.getFont(), text).x;
   }
   return result;
 }
Ejemplo n.º 2
0
 /**
  * Returns a rectangle describing the receiver's size and location relative to its parent.
  *
  * @return the receiver's bounding rectangle
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  *
  * @since 1.3
  */
 public Rectangle getBounds() {
   checkWidget();
   Rectangle result = new Rectangle(0, 0, 0, 0);
   int index = parent.indexOf(this);
   if (index != -1) {
     int selectionIndex = parent.getSelectionIndex();
     boolean selected = index == selectionIndex;
     Rectangle padding = parent.getItemPadding(selected);
     String text = getText();
     if (text != null) {
       Point extent = Graphics.stringExtent(parent.getFont(), text);
       result.width = extent.x;
       result.height = extent.y;
     }
     Image image = getImage();
     if (image != null) {
       Rectangle imageSize = image.getBounds();
       result.width += imageSize.width + IMAGE_TEXT_SPACING;
       result.height = Math.max(result.height, imageSize.height);
     }
     result.width += 2 * ITEM_BORDER + padding.width;
     result.height += ITEM_BORDER + padding.height;
     if (selected) {
       result.height += SELECTED_ITEM_BORDER;
     }
     if (selectionIndex != -1) {
       if (index + 1 == selectionIndex || index - 1 == selectionIndex) {
         result.width -= ITEM_BORDER;
       }
     }
     if (isBarTop()) {
       if (index != selectionIndex) {
         result.y += SELECTED_ITEM_BORDER;
       }
     } else {
       result.y = parent.getBounds().height - 2 * parent.getBorderWidth() - result.height;
       if (index != selectionIndex) {
         result.y -= SELECTED_ITEM_BORDER;
       }
     }
     if (index > 0) {
       TabItem leftItem = parent.getItem(index - 1);
       Rectangle leftItemBounds = leftItem.getBounds();
       result.x = leftItemBounds.x + leftItemBounds.width + TABS_SPACING;
       if (index == selectionIndex || index - 1 == selectionIndex) {
         result.x -= TABS_SPACING;
       }
     }
   }
   return result;
 }
Ejemplo n.º 3
0
 /**
  * Returns a rectangle describing the size and location relative to its parent of the text at a
  * column in the table. An empty rectangle is returned if index exceeds the index of the table's
  * last column.
  *
  * @param index the index that specifies the column
  * @return the receiver's bounding text rectangle
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  */
 public Rectangle getTextBounds(final int index) {
   checkWidget();
   int itemIndex = parent.indexOf(this);
   if (!parent.checkData(this, itemIndex)) {
     error(SWT.ERROR_WIDGET_DISPOSED);
   }
   int left = 0;
   int top = 0;
   int width = 0;
   Rectangle cellPadding = parent.getCellPadding();
   if (index == 0 && parent.getColumnCount() == 0) {
     int imageWidth = 0;
     int spacing = 0;
     if (parent.hasColumnImages(0)) {
       imageWidth = parent.getItemImageSize().x;
       spacing = getSpacing(0);
     }
     left = getLeft(0) + cellPadding.x + imageWidth + spacing;
     top = getTop(itemIndex);
     Font font = getFont();
     width = Graphics.stringExtent(font, getText(0)).x;
   } else if (itemIndex != -1 && index < parent.getColumnCount()) {
     int imageWidth = 0;
     if (parent.hasColumnImages(index)) {
       imageWidth = parent.getItemImageSize().x;
     }
     int spacing = getSpacing(index);
     left = getLeft(index) + cellPadding.x + imageWidth + spacing;
     top = getTop(itemIndex);
     width = getColumnWidth(index) - cellPadding.width - imageWidth - spacing;
     if (width < 0) {
       width = 0;
     }
   }
   int height = getHeight(index);
   return new Rectangle(left, top, width, height);
 }