001: /* SwingML
002: * Copyright (C) 2002 SwingML Team
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the
016: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
017: * Boston, MA 02111-1307, USA.
018: *
019: * Authors:
020: * Ezequiel Cuellar <ecuellar@crosslogic.com>
021: * Farid Ibrahim <faridibrahim@lycos.com>
022: */
023:
024: package org.swingml.component;
025:
026: import java.awt.BorderLayout;
027: import java.awt.Component;
028: import java.awt.Container;
029: import java.awt.FlowLayout;
030: import java.awt.GridLayout;
031: import java.util.StringTokenizer;
032:
033: import javax.swing.JInternalFrame;
034: import javax.swing.event.InternalFrameEvent;
035: import javax.swing.event.InternalFrameListener;
036:
037: import org.swingml.Constants;
038: import org.swingml.RenderingThread;
039: import org.swingml.SubmittingThread;
040: import org.swingml.event.EventHandler;
041: import org.swingml.model.JInternalFrameModel;
042:
043: public class JInternalFrameComponent extends JInternalFrame implements
044: InternalFrameListener {
045:
046: private EventHandler eventHandler = EventHandler.getInstance();
047: private JInternalFrameModel model = null;
048:
049: public JInternalFrameComponent(JInternalFrameModel aModel) {
050: String theName = aModel.getName();
051: String theText = aModel.getText();
052: String theLayout = aModel.getLayout();
053: String theTooltip = aModel.getTooltip();
054: boolean theIconifiable = aModel.isIconifiable();
055: boolean theClosable = aModel.isClosable();
056: boolean theMaximizable = aModel.isMaximizable();
057: boolean theResizable = aModel.isResizable();
058: int theWidth = aModel.getWidth();
059: int theHeight = aModel.getHeight();
060: super .setName(theName);
061: super .setTitle(theText);
062: super .setToolTipText(theTooltip);
063: super .setSize(theWidth, theHeight);
064: super .setClosable(theClosable);
065: super .setResizable(theResizable);
066: super .setMaximizable(theMaximizable);
067: super .setIconifiable(theIconifiable);
068: this .model = aModel;
069: super .addInternalFrameListener(this );
070: if (theLayout.equalsIgnoreCase(Constants.FLOWLAYOUT)) {
071: super .getContentPane().setLayout(new FlowLayout());
072: }
073: if (theLayout.equalsIgnoreCase(Constants.GRIDLAYOUT)) {
074: super .getContentPane().setLayout(new GridLayout());
075: }
076: if (theLayout.equalsIgnoreCase(Constants.BORDERLAYOUT)) {
077: super .getContentPane().setLayout(new BorderLayout());
078: }
079: if (theLayout.equalsIgnoreCase(Constants.NONE)) {
080: super .getContentPane().setLayout(null);
081: }
082: if (aModel.getLocation() != null) {
083: StringTokenizer theTokens = new StringTokenizer(aModel
084: .getLocation(), ",");
085: int theX = Integer.parseInt(theTokens.nextToken());
086: int theY = Integer.parseInt(theTokens.nextToken());
087: super .setLocation(theX, theY);
088: }
089: }
090:
091: public void submit(String anAddress) {
092: SubmittingThread theThread = new SubmittingThread(anAddress,
093: this , this , true);
094: theThread.start();
095: }
096:
097: public void submit(String anAddress, String aTargetContainer,
098: boolean aRepaint) {
099: Component theTargetContainer = this .eventHandler
100: .findActionTarget(super .getTopLevelAncestor(),
101: aTargetContainer);
102: SubmittingThread theThread = new SubmittingThread(anAddress,
103: this , (Container) theTargetContainer, aRepaint);
104: theThread.start();
105: }
106:
107: public void render(String aUrl, String aParent) {
108: Component theParentComponent = this .eventHandler
109: .findActionTarget(super .getTopLevelAncestor(), aParent);
110: RenderingThread theThread = new RenderingThread(aUrl,
111: (Container) theParentComponent);
112: theThread.start();
113: }
114:
115: private void handleEvent(String aEventType) {
116: Container theTopLevelAncestor = super .getTopLevelAncestor();
117: if (theTopLevelAncestor != null) {
118: this .eventHandler.handleEvent(this .model, aEventType, this );
119: }
120: }
121:
122: // InternalFrameListener Realization.
123: /**
124: * @see javax.swing.event.InternalFrameListener#internalFrameActivated(InternalFrameEvent)
125: */
126: public void internalFrameActivated(InternalFrameEvent aEvt) {
127: this .handleEvent(Constants.WINDOW_ACTIVATED);
128: }
129:
130: /**
131: * @see javax.swing.event.InternalFrameListener#internalFrameClosed(InternalFrameEvent)
132: */
133: public void internalFrameClosed(InternalFrameEvent aEvt) {
134: this .handleEvent(Constants.WINDOW_CLOSED);
135: }
136:
137: /**
138: * @see javax.swing.event.InternalFrameListener#internalFrameClosing(InternalFrameEvent)
139: */
140: public void internalFrameClosing(InternalFrameEvent aEvt) {
141: this .handleEvent(Constants.WINDOW_CLOSING);
142: }
143:
144: /**
145: * @see javax.swing.event.InternalFrameListener#internalFrameDeactivated(InternalFrameEvent)
146: */
147: public void internalFrameDeactivated(InternalFrameEvent aEvt) {
148: this .handleEvent(Constants.WINDOW_DEACTIVATED);
149: }
150:
151: /**
152: * @see javax.swing.event.InternalFrameListener#internalFrameDeiconified(InternalFrameEvent)
153: */
154: public void internalFrameDeiconified(InternalFrameEvent aEvt) {
155: this .handleEvent(Constants.WINDOW_DEICONIFIED);
156: }
157:
158: /**
159: * @see javax.swing.event.InternalFrameListener#internalFrameIconified(InternalFrameEvent)
160: */
161: public void internalFrameIconified(InternalFrameEvent aEvt) {
162: this .handleEvent(Constants.WINDOW_ICONIFIED);
163: }
164:
165: /**
166: * @see javax.swing.event.InternalFrameListener#internalFrameOpened(InternalFrameEvent)
167: */
168: public void internalFrameOpened(InternalFrameEvent aEvt) {
169: this.handleEvent(Constants.WINDOW_OPENED);
170: }
171: }
|