示例#1
0
 public Region getRegion(Image image) {
   Region region = new Region();
   final ImageData imageData = image.getImageData();
   if (imageData.alphaData != null) {
     Rectangle pixel = new Rectangle(0, 0, 1, 1);
     for (int y = 0; y < imageData.height; y++) {
       for (int x = 0; x < imageData.width; x++) {
         if (imageData.getAlpha(x, y) == 255) {
           pixel.x = imageData.x + x;
           pixel.y = imageData.y + y;
           region.add(pixel);
         }
       }
     }
   } else {
     ImageData mask = imageData.getTransparencyMask();
     Rectangle pixel = new Rectangle(0, 0, 1, 1);
     for (int y = 0; y < mask.height; y++) {
       for (int x = 0; x < mask.width; x++) {
         if (mask.getPixel(x, y) != 0) {
           pixel.x = imageData.x + x;
           pixel.y = imageData.y + y;
           region.add(pixel);
         }
       }
     }
   }
   return region;
 }
示例#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;
 }
示例#3
0
  protected void mouseMoveSelectMode(MouseEvent e) {
    switch (dragging) {
      case DRAG_OBJECT:
        if (!draggedAway
            && (Math.abs(e.x - dragPoint.x) >= 5 || Math.abs(e.y - dragPoint.y) >= 5)) {
          draggedAway = true;
          startDraggingSelectedObjects();
        }
        if (draggedAway) {
          dragSelectedObjectsBy(e.x - dragPoint.x, e.y - dragPoint.y);
        }
        break;

      case DRAG_SELECTIONRECTANGLE:
        if (!draggedAway
            && (Math.abs(e.x - dragPoint.x) >= 5 || Math.abs(e.y - dragPoint.y) >= 5)) {
          draggedAway = true;
        }
        if (draggedAway) {
          Rectangle r = new Rectangle(0, 0, 0, 0);
          r.x = Math.min(dragPoint.x, e.x);
          r.y = Math.min(dragPoint.y, e.y);
          r.width = Math.max(dragPoint.x, e.x) - r.x;
          r.height = Math.max(dragPoint.y, e.y) - r.y;
          setSelectionRectangle(r);
        }
        break;
    }
  }
示例#4
0
  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);
  }
示例#5
0
 /**
  * @see ch.post.pf.gui.ocp.wt.ext.dialogs.OcpDialog#showDialogFor(org.eclipse.swt.widgets.Control)
  */
 public int showDialogFor(Control field) {
   create();
   getShell()
       .addShellListener(
           new ShellAdapter() {
             @Override
             public void shellDeactivated(ShellEvent e) {
               close();
             }
           });
   // make sure that the popup fit into the application window.
   Rectangle appBounds = getEnvironment().getDisplay().getBounds();
   Point absPrefPos =
       field.toDisplay(field.getSize().x - getShell().getSize().x, field.getSize().y);
   Rectangle prefBounds =
       new Rectangle(absPrefPos.x, absPrefPos.y, getShell().getSize().x, getShell().getSize().y);
   // horizontal correction
   if (prefBounds.x + prefBounds.width > appBounds.width) {
     prefBounds.x = appBounds.width - prefBounds.width;
   }
   // vertical correciton
   if (prefBounds.y + prefBounds.height > appBounds.height) {
     prefBounds.y = appBounds.height - prefBounds.height;
   }
   getShell().setLocation(prefBounds.x, prefBounds.y);
   int ret = this.open();
   return ret;
 }
  /**
   * Handling mouse over event to display hand cursor in case cell contains an URL
   *
   * @param e mouse event
   */
  void handleMouseOver(MouseEvent e) {
    Point pt = new Point(e.x, e.y);
    ViewerCell cell = getViewer().getCell(pt);
    boolean cursorSet = false;

    if (cell != null) {
      int colIndex = cell.getColumnIndex();
      Object element = cell.getElement();
      if (getCellControlType(element, colIndex) == CellControlType.URL) {
        Rectangle cellBounds = cell.getBounds();
        Image img = getImage(element, colIndex);
        if (img != null) {
          cellBounds.x += img.getBounds().width;
        }
        if (cellBounds.contains(pt)) {
          if (getString(element, colIndex) != null) {
            this.control.setCursor(CURSOR_HAND);
            cursorSet = true;
          }
        }
      }
    }

    if (!cursorSet) {
      handleMouseExit(e);
    }
  }
    public void handleEvent(final Event event) {
      // only go further if the event has a new time stamp
      if (mayScroll() && acceptEvent(event)) {
        lastEventTime = event.time;
        final Rectangle navigationComponentBounds = getNavigationComponent().getBounds();

        // convert navigation bounds relative to display
        final Point navigationPtAtDisplay = getNavigationComponent().toDisplay(0, 0);
        navigationComponentBounds.x = navigationPtAtDisplay.x;
        navigationComponentBounds.y = navigationPtAtDisplay.y;

        if (event.widget instanceof Control) {
          final Control widget = (Control) event.widget;
          // convert widget event point relative to display
          final Point evtPt = widget.toDisplay(event.getBounds().x, event.getBounds().y);
          // now check if inside navigation
          if (navigationComponentBounds.contains(evtPt.x, evtPt.y)) {
            if (event.count > 0) {
              scrollUp(SCROLLING_STEP);
            } else {
              scrollDown(SCROLLING_STEP);
            }
          }
        }
      }
    }
 public Rectangle buildHighlightRectangle(
     TreeItem item,
     boolean includeChildren,
     GC gc,
     boolean includeHeaderHeight,
     boolean adjustHeight) {
   TreeItem parentItem = item.getParentItem();
   Rectangle bounds = item.getBounds();
   if (parentItem != null) {
     bounds = parentItem.getBounds(0);
   }
   Rectangle itemBounds = item.getBounds();
   int x = bounds.x;
   int width = itemBounds.width + itemBounds.x - bounds.x;
   if (parentItem == null) {
     x = 0;
     width = bounds.width + bounds.x;
   }
   Rectangle highlight = new Rectangle(x, itemBounds.y, width, getTree().getItemHeight());
   // expand for column text
   String columnText = ((ITableLabelProvider) getLabelProvider()).getColumnText(item.getData(), 1);
   if (columnText != null) {
     Point textExtent = gc.textExtent(columnText);
     int textWidth = textExtent.x;
     Rectangle columnBounds = item.getBounds(1);
     highlight.width = (columnBounds.x + textWidth) - highlight.x;
     // increase width to account for space where icon would be
     // later we will need to account for the icons directly (currently
     // there are no icons for the second column)
     highlight.width = highlight.width + 16;
   }
   // expand for children if necessary
   if (includeChildren) {
     TreeItem[] children = item.getItems();
     if (children.length != 0) {
       expandHighlightRectangleForChildren(highlight, children, gc);
     }
   }
   // shrink the rectangle by one pixel so that back to back
   // highlights do not overlap
   if (adjustHeight) {
     int itemSpace = item.getBounds().height - getTree().getItemHeight();
     itemSpace = Math.abs(itemSpace);
     highlight.height = highlight.height - itemSpace;
   }
   if (SWT.getPlatform().equals("gtk") && item.getParentItem() != null) { // $NON-NLS-1$
     // GTK puts expansion handles directly
     // at the location of the parent bounds
     // we use that location to start the box
     // to allow better looking highlights
     // increase the size a bit for linux
     highlight.x = highlight.x - 5;
     highlight.width = highlight.width + 5;
   }
   if (includeHeaderHeight) {
     highlight.y = highlight.y + getTree().getHeaderHeight();
   }
   return highlight;
 }
    private synchronized void calcPaddings(int width, int height) {
      Point canvasSize = getSize();

      mPadding.x = (canvasSize.x - width) / 2;
      mPadding.y = (canvasSize.y - height) / 2;

      mPadding.width = width;
      mPadding.height = height;
    }
示例#10
0
  private Rectangle getDrawBounds(TableCellSWT cell) {
    Rectangle bounds = cell.getBounds();
    bounds.height -= 12;
    bounds.y += 6;
    bounds.x += 4;
    bounds.width -= 4;

    return bounds;
  }
示例#11
0
 private void setHoverLocation(
     org.eclipse.swt.widgets.Shell shell, org.eclipse.swt.graphics.Point position) {
   org.eclipse.swt.graphics.Rectangle displayBounds = shell.getDisplay().getBounds();
   org.eclipse.swt.graphics.Rectangle shellBounds = shell.getBounds();
   shellBounds.x = Math.max(Math.min(position.x, displayBounds.width - shellBounds.width), 0);
   shellBounds.y =
       Math.max(Math.min(position.y + 16, displayBounds.height - shellBounds.height), 0);
   shell.setBounds(shellBounds);
 }
示例#12
0
 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;
 }
示例#13
0
 /**
  * Scrolls the content so that the given revision is visible.
  *
  * @param revision the revision to scroll the client area to.
  */
 private void scrollToRevision(Revision revision) {
   Rectangle revBounds = revision.getBounds();
   Rectangle clientArea = getClientArea();
   clientArea.x = getOrigin().x;
   clientArea.y = getOrigin().y;
   if (!clientArea.contains(revBounds.x, revBounds.y)
       && !clientArea.contains(revBounds.x + revBounds.width, revBounds.y + revBounds.height)) {
     setOrigin(revBounds.x, revBounds.y);
   }
 }
示例#14
0
 @Override
 protected Rectangle getConstrainedShellBounds(Rectangle preferredSize) {
   decideShellSize(getShell());
   Rectangle rect = getShell().getDisplay().getClientArea();
   rect.x = rect.width - shellWidth;
   rect.y = rect.height - shellHeight;
   rect.width = shellWidth;
   rect.height = shellHeight;
   return rect;
 }
示例#15
0
文件: MButton.java 项目: koson/xmind3
  protected void buildCaches() {
    bounds = control.getClientArea();
    bounds.x += MARGIN;
    bounds.y += MARGIN;
    bounds.width -= MARGIN * 2;
    bounds.height -= MARGIN * 2;
    int x1 = bounds.x + BORDER;
    int y1 = bounds.y + BORDER;
    int w1 = bounds.width - BORDER * 2;
    int h1 = bounds.height - BORDER * 2;
    boolean hasArrows = hasArrows();

    if (hasArrows) {
      arrowLoc =
          new Point(
              x1 + w1 + BORDER / 2 - ARROW_WIDTH,
              y1 + (h1 - ARROW_HEIGHT * 2 - ARROWS_SPACING) / 2 - 1);
    }
    contentArea =
        new Rectangle(x1, y1, w1 - (hasArrows ? ARROW_WIDTH + CONTENT_ARROW_SPACING : 0), h1);

    boolean hasImage = hasImage();
    boolean hasText = hasText();
    if (hasImage) {
      if (hasText) {
        Point imgSize = getImageSize();
        imgArea = new Rectangle(x1, y1, imgSize.x, h1);
      } else {
        imgArea = contentArea;
      }
    }

    if (hasText) {
      if (hasImage) {
        int w = imgArea.width + IMAGE_TEXT_SPACING;
        textArea = new Rectangle(imgArea.x + w, y1, contentArea.width - w, h1);
      } else {
        textArea = contentArea;
      }
      int maxTextWidth = textArea.width;
      Point textSize = getTextSize();
      if (textSize.x > maxTextWidth) {
        GC gc = new GC(getControl().getDisplay());
        try {
          gc.setFont(getControl().getFont());
          appliedText =
              getSubString(gc, text, maxTextWidth - gc.stringExtent(ELLIPSIS).x) + ELLIPSIS;
        } finally {
          gc.dispose();
        }
      } else {
        appliedText = text;
      }
    }
  }
示例#16
0
  public Image captureImage(Control control) {
    Rectangle rectangle = control.getBounds();
    Display display = control.getDisplay();
    Image image = null;
    if (control instanceof Shell) {
      Shell shell = (Shell) control;
      shell.layout();
      Point parentLocation = control.toDisplay(0, 0);
      image = getImage(control, rectangle.width, rectangle.height, false);

      rectangle.x = parentLocation.x;
      rectangle.y = parentLocation.y;

      GC myImageGC = new GC(image);
      try {
        for (Control child : shell.getChildren()) {
          Rectangle childBounds = child.getBounds();
          // bug of SWT on Win32, child bounds is not correct in the Window is not in the ToolBar
          int x = (rectangle.width - childBounds.width) / 2;
          int y = (rectangle.height - childBounds.height) - x;
          childBounds.x = rectangle.x + x;
          childBounds.y = rectangle.y + y;
          if (!rectangle.intersects(childBounds)) continue; // Child is completely outside parent.

          Image childImage = new Image(display, child.getBounds());
          GC gc = new GC(childImage);
          child.print(gc);
          DisposeUtil.dispose(gc);
          try {
            myImageGC.drawImage(childImage, x, y);
          } finally {
            childImage.dispose();
          }
        }
      } finally {
        myImageGC.dispose();
      }
    } else {
      image = defaultCapture(control);
    }
    return image;
  }
  private void drawDurationItem(
      final GanttRenderingData data, final IDuration d, final GanttDraw ganttDrawData) {
    final TaskLaneEntry taskFigure = lanes.get(d.getOwner().getName());

    // if task is filtered out
    if (taskFigure == null) {
      return;
    }
    final int y = LANE_START + taskFigure.getLane() * LANE_HEIGHT + DURATION_MARGIN;

    int xStart = ruler.toScreen(d.getStartTime()) - data.getBounds().x / 2;

    final Rectangle dataArea = getDataArea(data);
    dataArea.x = 0;
    if (xStart < dataArea.x) {
      xStart = dataArea.x;
    }
    int xEnd = ruler.toScreen(d.getStartTime() + d.getDurationTime()) - data.getBounds().x / 2;
    if (xEnd < dataArea.x) {
      return;
    }
    if (xEnd - xStart < 1) {
      xEnd = xStart + 1;
    }

    final Rectangle rect = new Rectangle(xStart, y, (xEnd - xStart), DURATION_HEIGHT);

    // If the rectangle width is enormous (when zooming a lot) the clipping
    // mechanism is not working, therefore limit the width below manually
    if (rect.width > dataArea.width) {
      rect.width = dataArea.width;
    }

    final ObjectFigure exec = new TaskExecution(d, rect);
    exec.setBackgroundColor(taskFigure.getBackgroundColor());

    doDrawEvents =
        SeUiPlugin.getDefault()
            .getPreferenceStore()
            .getBoolean(GanttPreferencePage.TAG_SHOW_EVENTS);
    if (doDrawEvents) {
      String idz =
          SeUiPlugin.getDefault()
              .getPreferenceStore()
              .getString(GanttPreferencePage.TAG_SHOW_EVENTS_IDS);
      if (typeReg != null && idz.length() > 0) {
        this.typeArray = idz.split(GanttPreferencePage.SEPARATOR);
      }
      if (typeArray != null && typeArray.length > 0) {
        drawLogEvents(data, d, ganttDrawData, y);
      }
    }
    ganttDrawData.add(exec);
  }
  @Override
  public Rectangle computeTrim() {
    final Rectangle trim = super.computeTrim();

    final Rectangle textTrim = fInfoText.computeTrim(0, 0, 0, 0);
    trim.x += textTrim.x;
    trim.y += textTrim.y;
    trim.width += textTrim.width;
    trim.height += textTrim.height;

    return trim;
  }
 public static Rectangle calculatePageBounds(TabFolder folder) {
   if (folder == null) {
     return new Rectangle(0, 0, 0, 0);
   }
   Rectangle bounds = folder.getBounds();
   Rectangle offset = folder.getClientArea();
   bounds.x += offset.x;
   bounds.y += offset.y;
   bounds.width = offset.width;
   bounds.height = offset.height;
   return bounds;
 }
示例#20
0
  /**
   * Returns the location where the checked symbol should be painted.
   *
   * <p>Note that this is only a subarea of the area covered by an image, since the image contains a
   * border area that is not needed here.
   *
   * @param rect The cell area
   * @param img The image to take the size of the checked symbol from.
   * @return Returns the area that should be filled with a checked/unchecked symbol.
   */
  protected Rectangle getAlignedLocation(Rectangle rect, Image img) {
    Rectangle bounds = img.getBounds();
    bounds.x -= 2;
    bounds.y -= 2;
    bounds.height -= 4;
    bounds.width -= 4;

    if ((getAlignment() & SWTX.ALIGN_HORIZONTAL_CENTER) != 0)
      bounds.x = rect.x + (rect.width - bounds.width) / 2;
    else if ((getAlignment() & SWTX.ALIGN_HORIZONTAL_RIGHT) != 0)
      bounds.x = rect.x + rect.width - bounds.width - 2;
    else bounds.x = rect.x + 2;

    if ((getAlignment() & SWTX.ALIGN_VERTICAL_CENTER) != 0)
      bounds.y = rect.y + (rect.height - bounds.height) / 2;
    else if ((getAlignment() & SWTX.ALIGN_VERTICAL_BOTTOM) != 0)
      bounds.y = rect.y + rect.height - bounds.height - 2;
    else bounds.y = rect.y + 2;

    return bounds;
  }
示例#21
0
  private void doLayout() {
    if (left == null && top == null) {
      Rectangle area = getClientArea();
      if (!editor.getBounds().equals(area)) editor.setBounds(area);
      return;
    }

    int leftWidth = 0, topHeight = 0;
    Rectangle leftTrim = null, topTrim = null;
    if (left != null) {
      leftTrim = calculateRulerTrim((Canvas) left.getControl());
      // Adding the trim width here because FigureCanvas#computeSize() does not
      leftWidth = left.getControl().computeSize(SWT.DEFAULT, SWT.DEFAULT).x + leftTrim.width;
    }
    if (top != null) {
      topTrim = calculateRulerTrim((Canvas) top.getControl());
      topHeight = top.getControl().computeSize(SWT.DEFAULT, SWT.DEFAULT).y + topTrim.height;
    }

    Rectangle editorSize = getClientArea();
    editorSize.x = leftWidth;
    editorSize.y = topHeight;
    editorSize.width -= leftWidth;
    editorSize.height -= topHeight;
    editor.setBounds(editorSize);

    /*
     * Fix for Bug# 67554
     * Take trim into account.  Some platforms (such as MacOS and Motif) leave some
     * trimming around some canvasses.
     */
    Rectangle trim = calculateEditorTrim(editor);
    if (left != null) {
      // The - 1 and + 1 are to compensate for the RulerBorder
      left.getControl()
          .setBounds(
              0,
              topHeight - trim.x + leftTrim.x - 1,
              leftWidth,
              editorSize.height - trim.height + leftTrim.height + 1);
    }
    if (top != null) {
      top.getControl()
          .setBounds(
              leftWidth - trim.y + topTrim.y - 1,
              0,
              editorSize.width - trim.width + topTrim.width + 1,
              topHeight);
    }
  }
示例#22
0
 void moveRectangles(int xChange, int yChange) {
   if (bounds == null) return;
   if (xChange < 0 && ((style & SWT.LEFT) == 0)) xChange = 0;
   if (xChange > 0 && ((style & SWT.RIGHT) == 0)) xChange = 0;
   if (yChange < 0 && ((style & SWT.UP) == 0)) yChange = 0;
   if (yChange > 0 && ((style & SWT.DOWN) == 0)) yChange = 0;
   if (xChange == 0 && yChange == 0) return;
   bounds.x += xChange;
   bounds.y += yChange;
   for (int i = 0; i < rectangles.length; i++) {
     rectangles[i].x += xChange;
     rectangles[i].y += yChange;
   }
 }
  protected void layout(Composite composite, boolean flushCache) {
    if (inLayout) return;
    CoolScrolledComposite sc = (CoolScrolledComposite) composite.getParent();
    if (sc.content == null) return;

    CoolScrollBar horizontalBar = sc.horizontalBar;
    CoolScrollBar verticalBar = sc.verticalBar;

    if (horizontalBar.getSize().y >= sc.getSize().y) {
      return;
    }
    if (verticalBar.getSize().x >= sc.getSize().x) {
      return;
    }

    inLayout = true;
    Rectangle contentRect = sc.content.getBounds();

    Rectangle hostRect = composite.getClientArea();
    if (sc.expandHorizontal) {
      contentRect.width = Math.max(sc.minWidth, hostRect.width);
    }
    if (sc.expandVertical) {
      contentRect.height = Math.max(sc.minHeight, hostRect.height);
    }

    horizontalBar.setRunnerSize(contentRect.width, hostRect.width);
    float hPosition = horizontalBar.getPosition();
    if (hPosition > 0) contentRect.x = (int) -hPosition;

    verticalBar.setRunnerSize(contentRect.height, hostRect.height);
    float vPosition = verticalBar.getPosition();
    if (vPosition > 0) contentRect.x = (int) -vPosition;

    sc.content.setBounds(contentRect);
    inLayout = false;
  }
 /**
  * Calculates the proper trim. Includes scrollbars' sizes only if they're visible.
  *
  * @param canvas The canvas.
  * @since 3.6
  */
 public static Rectangle calculateEditorTrim(Composite canvas) {
   /*
    * Workaround for Bug# 87712 Calculating the trim using the clientArea.
    */
   Rectangle bounds = canvas.getBounds();
   Rectangle clientArea = canvas.getClientArea();
   Rectangle result =
       new Rectangle(0, 0, bounds.width - clientArea.width, bounds.height - clientArea.height);
   if (result.width != 0 || result.height != 0) {
     Rectangle trim = canvas.computeTrim(0, 0, 0, 0);
     result.x = result.height == 0 ? 0 : trim.x;
     result.y = result.width == 0 ? 0 : trim.y;
   }
   return result;
 }
  private void resize() {

    if (isFirstPage()) {
      getShell().setBounds(fInitialSize);
      return;
    }

    Control control = fPageContainer.getTopPage();
    Point size = control.getSize();
    int dw = Math.max(0, fPreviewWidth - size.x);
    int dh = Math.max(0, fPreviewHeight - size.y);
    int dx = dw / 2;
    int dy = dh / 2;
    Shell shell = getShell();
    Rectangle rect = shell.getBounds();
    Rectangle clientRect = shell.getMonitor().getClientArea();
    rect.x = Math.max(clientRect.x, rect.x - dx);
    rect.y = Math.max(clientRect.y, rect.y - dy);

    // limit with and height to monitor
    rect.width = Math.min(rect.width + dw, clientRect.width);
    rect.height = Math.min(rect.height + dh, clientRect.height);

    // Reposition the dialog so that it will be fully visible.
    // Normalize x and y relative to the client area.
    int xe = (rect.x - clientRect.x) + rect.width;
    if (xe > clientRect.width) {
      rect.x -= xe - clientRect.width;
    }
    int ye = (rect.y - clientRect.y) + rect.height;
    if (ye > clientRect.height) {
      rect.y -= ye - clientRect.height;
    }

    shell.setBounds(rect);
  }
示例#26
0
  /** Sets the zoom factor to use in the instance */
  @Override
  public void applyZoomFactor() {
    if (getZoomFactor() == 0) {
      scrollBarsUsed = false;
      getVerticalBar().setEnabled(false);
      getHorizontalBar().setEnabled(false);
    } else {
      scrollBarsUsed = true;
      getVerticalBar().setEnabled(true);
      getHorizontalBar().setEnabled(true);
    }

    // Resets translation
    displayRectangle.x = 0;
    displayRectangle.y = 0;

    redrawReleasedImage();
  }
示例#27
0
 void resizeControl() {
   if (control != null && !control.isDisposed()) {
     /*
      * Set the size and location of the control
      * separately to minimize flashing in the
      * case where the control does not resize
      * to the size that was requested.  This
      * case can occur when the control is a
      * combo box.
      */
     Rectangle itemRect = getBounds();
     control.setSize(itemRect.width, itemRect.height);
     Rectangle rect = control.getBounds();
     rect.x = itemRect.x + (itemRect.width - rect.width) / 2;
     rect.y = itemRect.y + (itemRect.height - rect.height) / 2;
     control.setLocation(rect.x, rect.y);
   }
 }
  void paint(PaintEvent e) {
    GC gc = e.gc;
    Point size = comp.getSize();
    if (curveColor == null) curveColor = e.display.getSystemColor(SWT.COLOR_BLACK);
    int h = size.y;
    int[] simpleCurve = new int[] {0, h - 1, 1, h - 1, 2, h - 2, 2, 1, 3, 0};
    // draw border
    gc.setForeground(curveColor);
    gc.setAdvanced(true);
    if (gc.getAdvanced()) {
      gc.setAntialias(SWT.ON);
    }
    gc.drawPolyline(simpleCurve);

    Rectangle bounds = ((Control) e.widget).getBounds();
    bounds.x = bounds.y = 0;
    Region r = new Region();
    r.add(bounds);
    int[] simpleCurveClose = new int[simpleCurve.length + 4];
    System.arraycopy(simpleCurve, 0, simpleCurveClose, 0, simpleCurve.length);
    int index = simpleCurve.length;
    simpleCurveClose[index++] = bounds.width;
    simpleCurveClose[index++] = 0;
    simpleCurveClose[index++] = bounds.width;
    simpleCurveClose[index++] = bounds.height;
    r.subtract(simpleCurveClose);
    Region clipping = new Region();
    gc.getClipping(clipping);
    r.intersect(clipping);
    gc.setClipping(r);
    Image b = toolParent.getBackgroundImage();
    if (b != null && !b.isDisposed()) gc.drawImage(b, 0, 0);

    r.dispose();
    clipping.dispose();
    // // gc.fillRectangle(bounds);
    // Rectangle mappedBounds = e.display.map(comp, comp.getParent(),
    // bounds);
    // ((Composite) toolParent).drawBackground(gc, bounds.x, bounds.y,
    // bounds.width,
    // bounds.height, mappedBounds.x, mappedBounds.y);

  }
示例#29
0
 /*
  * Adjust the bounds so that we appear adjacent to our parent shell
  */
 protected void adjustBounds() {
   Rectangle parentBounds = getParentShell().getBounds();
   Rectangle proposedBounds;
   // Try placing the info popup to the right
   Rectangle rightProposedBounds =
       new Rectangle(
           parentBounds.x + parentBounds.width + PopupDialog.POPUP_HORIZONTALSPACING,
           parentBounds.y + PopupDialog.POPUP_VERTICALSPACING,
           parentBounds.width,
           parentBounds.height);
   rightProposedBounds = getConstrainedShellBounds(rightProposedBounds);
   // If it won't fit on the right, try the left
   if (rightProposedBounds.intersects(parentBounds)) {
     Rectangle leftProposedBounds =
         new Rectangle(
             parentBounds.x - parentBounds.width - POPUP_HORIZONTALSPACING - 1,
             parentBounds.y,
             parentBounds.width,
             parentBounds.height);
     leftProposedBounds = getConstrainedShellBounds(leftProposedBounds);
     // If it won't fit on the left, choose the proposed bounds
     // that fits the best
     if (leftProposedBounds.intersects(parentBounds)) {
       if (rightProposedBounds.x - parentBounds.x >= parentBounds.x - leftProposedBounds.x) {
         rightProposedBounds.x =
             parentBounds.x + parentBounds.width + PopupDialog.POPUP_HORIZONTALSPACING;
         proposedBounds = rightProposedBounds;
       } else {
         leftProposedBounds.width =
             parentBounds.x - POPUP_HORIZONTALSPACING - leftProposedBounds.x;
         proposedBounds = leftProposedBounds;
       }
     } else {
       // use the proposed bounds on the left
       proposedBounds = leftProposedBounds;
     }
   } else {
     // use the proposed bounds on the right
     proposedBounds = rightProposedBounds;
   }
   getShell().setBounds(proposedBounds);
 }
示例#30
0
  /**
   * Loads a new screen image to the currentSkin attribute. This action updates the skin image that
   * is drawn as skin
   *
   * @param imageToSet The new skin pixel data, as retrieved from the skin plugin
   * @param changedKey The key that has changed, if any. If one if provided, only the key area
   *     should be redrawn. Can be <code>null</code>.
   * @param forceDraw true if a draw is needed after setting the new image; false if replacing skin
   *     image only will be performed.
   */
  private void setSkinImage(ImageData imageToSet, IAndroidKey changedKey, boolean forceDraw) {

    recalculateZoomFactor();

    if (imageToSet != null) {
      if (currentSkinImage != null) {
        currentSkinImage.dispose();
      }

      // Scales the chosen image and sets to currentSkin attribute
      //
      // NOTE: width and height cannot be equal to MINIMUM_ZOOM_FACTOR,
      // because this
      // will raise an IllegalArgumentException when constructing the
      // Image object
      int width = (zoomFactor == MINIMUM_ZOOM_FACTOR ? 1 : (int) (imageToSet.width * zoomFactor));
      int height = (zoomFactor == MINIMUM_ZOOM_FACTOR ? 1 : (int) (imageToSet.height * zoomFactor));
      currentSkinImage = new Image(getDisplay(), imageToSet.scaledTo(width, height));

      // It only makes sense to reset the translation if the skin image is
      // really being changed
      // It will happen if we set a image data without specifying a
      // changed key
      if (changedKey == null) {
        displayRectangle.x = 0;
        displayRectangle.y = 0;
      }

      if (forceDraw) {
        layout();

        GC gc = new GC(this);
        drawSkin(gc, changedKey);
        gc.dispose();
      }
    } else {
      info("It was requested to set a skin image that was null. Operation aborted.");
    }
  }