diff options
| author | Paul Buetow <paul@buetow.org> | 2009-03-04 18:25:32 +0000 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2009-03-04 18:25:32 +0000 |
| commit | 6deeb57d62c238d3f152cdef1d782b441c73797a (patch) | |
| tree | f12600b080dbcdfed825f2a79f58c2d45fda93de /libs/FLib/TableLayout/org | |
| parent | 9129838d208c0df7293e5b757661125545cd6df8 (diff) | |
jcalendar lib
Diffstat (limited to 'libs/FLib/TableLayout/org')
| -rw-r--r-- | libs/FLib/TableLayout/org/freixas/tablelayout/TableLayout.java | 3114 |
1 files changed, 1558 insertions, 1556 deletions
diff --git a/libs/FLib/TableLayout/org/freixas/tablelayout/TableLayout.java b/libs/FLib/TableLayout/org/freixas/tablelayout/TableLayout.java index 870115d..75d42f3 100644 --- a/libs/FLib/TableLayout/org/freixas/tablelayout/TableLayout.java +++ b/libs/FLib/TableLayout/org/freixas/tablelayout/TableLayout.java @@ -263,7 +263,7 @@ import java.util.Iterator; // All Rights Reserved. public class TableLayout - implements LayoutManager2 + implements LayoutManager2 { //********************************************************************** @@ -273,554 +273,554 @@ public class TableLayout // This is the set of attributes applied to the table. Some attributes // are used as cell defaults. Cell-only attributes are ignored -private Attributes tableAttributes; + private Attributes tableAttributes; // Attributes for each component can be found in these hash tables -private HashMap compAttributes = new HashMap(); + private HashMap compAttributes = new HashMap(); // These variables store information about the row/col arrangement of // the components. These are set by placeComponents() -private int nRows = 0; -private int nCols = 0; -private Component[][] components = null; + private int nRows = 0; + private int nCols = 0; + private Component[][] components = null; // We cache measureComponents() information so that it is recalculated // after invalidateLayout() is called -private boolean useCacheMeasureResults = false; + private boolean useCacheMeasureResults = false; // These variables store sizing information set by measureComponents() -private int[] minWidth; -private int[] prefWidth; -private int[] maxWidth; -private int[] adjWidth; -private int[] colWeight; + private int[] minWidth; + private int[] prefWidth; + private int[] maxWidth; + private int[] adjWidth; + private int[] colWeight; -private int[] minHeight; -private int[] prefHeight; -private int[] maxHeight; -private int[] adjHeight; -private int[] rowWeight; + private int[] minHeight; + private int[] prefHeight; + private int[] maxHeight; + private int[] adjHeight; + private int[] rowWeight; // These sizes are the minimum width for the table, not including // either the container's insets or the table's insets -private int MinWidth = 0; -private int MinHeight = 0; -private int PrefWidth = 0; -private int PrefHeight = 0; -private int MaxWidth = 0; -private int MaxHeight = 0; -private int ColWeight = 0; -private int RowWeight = 0; + private int MinWidth = 0; + private int MinHeight = 0; + private int PrefWidth = 0; + private int PrefHeight = 0; + private int MaxWidth = 0; + private int MaxHeight = 0; + private int ColWeight = 0; + private int RowWeight = 0; -static private int classCount = 0; -private int instanceCount = classCount++; + static private int classCount = 0; + private int instanceCount = classCount++; //********************************************************************** // Constructors //********************************************************************** -/** - * Construct a new TableLayout. - */ - -public -TableLayout() -{ - this(null); -} + /** + * Construct a new TableLayout. + */ -/** - * Construct a new TableLayout with the given attributes. - * - * @param attributes A list of attributes for the table. The list is - * described in the class documentation above. Cell-only - * attributes are ignored. - */ + public + TableLayout() + { + this(null); + } -public -TableLayout( - String attributes) -{ - tableAttributes = new Attributes(attributes); -} + /** + * Construct a new TableLayout with the given attributes. + * + * @param attributes A list of attributes for the table. The list is + * described in the class documentation above. Cell-only + * attributes are ignored. + */ + + public + TableLayout( + String attributes) + { + tableAttributes = new Attributes(attributes); + } //********************************************************************** // Public //********************************************************************** -/** - * Reset the table attributes for the layout. - * - * @param attributes The new table attributes. - */ - -public void -setTableAttributes( - String attributes) -{ - // Set the attributes for the table - - tableAttributes = new Attributes(attributes); - - // Since the component attributes "inherit" from the table - // attributes, any change to the table attributes causes us to - // reprocess all existing component attributes - - Iterator iter = compAttributes.keySet().iterator(); - while (iter.hasNext()) { - Component comp = (Component)iter.next(); - Attributes a = (Attributes)compAttributes.get(comp); - a.parse(); // Re-parse + /** + * Reset the table attributes for the layout. + * + * @param attributes The new table attributes. + */ + + public void + setTableAttributes( + String attributes) + { + // Set the attributes for the table + + tableAttributes = new Attributes(attributes); + + // Since the component attributes "inherit" from the table + // attributes, any change to the table attributes causes us to + // reprocess all existing component attributes + + Iterator iter = compAttributes.keySet().iterator(); + while (iter.hasNext()) { + Component comp = (Component)iter.next(); + Attributes a = (Attributes)compAttributes.get(comp); + a.parse(); // Re-parse + } + + components = null; + useCacheMeasureResults = false; } - components = null; - useCacheMeasureResults = false; -} - -/** - * Reset the attributes for a component in the layout. The component - * must already have been added to the container or else this call has - * no effect. - * - * @param comp The component to alter. - * @param attributes The new attributes for the component. - */ - -public void -setAttributes( - Component comp, - String attributes) -{ - if (compAttributes.get(comp) != null) { - Attributes a = new Attributes(attributes, false); - compAttributes.put(comp, a); - - components = null; - useCacheMeasureResults = false; + /** + * Reset the attributes for a component in the layout. The component + * must already have been added to the container or else this call has + * no effect. + * + * @param comp The component to alter. + * @param attributes The new attributes for the component. + */ + + public void + setAttributes( + Component comp, + String attributes) + { + if (compAttributes.get(comp) != null) { + Attributes a = new Attributes(attributes, false); + compAttributes.put(comp, a); + + components = null; + useCacheMeasureResults = false; + } } -} -/** - * Adds the component with the specified attributes to the layout. - * - * @param attributes A list of attributes for the component. The list - * is described in the class documentation above. Table-only - * attributes are ignored. - * @param comp The component to be added. - */ + /** + * Adds the component with the specified attributes to the layout. + * + * @param attributes A list of attributes for the component. The list + * is described in the class documentation above. Table-only + * attributes are ignored. + * @param comp The component to be added. + */ -public void -addLayoutComponent( - String attributes, - Component comp) -{ - Attributes a = new Attributes(attributes, false); - compAttributes.put(comp, a); + public void + addLayoutComponent( + String attributes, + Component comp) + { + Attributes a = new Attributes(attributes, false); + compAttributes.put(comp, a); - components = null; - useCacheMeasureResults = false; + components = null; + useCacheMeasureResults = false; - // DEBUG + // DEBUG // if ("DEBUG".equals(comp.getName())) { // System.out.println( // "Adding comp " + comp.getClass().getName() + " " + a); // } -} - -/** - * Adds the specified component to the layout, using the specified - * constraint object (which we expect to be a String of attributes). - * - * @param comp The component to be added. - * @param constraints A list of attributes for the component. The list - * is described in the class documentation above. Table-only - * attributes are ignored. - */ - -public void -addLayoutComponent( - Component comp, - Object constraints) -{ - String attributes = ""; - if (constraints instanceof String) { - attributes = (String)constraints; } - addLayoutComponent(attributes, comp); -} -/** - * Removes the specified component from the layout. - - * @param comp The component to be removed. - */ - -public void -removeLayoutComponent( - Component comp) -{ - compAttributes.remove(comp); - components = null; -} - -/** - * Calculates the minimum size dimensions for the layout given the - * components in the a parent container. - * - * @param parent The container to be laid out. - * @return The minimum layout size. - * @see #preferredLayoutSize(Container) - * @see #maximumLayoutSize(Container) - */ - -public Dimension -minimumLayoutSize( - Container parent) -{ - Insets insets = parent.getInsets(); - measureComponents(parent); - int w = - insets.left + insets.right + - tableAttributes.tableInsets.left + - tableAttributes.tableInsets.right + - MinWidth; - int h = - insets.top + insets.bottom + - tableAttributes.tableInsets.top + - tableAttributes.tableInsets.bottom + - MinHeight; - if (w > Short.MAX_VALUE) w = Short.MAX_VALUE; - if (h > Short.MAX_VALUE) h = Short.MAX_VALUE; - - return new Dimension(w, h); -} - -/** - * Calculates the preferred size dimensions for the layout given the - * components in a parent container. - * - * @param parent The container to be laid out. - * @return The preferred layout size. - * @see #minimumLayoutSize(Container) - * @see #maximumLayoutSize(Container) - */ + /** + * Adds the specified component to the layout, using the specified + * constraint object (which we expect to be a String of attributes). + * + * @param comp The component to be added. + * @param constraints A list of attributes for the component. The list + * is described in the class documentation above. Table-only + * attributes are ignored. + */ + + public void + addLayoutComponent( + Component comp, + Object constraints) + { + String attributes = ""; + if (constraints instanceof String) { + attributes = (String)constraints; + } + addLayoutComponent(attributes, comp); + } -public Dimension -preferredLayoutSize( - Container parent) -{ - Insets insets = parent.getInsets(); - measureComponents(parent); - int w = - insets.left + insets.right + - tableAttributes.tableInsets.left + - tableAttributes.tableInsets.right + - PrefWidth; - int h = - insets.top + insets.bottom + - tableAttributes.tableInsets.top + - tableAttributes.tableInsets.bottom + - PrefHeight; - if (w > Short.MAX_VALUE) w = Short.MAX_VALUE; - if (h > Short.MAX_VALUE) h = Short.MAX_VALUE; - - return new Dimension(w, h); -} + /** + * Removes the specified component from the layout. -/** - * Calculates the maximum size dimensions for the layout given the - * components in a parent container. - * - * @param parent The container parent. - * @return The maximum layout size. - * @see #minimumLayoutSize(Container) - * @see #preferredLayoutSize(Container) - */ + * @param comp The component to be removed. + */ -public Dimension -maximumLayoutSize( - Container parent) -{ - Insets insets = parent.getInsets(); - measureComponents(parent); - - // Note that the maximum size of the container is not the maximum - // size of the table if the fill options are not used - - int w = Short.MAX_VALUE; - if (tableAttributes.tableHorizontal != Attributes.FILL) { - w = insets.left + insets.right + - tableAttributes.tableInsets.left + - tableAttributes.tableInsets.right + - MaxWidth; - if (w > Short.MAX_VALUE) w = Short.MAX_VALUE; + public void + removeLayoutComponent( + Component comp) + { + compAttributes.remove(comp); + components = null; } - int h = Short.MAX_VALUE; - if (tableAttributes.tableVertical != Attributes.FILL) { - h = insets.top + insets.bottom + - tableAttributes.tableInsets.top + - tableAttributes.tableInsets.bottom + - MaxHeight; - if (h > Short.MAX_VALUE) h = Short.MAX_VALUE; + /** + * Calculates the minimum size dimensions for the layout given the + * components in the a parent container. + * + * @param parent The container to be laid out. + * @return The minimum layout size. + * @see #preferredLayoutSize(Container) + * @see #maximumLayoutSize(Container) + */ + + public Dimension + minimumLayoutSize( + Container parent) + { + Insets insets = parent.getInsets(); + measureComponents(parent); + int w = + insets.left + insets.right + + tableAttributes.tableInsets.left + + tableAttributes.tableInsets.right + + MinWidth; + int h = + insets.top + insets.bottom + + tableAttributes.tableInsets.top + + tableAttributes.tableInsets.bottom + + MinHeight; + if (w > Short.MAX_VALUE) w = Short.MAX_VALUE; + if (h > Short.MAX_VALUE) h = Short.MAX_VALUE; + + return new Dimension(w, h); } - return new Dimension(w, h); -} - -/** - * Returns the alignment along the x axis. This always returns 0.5. - * - * @param parent The container whose alignment we want. - * @return The alignment along the x axis. - */ - -public float -getLayoutAlignmentX( - Container parent) -{ - return 0.5f; -} - -/** - * Returns the alignment along the y axis. This always returns 0.5. - * - * @param parent The container whose alignment we want. - * @return The alignment along the y axis. - */ - -public float -getLayoutAlignmentY( - Container parent) -{ - return 0.5f; -} - -/** - * Invalidates the layout. Cached information will be discarded. - * - * @param parent The container whose alignment we want. - */ - -public void -invalidateLayout( - Container parent) -{ - useCacheMeasureResults = false; -} - -/** - * Lays out the components in the given container. - * - * @param parent The container which needs to be laid out. - */ - -public void -layoutContainer( - Container parent) -{ - // Get the row and column measurements - - measureComponents(parent); - - // Get the parent insets and determine the full amount of space we - // have available - - Insets insets = parent.getInsets(); - int fullWidth = - parent.getSize().width - - (insets.left + insets.right) - - (tableAttributes.tableInsets.left + - tableAttributes.tableInsets.right); - int fullHeight = parent.getSize().height - - (insets.top + insets.bottom) - - (tableAttributes.tableInsets.top + - tableAttributes.tableInsets.bottom); - - // We normally draw each row and column in its preferred size. If - // we have more space, we grow the cells. If less, we shrink the - // cells - - boolean shrinkWidth = fullWidth < PrefWidth; - boolean shrinkHeight = fullHeight < PrefHeight; - - // Get the position and size of the table. There are three - // possibilities for the table size: - // - // * The available space equals or exceeds the preferred size - // and the table is filled - use the full space available. We - // will expand the cells in a later step. - // - // * The available space equals or exceeds the preferred size - // and the table is not filled - use the preferred size. - // - // * The available space is less than the preferred size - use - // the available space. We will shrink the cells in a later - // step. - - int tableX = insets.left + tableAttributes.tableInsets.left; - int tableY = insets.top + tableAttributes.tableInsets.top; - - int tableWidth = PrefWidth; - if (shrinkWidth || - tableAttributes.tableHorizontal == Attributes.FILL) { - tableWidth = fullWidth; - } - int tableHeight = PrefHeight; - if (shrinkHeight || - tableAttributes.tableVertical == Attributes.FILL) { - tableHeight = fullHeight; + /** + * Calculates the preferred size dimensions for the layout given the + * components in a parent container. + * + * @param parent The container to be laid out. + * @return The preferred layout size. + * @see #minimumLayoutSize(Container) + * @see #maximumLayoutSize(Container) + */ + + public Dimension + preferredLayoutSize( + Container parent) + { + Insets insets = parent.getInsets(); + measureComponents(parent); + int w = + insets.left + insets.right + + tableAttributes.tableInsets.left + + tableAttributes.tableInsets.right + + PrefWidth; + int h = + insets.top + insets.bottom + + tableAttributes.tableInsets.top + + tableAttributes.tableInsets.bottom + + PrefHeight; + if (w > Short.MAX_VALUE) w = Short.MAX_VALUE; + if (h > Short.MAX_VALUE) h = Short.MAX_VALUE; + + return new Dimension(w, h); } - if (tableAttributes.tableHorizontal == Attributes.CENTER || - tableAttributes.tableHorizontal == Attributes.FILL) { - tableX += (fullWidth - tableWidth) / 2; - } - else if (tableAttributes.tableHorizontal == Attributes.RIGHT) { - tableX += fullWidth - tableWidth; + /** + * Calculates the maximum size dimensions for the layout given the + * components in a parent container. + * + * @param parent The container parent. + * @return The maximum layout size. + * @see #minimumLayoutSize(Container) + * @see #preferredLayoutSize(Container) + */ + + public Dimension + maximumLayoutSize( + Container parent) + { + Insets insets = parent.getInsets(); + measureComponents(parent); + + // Note that the maximum size of the container is not the maximum + // size of the table if the fill options are not used + + int w = Short.MAX_VALUE; + if (tableAttributes.tableHorizontal != Attributes.FILL) { + w = insets.left + insets.right + + tableAttributes.tableInsets.left + + tableAttributes.tableInsets.right + + MaxWidth; + if (w > Short.MAX_VALUE) w = Short.MAX_VALUE; + } + + int h = Short.MAX_VALUE; + if (tableAttributes.tableVertical != Attributes.FILL) { + h = insets.top + insets.bottom + + tableAttributes.tableInsets.top + + tableAttributes.tableInsets.bottom + + MaxHeight; + if (h > Short.MAX_VALUE) h = Short.MAX_VALUE; + } + + return new Dimension(w, h); } - if (tableAttributes.tableVertical == Attributes.CENTER || - tableAttributes.tableVertical == Attributes.FILL) { - tableY += (fullHeight - tableHeight) / 2; - } - else if (tableAttributes.tableVertical == Attributes.BOTTOM) { - tableY += fullHeight - tableHeight; + /** + * Returns the alignment along the x axis. This always returns 0.5. + * + * @param parent The container whose alignment we want. + * @return The alignment along the x axis. + */ + + public float + getLayoutAlignmentX( + Container parent) + { + return 0.5f; } - // Now adjust the column and row cell sizes + /** + * Returns the alignment along the y axis. This always returns 0.5. + * + * @param parent The container whose alignment we want. + * @return The alignment along the y axis. + */ + + public float + getLayoutAlignmentY( + Container parent) + { + return 0.5f; + } - adjustCellSizes( - nCols, - (tableAttributes.tableHorizontal == Attributes.FILL), - shrinkWidth, - minWidth, - PrefWidth, prefWidth, - fullWidth, - ColWeight, colWeight, - adjWidth, - parent); + /** + * Invalidates the layout. Cached information will be discarded. + * + * @param parent The container whose alignment we want. + */ + + public void + invalidateLayout( + Container parent) + { + useCacheMeasureResults = false; + } - adjustCellSizes( - nRows, - (tableAttributes.tableVertical == Attributes.FILL), - shrinkHeight, - minHeight, - PrefHeight, prefHeight, - fullHeight, - RowWeight, rowWeight, - adjHeight, - parent); - - // Begin the component layout loop - - for (int r = 0; r < nRows; r++) { - for (int c = 0; c < nCols; c++) { - Component comp = components[r][c]; - if (comp == null) continue; - - Attributes attributes = (Attributes)compAttributes.get(comp); - - Dimension compMinSize = comp.getMinimumSize(); - Dimension compPrefSize = comp.getPreferredSize(); - Dimension compMaxSize = comp.getMaximumSize(); - - // Base position - - int compX = - tableX + - (tableAttributes.cGap * c) + - attributes.cellInsets.left; - for (int i = 0; i < c; i++) compX += adjWidth[i]; - - int compY = - tableY + - (tableAttributes.rGap * r) + - attributes.cellInsets.top; - for (int i = 0; i < r; i++) compY += adjHeight[i]; - - // Get the cell size. This has to take into account row - // and column spanning - - int cellWidth = adjWidth[c]; - for (int i = 1; i < attributes.cSpan; i++) { - cellWidth += tableAttributes.cGap + adjWidth[c + i]; - } - - int cellHeight = adjHeight[r]; - for (int i = 1; i < attributes.rSpan; i++) { - cellHeight += tableAttributes.rGap + adjHeight[r + i]; - } - - int insetCellWidth = - cellWidth - - attributes.cellInsets.left - attributes.cellInsets.right; - int insetCellHeight = - cellHeight - - attributes.cellInsets.top - attributes.cellInsets.bottom; - - // Get the component size. Use the preferred size, if - // possible. If not use the cell size minus insets - - int compWidth = compPrefSize.width; - int compHeight = compPrefSize.height; - if (compWidth > insetCellWidth) compWidth = insetCellWidth; - if (compHeight > insetCellHeight) compHeight = insetCellHeight; - - // Adjust for fill - - if (attributes.horizontal == Attributes.FILL) { - compWidth = insetCellWidth; - compWidth = Math.max(compWidth, compMinSize.width); - // Some components (like JButton) can exceed their max size - // compWidth = Math.min(compWidth, compMaxSize.width); - } - if (attributes.vertical == Attributes.FILL) { - compHeight = insetCellHeight; - compHeight = Math.max(compHeight, compMinSize.height); - // Some components (like JButton) can exceed their max size - // compHeight = Math.min(compHeight, compMaxSize.height); - } - - // Position properly. We treat FILL like CENTER since - // the min/max limits may have prevented us from really - // filling - - if (attributes.horizontal == Attributes.CENTER || - attributes.horizontal == Attributes.FILL) { - compX += (cellWidth - - (attributes.cellInsets.left + - attributes.cellInsets.right) - compWidth) / 2; - } - else if (attributes.horizontal == Attributes.RIGHT) { - compX += (cellWidth - - (attributes.cellInsets.left + - attributes.cellInsets.right) - compWidth); - } - - if (attributes.vertical == Attributes.CENTER || - attributes.vertical == Attributes.FILL) { - compY += (cellHeight - - (attributes.cellInsets.top + - attributes.cellInsets.bottom) - compHeight) / 2; - } - else if (attributes.vertical == Attributes.BOTTOM) { - compY += (cellHeight - - (attributes.cellInsets.top + - attributes.cellInsets.bottom) - compHeight); - } - - // Place the component - - comp.setBounds(compX, compY, compWidth, compHeight); - - // DEBUG + /** + * Lays out the components in the given container. + * + * @param parent The container which needs to be laid out. + */ + + public void + layoutContainer( + Container parent) + { + // Get the row and column measurements + + measureComponents(parent); + + // Get the parent insets and determine the full amount of space we + // have available + + Insets insets = parent.getInsets(); + int fullWidth = + parent.getSize().width - + (insets.left + insets.right) - + (tableAttributes.tableInsets.left + + tableAttributes.tableInsets.right); + int fullHeight = parent.getSize().height - + (insets.top + insets.bottom) - + (tableAttributes.tableInsets.top + + tableAttributes.tableInsets.bottom); + + // We normally draw each row and column in its preferred size. If + // we have more space, we grow the cells. If less, we shrink the + // cells + + boolean shrinkWidth = fullWidth < PrefWidth; + boolean shrinkHeight = fullHeight < PrefHeight; + + // Get the position and size of the table. There are three + // possibilities for the table size: + // + // * The available space equals or exceeds the preferred size + // and the table is filled - use the full space available. We + // will expand the cells in a later step. + // + // * The available space equals or exceeds the preferred size + // and the table is not filled - use the preferred size. + // + // * The available space is less than the preferred size - use + // the available space. We will shrink the cells in a later + // step. + + int tableX = insets.left + tableAttributes.tableInsets.left; + int tableY = insets.top + tableAttributes.tableInsets.top; + + int tableWidth = PrefWidth; + if (shrinkWidth || + tableAttributes.tableHorizontal == Attributes.FILL) { + tableWidth = fullWidth; + } + int tableHeight = PrefHeight; + if (shrinkHeight || + tableAttributes.tableVertical == Attributes.FILL) { + tableHeight = fullHeight; + } + + if (tableAttributes.tableHorizontal == Attributes.CENTER || + tableAttributes.tableHorizontal == Attributes.FILL) { + tableX += (fullWidth - tableWidth) / 2; + } + else if (tableAttributes.tableHorizontal == Attributes.RIGHT) { + tableX += fullWidth - tableWidth; + } + + if (tableAttributes.tableVertical == Attributes.CENTER || + tableAttributes.tableVertical == Attributes.FILL) { + tableY += (fullHeight - tableHeight) / 2; + } + else if (tableAttributes.tableVertical == Attributes.BOTTOM) { + tableY += fullHeight - tableHeight; + } + + // Now adjust the column and row cell sizes + + adjustCellSizes( + nCols, + (tableAttributes.tableHorizontal == Attributes.FILL), + shrinkWidth, + minWidth, + PrefWidth, prefWidth, + fullWidth, + ColWeight, colWeight, + adjWidth, + parent); + + adjustCellSizes( + nRows, + (tableAttributes.tableVertical == Attributes.FILL), + shrinkHeight, + minHeight, + PrefHeight, prefHeight, + fullHeight, + RowWeight, rowWeight, + adjHeight, + parent); + + // Begin the component layout loop + + for (int r = 0; r < nRows; r++) { + for (int c = 0; c < nCols; c++) { + Component comp = components[r][c]; + if (comp == null) continue; + + Attributes attributes = (Attributes)compAttributes.get(comp); + + Dimension compMinSize = comp.getMinimumSize(); + Dimension compPrefSize = comp.getPreferredSize(); + Dimension compMaxSize = comp.getMaximumSize(); + + // Base position + + int compX = + tableX + + (tableAttributes.cGap * c) + + attributes.cellInsets.left; + for (int i = 0; i < c; i++) compX += adjWidth[i]; + + int compY = + tableY + + (tableAttributes.rGap * r) + + attributes.cellInsets.top; + for (int i = 0; i < r; i++) compY += adjHeight[i]; + + // Get the cell size. This has to take into account row + // and column spanning + + int cellWidth = adjWidth[c]; + for (int i = 1; i < attributes.cSpan; i++) { + cellWidth += tableAttributes.cGap + adjWidth[c + i]; + } + + int cellHeight = adjHeight[r]; + for (int i = 1; i < attributes.rSpan; i++) { + cellHeight += tableAttributes.rGap + adjHeight[r + i]; + } + + int insetCellWidth = + cellWidth - + attributes.cellInsets.left - attributes.cellInsets.right; + int insetCellHeight = + cellHeight - + attributes.cellInsets.top - attributes.cellInsets.bottom; + + // Get the component size. Use the preferred size, if + // possible. If not use the cell size minus insets + + int compWidth = compPrefSize.width; + int compHeight = compPrefSize.height; + if (compWidth > insetCellWidth) compWidth = insetCellWidth; + if (compHeight > insetCellHeight) compHeight = insetCellHeight; + + // Adjust for fill + + if (attributes.horizontal == Attributes.FILL) { + compWidth = insetCellWidth; + compWidth = Math.max(compWidth, compMinSize.width); + // Some components (like JButton) can exceed their max size + // compWidth = Math.min(compWidth, compMaxSize.width); + } + if (attributes.vertical == Attributes.FILL) { + compHeight = insetCellHeight; + compHeight = Math.max(compHeight, compMinSize.height); + // Some components (like JButton) can exceed their max size + // compHeight = Math.min(compHeight, compMaxSize.height); + } + + // Position properly. We treat FILL like CENTER since + // the min/max limits may have prevented us from really + // filling + + if (attributes.horizontal == Attributes.CENTER || + attributes.horizontal == Attributes.FILL) { + compX += (cellWidth - + (attributes.cellInsets.left + + attributes.cellInsets.right) - compWidth) / 2; + } + else if (attributes.horizontal == Attributes.RIGHT) { + compX += (cellWidth - + (attributes.cellInsets.left + + attributes.cellInsets.right) - compWidth); + } + + if (attributes.vertical == Attributes.CENTER || + attributes.vertical == Attributes.FILL) { + compY += (cellHeight - + (attributes.cellInsets.top + + attributes.cellInsets.bottom) - compHeight) / 2; + } + else if (attributes.vertical == Attributes.BOTTOM) { + compY += (cellHeight - + (attributes.cellInsets.top + + attributes.cellInsets.bottom) - compHeight); + } + + // Place the component + + comp.setBounds(compX, compY, compWidth, compHeight); + + // DEBUG // if ("DEBUG".equals(parent.getName())) { // System.out.println("Placing component " + @@ -828,9 +828,9 @@ layoutContainer( // " (" + compX + ", " + compY + ") " + // compWidth + " x " + compHeight); // } - } + } + } } -} // The inherited toString() method is acceptable. @@ -838,160 +838,162 @@ layoutContainer( // Private //********************************************************************** -/** - * The row or column sizes need to be adjusted. We may want to grow - * or shrink the sizes, based on whether the available space is larger - * or smaller than the preferred size. - * <p> - * If we grow the table, we pay attention to the user's weighting - * factors. If we shrink the table, we assign all cells a weight - * factor of 1. - * - * @param nCells The number of cells in the row or column. - * @param fill True if the table rows or columns should fill the - * available space. - * @param shrink True if the available size is less than the preferred - * size. - * @param minSize The minimum sizes of each row or column. - * @param PrefSize The sum of the preferred sizes of all cells in the - * row or column plus any cell gaps. - * @param prefSize The preferred sizes of each row or column. - * @param CellWeight The sum of all cell weights in the row or column. - * @param cellWeight The weight of each row or column. - * @param adjSize The adjusted size of each row or column. The - * contents of this array are set and returned. - */ - -private void -adjustCellSizes( - int nCells, - boolean fill, - boolean shrink, - int[] minSize, - int PrefSize, - int[] prefSize, - int fullSize, - int CellWeight, - int[] cellWeight, < |
