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

📄 datarowbackend.java

📁 swing编写的库存管理程序。毕业设计类
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**
 * ========================================
 * JFreeReport : a free Java report library
 * ========================================
 *
 * Project Info:  http://www.jfree.org/jfreereport/index.html
 * Project Lead:  Thomas Morgner;
 *
 * (C) Copyright 2000-2003, by Object Refinery 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.
 *
 * -------------------
 * DataRowBackend.java
 * -------------------
 * (C)opyright 2000-2003, by Thomas Morgner and Contributors.
 *
 * Original Author:  Thomas Morgner;
 * Contributor(s):   David Gilbert (for Object Refinery Limited);
 *
 * $Id: DataRowBackend.java,v 1.4 2003/09/09 15:52:53 taqua Exp $
 *
 * Changes
 * -------
 * 27-Jul-2002 : Initial version
 * 01-Sep-2002 : Deadlockcheck added. If a column is accessed twice within a single query, (can
 *               happen on expression evaluation), a IllegalStateException is thrown
 * 02-Sep-2002 : Deadlock detection was no implemented correctly, fixed.
 * 05-Dec-2002 : Updated Javadocs (DG);
 * 13-Sep-2002 : Ran Checkstyle agains the sources
 * 15-Oct-2002 : Functions and Expressions are now contained in an LevelledExpressionList
 * 23-Oct-2002 : Added support for ReportProperty-Queries to the datarow.
 * 06-Dec-2002 : Added configurable Invalid-Column-Warning
 * 05-Feb-2002 : Removed/Changed log statements
 */

package org.jfree.report.states;

import java.util.HashMap;
import javax.swing.table.TableModel;

import org.jfree.report.DataRow;
import org.jfree.report.function.Expression;
import org.jfree.report.function.LevelledExpressionList;
import org.jfree.report.util.Log;
import org.jfree.report.util.ReportConfiguration;
import org.jfree.report.util.ReportPropertiesList;

/**
 * The DataRow-Backend maintains the state of a datarow. Whenever the  report state changes
 * the backend of the datarow is updated and then reconnected with the DataRowConnector.
 *
 * @see DataRowConnector
 *
 * @author Thomas Morgner
 */
public class DataRowBackend implements Cloneable
{

  /** The item cache. */
  private final HashMap colcache;

  /** The functions (set by the report state). */
  private LevelledExpressionList functions;

  /** The table model (set by the report state). */
  private TableModel tablemodel;

  /** all previously marked report-properties for this report. */
  private ReportPropertiesList reportProperties;

  /** The current row (set by the report state). */
  private int currentRow = -1;

  /** Column locks. */
  private boolean[] columnlocks;

  /** if true, invalid columns get printed to the logs. */
  private final boolean warnInvalidColumns;

  /** An empty boolean array. */
  private static final boolean[] EMPTY_BOOLS = new boolean[0];

  /** The index of the last function. */
  private int functionsEndIndex;

  /** The index of the last property. */
  private int propertiesEndIndex;

  /** The index of the table end. */
  private int tableEndIndex;

  /** The last row. */
  private int lastRow;

  /** The datarow connector that is used to feed the functions.*/
  private DataRowConnector dataRowConnector;

  /**
   * Creates a new DataRowBackend.
   */
  public DataRowBackend()
  {
    columnlocks = EMPTY_BOOLS;
    dataRowConnector = new DataRowConnector();
    dataRowConnector.setDataRowBackend(this);
    colcache = new HashMap();
    warnInvalidColumns = ReportConfiguration.getGlobalConfig().isWarnInvalidColumns();
    lastRow = -1;
    revalidateColumnLock();
  }

  /**
   * Creates a new DataRowBackend based on the given datarow backend.
   * Both datarow backends will share the objects, no cloning is done.
   * Functions will not be included in the copy...
   *
   * @param db  the data row backend.
   */
  protected DataRowBackend(final DataRowBackend db)
  {
    this.dataRowConnector = new DataRowConnector();
    this.dataRowConnector.setDataRowBackend(this);
    this.columnlocks = EMPTY_BOOLS;
    this.colcache = new HashMap();
    this.warnInvalidColumns = db.warnInvalidColumns;
    this.tablemodel = db.tablemodel;
    this.lastRow = db.lastRow;
    this.reportProperties = db.reportProperties;
    revalidateColumnLock();
  }

  /**
   * Returns the datarow connector used to connect the functions and element
   * with this datarow.
   * 
   * @return the datarow connector.
   */
  protected DataRowConnector getDataRowConnector()
  {
    return dataRowConnector;
  }

  /**
   * Returns the public datarow instance used to query this datarow.. 
   * 
   * @return the datarow.
   */
  public DataRow getDataRow()
  {
    return getDataRowConnector();
  }

  /**
   * Returns the function collection used in this DataRowBackend. The FunctionCollection is
   * stateful and will be set to a new function collection when the ReportState advances.
   *
   * @return the currently set function collection
   */
  public LevelledExpressionList getFunctions()
  {
    return functions;
  }

  /**
   * Returns the tablemodel used in this DataRowBackend.
   *
   * @return the TableModel of the Report.
   */
  public TableModel getTablemodel()
  {
    return tablemodel;
  }

  /**
   * Returns the current row in the tablemodel. The row is advanced while the report is processed.
   * If the row is negative, the DataRowBackend <code>isBeforeFirstRow</code>.
   *
   * @return the current row.
   */
  public int getCurrentRow()
  {
    return currentRow;
  }

  /**
   * Sets the current row of the tablemodel. The current row is advanced while the Report is being
   * processed.
   *
   * @param currentRow the current row
   */
  public void setCurrentRow(final int currentRow)
  {
    if (currentRow < -1)
    {
      throw new IllegalArgumentException("CurrentRow must not be < -1");
    }
    if (getTablemodel() != null)
    {
      // in some cases, the current row can be +1 greater than the row count.
      // (when empty table model given or in preview at the end of the table)
      if (currentRow > getTablemodel().getRowCount())
      {
        throw new IllegalArgumentException
            ("CurrentRow cannot be greater than the tablemodel's rowcount." + currentRow);
      }
    }
    else
    {
      if (currentRow != -1)
      {
        throw new IllegalArgumentException
            ("Without an TableModel, the currentRow must always be -1");
      }
    }
    this.currentRow = currentRow;
  }

  /**
   * Sets the function collection used in this DataRow. This also
   * updates the function's dataRow reference.
   *
   * @param functions the current function collection
   */
  public void setFunctions(final LevelledExpressionList functions)
  {
    if (this.functions != null)
    {
      // remove the old dataRow
      this.functions.setDataRow(null);
    }
    this.functions = functions;
    if (this.functions != null)
    {
      // and connect the new one...
      this.functions.setDataRow(getDataRow());
    }
    revalidateColumnLock();
  }

  /**
   * sets the tablemodel used in this DataRow. The tablemodel contains the base values for the
   * report and the currentRow-property contains a pointer to the current row within the
   * tablemodel.
   *
   * @param tablemodel the tablemodel used as base for the reporting
   */
  public void setTablemodel(final TableModel tablemodel)
  {
    this.tablemodel = tablemodel;
    if (tablemodel != null)
    {
      this.lastRow = (tablemodel.getRowCount() - 1);
    }
    else
    {
      this.lastRow = -1;
    }
    revalidateColumnLock();
  }

  /**
   * Returns the value of the function, expression or column in the tablemodel using the column
   * number.
   *
   * @param column  the item index.
   *
   * @return The item value.
   *
   * @throws IndexOutOfBoundsException if the index is negative or greater than the number of
   *         columns in this row.
   * @throws IllegalStateException if a deadlock is detected.
   */
  public Object get(final int column)
  {
    if (column >= getColumnCount())
    {
      throw new IndexOutOfBoundsException("requested " + column + " , have " + getColumnCount());
    }
    if (column < 0)
    {
      throw new IndexOutOfBoundsException("Column with negative index is invalid");
    }
    if (columnlocks[column])
    {
      throw new IllegalStateException("Column " + column + " already accessed. Deadlock!");
    }

    Object returnValue = null;
    try
    {
      columnlocks[column] = true;
      int col = column;
      if (col < getTableEndIndex())

⌨️ 快捷键说明

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