Package org.swingml.component

Source Code of org.swingml.component.JInternalFrameComponent

/* SwingML
* Copyright (C) 2002 SwingML Team
*
* 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:
*     Ezequiel Cuellar <ecuellar@crosslogic.com>
*     Farid Ibrahim <faridibrahim@lycos.com>
*/

package org.swingml.component;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.util.StringTokenizer;

import javax.swing.JInternalFrame;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameListener;

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



public class JInternalFrameComponent extends JInternalFrame implements InternalFrameListener {

    private EventHandler eventHandler = EventHandler.getInstance();
    private JInternalFrameModel model = null;

    public JInternalFrameComponent(JInternalFrameModel aModel) {
        String theName = aModel.getName();
        String theText = aModel.getText();
        String theLayout = aModel.getLayout();
        String theTooltip = aModel.getTooltip();
        boolean theIconifiable = aModel.isIconifiable();
        boolean theClosable = aModel.isClosable();
        boolean theMaximizable = aModel.isMaximizable();
        boolean theResizable = aModel.isResizable();
        int theWidth = aModel.getWidth();
        int theHeight = aModel.getHeight();
        super.setName(theName);
        super.setTitle(theText);
        super.setToolTipText(theTooltip);
        super.setSize(theWidth, theHeight);
        super.setClosable(theClosable);
        super.setResizable(theResizable);
        super.setMaximizable(theMaximizable);
        super.setIconifiable(theIconifiable);
        this.model = aModel;
        super.addInternalFrameListener(this);
        if (theLayout.equalsIgnoreCase(Constants.FLOWLAYOUT)) {
            super.getContentPane().setLayout(new FlowLayout());
        }
        if (theLayout.equalsIgnoreCase(Constants.GRIDLAYOUT)) {
            super.getContentPane().setLayout(new GridLayout());
        }
        if (theLayout.equalsIgnoreCase(Constants.BORDERLAYOUT)) {
            super.getContentPane().setLayout(new BorderLayout());
        }
        if (theLayout.equalsIgnoreCase(Constants.NONE)) {
            super.getContentPane().setLayout(null);
        }
        if (aModel.getLocation() != null) {
            StringTokenizer theTokens = new StringTokenizer(aModel.getLocation(), ",");
            int theX = Integer.parseInt(theTokens.nextToken());
            int theY = Integer.parseInt(theTokens.nextToken());
            super.setLocation(theX, theY);
        }
    }

    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();
    }

    private void handleEvent(String aEventType) {
        Container theTopLevelAncestor = super.getTopLevelAncestor();
        if (theTopLevelAncestor != null) {
            this.eventHandler.handleEvent(this.model, aEventType, this);
        }
    }

    // InternalFrameListener Realization.
    /**
     * @see javax.swing.event.InternalFrameListener#internalFrameActivated(InternalFrameEvent)
     */
    public void internalFrameActivated(InternalFrameEvent aEvt) {
        this.handleEvent(Constants.WINDOW_ACTIVATED);
    }

    /**
     * @see javax.swing.event.InternalFrameListener#internalFrameClosed(InternalFrameEvent)
     */
    public void internalFrameClosed(InternalFrameEvent aEvt) {
        this.handleEvent(Constants.WINDOW_CLOSED);
    }

    /**
     * @see javax.swing.event.InternalFrameListener#internalFrameClosing(InternalFrameEvent)
     */
    public void internalFrameClosing(InternalFrameEvent aEvt) {
        this.handleEvent(Constants.WINDOW_CLOSING);
    }

    /**
     * @see javax.swing.event.InternalFrameListener#internalFrameDeactivated(InternalFrameEvent)
     */
    public void internalFrameDeactivated(InternalFrameEvent aEvt) {
        this.handleEvent(Constants.WINDOW_DEACTIVATED);
    }

    /**
     * @see javax.swing.event.InternalFrameListener#internalFrameDeiconified(InternalFrameEvent)
     */
    public void internalFrameDeiconified(InternalFrameEvent aEvt) {
        this.handleEvent(Constants.WINDOW_DEICONIFIED);
    }

    /**
     * @see javax.swing.event.InternalFrameListener#internalFrameIconified(InternalFrameEvent)
     */
    public void internalFrameIconified(InternalFrameEvent aEvt) {
        this.handleEvent(Constants.WINDOW_ICONIFIED);
    }

    /**
     * @see javax.swing.event.InternalFrameListener#internalFrameOpened(InternalFrameEvent)
     */
    public void internalFrameOpened(InternalFrameEvent aEvt) {
        this.handleEvent(Constants.WINDOW_OPENED);
    }
}
TOP

Related Classes of org.swingml.component.JInternalFrameComponent

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.