コード例 #1
0
 public void setViewport(Viewport _viewport) {
   if (_viewport != null) { // disconnect from old viewport
     _viewport.setContainer(null);
   }
   mViewport = _viewport;
   if (mViewport != null) { // connect to new Satellite
     mViewport.setContainer(this);
     // resize to show entire view of satellite
     Dimension size = mViewport.getPreferredSize();
     setViewportSize(size);
     // resize the window to fit the image
     setSize(
         size.width + getInsets().left + getInsets().right + 2 * INSET,
         size.height + getInsets().top + getInsets().bottom + 2 * INSET);
   }
 }
コード例 #2
0
 public void dispose() {
   super.dispose();
   if (mViewport != null) {
     mViewport.terminate();
     mViewport = null;
   }
   setUniverse(null);
   if (mBackBufferGfx != null) {
     mBackBufferGfx.dispose();
   }
   Logger.log("FramedViewportContainer terminated");
 }
コード例 #3
0
 public void setViewportSize(Dimension _size) {
   mViewportSize = new Dimension(_size);
   int w = mViewportSize.width + 2 * INSET;
   int h = mViewportSize.height + 2 * INSET;
   // create an off screen buffer for drawing
   if (mBackBufferGfx != null) {
     mBackBufferGfx.dispose(); // free old one
   }
   mBackBufferImg = createImage(w, h);
   Logger.log("Create off-screen buffer of " + w + "x" + h + " (" + mBackBufferImg + ")");
   mBackBufferGfx = mBackBufferImg.getGraphics();
   // Determine the graphics context for the viewport
   mDrawGfx = mBackBufferGfx.create(INSET, INSET, mViewportSize.width, mViewportSize.height);
   mViewport.setActualSize(mViewportSize);
   Logger.log("Viewport resized");
 }
コード例 #4
0
ファイル: VisualContext.java プロジェクト: eduardoejp/CSSBox
  /**
   * Converts a length from a CSS length or percentage to 'pt'.
   *
   * @param spec the CSS length specification
   * @param whole the value that corresponds to 100%. It is used only when spec is a percentage.
   * @return the length in 'pt'
   */
  public double ptLength(TermLengthOrPercent spec, double whole) {
    float nval = spec.getValue();
    if (spec.isPercentage()) return (whole * nval) / 100;
    else {
      TermLength.Unit unit = spec.getUnit();

      double ret = 0;
      if (unit == TermLength.Unit.pt) {
        ret = nval;
      } else if (unit == TermLength.Unit.in) {
        ret = nval * 72;
      } else if (unit == TermLength.Unit.cm) {
        ret = (nval * 72) / 2.54;
      } else if (unit == TermLength.Unit.mm) {
        ret = (nval * 72) / 25.4;
      } else if (unit == TermLength.Unit.pc) {
        ret = nval * 12;
      } else if (unit == TermLength.Unit.px) {
        ret = (nval * 72) / dpi;
      } else if (unit == TermLength.Unit.em) {
        ret = (em * nval * 72) / dpi; // em is in pixels
      } else if (unit == TermLength.Unit.rem) {
        ret = (rem * nval * 72) / dpi;
      } else if (unit == TermLength.Unit.ex) {
        ret = (ex * nval * 72) / dpi;
      } else if (unit == TermLength.Unit.ch) {
        ret = (ch * nval * 72) / dpi;
      } else if (unit == TermLength.Unit.vw) {
        return (viewport.getVisibleRect().getWidth() * nval * 72) / (100.0 * dpi);
      } else if (unit == TermLength.Unit.vh) {
        return (viewport.getVisibleRect().getHeight() * nval * 72) / (100.0 * dpi);
      } else if (unit == TermLength.Unit.vmin) {
        return (Math.min(
                    viewport.getVisibleRect().getWidth(), viewport.getVisibleRect().getHeight())
                * nval
                * 72)
            / (100.0 * dpi);
      } else if (unit == TermLength.Unit.vmax) {
        return (Math.max(
                    viewport.getVisibleRect().getWidth(), viewport.getVisibleRect().getHeight())
                * nval
                * 72)
            / (100.0 * dpi);
      }
      return ret;
    }
  }
コード例 #5
0
 public void doTimer(TimerTrigger tt) {
   mViewport.paint(mDrawGfx);
   repaint();
 }