Package cookxml.cookswing.creator

Source Code of cookxml.cookswing.creator.SpringGridCreator

/*
* (c) Copyright 2004 by Heng Yuan
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* ITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package cookxml.cookswing.creator;

import java.awt.*;
import java.util.Iterator;
import javax.swing.*;

import org.w3c.dom.Element;

import cookxml.cookswing.helper.SpringGridHelper;
import cookxml.cookswing.util.SpringLayoutUtilities;
import cookxml.core.DecodeEngine;
import cookxml.core.interfaces.Creator;

/**
* This creator creates a SpringGridHelper object, and when finished, it layout
* the components in a grid using SpringLayout.
*
* @see javax.swing.SpringLayout
* @see cookxml.cookswing.util.SpringLayoutUtilities
* @author Heng Yuan
* @version $Id: SpringGridCreator.java 233 2007-06-06 08:08:49Z coconut $
* @since CookSwing 1.0
*/
public class SpringGridCreator implements Creator
{
  public Object create (String parentNS, String parentTag, Element elm, Object parentObj, DecodeEngine decodeEngine)
  {
    if (parentObj == null ||
        !(parentObj instanceof Container))
      return null;
    return new SpringGridHelper ();
  }

  public Object editFinished (String parentNS, String parentTag, Element elm, Object parentObj, Object obj, DecodeEngine decodeEngine)
  {
    if (parentObj == null || obj == null ||
      !(parentObj instanceof Container) ||
      !(obj instanceof SpringGridHelper))
      return obj;

    Container container = (Container)parentObj;
    container.setLayout (new SpringLayout ());
    SpringGridHelper helper = (SpringGridHelper)obj;
    for (Iterator iter = helper.getComponents ().iterator (); iter.hasNext ();)
      container.add ((Component)iter.next ());

    if (helper.compact)
      SpringLayoutUtilities.makeCompactGrid (container, helper.rows, helper.columns,
                           helper.initialX, helper.initialY, helper.hgap, helper.vgap);
    else
      SpringLayoutUtilities.makeGrid (container, helper.rows, helper.columns,
                      helper.initialX, helper.initialY, helper.hgap, helper.vgap);
    return obj;
  }
}
TOP

Related Classes of cookxml.cookswing.creator.SpringGridCreator

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.