tablelayout.java

来自「Rapla是一个灵活的多用户资源管理系统。它提供的一些功能有:日历GUI」· Java 代码 · 共 2,050 行 · 第 1/5 页

JAVA
2,050
字号
{
    // Make sure size is valid
    if ((size < 0.0) &&
        (size != FILL) &&
        (size != PREFERRED) &&
        (size != MINIMUM))
    {
        size = 0.0;
    }

    // Copy new size
    columnSpec[i] = size;

    // Indicate that the cell sizes are not known
    dirty = true;
}



/**
 * Adjusts the height of a single row in this layout.  After calling this
 * method, the caller should request this layout manager to perform the
 * layout.  This can be done with the following code:
 *
 * <code>
 *     layout.layoutContainer(container);
 *     container.repaint();
 * </code>
 *
 * or
 *
 * <pre>
 *     window.pack()
 * </pre>
 *
 * If this is not done, the changes in the layout will not be seen until the
 * container is resized.
 *
 * @param i       zero-based index of row to set.  If this parameter is not
 *                valid, an ArrayOutOfBoundsException will be thrown.
 * @param size    height of the row.  This parameter cannot be null.
 *
 * @see #getRow
 */

public void setRow (int i, double size)
{
    // Make sure size is valid
    if ((size < 0.0) &&
        (size != FILL) &&
        (size != PREFERRED) &&
        (size != MINIMUM))
    {
        size = 0.0;
    }

    // Copy new size
    rowSpec[i] = size;

    // Indicate that the cell sizes are not known
    dirty = true;
}



/**
 * Gets the sizes of columns in this layout.
 *
 * @return widths of each of the columns
 *
 * @see #setColumn
 */

public double [] getColumn ()
{
    // Copy columns
    double column[] = new double[columnSpec.length];
    System.arraycopy (columnSpec, 0, column, 0, column.length);

    return column;
}



/**
 * Gets the height of a single row in this layout.
 *
 * @return height of the requested row
 *
 * @see #setRow
 */

public double [] getRow ()
{
    // Copy rows
    double row[] = new double[rowSpec.length];
    System.arraycopy (rowSpec, 0, row, 0, row.length);

    return row;
}



/**
 * Gets the width of a single column in this layout.
 *
 * @param i    zero-based index of row to get.  If this parameter is not valid,
 *             an ArrayOutOfBoundsException will be thrown.
 *
 * @return width of the requested column
 *
 * @see #setRow
 */

public double getColumn (int i)
{
    return columnSpec[i];
}



/**
 * Gets the sizes of a row in this layout.
 *
 * @param i    zero-based index of row to get.  If this parameter is not valid,
 *             an ArrayOutOfBoundsException will be thrown.
 *
 * @return height of each of the requested row
 *
 * @see #setRow
 */

public double getRow (int i)
{
    return rowSpec[i];
}



/**
 * Gets the number of columns in this layout.
 *
 * @return the number of columns
 */

public int getNumColumn ()
{
    return columnSpec.length;
}



/**
 * Gets the number of rows in this layout.
 *
 * @return the number of rows
 */

public int getNumRow ()
{
    return rowSpec.length;
}



//******************************************************************************
//** Insertion/Deletion methods                                              ***
//******************************************************************************



/**
 * Inserts a column in this layout.  All components to the right of the
 * insertion point are moved right one column.  The container will need to
 * be laid out after this method returns.  See <code>setColumn</code>.
 *
 * @param i       zero-based index at which to insert the column.
 * @param size    size of the column to be inserted
 *
 * @see #setColumn
 * @see #deleteColumn
 */

public void insertColumn (int i, double size)
{
    // Make sure position is valid
    if ((i < 0) || (i > columnSpec.length))
        throw new IllegalArgumentException
            ("Parameter i is invalid.  i = " + i + ".  Valid range is [0, " +
             columnSpec.length + "].");

    // Make sure column size is valid
    if ((size < 0.0) &&
        (size != FILL) &&
        (size != PREFERRED) &&
        (size != MINIMUM))
    {
        size = 0.0;
    }

    // Copy columns
    double column[] = new double[columnSpec.length + 1];
    System.arraycopy (columnSpec, 0, column, 0, i);
    System.arraycopy (columnSpec, i, column, i + 1, columnSpec.length - i);

    // Insert column
    column[i] = size;
    columnSpec = column;

    // Move all components that are to the right of new row
    ListIterator iterator = list.listIterator(0);
    
    while (iterator.hasNext())
    {
        // Get next entry
        Entry entry = (Entry) iterator.next();

        // Is the first column to the right of the new column
        if (entry.col1 >= i)
            // Move first column
            entry.col1++;

        // Is the second column to the right of the new column
        if (entry.col2 >= i)
            // Move second column
            entry.col2++;
    }

    // Indicate that the cell sizes are not known
    dirty = true;
}



/**
 * Inserts a row in this layout.  All components below the insertion point
 * are moved down one row.  The container will need to be laid out after this
 * method returns.  See <code>setRow</code>.
 *
 * @param i       zero-based index at which to insert the column.
 * @param size    size of the row to be inserted
 *
 * @see #setRow
 * @see #deleteRow
 */

public void insertRow (int i, double size)
{
    // Make sure position is valid
    if ((i < 0) || (i > rowSpec.length))
        throw new IllegalArgumentException
            ("Parameter i is invalid.  i = " + i + ".  Valid range is [0, " +
             rowSpec.length + "].");

    // Make sure row size is valid
    if ((size < 0.0) &&
        (size != FILL) &&
        (size != PREFERRED) &&
        (size != MINIMUM))
    {
        size = 0.0;
    }

    // Copy rows
    double row[] = new double[rowSpec.length + 1];
    System.arraycopy (rowSpec, 0, row, 0, i);
    System.arraycopy (rowSpec, i, row, i + 1, rowSpec.length - i);

    // Insert row
    row[i] = size;
    rowSpec = row;

    // Move all components that are below the new row
    ListIterator iterator = list.listIterator(0);
    
    while (iterator.hasNext())
    {
        // Get next entry
        Entry entry = (Entry) iterator.next();

        // Is the first row to the right of the new row
        if (entry.row1 >= i)
            // Move first row
            entry.row1++;

        // Is the second row to the right of the new row
        if (entry.row2 >= i)
            // Move second row
            entry.row2++;
    }

    // Indicate that the cell sizes are not known
    dirty = true;
}



/**
 * Deletes a column in this layout.  All components to the right of the
 * deletion point are moved left one column.  The container will need to
 * be laid out after this method returns.  See <code>setColumn</code>.
 *
 * @param i    zero-based index of column to delete
 *
 * @see #setColumn
 * @see #deleteColumn
 */

public void deleteColumn (int i)
{
    // Make sure position is valid
    if ((i < 0) || (i >= columnSpec.length))
        throw new IllegalArgumentException
            ("Parameter i is invalid.  i = " + i + ".  Valid range is [0, " +
             (columnSpec.length - 1) + "].");

    // Copy columns
    double column[] = new double[columnSpec.length - 1];
    System.arraycopy (columnSpec, 0, column, 0, i);
    System.arraycopy (columnSpec, i + 1, column, i, columnSpec.length - i - 1);

    // Delete column
    columnSpec = column;

    // Move all components that are to the right of row deleted
    ListIterator iterator = list.listIterator(0);
    
    while (iterator.hasNext())
    {
        // Get next entry
        Entry entry = (Entry) iterator.next();

        // Is the first column to the right of the new column
        if (entry.col1 >= i)
            // Move first column
            entry.col1--;

        // Is the second column to the right of the new column
        if (entry.col2 >= i)
            // Move second column
            entry.col2--;
    }

    // Indicate that the cell sizes are not known
    dirty = true;
}



/**
 * Deletes a row in this layout.  All components below the deletion point are
 * moved up one row.  The container will need to be laid out after this method
 * returns.  See <code>setRow</code>.  There must be at least two rows in order
 * to delete a row.
 *
 * @param i    zero-based index of column to delete
 *
 * @see #setRow
 * @see #deleteRow
 */

public void deleteRow (int i)
{
    // Make sure position is valid
    if ((i < 0) || (i >= rowSpec.length))
        throw new IllegalArgumentException
            ("Parameter i is invalid.  i = " + i + ".  Valid range is [0, " +
             (rowSpec.length - 1) + "].");

    // Copy rows
    double row[] = new double[rowSpec.length - 1];
    System.arraycopy (rowSpec, 0, row, 0, i);
    System.arraycopy (rowSpec, i + 1, row, i, rowSpec.length - i - 1);

    // Delete row
    rowSpec = row;

    // Move all components that are to below the row deleted
    ListIterator iterator = list.listIterator(0);
    
    while (iterator.hasNext())
    {
        // Get next entry
        Entry entry = (Entry) iterator.next();

        // Is the first row below the new row
        if (entry.row1 >= i)
            // Move first row
            entry.row1--;

        // Is the second row below the new row
        if (entry.row2 >= i)
            // Move second row
            entry.row2--;
    }

    // Indicate that the cell sizes are not known
    dirty = true;
}



//******************************************************************************
//** Misc methods                                                            ***
//******************************************************************************



/**
 * Converts this TableLayout to a string.

⌨️ 快捷键说明

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