Beispiel #1
0
 void updateBar(int selection, int minimum, int maximum, int thumb) {
   NSScroller widget = (NSScroller) view;
   selection = Math.max(minimum, Math.min(maximum - thumb, selection));
   float fraction =
       minimum == maximum ? 1 : (float) (selection - minimum) / (maximum - thumb - minimum);
   float knob = minimum == maximum ? 1 : (float) (thumb - minimum) / (maximum - minimum);
   widget.setFloatValue(fraction, knob);
 }
Beispiel #2
0
 /**
  * Sets the minimum value. If this value is negative or greater than or equal to the maximum, the
  * value is ignored. If necessary, first the thumb and then the selection are adjusted to fit
  * within the new range.
  *
  * @param value the new minimum
  * @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 void setMinimum(int value) {
   checkWidget();
   if (value < 0) return;
   if (value >= maximum) return;
   if (maximum - value < thumb) {
     thumb = maximum - value;
   }
   int selection = Math.min(maximum - thumb, Math.max(getSelection(), value));
   this.minimum = value;
   updateBar(selection, value, maximum, thumb);
 }
Beispiel #3
0
 /**
  * Sets the maximum. If this value is negative or less than or equal to the minimum, the value is
  * ignored. If necessary, first the thumb and then the selection are adjusted to fit within the
  * new range.
  *
  * @param value the new maximum, which must be greater than the current minimum
  * @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 void setMaximum(int value) {
   checkWidget();
   if (value < 0) return;
   if (value <= minimum) return;
   if (value - minimum < thumb) {
     thumb = value - minimum;
   }
   int selection = Math.max(minimum, Math.min(getSelection(), value - thumb));
   this.maximum = value;
   updateBar(selection, minimum, value, thumb);
 }
Beispiel #4
0
 /**
  * Sets the size of the receiver's thumb relative to the difference between its maximum and
  * minimum values. This new value will be ignored if it is less than one, and will be clamped if
  * it exceeds the receiver's current range.
  *
  * @param value the new thumb value, which must be at least one and not larger than the size of
  *     the current range
  * @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 void setThumb(int value) {
   checkWidget();
   if (value < 1) return;
   value = Math.min(value, maximum - minimum);
   this.thumb = value;
   updateBar(getSelection(), minimum, maximum, value);
 }
 /**
  * Sets the width of the receiver.
  *
  * @param width the new width
  * @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 void setWidth(int width) {
   checkWidget();
   if (width < 0) return;
   // TODO how to differentiate 0 and 1 cases?
   width = Math.max(0, width - Tree.CELL_GAP);
   nsColumn.setWidth(width);
 }
Beispiel #6
0
 /**
  * Sets the receiver's selection, minimum value, maximum value, thumb, increment and page
  * increment all at once.
  *
  * <p>Note: This is similar to setting the values individually using the appropriate methods, but
  * may be implemented in a more efficient fashion on some platforms.
  *
  * @param selection the new selection value
  * @param minimum the new minimum value
  * @param maximum the new maximum value
  * @param thumb the new thumb value
  * @param increment the new increment value
  * @param pageIncrement the new pageIncrement value
  * @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 void setValues(
     int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) {
   checkWidget();
   if (minimum < 0) return;
   if (maximum < 0) return;
   if (thumb < 1) return;
   if (increment < 1) return;
   if (pageIncrement < 1) return;
   thumb = Math.min(thumb, maximum - minimum);
   this.increment = increment;
   this.pageIncrement = pageIncrement;
   updateBar(selection, minimum, maximum, thumb);
 }
  /**
   * Causes the receiver to be resized to its preferred size. For a composite, this involves
   * computing the preferred size from its layout, if there is one.
   *
   * @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 void pack() {
    checkWidget();

    int width = 0;

    /* compute header width */
    NSTableHeaderCell headerCell = nsColumn.headerCell();
    NSSize size = headerCell.cellSize();
    width += Math.ceil(size.width);
    if (image != null) {
      NSSize imageSize = image.handle.size();
      width += Math.ceil(imageSize.width) + MARGIN;
    }
    if (parent.sortColumn == this && parent.sortDirection != SWT.NONE) {
      NSRect sortRect = headerCell.sortIndicatorRectForBounds(new NSRect());
      width += Math.ceil(sortRect.width + 2 * MARGIN);
    }

    /* compute item widths down column */
    GC gc = new GC(parent);
    width = Math.max(width, parent.calculateWidth(parent.items, parent.indexOf(this), gc, true));
    gc.dispose();
    setWidth(width);
  }
Beispiel #8
0
 public Path(Device device, Path path, float flatness) {
   super(device);
   if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
   if (path.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   flatness = Math.max(0, flatness);
   if (flatness == 0) {
     handle = new NSBezierPath(path.handle.copy().id);
   } else {
     float defaultFlatness = NSBezierPath.defaultFlatness();
     NSBezierPath.setDefaultFlatness(flatness);
     handle = path.handle.bezierPathByFlatteningPath();
     NSBezierPath.setDefaultFlatness(defaultFlatness);
   }
   if (handle == null) SWT.error(SWT.ERROR_NO_HANDLES);
   init();
 }
  void drawInteriorWithFrame_inView(
      long /*int*/ id, long /*int*/ sel, NSRect cellRect, long /*int*/ view) {
    /*
     * Feature in Cocoa.  When the last column in a tree does not reach the
     * rightmost edge of the tree view, the cell that draws the rightmost-
     * column's header is also invoked to draw the header space between its
     * right edge and the tree's right edge.  If this case is detected then
     * nothing should be drawn.
     */
    int columnIndex = parent.indexOf(nsColumn);
    NSRect headerRect = parent.headerView.headerRectOfColumn(columnIndex);
    if (headerRect.x != cellRect.x || headerRect.width != cellRect.width) return;

    NSGraphicsContext context = NSGraphicsContext.currentContext();
    context.saveGraphicsState();

    int contentWidth = 0;
    NSSize stringSize = null, imageSize = null;
    NSAttributedString attrString = null;
    NSTableHeaderCell headerCell = nsColumn.headerCell();
    if (displayText != null) {
      Font font = Font.cocoa_new(display, headerCell.font());
      attrString =
          parent.createString(
              displayText, font, null, SWT.LEFT, false, (parent.state & DISABLED) == 0, false);
      stringSize = attrString.size();
      contentWidth += Math.ceil(stringSize.width);
      if (image != null) contentWidth += MARGIN; /* space between image and text */
    }
    if (image != null) {
      imageSize = image.handle.size();
      contentWidth += Math.ceil(imageSize.width);
    }

    if (parent.sortColumn == this && parent.sortDirection != SWT.NONE) {
      boolean ascending = parent.sortDirection == SWT.UP;
      headerCell.drawSortIndicatorWithFrame(cellRect, new NSView(view), ascending, 0);
      /* remove the arrow's space from the available drawing width */
      NSRect sortRect = headerCell.sortIndicatorRectForBounds(cellRect);
      cellRect.width = Math.max(0, sortRect.x - cellRect.x);
    }

    int drawX = 0;
    if ((style & SWT.CENTER) != 0) {
      drawX = (int) (cellRect.x + Math.max(MARGIN, ((cellRect.width - contentWidth) / 2)));
    } else if ((style & SWT.RIGHT) != 0) {
      drawX = (int) (cellRect.x + Math.max(MARGIN, cellRect.width - contentWidth - MARGIN));
    } else {
      drawX = (int) cellRect.x + MARGIN;
    }

    if (image != null) {
      NSRect destRect = new NSRect();
      destRect.x = drawX;
      destRect.y = cellRect.y;
      destRect.width = Math.min(imageSize.width, cellRect.width - 2 * MARGIN);
      destRect.height = Math.min(imageSize.height, cellRect.height);
      boolean isFlipped = new NSView(view).isFlipped();
      if (isFlipped) {
        context.saveGraphicsState();
        NSAffineTransform transform = NSAffineTransform.transform();
        transform.scaleXBy(1, -1);
        transform.translateXBy(0, -(destRect.height + 2 * destRect.y));
        transform.concat();
      }
      NSRect sourceRect = new NSRect();
      sourceRect.width = destRect.width;
      sourceRect.height = destRect.height;
      image.handle.drawInRect(destRect, sourceRect, OS.NSCompositeSourceOver, 1f);
      if (isFlipped) context.restoreGraphicsState();
      drawX += destRect.width;
    }

    if (displayText != null && displayText.length() > 0) {
      if (image != null) drawX += MARGIN; /* space between image and text */
      NSRect destRect = new NSRect();
      destRect.x = drawX;
      destRect.y = cellRect.y;
      destRect.width = Math.min(stringSize.width, cellRect.x + cellRect.width - MARGIN - drawX);
      destRect.height = Math.min(stringSize.height, cellRect.height);
      attrString.drawInRect(destRect);
    }
    if (attrString != null) attrString.release();

    context.restoreGraphicsState();
  }