org.mlc.swing.layout
Class LayoutConstraintsManager

java.lang.Object
  extended by org.mlc.swing.layout.LayoutConstraintsManager

public class LayoutConstraintsManager
extends java.lang.Object

This class handles the serialization and deserialization of the xml files that we are using to store the layout constraints.

In the consuming program, the use of this class might look like:
InputStream constraints = this.getClass().getResourceAsStream(xmlFile); LayoutConstraintsManager layoutConstraintsManager = LayoutConstraintsManager.getLayoutConstraintsManager(constraints); LayoutManager layout = layoutConstraintsManager.createLayout("panel", this); this.setLayout(layout);

[I'm sure there are more elegant ways of handling this (like JAXB) or some other mapping software but this is simple, it works, and we don't have to package a bunch of other software or files.]

Author:
Michael Connor

Field Summary
static java.lang.String BOTTOM
           
static java.lang.String CENTER
           
static java.lang.String DEFAULT
           
static java.lang.String FILL
           
static java.lang.String LEFT
           
static java.lang.String RIGHT
           
static java.lang.String TOP
           
 
Constructor Summary
LayoutConstraintsManager()
          This method will create a LayoutConstraintsManager with default JGoodies row and column specs that are common in applications.
LayoutConstraintsManager(java.lang.String defaultColumnSpecs, java.lang.String defaultRowSpecs)
          This method will create a LayoutConstraintsManager with the JGoodies specs provided as default
 
Method Summary
 void addLayout(ContainerLayout containerLayout)
           
 ContainerLayout createLayout(java.lang.String name, java.awt.Container container)
          This method creates a layout by first trying to look in memory to see if a layout has been defined with the given name.
static java.lang.String getAlignment(com.jgoodies.forms.layout.CellConstraints.Alignment alignment)
          Translates an alignment value to a string.
static com.jgoodies.forms.layout.CellConstraints.Alignment getAlignment(java.lang.String value)
          Translates a string to an alignment value.
 java.awt.Container getContainer(ContainerLayout layout)
           
 ContainerLayout getContainerLayout(java.lang.String containerName)
           
static LayoutConstraintsManager getLayoutConstraintsManager(java.io.InputStream stream)
          Returns a LayoutConstraintsManager based on an input stream for an xml file.
static LayoutConstraintsManager getLayoutConstraintsManager(org.w3c.dom.Node containersNode)
          Returns a layout constraints manager given a containers node.
 java.util.List<ContainerLayout> getLayouts()
           
 java.lang.String getXML()
          Get an XML representation of the FormLayout constraints for all containers in this manager.
static boolean isTextComponent(java.awt.Component component)
           
static void main(java.lang.String[] args)
           
 void removeLayout(ContainerLayout containerLayout)
           
 void setLayout(java.lang.String name, java.awt.Container container)
          This method will build a layout from the xml file based on the name and call setLayout on the container passed in.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT

public static final java.lang.String DEFAULT
See Also:
Constant Field Values

FILL

public static final java.lang.String FILL
See Also:
Constant Field Values

CENTER

public static final java.lang.String CENTER
See Also:
Constant Field Values

LEFT

public static final java.lang.String LEFT
See Also:
Constant Field Values

RIGHT

public static final java.lang.String RIGHT
See Also:
Constant Field Values

TOP

public static final java.lang.String TOP
See Also:
Constant Field Values

BOTTOM

public static final java.lang.String BOTTOM
See Also:
Constant Field Values
Constructor Detail

LayoutConstraintsManager

public LayoutConstraintsManager()
This method will create a LayoutConstraintsManager with default JGoodies row and column specs that are common in applications. The user can then manipulate these default specs using the LayoutFrame to fine tune the specs to be whatever they want.


LayoutConstraintsManager

public LayoutConstraintsManager(java.lang.String defaultColumnSpecs,
                                java.lang.String defaultRowSpecs)
This method will create a LayoutConstraintsManager with the JGoodies specs provided as default

Method Detail

getLayouts

public java.util.List<ContainerLayout> getLayouts()

setLayout

public void setLayout(java.lang.String name,
                      java.awt.Container container)
This method will build a layout from the xml file based on the name and call setLayout on the container passed in.


createLayout

public ContainerLayout createLayout(java.lang.String name,
                                    java.awt.Container container)
This method creates a layout by first trying to look in memory to see if a layout has been defined with the given name. If a layout exists, it is returned. Note that when I say in memory that probably means that it was defined in the xml file. If one doesn't exist, a layout with what I consider relatively generic constraints will be created and returned. The reason this method requires the container is because in the case where you are trying to layout the container visually, I need to be able to get a handle on the container so I can make calls to add components to it during interactive layout. This will not be touched at runtime if you are not doing anything interactively. This method should be seen as a replacement for LayoutConstraintsManager.setLayout(String name, Container container) as it's more natural to set the layout on the container yourself.


getContainer

public java.awt.Container getContainer(ContainerLayout layout)

getContainerLayout

public ContainerLayout getContainerLayout(java.lang.String containerName)

removeLayout

public void removeLayout(ContainerLayout containerLayout)

addLayout

public void addLayout(ContainerLayout containerLayout)

getXML

public java.lang.String getXML()
Get an XML representation of the FormLayout constraints for all containers in this manager.


isTextComponent

public static boolean isTextComponent(java.awt.Component component)

getAlignment

public static java.lang.String getAlignment(com.jgoodies.forms.layout.CellConstraints.Alignment alignment)
Translates an alignment value to a string.


getAlignment

public static com.jgoodies.forms.layout.CellConstraints.Alignment getAlignment(java.lang.String value)
Translates a string to an alignment value.


getLayoutConstraintsManager

public static LayoutConstraintsManager getLayoutConstraintsManager(java.io.InputStream stream)
Returns a LayoutConstraintsManager based on an input stream for an xml file. The root node in the xml file should be called containers and should adhere to the xml format for this tool.


getLayoutConstraintsManager

public static LayoutConstraintsManager getLayoutConstraintsManager(org.w3c.dom.Node containersNode)
Returns a layout constraints manager given a containers node. This will enable you to keep a lot of different constraints in a single file or at least provide a little more flexibility.


main

public static void main(java.lang.String[] args)