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

📄 testlayoutaction.java

📁 报表设计软件,很好的
💻 JAVA
字号:
/**
 * ========================================
 * JFreeReport : a free Java report library
 * ========================================
 *
 * Project Info:  http://www.jfree.org/jfreereport/index.html
 * Project Lead:  Thomas Morgner (taquera@sherito.org);
 *
 * (C) Copyright 2000-2003, by Simba Management Limited and Contributors.
 *
 * This library is free software; you can redistribute it and/or modify it under the terms
 * of the GNU Lesser General Public License as published by the Free Software Foundation;
 * either version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this
 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * ------------------------------
 * TestLayoutAction.java
 * ------------------------------
 * (C)opyright 2003, by Thomas Morgner and Contributors.
 *
 * Original Author:  Thomas Morgner;
 * Contributor(s):   David Gilbert (for Simba Management Limited);
 *
 * $Id: TestLayoutAction.java,v 1.2 2004/04/20 18:54:54 taqua Exp $
 *
 * Changes
 * -------------------------
 * 25.10.2003 : Initial version
 *
 */

package org.jfree.designer.visualeditor.actions;

import java.awt.event.ActionEvent;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.List;
import javax.swing.Action;

import org.jfree.designer.util.AbstractDesignerAction;
import org.jfree.designer.visualeditor.VisualEditPanel;
import org.jfree.designer.visualeditor.bandeditor.ReportBandEditor;
import org.jfree.report.Band;
import org.jfree.report.Element;
import org.jfree.report.layout.BandLayoutManagerUtil;
import org.jfree.report.util.ImageUtils;
import org.jfree.report.util.Log;

public final class TestLayoutAction
        extends AbstractDesignerAction
{
  private static final class BandOverlayTestResult
  {
    private final Element element1;
    private final Element element2;

    public BandOverlayTestResult (final Element element1, final Element element2)
    {
      this.element1 = element1;
      this.element2 = element2;
    }

    public final boolean equals (final Object o)
    {
      if (this == o)
      {
        return true;
      }
      if (!(o instanceof BandOverlayTestResult))
      {
        return false;
      }

      final BandOverlayTestResult bandOverlayTestResult = (BandOverlayTestResult) o;

      if (element1 == bandOverlayTestResult.element1 && element2 == bandOverlayTestResult.element2)
      {
        return true;
      }
      if (element1 == bandOverlayTestResult.element2 && element2 == bandOverlayTestResult.element1)
      {
        return true;
      }
      return false;
    }

    public final int hashCode ()
    {
      int result;
      result = element1.hashCode();
      result = 29 * result + element2.hashCode();
      return result;
    }
  }

  private final VisualEditPanel visualEditPanel;

  /**
   * Defines an <code>Action</code> object with a default description string and default
   * icon.
   */
  public TestLayoutAction (final VisualEditPanel visualEditPanel)
  {
    this.visualEditPanel = visualEditPanel;
    putValue(Action.NAME, getResources().getString("action.visual.test-layout.Name"));
    putValue(SMALL_ICON, ImageUtils.createTransparentIcon(16, 16));
  }

  /**
   * Invoked when an action occurs.
   */
  public final void actionPerformed (final ActionEvent e)
  {
    final ReportBandEditor[] editors = visualEditPanel.getCurrentRootBandEditors();
    final ArrayList results = new ArrayList();
    for (int i = 0; i < editors.length; i++)
    {
      performTestLayout(editors[i].getBand(), results);
    }
  }

  /**
   * This test will not detect "dynamic" overlays.
   *
   * @param band
   */
  protected final void performTestLayout (final Band band, final List results)
  {
    final Element[] elements = band.getElementArray();
    Rectangle2D sourceBounds = null;
    Rectangle2D targetBounds = null;
    for (int i = 0; i < elements.length; i++)
    {
      final Element source = elements[i];
      sourceBounds = BandLayoutManagerUtil.getBounds(source, sourceBounds);

      for (int j = 0; j < elements.length; j++)
      {
        if (i == j)
        {
          continue;
        }
        final Element target = elements[j];
        targetBounds = BandLayoutManagerUtil.getBounds(target, targetBounds);

        if (sourceBounds.intersects(targetBounds))
        {
          final BandOverlayTestResult result =
                  new BandOverlayTestResult(source, target);
          if (results.contains(result) == false)
          {
            Log.debug("Source " + source + " overlaps " + target);
            results.add(result);
          }
        }
      }
      if (source instanceof Band)
      {
        performTestLayout((Band) source, results);
      }
    }
  }
}

⌨️ 快捷键说明

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