Exemple #1
0
 /**
  * This does the work of laying out our controls.
  *
  * @see org.eclipse.swt.widgets.Layout#layout(org.eclipse.swt.widgets.Composite, boolean)
  */
 protected void layout(Composite composite, boolean flushCache) {
   getControls(composite);
   Rectangle rect = composite.getClientArea();
   int left = rect.x, right = rect.width, top = rect.y, bottom = rect.height;
   if (north != null) {
     Point pt = getSize(north, flushCache);
     north.setBounds(left, top, rect.width, pt.y);
     top += pt.y;
   }
   if (south != null) {
     Point pt = getSize(south, flushCache);
     south.setBounds(left, rect.height - pt.y, rect.width, pt.y);
     bottom -= pt.y;
   }
   if (east != null) {
     Point pt = getSize(east, flushCache);
     east.setBounds(rect.width - pt.x, top, pt.x, (bottom - top));
     right -= pt.x;
   }
   if (west != null) {
     Point pt = getSize(west, flushCache);
     west.setBounds(left, top, pt.x, (bottom - top));
     left += pt.x;
   }
   if (center != null) {
     center.setBounds(left, top, (right - left), (bottom - top));
   }
 }
Exemple #2
0
 @Override
 public void layout(Composite editor, boolean force) {
   Rectangle bounds = editor.getClientArea();
   Point size = textControl.computeSize(SWT.DEFAULT, SWT.DEFAULT, force);
   textControl.setBounds(0, 0, bounds.width - size.y, bounds.height);
   button.setBounds(bounds.width - size.y, 0, size.y, bounds.height);
 }
Exemple #3
0
  protected void layout(Composite composite, boolean flushCache) {
    Rectangle clientArea = composite.getClientArea();
    Control[] children = composite.getChildren();
    int nbOfVisibleChildren = 0;
    for (int i = 0; i < children.length; i++) {
      // if (children[i].isVisible())
      nbOfVisibleChildren++;
    }
    if (nbOfVisibleChildren == 0) return;

    int r = rows;
    int c = columns;
    if (r == 0) r = nbOfVisibleChildren / c + ((nbOfVisibleChildren % c) == 0 ? 0 : 1);
    else if (c == 0) c = nbOfVisibleChildren / r + ((nbOfVisibleChildren % r) == 0 ? 0 : 1);
    int width = (clientArea.width - (c - 1) * hgap) / c;
    int height = (clientArea.height - (r - 1) * vgap) / r;

    int x = clientArea.x;
    int y = clientArea.y;
    for (int i = 0; i < children.length; i++) {
      // if (!children[i].isVisible())
      // continue;
      children[i].setBounds(x, y, width, height);
      if (((i + 1) % c) == 0) // if new line
      {
        x = clientArea.x;
        y += height + vgap;
      } else x += width + hgap;
    }
  }
 @Override
 public void layout(Composite composite, boolean force) {
   Rectangle rect = composite.getClientArea();
   Control[] children = composite.getChildren();
   for (int i = 0; i < children.length; i++) {
     children[i].setSize(rect.width, rect.height);
   }
 }
    protected void layout(Composite composite, boolean flushCache) {
      Rectangle rect = composite.getClientArea();

      Control[] children = composite.getChildren();
      for (int i = 0; i < children.length; i++) {
        children[i].setBounds(rect);
      }
    }
Exemple #6
0
  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;
      }
    }
  }
    public void layout(Composite composite, boolean force) {

      // determine some derived sizes
      int headerHeight = fLeftLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).y;
      Rectangle r = composite.getClientArea();

      int centerWidth = getCenterWidth();
      int width1 = (int) ((r.width - centerWidth) * getHorizontalSplitRatio());
      int width2 = r.width - width1 - centerWidth;

      int height1 = 0;
      int height2 = 0;
      if (fIsThreeWay && fAncestorVisible) {
        height1 = (int) ((r.height - (2 * headerHeight)) * fVSplit);
        height2 = r.height - (2 * headerHeight) - height1;
      } else {
        height1 = 0;
        height2 = r.height - headerHeight;
      }

      int y = 0;

      if (fIsThreeWay && fAncestorVisible) {
        fAncestorLabel.setBounds(0, y, r.width, headerHeight);
        fAncestorLabel.setVisible(true);
        y += headerHeight;
        handleResizeAncestor(0, y, r.width, height1);
        y += height1;
      } else {
        fAncestorLabel.setVisible(false);
        handleResizeAncestor(0, 0, 0, 0);
      }

      fLeftLabel.getSize(); // without this resizing would not always work

      if (centerWidth > 3) {
        fLeftLabel.setBounds(0, y, width1 + 1, headerHeight);
        fDirectionLabel.setVisible(true);
        fDirectionLabel.setBounds(width1 + 1, y, centerWidth - 1, headerHeight);
        fRightLabel.setBounds(width1 + centerWidth, y, width2, headerHeight);
      } else {
        fLeftLabel.setBounds(0, y, width1, headerHeight);
        fDirectionLabel.setVisible(false);
        fRightLabel.setBounds(width1, y, r.width - width1, headerHeight);
      }

      y += headerHeight;

      if (fCenter != null && !fCenter.isDisposed())
        fCenter.setBounds(width1, y, centerWidth, height2);

      handleResizeLeftRight(0, y, width1, centerWidth, width2, height2);
    }
  protected Point getInitialLocation(Point initialSize) {
    Composite parent = getParent();

    Rectangle parentBounds = parent.getClientArea();
    Point centerPoint = Geometry.centerPoint(parent.getBounds());

    return new Point(
        centerPoint.x - (initialSize.x / 2),
        Math.max(
            parentBounds.y,
            Math.min(
                centerPoint.y - (initialSize.y * 2 / 3),
                parentBounds.y + parentBounds.height - initialSize.y)));
  }
 /** The SWT paint callback */
 public void paintControl(PaintEvent pe) {
   if (chart == null) return;
   try {
     render.setProperty(IDeviceRenderer.GRAPHICS_CONTEXT, pe.gc);
     Composite co = (Composite) pe.getSource();
     Rectangle re = co.getClientArea();
     Bounds bo = BoundsImpl.create(re.x, re.y, re.width, re.height);
     bo.scale(72d / render.getDisplayServer().getDpiResolution());
     Generator gr = Generator.instance();
     state = gr.build(render.getDisplayServer(), chart, bo, null, null, null);
     gr.render(render, state);
   } catch (ChartException e) {
     //     e.printStackTrace();
   }
 }
 /**
  * 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;
 }
Exemple #11
0
    /*
     * @see Layout#layout(Composite, boolean)
     */
    protected void layout(Composite composite, boolean flushCache) {
      Rectangle clArea = composite.getClientArea();
      Rectangle trim = getTextWidget().computeTrim(0, 0, 0, 0);
      int topTrim = -trim.y;
      int scrollbarHeight = trim.height - topTrim; // scrollbar is only under the client area

      int x = clArea.x;
      int width = clArea.width;

      if (fOverviewRuler != null && fIsOverviewRulerVisible) {
        int overviewRulerWidth = fOverviewRuler.getWidth();
        fOverviewRuler
            .getControl()
            .setBounds(
                clArea.x + clArea.width - overviewRulerWidth - 1,
                clArea.y + scrollbarHeight,
                overviewRulerWidth,
                clArea.height - 3 * scrollbarHeight);
        fOverviewRuler
            .getHeaderControl()
            .setBounds(
                clArea.x + clArea.width - overviewRulerWidth - 1,
                clArea.y,
                overviewRulerWidth,
                scrollbarHeight);

        width -= overviewRulerWidth + fGap;
      }

      if (fVerticalRuler != null && fIsVerticalRulerVisible) {
        int verticalRulerWidth = fVerticalRuler.getWidth();
        final Control verticalRulerControl = fVerticalRuler.getControl();
        int oldWidth = verticalRulerControl.getBounds().width;
        verticalRulerControl.setBounds(
            clArea.x,
            clArea.y + topTrim,
            verticalRulerWidth,
            clArea.height - scrollbarHeight - topTrim);
        if (flushCache && getVisualAnnotationModel() != null && oldWidth == verticalRulerWidth)
          verticalRulerControl.redraw();

        x += verticalRulerWidth + fGap;
        width -= verticalRulerWidth + fGap;
      }

      getTextWidget().setBounds(x, clArea.y, width, clArea.height);
    }
Exemple #12
0
 @Override
 protected void layout(Composite composite, boolean flushCache) {
   //		System.out.println("YO1 " + composite + " " + flushCache + composite.getSize());
   Control children[] = composite.getChildren();
   Rectangle clientArea = composite.getClientArea();
   if (flushCache
       || sizes == null
       || sizes.length != children.length
       || clientArea.width != totalWidth
       || clientArea.height != totalHeight) {
     initialize(composite, clientArea.width, clientArea.height);
   }
   // Rectangle rect = composite.getClientArea();
   for (int i = 0; i < children.length; i++) {
     children[i].setBounds(childrenBounds[i]);
   }
 }
  /* (non-Javadoc)
   * @see org.eclipse.swt.events.ControlListener#controlResized(org.eclipse.swt.events.ControlEvent)
   */
  @Override
  public void controlResized(ControlEvent e) {
    Composite container = table.getParent();
    Rectangle area = container.getClientArea();
    Point preferredSize = table.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    int width =
        area.width
            - 2 * table.getBorderWidth()
            - margin; // swjTODO: find where this extra space is coming from.
    if (preferredSize.y > area.height) {
      // Subtract the scrollbar width from the total column width
      // if a vertical scrollbar will be required
      Point vBarSize = table.getVerticalBar().getSize();
      width -= vBarSize.x;
    }
    Point oldSize = table.getSize();

    TableColumn[] columns = table.getColumns();
    if (columns.length == 2) {
      if (oldSize.x > area.width) {
        // table is getting smaller so make the columns
        // smaller first and then resize the table to
        // match the client area width
        columns[0].setWidth(width / 2);
        columns[1].setWidth(width - columns[0].getWidth());
        table.setSize(area.width, area.height);
      } else {
        // table is getting bigger so make the table
        // bigger first and then make the columns wider
        // to match the client area width
        table.setSize(area.width, area.height);
        columns[0].setWidth(width / 2);
        columns[1].setWidth(width - columns[0].getWidth());
      }
    } else if (columns.length == 1) {
      columns[0].setWidth(width);
      //        } else if ( columns.length > 2 ) {
      //            //modTODO: figure out how to support n columns (by resizing only the last
      // column).
      //            throw new RuntimeException("TableSizeAdapter does not support tables containing
      // " + columns.length + " columns"); //$NON-NLS-1$ //$NON-NLS-2$
    }
  }
  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;
  }
  /**
   * Add a new (SQL) Execution Tab
   *
   * @param AbstractSQLExecution
   */
  public void addSQLExecution(AbstractSQLExecution sqlExecution) {

    if (_tabFolder == null || _tabFolder.isDisposed()) {

      clearParent();

      // create tab folder for different sessions
      _tabFolder = new TabFolder(_parent, SWT.NULL);

      _parent.layout();
      _parent.redraw();
    }

    // create tab
    _lastTabNumber = _lastTabNumber + 1;
    final TabItem tabItem = new TabItem(_tabFolder, SWT.NULL);

    // set tab text & tooltip
    String labelText = "" + _lastTabNumber;
    tabItem.setText(labelText);
    tabItem.setData("tabLabel", labelText);
    tabItem.setToolTipText(TextUtil.getWrappedText(sqlExecution.getSqlStatement()));

    // create composite for our result
    Composite composite = new Composite(_tabFolder, SWT.NULL);

    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    layout.marginLeft = 0;
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 2;
    layout.marginWidth = 0;
    layout.marginHeight = 0;

    composite.setLayout(layout);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));

    tabItem.setControl(composite);
    tabItem.setData(sqlExecution);

    tabItem.addDisposeListener(
        new DisposeListener() {

          public void widgetDisposed(final DisposeEvent e) {

            BusyIndicator.showWhile(
                Display.getCurrent(),
                new Runnable() {

                  public void run() {

                    // stop all sql execution if still running
                    TabItem tabItem = (TabItem) e.getSource();
                    AbstractSQLExecution sqlExecution = (AbstractSQLExecution) tabItem.getData();
                    sqlExecution.stop();
                    tabItem.setData(null);

                    if (_tabFolder != null && !_tabFolder.isDisposed()) {

                      if (_tabFolder.getItemCount() == 0) {
                        // this is last tab..
                        clearParent();
                        setDefaultMessage();
                      }

                    } else if (_tabFolder.isDisposed()) {
                      clearParent();
                      setDefaultMessage();
                    }
                  }
                });
          }
        });

    // add sql statement, first create temp label to calculate correct size

    String sqlStatement = sqlExecution.getSqlStatement();

    int labelHeight = 60;
    int labelStyle = SWT.WRAP | SWT.MULTI;

    Text tmpLabel = new Text(composite, labelStyle);
    tmpLabel.setText(TextUtil.removeLineBreaks(sqlExecution.getSqlStatement()));
    tmpLabel.setLayoutData(new FillLayout());
    int parentWidth = _parent.getClientArea().width;
    Point idealSize = tmpLabel.computeSize(parentWidth - 30, SWT.DEFAULT);

    if (idealSize.y <= 60) {
      // we don't need a scroll bar. minimize
      labelHeight = idealSize.y;
    } else {
      // we need a scroll bar
      labelStyle = SWT.WRAP | SWT.MULTI | SWT.V_SCROLL;
    }

    tmpLabel.dispose();

    // now create real label
    // create spanned cell for table data

    Composite headerComposite = new Composite(composite, SWT.FILL);
    headerComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));

    GridLayout hLayout = new GridLayout();
    hLayout.numColumns = 2;
    hLayout.marginLeft = 0;
    hLayout.horizontalSpacing = 0;
    hLayout.verticalSpacing = 0;
    hLayout.marginWidth = 0;
    hLayout.marginHeight = 0;

    headerComposite.setLayout(hLayout);

    Text label = new Text(headerComposite, labelStyle);
    label.setEditable(false);
    label.setBackground(_parent.getBackground());
    label.setText(TextUtil.removeLineBreaks(sqlStatement));
    label.setToolTipText(TextUtil.getWrappedText(sqlStatement));

    GridData labelGridData = new GridData(SWT.FILL, SWT.TOP, true, false);
    labelGridData.heightHint = labelHeight;
    label.setLayoutData(labelGridData);

    // add action bar

    ToolBarManager toolBarMgr = new ToolBarManager(SWT.FLAT);
    toolBarMgr.createControl(headerComposite);
    toolBarMgr.add(new CloseSQLResultTab(tabItem));
    toolBarMgr.update(true);
    GridData gid = new GridData();
    gid.horizontalAlignment = SWT.RIGHT;
    gid.verticalAlignment = SWT.TOP;
    toolBarMgr.getControl().setLayoutData(gid);

    // add detail composite to show progress bar and results
    Composite detailComposite = new Composite(composite, SWT.FILL);
    detailComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    sqlExecution.setComposite(detailComposite);
    sqlExecution.setParentTab(tabItem);
    sqlExecution.startExecution();

    // set new tab as the active one
    _tabFolder.setSelection(_tabFolder.getItemCount() - 1);

    // refresh view
    composite.layout();
    _tabFolder.layout();
    _tabFolder.redraw();

    // bring this view to top of the view stack
    getSite().getPage().bringToTop(this);
  }
  /**
   * Shows the preference page corresponding to the given preference node. Does nothing if that page
   * is already current.
   *
   * @param node the preference node, or <code>null</code> if none
   * @return <code>true</code> if the page flip was successful, and <code>false</code> is
   *     unsuccessful
   */
  protected boolean showPage(IPreferenceNode node) {
    if (node == null) {
      return false;
    }
    // Create the page if nessessary
    if (node.getPage() == null) {
      createPage(node);
    }
    if (node.getPage() == null) {
      return false;
    }
    IPreferencePage newPage = getPage(node);
    if (newPage == currentPage) {
      return true;
    }
    if (currentPage != null) {
      if (!currentPage.okToLeave()) {
        return false;
      }
    }
    IPreferencePage oldPage = currentPage;
    currentPage = newPage;
    // Set the new page's container
    currentPage.setContainer(this);
    // Ensure that the page control has been created
    // (this allows lazy page control creation)
    if (currentPage.getControl() == null) {
      final boolean[] failed = {false};
      SafeRunnable.run(
          new ISafeRunnable() {
            @Override
            public void handleException(Throwable e) {
              failed[0] = true;
            }

            @Override
            public void run() {
              createPageControl(currentPage, pageContainer);
            }
          });
      if (failed[0]) {
        return false;
      }
      // the page is responsible for ensuring the created control is
      // accessable
      // via getControl.
      Assert.isNotNull(currentPage.getControl());
    }
    // Force calculation of the page's description label because
    // label can be wrapped.
    final Point[] size = new Point[1];
    final Point failed = new Point(-1, -1);
    SafeRunnable.run(
        new ISafeRunnable() {
          @Override
          public void handleException(Throwable e) {
            size[0] = failed;
          }

          @Override
          public void run() {
            size[0] = currentPage.computeSize();
          }
        });
    if (size[0].equals(failed)) {
      return false;
    }
    Point contentSize = size[0];
    // Do we need resizing. Computation not needed if the
    // first page is inserted since computing the dialog's
    // size is done by calling dialog.open().
    // Also prevent auto resize if the user has manually resized
    Shell shell = getShell();
    Point shellSize = shell.getSize();
    if (oldPage != null) {
      Rectangle rect = pageContainer.getClientArea();
      Point containerSize = new Point(rect.width, rect.height);
      int hdiff = contentSize.x - containerSize.x;
      int vdiff = contentSize.y - containerSize.y;
      if ((hdiff > 0 || vdiff > 0) && shellSize.equals(lastShellSize)) {
        hdiff = Math.max(0, hdiff);
        vdiff = Math.max(0, vdiff);
        setShellSize(shellSize.x + hdiff, shellSize.y + vdiff);
        lastShellSize = shell.getSize();
        if (currentPage.getControl().getSize().x == 0) {
          currentPage.getControl().setSize(containerSize);
        }

      } else {
        currentPage.getControl().setSize(containerSize);
      }
    }

    scrolled.setMinSize(contentSize);
    // Ensure that all other pages are invisible
    // (including ones that triggered an exception during
    // their creation).
    Control[] children = pageContainer.getChildren();
    Control currentControl = currentPage.getControl();
    for (int i = 0; i < children.length; i++) {
      if (children[i] != currentControl) {
        children[i].setVisible(false);
      }
    }
    // Make the new page visible
    currentPage.setVisible(true);
    if (oldPage != null) {
      oldPage.setVisible(false);
    }
    // update the dialog controls
    update();
    return true;
  }