⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reportbandeditor.java

📁 报表设计软件,很好的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
  {
    return renderer;
  }

  public final void setRenderer (final ElementRenderer renderer)
  {
    this.renderer = renderer;
  }

  public final float getBandWidth ()
  {
    return width;
  }

  public final Band getBand ()
  {
    return band;
  }

  public final String getTitle ()
  {
    return title;
  }

  public final ReportDefinitionSelectionModel getSelectionModel ()
  {
    return selectionModel;
  }

  public final void setSelectionModel (final ReportDefinitionSelectionModel model)
  {
    if (model == null)
    {
      throw new NullPointerException();
    }
    selectionModel.removeReportSelectionListener(reportSelectionHandler);
    selectionModel = model;
    selectionModel.addReportSelectionListener(reportSelectionHandler);
  }

  /**
   * Invalidates the container.  The container and all parents above it are marked as
   * needing to be laid out.  This method can be called often, so it needs to execute
   * quickly.
   *
   * @see #validate
   * @see #layout
   * @see java.awt.LayoutManager
   */
  public final void invalidate ()
  {
    super.invalidate();
    cachedRenderingSize = null;
  }

  private Dimension computeRenderingSize ()
  {
    if (cachedRenderingSize != null)
    {
      return cachedRenderingSize;
    }

    final Insets ins = getInsets();
    if (band == null)
    {
      cachedRenderingSize = new Dimension(ins.left + ins.right, ins.top + ins.bottom);
    }
    else
    {
      final Rectangle2D rect = BandLayoutManagerUtil.doLayout
              (band, new DefaultLayoutSupport(), width, Float.MAX_VALUE);
      final int insetsHorizontal = ins.left + ins.right;
      final int insetsVertical = ins.top + ins.bottom;
      final int contentWidth =
              (int) Math.ceil((rect.getX() + rect.getWidth()) * getDetailLevel());
      final int contentHeight =
              (int) Math.ceil((rect.getY() + rect.getHeight()) * getDetailLevel());


      final Dimension dim = new Dimension
              (insetsHorizontal + contentWidth, insetsVertical + contentHeight);
      cachedRenderingSize = dim;
    }
    return cachedRenderingSize;
  }

  protected final void paintComponent (final Graphics g)
  {
    // Without the complete removeal of all double buffering, swing will
    // behave incorrectly when creating child graphics...
    final boolean db =
            RepaintManager.currentManager(this).isDoubleBufferingEnabled();
    RepaintManager.currentManager(this).setDoubleBufferingEnabled(false);

    final Graphics2D scapGraphics = (Graphics2D) g.create();
    scapGraphics.setRenderingHint
            (RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
    final Insets ins = getInsets();
    scapGraphics.translate(ins.left, ins.top);
    scapGraphics.scale(getDetailLevel(), getDetailLevel());
    renderElement(band, scapGraphics);

    scapGraphics.dispose();
    RepaintManager.currentManager(this).setDoubleBufferingEnabled(db);
  }

  private void renderElement (final Element element, final Graphics2D g2)
  {
    Rectangle2D bounds = new Rectangle2D.Float();

    final JComponent rendererComponent =
            renderer.getElementRenderer
            (element, getSelectionModel().isSelected(element), false, detailLevel);

    bounds = BandLayoutManagerUtil.getBounds(element, bounds);
    // Log.debug ("Bounds -->: " + bounds);

    final int x = (int) bounds.getX();
    final int y = (int) bounds.getY();
    final int width = Math.max(1, (int) bounds.getWidth());
    final int height = Math.max(1, (int) bounds.getHeight());

    final Graphics2D cliped = (Graphics2D) g2.create(x, y, width, height);

    cellRendererPane.add(rendererComponent);
    rendererComponent.setBounds(x, y, width, height);
    rendererComponent.validate();
    rendererComponent.paint(cliped);
    cellRendererPane.remove(rendererComponent);

    // Log.debug ("Rendered -->: " + e.getName());

    cliped.dispose();

    if (element instanceof Band)
    {
      final Band band = (Band) element;
      final Element[] elements = band.getElementArray();
      for (int i = 0; i < elements.length; i++)
      {
        final Element e = elements[i];
        renderElement(e, g2);
      }
    }

  }

  public final float getDetailLevel ()
  {
    return detailLevel;
  }

  public final void setDetailLevel (final float detailLevel)
  {
    this.detailLevel = detailLevel;
    invalidate();
  }

  /**
   * Returns the element that is at position (x,y).
   *
   * @param x an integer giving the number of pixels horizontally from the left edge of
   *          the display area, minus any left margin
   * @param y an integer giving the number of pixels vertically from the top of the
   *          display area, minus any top margin
   * @return the top most element on that location or null if there is no element at that
   *         location.
   */
  public final Element getElementForLocation (final int x, final int y)
  {
    final float normalizedX = x / getDetailLevel();
    final float normalizedY = y / getDetailLevel();

    final Rectangle2D bounds = BandLayoutManagerUtil.getBounds(band, null);
    if (bounds.contains(normalizedX, normalizedY) == false)
    {
      return null;
    }
    return getElementForLocation(band, normalizedX, normalizedY, bounds);
  }

  private Element getElementForLocation
          (final Band band, final float x, final float y, Rectangle2D bounds)
  {
    Element retVal = band;
    bounds = BandLayoutManagerUtil.getBounds(band, bounds);

    if (bounds.contains(x, y) == false)
    {
      return null;
    }

    final Element[] elements = band.getElementArray();
    for (int i = 0; i < elements.length; i++)
    {
      bounds = BandLayoutManagerUtil.getBounds(elements[i], bounds);
      if (bounds.contains(x, y))
      {
        retVal = elements[i];
        if (retVal instanceof Band)
        {
          return getElementForLocation((Band) retVal, x, y, bounds);
        }
      }
    }
    return retVal;
  }

  /**
   * If the minimum size has been set to a non-<code>null</code> value just returns it.
   * If the UI delegate's <code>getMinimumSize</code> method returns a
   * non-<code>null</code> value then return that; otherwise defer to the component's
   * layout manager.
   *
   * @return the value of the <code>minimumSize</code> property
   *
   * @see #setMinimumSize
   * @see javax.swing.plaf.ComponentUI
   */
  public final Dimension getMinimumSize ()
  {
    return computeRenderingSize();
  }

  /**
   * If the maximum size has been set to a non-<code>null</code> value just returns it.
   * If the UI delegate's <code>getMaximumSize</code> method returns a
   * non-<code>null</code> value then return that; otherwise defer to the component's
   * layout manager.
   *
   * @return the value of the <code>maximumSize</code> property
   *
   * @see #setMaximumSize
   * @see javax.swing.plaf.ComponentUI
   */
  public final Dimension getMaximumSize ()
  {
    return computeRenderingSize();
  }

  /**
   * If the <code>preferredSize</code> has been set to a non-<code>null</code> value just
   * returns it. If the UI delegate's <code>getPreferredSize</code> method returns a non
   * <code>null</code> value then return that; otherwise defer to the component's layout
   * manager.
   *
   * @return the value of the <code>preferredSize</code> property
   *
   * @see #setPreferredSize
   * @see javax.swing.plaf.ComponentUI
   */
  public final Dimension getPreferredSize ()
  {
    return computeRenderingSize();
  }

  /**
   * Causes this container to lay out its components.  Most programs should not call this
   * method directly, but should invoke the <code>validate</code> method instead.
   *
   * @see java.awt.LayoutManager#layoutContainer
   * @see #setLayout
   * @see #validate
   * @since JDK1.1
   */
  public final void doLayout ()
  {
    // do no layout, never !
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -