/*
* This file is part of WebLookAndFeel library.
*
* WebLookAndFeel library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* WebLookAndFeel 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WebLookAndFeel library. If not, see
User code should not have to call this method * directly.
* * @param container container being served by this layout manager */ public void layoutContainer ( Container container ) { // Use preferred size to get maximum width or height Dimension size = container.getSize (); // Get the container's insets Insets inset = container.getInsets (); // Start at top left of container int x = inset.left; int y = inset.top; // Get the components inside the container Component component[] = container.getComponents (); // Components arranged in a column if ( orientation == COLUMN ) // Add each component { for ( int counter = 0; counter < component.length; counter++ ) { // Use preferred size of component Dimension d = component[ counter ].getPreferredSize (); // Align component switch ( justification ) { case LEFT: x = inset.left; break; case CENTER: x = ( ( size.width - d.width ) >> 1 ) + inset.left - inset.right; break; case FULL: x = inset.left; d.width = size.width - inset.left - inset.right; break; case RIGHT: x = size.width - d.width - inset.right; break; } // Set size and location component[ counter ].setBounds ( x, y, d.width, d.height ); // Increment y y += d.height + gap; } } // Components arranged in a row else // Add each component { for ( int counter = 0; counter < component.length; counter++ ) { // Use preferred size of component Dimension d = component[ counter ].getPreferredSize (); // Align component switch ( justification ) { case TOP: y = inset.top; break; case CENTER: y = ( ( size.height - d.height ) >> 1 ) + inset.top - inset.bottom; break; case FULL: y = inset.top; d.height = size.height - inset.top - inset.bottom; break; case BOTTOM: y = size.height - d.height - inset.bottom; break; } // Set size and location component[ counter ].setBounds ( x, y, d.width, d.height ); // Increment x x += d.width + gap; } } } /** * Determines the preferred size of the container argument using this layout. The preferred size * is the smallest size that, if used for the container's size, will ensure that no component is * truncated when the component is it's preferred size. * * @param container container being served by this layout manager * @return a dimension indicating the container's preferred size */ public Dimension preferredLayoutSize ( Container container ) { int totalWidth = 0; // Width of all components int totalHeight = 0; // Height of all components // Get the components inside the container Component component[] = container.getComponents (); // Components arranged in a column if ( orientation == COLUMN ) { // Add each component for ( int counter = 0; counter < component.length; counter++ ) { Dimension d = component[ counter ].getPreferredSize (); if ( totalWidth < d.width ) { totalWidth = d.width; } totalHeight += d.height + gap; } // Subtract extra gap totalHeight -= gap; } // Components arranged in a row else { // Add each component for ( int counter = 0; counter < component.length; counter++ ) { Dimension d = component[ counter ].getPreferredSize (); totalWidth += d.width + gap; if ( totalHeight < d.height ) { totalHeight = d.height; } } // Subtract extra gap totalWidth -= gap; } // Add insets to preferred size Insets inset = container.getInsets (); totalWidth += inset.left + inset.right; totalHeight += inset.top + inset.bottom; return new Dimension ( totalWidth, totalHeight ); } /** * Determines the minimum size of the container argument using this layout. The minimum size is * the smallest size that, if used for the container's size, will ensure that no component is * truncated. The minimum size is the preferred size. * * @param container container being served by this layout manager * @return a dimension indicating the container's minimum size */ public Dimension minimumLayoutSize ( Container container ) { int totalWidth = 0; // Width of all components int totalHeight = 0; // Height of all components // Get the components inside the container Component component[] = container.getComponents (); // Components arranged in a column if ( orientation == COLUMN ) { // Add each component for ( int counter = 0; counter < component.length; counter++ ) { Dimension d = component[ counter ].getMinimumSize (); if ( totalWidth < d.width ) { totalWidth = d.width; } totalHeight += d.height + gap; } // Subtract extra gap totalHeight -= gap; } // Components arranged in a row else { // Add each component for ( int counter = 0; counter < component.length; counter++ ) { Dimension d = component[ counter ].getMinimumSize (); totalWidth += d.width + gap; if ( totalHeight < d.height ) { totalHeight = d.height; } } // Subtract extra gap totalWidth = -gap; } // Add insets to preferred size Insets inset = container.getInsets (); totalWidth += inset.left + inset.right; totalHeight += inset.top + inset.bottom; return new Dimension ( totalWidth, totalHeight ); } /** * Adds the specified component with the specified name to the layout. * * @param name dummy parameter * @param component component to add */ public void addLayoutComponent ( String name, Component component ) { // } /** * Removes the specified component with the specified name from the layout. * * @param component component being removed */ public void removeLayoutComponent ( Component component ) { // } }