Package org.swingml.component

Source Code of org.swingml.component.GridBagPanelComponent

/* SwingML
* Copyright (C) 2002 Robert Morris.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Authors:
*     Robert Morris <robertj@morris.net>
*
*/

package org.swingml.component;

import java.awt.Component;
import java.awt.Container;
import java.awt.GridBagLayout;
import java.util.Vector;

import javax.swing.JPanel;
import javax.swing.border.BevelBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;

import org.swingml.Constants;
import org.swingml.RenderingThread;
import org.swingml.SubmittingThread;
import org.swingml.event.EventHandler;
import org.swingml.model.GridBagPanelModel;



/**
* This class provides the actual instantiation and management of the
* &lt;GRIDBAG-PANEL&gt; tag on the rendered form.  This class operates
* essentially as a SwingML-style wrapper around a standard JPanel
* that lays out its child components using GridBagLayout.
* The overridden add() method accepts GridBagRowComponents that in
* turn contain GridBagCell components which themselves contain the actual
* references to the component to display within the GridBagPanelComponent
* instance.  The detailed parameters regarding the layout settings for each
* component are hierarchically stored within the GridBagRowModel and GridBagCellModel
* components passed in during the add() invocation.
*/
public class GridBagPanelComponent extends JPanel {
    private EventHandler eventHandler = EventHandler.getInstance();
    private GridBagPanelModel m_model = null;
    private Vector m_rows = new Vector();

    /**
     * This overridden method handles the addition of GridBagRow components.
     * It is also important to note that after rendering is complete, it is possible
     * for InvokableEvent instances to call add() with other component instances.
     *
     * @param  component  The component to add to the current GridBagPanelComponent instance.
     *
     * @return  The component that was added to the GridBagPanelComponent.
     *
     * @see org.swingml.component.GridBagRowComponent
     *
     */
    public Component add(Component aComponent) {
        if (aComponent instanceof GridBagRowComponent) {
            GridBagRowComponent theComponent = (GridBagRowComponent) aComponent;
            theComponent.setParentPanel(this);
            this.m_rows.add(aComponent);
        } else {
            super.add(aComponent);
        }
        return aComponent;
    }

    /**
     * @see javax.swing.JPanel#add(Component, Object)
     */
    public void add(Component aComponent, Object aConstraints) {
        super.add(aComponent, aConstraints);
    }

    public void submit(String anAddress) {
        SubmittingThread theThread = new SubmittingThread(anAddress, this, this, true);
        theThread.start();
    }

    public void submit(String anAddress, String aTargetContainer, boolean aRepaint) {
        Component theTargetContainer = this.eventHandler.findActionTarget(super.getTopLevelAncestor(), aTargetContainer);
        SubmittingThread theThread = new SubmittingThread(anAddress, this, (Container) theTargetContainer, aRepaint);
        theThread.start();
    }

    public void render(String aUrl, String aParent) {
        Component theParentComponent = this.eventHandler.findActionTarget(super.getTopLevelAncestor(), aParent);
        RenderingThread theThread = new RenderingThread(aUrl, (Container) theParentComponent);
        theThread.start();
    }

    /**
     * Constructor for GridBagPanelComponent.  This
     * constructor essentially sets the layout to GridBagLayout
     * and assigns the necessary model information to properties
     * of this component.
     *
     * @param  model  A valid reference to an instance of the GridBagPanelModel class.
     *
     * @see org.swingml.model.GridBagPanelModel
     */
    public GridBagPanelComponent(GridBagPanelModel aModel) {
        this.m_model = aModel;
        super.setLayout(new GridBagLayout());
        super.setName(this.m_model.getName());
        String theBorder = this.m_model.getBorder();
        String theTitle = this.m_model.getTitle();
        int theBevelType = this.m_model.getBevelType();

        if (theBorder.equalsIgnoreCase(Constants.ETCHEDBORDER)) {
            if (theTitle == null) {
                super.setBorder(new EtchedBorder());
            } else {
                super.setBorder(new TitledBorder(new EtchedBorder(), theTitle));
            }
        }
        if (theBorder.equalsIgnoreCase(Constants.BEVELBORDER)) {
            if (theTitle == null) {
                super.setBorder(new BevelBorder(theBevelType));
            } else {
                super.setBorder(new TitledBorder(new BevelBorder(theBevelType), theTitle));
            }
        }
    }
}
TOP

Related Classes of org.swingml.component.GridBagPanelComponent

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.