Пример #1
0
 /**
  * Adds the listener to the collection of listeners who will be notified when the user changes the
  * receiver's selection, by sending it one of the messages defined in the <code>SelectionListener
  * </code> interface.
  *
  * <p>When <code>widgetSelected</code> is called, the item field of the event object is valid. If
  * the receiver has <code>SWT.CHECK</code> style set and the check selection changes, the event
  * object detail field contains the value <code>SWT.CHECK</code>. <code>widgetDefaultSelected
  * </code> is typically called when an item is double-clicked.
  *
  * @param listener the listener which should be notified when the user changes the receiver's
  *     selection
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT - if the listener is null
  *     </ul>
  *
  * @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>
  *
  * @see SelectionListener
  * @see SelectionEvent
  * @see #removeSelectionListener(SelectionListener)
  */
 public void addSelectionListener(SelectionListener listener) {
   checkWidget();
   if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
   TypedListener typedListener = new TypedListener(listener);
   addListener(SWT.Selection, typedListener);
   addListener(SWT.DefaultSelection, typedListener);
 }
Пример #2
0
 /**
  * Positions the TableCursor over the cell at the given row and column in the parent table.
  *
  * @param row the TableItem of the row for the cell to select
  * @param column the index of column for the cell to select
  * @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 setSelection(TableItem row, int column) {
   checkWidget();
   int columnCount = table.getColumnCount();
   int maxColumnIndex = columnCount == 0 ? 0 : columnCount - 1;
   if (row == null || row.isDisposed() || column < 0 || column > maxColumnIndex)
     SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   setRowColumn(table.indexOf(row), column, false);
 }
Пример #3
0
 /**
  * Positions the TableCursor over the cell at the given row and column in the parent table.
  *
  * @param row the index of the row for the cell to select
  * @param column the index of column for the cell to select
  * @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 setSelection(int row, int column) {
   checkWidget();
   int columnCount = table.getColumnCount();
   int maxColumnIndex = columnCount == 0 ? 0 : columnCount - 1;
   if (row < 0 || row >= table.getItemCount() || column < 0 || column > maxColumnIndex)
     SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   setRowColumn(row, column, false);
 }
Пример #4
0
 /**
  * Removes the listener from the collection of listeners who will be notified when the user
  * changes the receiver's selection.
  *
  * @param listener the listener which should no longer be notified
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT - if the listener is null
  *     </ul>
  *
  * @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>
  *
  * @see SelectionListener
  * @see #addSelectionListener(SelectionListener)
  * @since 3.0
  */
 public void removeSelectionListener(SelectionListener listener) {
   checkWidget();
   if (listener == null) {
     SWT.error(SWT.ERROR_NULL_ARGUMENT);
   }
   removeListener(SWT.Selection, listener);
   removeListener(SWT.DefaultSelection, listener);
 }
Пример #5
0
 /**
  * Set the horizontal alignment of the CLabel. Use the values LEFT, CENTER and RIGHT to align
  * image and text within the available space.
  *
  * @param align the alignment style of LEFT, RIGHT or CENTER
  * @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
  *       <li>ERROR_INVALID_ARGUMENT - if the value of align is not one of SWT.LEFT, SWT.RIGHT or
  *           SWT.CENTER
  *     </ul>
  */
 public void setAlignment(int align) {
   checkWidget();
   if (align != SWT.LEFT && align != SWT.RIGHT && align != SWT.CENTER) {
     SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   }
   if (this.align != align) {
     this.align = align;
     redraw();
   }
 }
Пример #6
0
 void paint(Event event) {
   if (row == null) return;
   int columnIndex = column == null ? 0 : table.indexOf(column);
   GC gc = event.gc;
   gc.setBackground(getBackground());
   gc.setForeground(getForeground());
   gc.fillRectangle(event.x, event.y, event.width, event.height);
   int x = 0;
   Point size = getSize();
   Image image = row.getImage(columnIndex);
   if (image != null) {
     Rectangle imageSize = image.getBounds();
     int imageY = (size.y - imageSize.height) / 2;
     gc.drawImage(image, x, imageY);
     x += imageSize.width;
   }
   String text = row.getText(columnIndex);
   if (text.length() > 0) {
     Rectangle bounds = row.getBounds(columnIndex);
     Point extent = gc.stringExtent(text);
     // Temporary code - need a better way to determine table trim
     String platform = SWT.getPlatform();
     if ("win32".equals(platform)) { // $NON-NLS-1$
       if (table.getColumnCount() == 0 || columnIndex == 0) {
         x += 2;
       } else {
         int alignmnent = column.getAlignment();
         switch (alignmnent) {
           case SWT.LEFT:
             x += 6;
             break;
           case SWT.RIGHT:
             x = bounds.width - extent.x - 6;
             break;
           case SWT.CENTER:
             x += (bounds.width - x - extent.x) / 2;
             break;
         }
       }
     } else {
       if (table.getColumnCount() == 0) {
         x += 5;
       } else {
         int alignmnent = column.getAlignment();
         switch (alignmnent) {
           case SWT.LEFT:
             x += 5;
             break;
           case SWT.RIGHT:
             x = bounds.width - extent.x - 2;
             break;
           case SWT.CENTER:
             x += (bounds.width - x - extent.x) / 2 + 2;
             break;
         }
       }
     }
     int textY = (size.y - extent.y) / 2;
     gc.drawString(text, x, textY);
   }
   if (isFocusControl()) {
     Display display = getDisplay();
     gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
     gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
     gc.drawFocus(0, 0, size.x, size.y);
   }
 }
Пример #7
0
  /**
   * Specify a gradient of colours to be drawn in the background of the CLabel.
   *
   * <p>For example, to draw a gradient that varies from dark blue to white in the vertical,
   * direction use the following call to setBackground:
   *
   * <pre>
   * clabel.setBackground(new Color[]{display.getSystemColor(SWT.COLOR_DARK_BLUE),
   * 	                           display.getSystemColor(SWT.COLOR_WHITE)},
   * 	                 new int[] {100}, true);
   * </pre>
   *
   * @param colors an array of Color that specifies the colors to appear in the gradient in order of
   *     appearance from left/top to right/bottom; The value <code>null</code> clears the background
   *     gradient; the value <code>null</code> can be used inside the array of Color to specify the
   *     background color.
   * @param percents an array of integers between 0 and 100 specifying the percent of the
   *     width/height of the widget at which the color should change; the size of the percents array
   *     must be one less than the size of the colors array.
   * @param vertical indicate the direction of the gradient. True is vertical and false is
   *     horizontal.
   * @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
   *       <li>ERROR_INVALID_ARGUMENT - if the values of colors and percents are not consistent
   *     </ul>
   *
   * @since 3.0
   */
  public void setBackground(Color[] colors, int[] percents, boolean vertical) {
    checkWidget();
    if (colors != null) {
      if (percents == null || percents.length != colors.length - 1) {
        SWT.error(SWT.ERROR_INVALID_ARGUMENT);
      }
      if (getDisplay().getDepth() < 15) {
        // Don't use gradients on low color displays
        colors = new Color[] {colors[colors.length - 1]};
        percents = new int[] {};
      }
      for (int i = 0; i < percents.length; i++) {
        if (percents[i] < 0 || percents[i] > 100) {
          SWT.error(SWT.ERROR_INVALID_ARGUMENT);
        }
        if (i > 0 && percents[i] < percents[i - 1]) {
          SWT.error(SWT.ERROR_INVALID_ARGUMENT);
        }
      }
    }

    // Are these settings the same as before?
    final Color background = getBackground();
    if (backgroundImage == null) {
      if ((gradientColors != null)
          && (colors != null)
          && (gradientColors.length == colors.length)) {
        boolean same = false;
        for (int i = 0; i < gradientColors.length; i++) {
          same =
              (gradientColors[i] == colors[i])
                  || ((gradientColors[i] == null) && (colors[i] == background))
                  || ((gradientColors[i] == background) && (colors[i] == null));
          if (!same) break;
        }
        if (same) {
          for (int i = 0; i < gradientPercents.length; i++) {
            same = gradientPercents[i] == percents[i];
            if (!same) break;
          }
        }
        if (same && this.gradientVertical == vertical) return;
      }
    } else {
      backgroundImage = null;
    }
    // Store the new settings
    if (colors == null) {
      gradientColors = null;
      gradientPercents = null;
      gradientVertical = false;
    } else {
      gradientColors = new Color[colors.length];
      for (int i = 0; i < colors.length; ++i)
        gradientColors[i] = (colors[i] != null) ? colors[i] : background;
      gradientPercents = new int[percents.length];
      for (int i = 0; i < percents.length; ++i) gradientPercents[i] = percents[i];
      gradientVertical = vertical;
    }
    // Refresh with the new settings
    redraw();
  }