예제 #1
0
 public Rectangle getBounds() {
   int minx = Integer.MAX_VALUE;
   int miny = Integer.MAX_VALUE;
   int maxx = Integer.MIN_VALUE;
   int maxy = Integer.MIN_VALUE;
   for (int i = 0; i < pieces.size(); i++) {
     PipAnimateFramePiece piece = pieces.get(i);
     double[][] points = piece.getBounds();
     for (int j = 0; j < 4; j++) {
       int px = (int) points[j][0];
       int py = (int) points[j][1];
       if (px < minx) {
         minx = px;
       }
       if (py < miny) {
         miny = py;
       }
       if (px > maxx) {
         maxx = px;
       }
       if (py > maxy) {
         maxy = py;
       }
     }
   }
   Rectangle rect = new Rectangle(minx, miny, maxx - minx, maxy - miny);
   if (rect.isEmpty()) {
     rect = new Rectangle(0, 0, 16, 16);
   }
   return rect;
 }
예제 #2
0
파일: UIUtils.java 프로젝트: ralic/dbeaver
 public static void packColumns(@NotNull Tree tree, boolean fit, @Nullable float[] ratios) {
   tree.setRedraw(false);
   try {
     // Check for disposed items
     // TODO: it looks like SWT error. Sometimes tree items are disposed and NPE is thrown from
     // column.pack
     for (TreeItem item : tree.getItems()) {
       if (item.isDisposed()) {
         return;
       }
     }
     int totalWidth = 0;
     final TreeColumn[] columns = tree.getColumns();
     for (TreeColumn column : columns) {
       column.pack();
       totalWidth += column.getWidth();
     }
     Rectangle clientArea = tree.getClientArea();
     if (clientArea.isEmpty()) {
       return;
     }
     if (fit) {
       int areaWidth = clientArea.width;
       if (tree.getVerticalBar() != null) {
         areaWidth -= tree.getVerticalBar().getSize().x;
       }
       if (totalWidth > areaWidth) {
         int extraSpace = totalWidth - areaWidth;
         for (TreeColumn tc : columns) {
           double ratio = (double) tc.getWidth() / totalWidth;
           tc.setWidth((int) (tc.getWidth() - extraSpace * ratio));
         }
       } else if (totalWidth < areaWidth) {
         float extraSpace = areaWidth - totalWidth;
         if (columns.length > 0) {
           if (ratios == null || ratios.length < columns.length) {
             extraSpace /= columns.length;
             extraSpace--;
             for (TreeColumn tc : columns) {
               tc.setWidth((int) (tc.getWidth() + extraSpace));
             }
           } else {
             for (int i = 0; i < columns.length; i++) {
               TreeColumn tc = columns[i];
               tc.setWidth((int) (tc.getWidth() + extraSpace * ratios[i]));
             }
           }
         }
       }
     }
   } finally {
     tree.setRedraw(true);
   }
 }
예제 #3
0
  /**
   * Helper method for {@linkplain #setDisplayArea} which is also called by other methods that want
   * to set the display area without provoking repainting of the display
   *
   * @param envelope requested display area
   */
  private void doSetDisplayArea(Envelope envelope) {
    assert (content != null && curPaintArea != null && !curPaintArea.isEmpty());

    if (equalsFullExtent(envelope)) {
      setTransforms(fullExtent, curPaintArea);
    } else {
      setTransforms(envelope, curPaintArea);
    }
    ReferencedEnvelope adjustedEnvelope = getDisplayArea();
    content.getViewport().setBounds(adjustedEnvelope);

    MapPaneEvent ev = new MapPaneEvent(this, MapPaneEvent.Type.DISPLAY_AREA_CHANGED);
    publishEvent(ev);
  }
예제 #4
0
  /**
   * Sets the area to display by calling the {@linkplain MapContext#setAreaOfInterest} method of
   * this pane's map context. Does nothing if the MapContext has not been set. If neither the
   * context or the envelope have coordinate reference systems defined this method does nothing.
   *
   * <p>The map area that ends up being displayed will often be larger than the requested display
   * area. For instance, if the square area is requested, but the map pane's screen area is a
   * rectangle with width greater than height, then the displayed area will be centred on the
   * requested square but include additional area on each side.
   *
   * <p>You can pass any GeoAPI Envelope implementation to this method such as ReferenedEnvelope or
   * Envelope2D.
   *
   * <p>Note: This method does <b>not</b> check that the requested area overlaps the bounds of the
   * current map layers.
   *
   * @param envelope the bounds of the map to display
   * @throws IllegalStateException if a map context is not set
   */
  public void setDisplayArea(Envelope envelope) {
    if (content != null) {
      if (curPaintArea == null || curPaintArea.isEmpty()) {
        return;
      } else {
        doSetDisplayArea(envelope);
        clearLabelCache = true;
        if (!isDisposed()) redraw();
      }

    } else {
      throw new IllegalStateException("Map context must be set before setting the display area");
    }
  }
예제 #5
0
 public Rectangle getBounds(int repImg, int src, int tgt, int offx, int offy) {
   int minx = 0;
   int miny = 0;
   int maxx = 0;
   int maxy = 0;
   for (int i = 0; i < pieces.size(); i++) {
     PipAnimateFramePiece piece = pieces.get(i);
     boolean replace = false;
     if (piece.getImageID() == repImg && piece.getFrame() == src) {
       piece.setFrame(tgt);
       piece.setDx(piece.getDx() + offx);
       piece.setDy(piece.getDy() + offy);
       replace = true;
     }
     int px = piece.getDx();
     int py = piece.getDy();
     int pw = piece.getWidth();
     int ph = piece.getHeight();
     if (px < minx) {
       minx = px;
     }
     if (py < miny) {
       miny = py;
     }
     if (px + pw > maxx) {
       maxx = px + pw;
     }
     if (py + ph > maxy) {
       maxy = py + ph;
     }
     if (replace) {
       piece.setFrame(src);
       piece.setDx(piece.getDx() - offx);
       piece.setDy(piece.getDy() - offy);
     }
   }
   Rectangle rect = new Rectangle(minx, miny, maxx - minx, maxy - miny);
   if (rect.isEmpty()) {
     rect = new Rectangle(0, 0, 16, 16);
   }
   return rect;
 }
 public int getViewportHeight() {
   StyledText te = getSourceViewer().getTextWidget();
   Rectangle clArea = te.getClientArea();
   if (!clArea.isEmpty()) return clArea.height;
   return 0;
 }