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.]

Since:
Ptolemy II 8.0
Version:
$Id: LayoutConstraintsManager.java 57044 2010-01-27 22:41:05Z cxh $
Author:
Michael Connor

Field Summary
static java.lang.String BOTTOM
           
static java.lang.String CENTER
           
(package private)  java.util.Map<ContainerLayout,java.awt.Container> containers
           
static java.lang.String DEFAULT
           
(package private)  java.lang.String defaultColumnSpecs
           
(package private)  java.lang.String defaultRowSpecs
           
static java.lang.String FILL
           
(package private)  java.util.List<ContainerLayout> layouts
           
static java.lang.String LEFT
           
static java.lang.String RIGHT
           
(package private) static java.util.Set<java.lang.Class> textComponents
           
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.
private static java.lang.String createString(org.w3c.dom.NodeList childNodes)
           
static java.lang.String getAlignment(CellConstraints.Alignment alignment)
          Translates an alignment value to a string.
static CellConstraints.Alignment getAlignment(java.lang.String value)
          Translates a string to an alignment value.
private static java.util.Map<java.lang.String,java.lang.String> getAttributeMap(org.w3c.dom.Node node)
           
 java.awt.Container getContainer(ContainerLayout layout)
           
 ContainerLayout getContainerLayout(java.lang.String containerName)
           
private  ContainerLayout getLayout(java.lang.String name)
           
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()
           
private static org.w3c.dom.Node[] getNodesNamed(org.w3c.dom.Node parent, java.lang.String nodeName)
           
 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

defaultColumnSpecs

java.lang.String defaultColumnSpecs

defaultRowSpecs

java.lang.String defaultRowSpecs

textComponents

static java.util.Set<java.lang.Class> textComponents

containers

java.util.Map<ContainerLayout,java.awt.Container> containers

layouts

java.util.List<ContainerLayout> layouts

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)

getLayout

private ContainerLayout getLayout(java.lang.String name)

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)

createString

private static java.lang.String createString(org.w3c.dom.NodeList childNodes)

getAlignment

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


getAlignment

public static 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.


getAttributeMap

private static java.util.Map<java.lang.String,java.lang.String> getAttributeMap(org.w3c.dom.Node node)

getNodesNamed

private static org.w3c.dom.Node[] getNodesNamed(org.w3c.dom.Node parent,
                                                java.lang.String nodeName)

main

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