void tableMouseDown(Event event) {
   if (isDisposed() || !isVisible()) return;
   Point pt = new Point(event.x, event.y);
   int lineWidth = table.getLinesVisible() ? table.getGridLineWidth() : 0;
   TableItem item = table.getItem(pt);
   if ((table.getStyle() & SWT.FULL_SELECTION) != 0) {
     if (item == null) return;
   } else {
     int start = item != null ? table.indexOf(item) : table.getTopIndex();
     int end = table.getItemCount();
     Rectangle clientRect = table.getClientArea();
     for (int i = start; i < end; i++) {
       TableItem nextItem = table.getItem(i);
       Rectangle rect = nextItem.getBounds(0);
       if (pt.y >= rect.y && pt.y < rect.y + rect.height + lineWidth) {
         item = nextItem;
         break;
       }
       if (rect.y > clientRect.y + clientRect.height) return;
     }
     if (item == null) return;
   }
   TableColumn newColumn = null;
   int columnCount = table.getColumnCount();
   if (columnCount == 0) {
     if ((table.getStyle() & SWT.FULL_SELECTION) == 0) {
       Rectangle rect = item.getBounds(0);
       rect.width += lineWidth;
       rect.height += lineWidth;
       if (!rect.contains(pt)) return;
     }
   } else {
     for (int i = 0; i < columnCount; i++) {
       Rectangle rect = item.getBounds(i);
       rect.width += lineWidth;
       rect.height += lineWidth;
       if (rect.contains(pt)) {
         newColumn = table.getColumn(i);
         break;
       }
     }
     if (newColumn == null) {
       if ((table.getStyle() & SWT.FULL_SELECTION) == 0) return;
       newColumn = table.getColumn(0);
     }
   }
   setRowColumn(item, newColumn, true);
   setFocus();
   return;
 }
  public void positionWindow(boolean resetToDefault) {
    String mapWindow;

    mapShellBounds = mapShell.getBounds();
    mapWindow = prefs.get(RadarConsts.PREF_KEY_MAP_WINDOW, "");

    if (mapWindow.equals("") || resetToDefault) {
      Rectangle dispBounds, tableBounds;

      dispBounds = ((Display.getCurrent()).getPrimaryMonitor()).getClientArea();
      tableBounds = display.getShells()[1].getBounds();

      mapShellBounds.width = dispBounds.width - tableBounds.width;
      mapShellBounds.height = dispBounds.height;
      mapShellBounds.x = dispBounds.x + tableBounds.width;
      mapShellBounds.y = dispBounds.y;
    } else {
      String[] tokens = mapWindow.split(",");

      mapShellBounds =
          new Rectangle(
              new Integer(tokens[0]), // X value
              new Integer(tokens[1]), // Y value
              new Integer(tokens[2]), // Width
              new Integer(tokens[3]) // Height
              );
    }
    mapShell.setBounds(mapShellBounds);
  }
  /*
   * Returns true if the pointer's orientation was initialized in some dimension,
   * and false otherwise.
   */
  boolean resizeRectangles(int xChange, int yChange) {
    if (bounds == null) return false;
    boolean orientationInit = false;
    /*
     * If the cursor orientation has not been set in the orientation of
     * this change then try to set it here.
     */
    if (xChange < 0 && ((style & SWT.LEFT) != 0) && ((cursorOrientation & SWT.RIGHT) == 0)) {
      if ((cursorOrientation & SWT.LEFT) == 0) {
        cursorOrientation |= SWT.LEFT;
        orientationInit = true;
      }
    }
    if (xChange > 0 && ((style & SWT.RIGHT) != 0) && ((cursorOrientation & SWT.LEFT) == 0)) {
      if ((cursorOrientation & SWT.RIGHT) == 0) {
        cursorOrientation |= SWT.RIGHT;
        orientationInit = true;
      }
    }
    if (yChange < 0 && ((style & SWT.UP) != 0) && ((cursorOrientation & SWT.DOWN) == 0)) {
      if ((cursorOrientation & SWT.UP) == 0) {
        cursorOrientation |= SWT.UP;
        orientationInit = true;
      }
    }
    if (yChange > 0 && ((style & SWT.DOWN) != 0) && ((cursorOrientation & SWT.UP) == 0)) {
      if ((cursorOrientation & SWT.DOWN) == 0) {
        cursorOrientation |= SWT.DOWN;
        orientationInit = true;
      }
    }

    /*
     * If the bounds will flip about the x or y axis then apply the adjustment
     * up to the axis (ie.- where bounds width/height becomes 0), change the
     * cursor's orientation accordingly, and flip each Rectangle's origin (only
     * necessary for > 1 Rectangles)
     */
    if ((cursorOrientation & SWT.LEFT) != 0) {
      if (xChange > bounds.width) {
        if ((style & SWT.RIGHT) == 0) return orientationInit;
        cursorOrientation |= SWT.RIGHT;
        cursorOrientation &= ~SWT.LEFT;
        bounds.x += bounds.width;
        xChange -= bounds.width;
        bounds.width = 0;
        if (proportions.length > 1) {
          for (int i = 0; i < proportions.length; i++) {
            Rectangle proportion = proportions[i];
            proportion.x = 100 - proportion.x - proportion.width;
          }
        }
      }
    } else if ((cursorOrientation & SWT.RIGHT) != 0) {
      if (bounds.width < -xChange) {
        if ((style & SWT.LEFT) == 0) return orientationInit;
        cursorOrientation |= SWT.LEFT;
        cursorOrientation &= ~SWT.RIGHT;
        xChange += bounds.width;
        bounds.width = 0;
        if (proportions.length > 1) {
          for (int i = 0; i < proportions.length; i++) {
            Rectangle proportion = proportions[i];
            proportion.x = 100 - proportion.x - proportion.width;
          }
        }
      }
    }
    if ((cursorOrientation & SWT.UP) != 0) {
      if (yChange > bounds.height) {
        if ((style & SWT.DOWN) == 0) return orientationInit;
        cursorOrientation |= SWT.DOWN;
        cursorOrientation &= ~SWT.UP;
        bounds.y += bounds.height;
        yChange -= bounds.height;
        bounds.height = 0;
        if (proportions.length > 1) {
          for (int i = 0; i < proportions.length; i++) {
            Rectangle proportion = proportions[i];
            proportion.y = 100 - proportion.y - proportion.height;
          }
        }
      }
    } else if ((cursorOrientation & SWT.DOWN) != 0) {
      if (bounds.height < -yChange) {
        if ((style & SWT.UP) == 0) return orientationInit;
        cursorOrientation |= SWT.UP;
        cursorOrientation &= ~SWT.DOWN;
        yChange += bounds.height;
        bounds.height = 0;
        if (proportions.length > 1) {
          for (int i = 0; i < proportions.length; i++) {
            Rectangle proportion = proportions[i];
            proportion.y = 100 - proportion.y - proportion.height;
          }
        }
      }
    }

    // apply the bounds adjustment
    if ((cursorOrientation & SWT.LEFT) != 0) {
      bounds.x += xChange;
      bounds.width -= xChange;
    } else if ((cursorOrientation & SWT.RIGHT) != 0) {
      bounds.width += xChange;
    }
    if ((cursorOrientation & SWT.UP) != 0) {
      bounds.y += yChange;
      bounds.height -= yChange;
    } else if ((cursorOrientation & SWT.DOWN) != 0) {
      bounds.height += yChange;
    }

    Rectangle[] newRects = new Rectangle[rectangles.length];
    for (int i = 0; i < rectangles.length; i++) {
      Rectangle proportion = proportions[i];
      newRects[i] =
          new Rectangle(
              proportion.x * bounds.width / 100 + bounds.x,
              proportion.y * bounds.height / 100 + bounds.y,
              proportion.width * bounds.width / 100,
              proportion.height * bounds.height / 100);
    }
    rectangles = newRects;
    return orientationInit;
  }
 void keyDown(Event event) {
   if (row == null) return;
   switch (event.character) {
     case SWT.CR:
       notifyListeners(SWT.DefaultSelection, new Event());
       return;
   }
   int rowIndex = table.indexOf(row);
   int columnIndex = column == null ? 0 : table.indexOf(column);
   switch (event.keyCode) {
     case SWT.ARROW_UP:
       setRowColumn(Math.max(0, rowIndex - 1), columnIndex, true);
       break;
     case SWT.ARROW_DOWN:
       setRowColumn(Math.min(rowIndex + 1, table.getItemCount() - 1), columnIndex, true);
       break;
     case SWT.ARROW_LEFT:
     case SWT.ARROW_RIGHT:
       {
         int columnCount = table.getColumnCount();
         if (columnCount == 0) break;
         int[] order = table.getColumnOrder();
         int index = 0;
         while (index < order.length) {
           if (order[index] == columnIndex) break;
           index++;
         }
         if (index == order.length) index = 0;
         int leadKey = (getStyle() & SWT.RIGHT_TO_LEFT) != 0 ? SWT.ARROW_RIGHT : SWT.ARROW_LEFT;
         if (event.keyCode == leadKey) {
           setRowColumn(rowIndex, order[Math.max(0, index - 1)], true);
         } else {
           setRowColumn(rowIndex, order[Math.min(columnCount - 1, index + 1)], true);
         }
         break;
       }
     case SWT.HOME:
       setRowColumn(0, columnIndex, true);
       break;
     case SWT.END:
       {
         int i = table.getItemCount() - 1;
         setRowColumn(i, columnIndex, true);
         break;
       }
     case SWT.PAGE_UP:
       {
         int index = table.getTopIndex();
         if (index == rowIndex) {
           Rectangle rect = table.getClientArea();
           TableItem item = table.getItem(index);
           Rectangle itemRect = item.getBounds(0);
           rect.height -= itemRect.y;
           int height = table.getItemHeight();
           int page = Math.max(1, rect.height / height);
           index = Math.max(0, index - page + 1);
         }
         setRowColumn(index, columnIndex, true);
         break;
       }
     case SWT.PAGE_DOWN:
       {
         int index = table.getTopIndex();
         Rectangle rect = table.getClientArea();
         TableItem item = table.getItem(index);
         Rectangle itemRect = item.getBounds(0);
         rect.height -= itemRect.y;
         int height = table.getItemHeight();
         int page = Math.max(1, rect.height / height);
         int end = table.getItemCount() - 1;
         index = Math.min(end, index + page - 1);
         if (index == rowIndex) {
           index = Math.min(end, index + page - 1);
         }
         setRowColumn(index, columnIndex, true);
         break;
       }
   }
 }