Class LayoutUtil

java.lang.Object
ucar.unidata.util.MenuUtil
ucar.unidata.util.LayoutUtil
Direct Known Subclasses:
GuiUtils

public class LayoutUtil extends MenuUtil
This is a vast catchall class to old various utilities for doing GUI things.
Author:
IDV development team
  • Field Details

    • tmpInsets

      public static Insets tmpInsets
      If you want to change the insets used in the doLayout routines you can set this and the routine will use the value and then set it to null. I know, I know, it isn't thread safe but...
    • INSETS_5

      public static final Insets INSETS_5
      5 pixel inset
    • INSETS_2

      public static final Insets INSETS_2
      2 pixel inset
    • tmpColFills

      public static int[] tmpColFills
      Use this to define your own column fills (i.e., horizontal expansion of the elements in the gribag). Will be set to null after use. Not thread safe but...
    • tmpAnchor

      public static int tmpAnchor
      Set this to define your own anchor in the doLayout routines. Will get reset after use. Not thread safe. You can also call setAnchorBottom() and setAnchorTop() for changing the anchor.
    • tmpFill

      public static int tmpFill
      Set this to define your own fill in the doLayout routines. Will get reset after use. Not thread safe. You can also call setNoFill() and setHFill() for doing no fill and horizontal fill.
    • ZERO_INSETS

      public static final Insets ZERO_INSETS
      A 0 inset
    • WT_Y

      public static final double[] WT_Y
      All of the WT_ members are used to define the column and row weights for the doLayout routines. They are double arrays, typically one for each col or row, that hold either a 1 or a 0. The "Y" and "N" implies YES or NO, i.e., does the corresponding row/column get weight (Y) or not get weight (N).

      So for example, if you wanted to have no stretchiness in the first column and put all of the stretchiness into the second column you would use:

       WT_NY

      Note, you can pass in your own double arrays to doLayout. These are just here for convenience.

    • WT_YY

      public static final double[] WT_YY
      doLayout weights
    • WT_YYY

      public static final double[] WT_YYY
      doLayout weights
    • WT_N

      public static final double[] WT_N
      doLayout weights
    • WT_NN

      public static final double[] WT_NN
      doLayout weights
    • WT_NNN

      public static final double[] WT_NNN
      doLayout weights
    • WT_YN

      public static final double[] WT_YN
      doLayout weights
    • WT_YYN

      public static final double[] WT_YYN
      doLayout weights
    • WT_YNYN

      public static final double[] WT_YNYN
      doLayout weights
    • WT_NYNYN

      public static final double[] WT_NYNYN
      doLayout weights
    • WT_NY

      public static final double[] WT_NY
      doLayout weights
    • WT_NYN

      public static final double[] WT_NYN
      doLayout weights
    • WT_YNY

      public static final double[] WT_YNY
      doLayout weights
    • WT_NYY

      public static final double[] WT_NYY
      doLayout weights
    • WT_YNN

      public static final double[] WT_YNN
      doLayout weights
    • WT_NNY

      public static final double[] WT_NNY
      doLayout weights
    • WT_NNNY

      public static final double[] WT_NNNY
      doLayout weights
    • WT_NNYN

      public static final double[] WT_NNYN
      doLayout weights
    • WT_NNYNY

      public static final double[] WT_NNYNY
      doLayout weights
    • WT_NNYNYNY

      public static final double[] WT_NNYNYNY
      doLayout weights
    • WT_NYNY

      public static final double[] WT_NYNY
      doLayout weights
  • Constructor Details

    • LayoutUtil

      public LayoutUtil()
  • Method Details

    • setNoFill

      public static void setNoFill()
      Turns off component fill for the doLayout routine
    • hfill

      public static JComponent hfill(JComponent comp)
      Wrap the component so that it only expands horizontally, not vertically
      Parameters:
      comp - The component
      Returns:
      The wrapped component
    • setHFill

      public static void setHFill()
      Turns on component horizontal fill for the doLayout routine
    • setAnchorBottom

      public static void setAnchorBottom()
      Sets the anchor to bottom for doLayout
    • setAnchorTop

      public static void setAnchorTop()
      Sets the anchor to top for doLayout
    • inset

      public static JPanel inset(Component c, int insetSize)
      Inset the given component by the given insetSize, both horizontally and vertically.
      Parameters:
      c - The component to wrap
      insetSize - Horizontal and vertical inset
      Returns:
      A JPanel that contains the given component inset the specified amount.
    • inset

      public static JPanel inset(Component c, int insetSizeHor, int insetSizeVert)
      Inset the given component by the given insetSize for horizontally and vertically.
      Parameters:
      c - The component to wrap
      insetSizeHor - Inset horizontal
      insetSizeVert - Inset vertical
      Returns:
      A JPanel that contains the given component inset the specified amount.
    • inset

      public static JPanel inset(Component c, Insets insets)
      Inset the given component by the given insets.
      Parameters:
      c - The component to wrap
      insets - The insets
      Returns:
      A JPanel that contains the given component inset the specified amount.
    • wrapLeft

      public static JPanel wrapLeft(Component c)
      Wrap the given component, aligning it to the left. It won't expand the component.
      Parameters:
      c - The component to wrap
      Returns:
      The wrapper
    • wrap

      public static JPanel wrap(Component c)
      Wrap the given component. This won't expand the component. Use this when you want to place a component and not expand it.
      Parameters:
      c - The component to wrap
      Returns:
      The wrapper
    • hflow

      public static JPanel hflow(List components)
      Create a new JPanel and add the given components to it using a FlowLayout.
      Parameters:
      components - The components to layout
      Returns:
      The new JPanel
    • hflow

      public static JPanel hflow(List components, int hgap, int vgap)
      Create a new JPanel and add the given components to it using a FlowLayout.
      Parameters:
      components - The components to layout
      hgap - Horizontal spacing
      vgap - Vertical spacing
      Returns:
      The new JPanel
    • hgrid

      public static JPanel hgrid(Component comp1, Component comp2)
      Do a horizontal grid layout of the given components
      Parameters:
      comp1 - comp1
      comp2 - comp2_
      Returns:
      The new JPanel holding the given components
    • hgrid

      public static JPanel hgrid(List components)
      Do a horizontal grid layout of the given components
      Parameters:
      components - The components to layout
      Returns:
      The new JPanel holding the given components
    • hgrid

      public static JPanel hgrid(List components, int space)
      Do a horizontal grid layout of the given components
      Parameters:
      components - The components to layout
      space - The spacing
      Returns:
      The new JPanel holding the given components
    • vgrid

      public static JPanel vgrid(List components)
      Do a single column grid layout of the components
      Parameters:
      components - The components to layout
      Returns:
      The new JPanel
    • vgrid

      public static JPanel vgrid(JPanel panel, List components, int space)
      Do a single column grid layout of the components
      Parameters:
      panel - The panel to add to
      components - The components to layout
      space - The spacing
      Returns:
      The panel
    • rowGrid

      public static JPanel rowGrid(List comps, int rows)
      Do a grid layout with the number of rows
      Parameters:
      comps - Components to layout
      rows - Number of rows
      Returns:
      The new panel
    • rowGrid

      public static JPanel rowGrid(Component[] components, int rows)
      Do a grid layout with the number of rows
      Parameters:
      components - Components to layout
      rows - Number of rows
      Returns:
      The new panel
    • colGrid

      public static JPanel colGrid(Component[] components, int cols)
      Do a grid layout with the number of columns
      Parameters:
      components - Components to layout
      cols - Number of cols
      Returns:
      The new panel
    • grid

      public static JPanel grid(Component[] components, int rows, int cols)
      Do a grid layout with the number of columns
      Parameters:
      components - Components to layout
      rows - Number of rows (0 implies not fixed)
      cols - Number of cols (0 implies not fixed)
      Returns:
      The new panel
    • grid

      public static JPanel grid(Component[] components, int rows, int cols, int space)
      Do a grid layout with the number of columns
      Parameters:
      components - Components to layout
      rows - Number of rows (0 implies not fixed)
      cols - Number of cols (0 implies not fixed)
      space - Spacing
      Returns:
      The new panel
    • inset

      public static JPanel inset(JPanel parent, Component c, int insetSize)
      Inset the given component, adding it into the given parent container, by the given insetSize, both horizontally and vertically.
      Parameters:
      parent - The panel to put the component in.
      c - The component to wrap
      insetSize - Horizontal and vertical inset
      Returns:
      A JPanel that contains the given component inset the specified amount.
    • doLayout

      public static JPanel doLayout(List components, int numberOfColumns, int hinset, int vinset)
      This does a column oriented grid bag layout. It will layout the given components in a grid with the given number of columns.
      Parameters:
      components - List of Components to layout
      numberOfColumns - How many columns in the grid layout
      hinset - hor. inset
      vinset - vert. inset
      Returns:
      THe new panel
    • getComponentArray

      public static Component[] getComponentArray(List listOfComponents)
      A utility to convert the listOfComponents into a Component array
      Parameters:
      listOfComponents - List of Components
      Returns:
      Component array
    • doLayout

      public static JPanel doLayout(List components, int numberOfColumns, double[] weightsX, double[] weightsY)
      This does a column oriented grid bag layout. It will layout the given components in a grid with the given number of columns.
      Parameters:
      components - The components to layout
      numberOfColumns - How many columns in the grid layout
      weightsX - Defines how much weight to give to each column width. If there are more columns than weights then we use the last weight.
      weightsY - Defines how much weight to give to each row height. If there are more rows than weights then we use the last weight.
      Returns:
      New panel
    • doLayout

      public static JPanel doLayout(Component[] components, int numberOfColumns, double[] weightsX, double[] weightsY)
      This does a column oriented grid bag layout. It will layout the given components in a grid with the given number of columns.
      Parameters:
      components - The components to layout
      numberOfColumns - How many columns in the grid layout
      weightsX - Defines how much weight to give to each column width. If there are more columns than weights then we use the last weight.
      weightsY - Defines how much weight to give to each row height. If there are more rows than weights then we use the last weight.
      Returns:
      New panel
    • doLayout

      public static JPanel doLayout(JPanel parentContainer, Component[] components, int numberOfColumns, double[] weightsX, double[] weightsY)
      This does a column oriented grid bag layout. It will layout the given components in a grid with the given number of columns.
      Parameters:
      parentContainer - The container to add components to. May be null.
      components - The components to layout
      numberOfColumns - How many columns in the grid layout
      weightsX - Defines how much weight to give to each column width. If there are more columns than weights then we use the last weight.
      weightsY - Defines how much weight to give to each row height. If there are more rows than weights then we use the last weight.
      Returns:
      New panel
    • vbox

      public static JPanel vbox(Component c1, Component c2)
      Layout the given components vertically.
      Parameters:
      c1 - Component 1
      c2 - Component 2
      Returns:
      The new container of the components.
    • vbox

      public static JPanel vbox(Component c1, Component c2, Component c3)
      Layout the given components vertically.
      Parameters:
      c1 - Component 1
      c2 - Component 2
      c3 - Component 3
      Returns:
      The new container of the components.
    • vbox

      public static JPanel vbox(Component c1, Component c2, Component c3, Component c4)
      Layout the given components vertically.
      Parameters:
      c1 - Component 1
      c2 - Component 2
      c3 - Component 3
      c4 - Component 4
      Returns:
      The new container of the components.
    • vbox

      public static JPanel vbox(Component c1, Component c2, Component c3, Component c4, Component c5)
      Layout the given components vertically.
      Parameters:
      c1 - Component 1
      c2 - Component 2
      c3 - Component 3
      c4 - Component 4
      Returns:
      The new container of the components.
    • vbox

      public static JPanel vbox(Component[] components)
      Layout the given components vertically.
      Parameters:
      components - The components
      Returns:
      The new container of the components.
    • toList

      public static List toList(Object[] l)
    • vbox

      public static JPanel vbox(List components)
      Layout the given components vertically.
      Parameters:
      components - The components
      Returns:
      The new container of the components.
    • vbox

      public static JPanel vbox(JPanel panel, List components)
      Layout the given components vertically.
      Parameters:
      panel - The panel to put the components in if on-null.
      components - The components
      Returns:
      The given panel if non-null, else the newly create panel.
    • leftVbox

      public static JPanel leftVbox(List components)
      This places the given components in a vertical orientation, left aligned.
      Parameters:
      components - The components
      Returns:
      The new container of the components.
    • hbox

      public static JPanel hbox(Component c1, Component c2, int spacing)
      Do a horizontal layout of the given components with the given spacing.
      Parameters:
      c1 - Component 1
      c2 - Component 2
      spacing - Inter component spacing
      Returns:
      The new container of the components
    • hbox

      public static JPanel hbox(Component c1, Component c2, Component c3, int spacing)
      Do a horizontal layout of the given components with the given spacing.
      Parameters:
      c1 - Component 1
      c2 - Component 2
      c3 - Component 3
      spacing - Inter component spacing
      Returns:
      The new container of the components
    • hbox

      public static JPanel hbox(Component c1, Component c2)
      Do a horizontal layout of the given components.
      Parameters:
      c1 - Component 1
      c2 - Component 2
      Returns:
      The new container of the components
    • hbox

      public static JPanel hbox(Component c1, Component c2, Component c3)
      Do a horizontal layout of the given components.
      Parameters:
      c1 - Component 1
      c2 - Component 2
      c3 - Component 3
      Returns:
      The new container of the components
    • hbox

      public static JPanel hbox(Component c1, Component c2, Component c3, Component c4)
      Do a horizontal layout of the given components.
      Parameters:
      c1 - Component 1
      c2 - Component 2
      c3 - Component 3
      c4 - Component 4
      Returns:
      The new container of the components
    • hbox

      public static JPanel hbox(List components, int spacing)
      Do a horizontal layout of the given components.
      Parameters:
      components - The components
      spacing - The spacing
      Returns:
      The new container of the components
    • hbox

      public static JPanel hbox(List components)
      Do a horizontal layout of the given components.
      Parameters:
      components - The components
      Returns:
      The new container of the components
    • hbox

      public static JPanel hbox(Component[] components)
      Do a horizontal layout of the given components.
      Parameters:
      components - The components
      Returns:
      The new container of the components
    • hbox

      public static JPanel hbox(Component[] components, int spacing)
      Do a horizontal layout of the given components.
      Parameters:
      components - The components
      spacing - _more_
      Returns:
      The new container of the components
    • hbox

      public static JPanel hbox(JPanel panel, List components)
      Do a horizontal layout of the given components.
      Parameters:
      panel - The panel to use or, if null, we'll create a new on.
      components - The components
      Returns:
      The container of the components
    • hbox

      public static JPanel hbox(JPanel panel, List components, int space)
      Do a horizontal layout of the given components.
      Parameters:
      panel - The panel to use or, if null, we'll create a new on.
      components - The components
      space - SPacing to use
      Returns:
      The container of the components
    • doLayout

      public static JPanel doLayout(JPanel parentContainer, Component[] components, int numberOfColumns, double[] weightsX, double[] weightsY, Hashtable anchors, Hashtable fills, Insets insets)
      This does a column oriented grid bag layout. It will layout the given components in a grid with the given number of columns. It is probably good to read up a bit on GridBagLayout

      The weights define how much weight or spacing to give to the width of each column and the height of each row.

      To define the anchor value, i.e., how to fill a component in its grid square, you can either set the global static member tmpAnchor or, for individual Components you can use the anchors table to provide a mapping from Component to an Integer object holding the anchor value.

      To define the fill value, i.e., how a component expands in its grid square, you can either set the global static member tmpFill or, for individual Components you can use the fills table to provide a mapping from Component to an Integer object holding the fill value.

      If insets is non-null it will use those insets for the spacing in the grid. else if the static member tmpInsets is non-null then it will use those values and then set tmpInsets to null. Else it uses DFLT_INSETS, which is 0 spacing.

      Parameters:
      parentContainer - The container to add components to. May be null.
      components - The components to layout
      numberOfColumns - How many columns in the grid layout
      weightsX - Defines how much weight to give to each column width. If there are more columns than weights then we use the last weight.
      weightsY - Defines how much weight to give to each row height. If there are more rows than weights then we use the last weight.
      anchors - Hashtable that maps Component to the Integer which defines the component anchor
      fills - Hashtable that maps Component to the Integer which defines the component fill
      insets - The insets to use in the grid
      Returns:
      The parentContainer or the new panel if parentContainer is null
    • topLeft

      public static JPanel topLeft(Component top)
      Creates a JPanel and does a BorderLayout-NORTH of the given component
      Parameters:
      top - The component to place
      Returns:
      The new JPanel
    • top

      public static JPanel top(Component top)
      Creates a JPanel and does a BorderLayout-NORTH of the given component
      Parameters:
      top - The component to place
      Returns:
      The new JPanel
    • left

      public static JPanel left(Component left)
      Creates a JPanel and does a BorderLayout.WEST of the given component
      Parameters:
      left - The component to place
      Returns:
      The new JPanel
    • topCenter

      public static JPanel topCenter(Component top, Component center)
      Creates a JPanel and does a BorderLayout NORTH/CENTER of the given components
      Parameters:
      top - The top component
      center - The center component
      Returns:
      The new JPanel
    • topBottom

      public static JPanel topBottom(Component top, Component bottom)
      Creates a JPanel and does a BorderLayout NORTH/BOTTOM of the given components
      Parameters:
      top - The top component
      bottom - The bottom component
      Returns:
      The new JPanel
    • centerBottom

      public static JPanel centerBottom(Component center, Component bottom)
      Creates a JPanel and does a BorderLayout CENTER/SOUTH of the given components
      Parameters:
      center - The center component
      bottom - The bottom component
      Returns:
      The new JPanel
    • bottom

      public static JPanel bottom(Component bottom)
      Creates a JPanel and does a BorderLayout SOUTH of the given component
      Parameters:
      bottom - The bottom component
      Returns:
      The new JPanel
    • center

      public static JPanel center(Component center)
      Creates a JPanel and does a BorderLayout CENTER of the given component
      Parameters:
      center - The center component
      Returns:
      The new JPanel
    • topCenterBottom

      public static JPanel topCenterBottom(Component top, Component center, Component bottom)
      Creates a JPanel and does a BorderLayout of the given components
      Parameters:
      top - The top component (may be null)
      center - The center component (may be null)
      bottom - The bottom component (may be null)
      Returns:
      The new JPanel
    • leftRight

      public static JPanel leftRight(Component left, Component right)
      Creates a JPanel and does a BorderLayout of the given components
      Parameters:
      left - The left component
      right - The right component
      Returns:
      The new panel
    • leftCenterRight

      public static JPanel leftCenterRight(Component left, Component center, Component right)
      Creates a JPanel and does a BorderLayout of the given components
      Parameters:
      left - The left component
      center - The center component
      right - The right component
      Returns:
      The new panel
    • centerRight

      public static JPanel centerRight(Component center, Component right)
      Creates a JPanel and does a BorderLayout of the given components
      Parameters:
      center - The center component
      right - The right component
      Returns:
      The new panel
    • right

      public static JPanel right(Component right)
      Creates a JPanel and does a BorderLayout of the given components
      Parameters:
      right - The right component
      Returns:
      The new panel
    • leftCenter

      public static JPanel leftCenter(Component left, Component center)
      Creates a JPanel and does a BorderLayout of the given components
      Parameters:
      left - The left component
      center - The center component
      Returns:
      The new panel
    • filler

      public static Component filler()
      A utility for having fillers in layout. This just returns an empty JPanel but we have it as a method so calling code can be explicit in what they are intending.
      Returns:
      Filler
    • filler

      public static JComponent filler(int width, int height)
      A utility for having fillers in layout. This just returns an empty JPanel but we have it as a method so calling code can be explicit in what they are intending.
      Parameters:
      width - filler width
      height - filler height
      Returns:
      Filler