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

📄 datarowbackend.java

📁 swing编写的库存管理程序。毕业设计类
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
      {
        // Handle Pos == BEFORE_FIRST_ROW
        final int currentRow = getCurrentRow();
        if (currentRow < 0 || currentRow > lastRow)
        {
          returnValue = null;
        }
        else
        {
          returnValue = getTablemodel().getValueAt(currentRow, col);
        }
      }
      else if (col < getFunctionEndIndex())
      {
        col -= getTableEndIndex();
        // the datarow preview will make sure that only expressions are
        // contained in the function collection.
        returnValue = getFunctions().getValue(col);
      }
      else if (col < getPropertiesEndIndex())
      {
        col -= getFunctionEndIndex();
        return getReportProperties().get(col);
      }
    }
    catch (IllegalStateException ise)
    {
      throw ise;
    }
    catch (Exception e)
    {
      Log.error(new org.jfree.util.Log.SimpleMessage("Column ", new Integer(column),
          " caused an error on get()", e));
    }
    finally
    {
      columnlocks[column] = false;
    }
    return returnValue;
  }

  /**
   * Returns the value of the function, expression or column using its specific name. This method
   * returns null if the named column was not found.
   *
   * @param name  the item name.
   *
   * @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 String name)
  {
    final int idx = findColumn(name);
    if (idx == -1)
    {
      return null;
    }
    return get(idx);
  }

  /**
   * Returns the count of columns in this datarow. The column count is the sum of all
   * DataSource columns, all Functions and all expressions.
   *
   * @return the number of accessible columns in this datarow.
   */
  public int getColumnCount()
  {
    return getPropertiesEndIndex();
  }

  /**
   * Looks up the position of the column with the name <code>name</code>.
   * returns the position of the column or -1 if no columns could be retrieved.
   *
   * @param name  the item name.
   *
   * @return the column position of the column, expression or function with the given name or
   * -1 if the given name does not exist in this DataRow.
   */
  public int findColumn(final String name)
  {
    final Integer integ = (Integer) colcache.get(name);
    if (integ != null)
    {
      return integ.intValue();
    }

    final int size = getColumnCount();
    for (int i = 0; i < size; i++)
    {
      final String column = getColumnName(i);
      if (column.equals(name))
      {
        colcache.put(name, new Integer(i));
        return i;
      }
    }
    if (warnInvalidColumns)
    {
      // print an warning for the logs.
      Log.warn(new Log.SimpleMessage("Invalid column name specified on query: ", name));
    }
    return -1;
  }

  /**
   * Returns the name of the column, expression or function.
   *
   * @param col  the column, expression or function index.
   *
   * @return  The column, expression or function name.
   */
  public String getColumnName(int col)
  {
    if (col >= getColumnCount())
    {
      throw new IndexOutOfBoundsException("requested " + col + " , have " + getColumnCount());
    }
    if (col < 0)
    {
      throw new IndexOutOfBoundsException("Requested Column cannot be negative");
    }
    if (col < getTableEndIndex())
    {
      return getTablemodel().getColumnName(col);
    }
    else if (col < getFunctionEndIndex())
    {
      col -= getTableEndIndex();
      final Expression f = getFunctions().getExpression(col);
      if (f == null)
      {
        Log.warn("No such function: " + col);
        return null;
      }
      return f.getName();
    }
    else
    {
      col -= getFunctionEndIndex();
      return getReportProperties().getColumnName(col);
    }
  }

  /**
   * Tests whether the current row is set before the first row in the tablemodel.
   *
   * @return true, if the processing has not yet started and the currentRow is lesser than 0.
   */
  public boolean isBeforeFirstRow()
  {
    return getCurrentRow() < 0;
  }

  /**
   * Tests whether the current row in the tablemodel is the last row in the tablemodel.
   *
   * @return true, if the current row is the last row in the tablemodel.
   */
  public boolean isLastRow()
  {
    return getCurrentRow() == lastRow;
  }

  /**
   * Clones this DataRowBackend. Does also clone the functions contained
   * in this datarow.
   *
   * @return the clone.
   *
   * @throws CloneNotSupportedException should never happen.
   */
  public Object clone() throws CloneNotSupportedException
  {
    final DataRowBackend db = (DataRowBackend) super.clone();
    db.columnlocks = new boolean[getColumnCount()];
    db.dataRowConnector = new DataRowConnector();
    db.dataRowConnector.setDataRowBackend(db);
    if (functions != null)
    {
      db.functions = (LevelledExpressionList) functions.clone();
      db.functions.updateDataRow(db.getDataRow());
    }
    return db;
  }

//  /**
//   * Create a preview backend. Such datarows will have no access to functions (all functions
//   * will return null).
//   * <p>
//   * This method will return null, if this is the last row.
//   *
//   * @return The 'preview' data row backend.
//   */
//  public DataRowBackend previewNextRow()
//  {
//    if (isLastRow())
//    {
//      return null;
//    }
//    if (preview == null)
//    {
//      preview = new DataRowPreview(this);
//    }
//    preview.update(this);
//    return preview;
//  }

  /**
   * Calculates the end index for tableentries. TableEntries are the first entries in the row.
   *
   * @return The end index.
   */
  private int getTableEndIndex()
  {
    return tableEndIndex;
  }

  /**
   * Calculates the endindex for function entries. Function entries are following the TableEntries
   * in the row.
   *
   * @return The function end index.
   */
  private int getFunctionEndIndex()
  {
    return functionsEndIndex;
  }

  /**
   * Returns the end index of the properties.
   *
   * @return the index.
   */
  private int getPropertiesEndIndex()
  {
    return propertiesEndIndex;
  }

  /**
   * Ensures that the columnLock does match the number of columns in this row.
   */
  private void revalidateColumnLock()
  {
    if (getTablemodel() == null)
    {
      tableEndIndex = 0;
    }
    else
    {
      tableEndIndex = getTablemodel().getColumnCount();
    }

    if (getFunctions() == null)
    {
      functionsEndIndex = tableEndIndex;
    }
    else
    {
      functionsEndIndex = tableEndIndex + getFunctions().size();
    }

    if (getReportProperties() == null)
    {
      propertiesEndIndex = functionsEndIndex;
    }
    else
    {
      propertiesEndIndex = functionsEndIndex + getReportProperties().getColumnCount();
    }

    if (getColumnCount() != columnlocks.length)
    {
      columnlocks = new boolean[getColumnCount()];
    }
  }

  /**
   * Returns the report properties.
   *
   * @return the report properties.
   */
  public ReportPropertiesList getReportProperties()
  {
    return reportProperties;
  }

  /**
   * Sets the report properties.
   *
   * @param properties  the report properties.
   */
  public void setReportProperties(final ReportPropertiesList properties)
  {
    this.reportProperties = properties;
    revalidateColumnLock();
  }
}

⌨️ 快捷键说明

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