/* 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>
*
*/
package org.swingml.component;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.JDesktopPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.BevelBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
import org.swingml.Constants;
import org.swingml.ExternalLookAndFeel;
import org.swingml.RenderingThread;
import org.swingml.SubmittingThread;
import org.swingml.SwingMLRenderer;
import org.swingml.URLHandler;
import org.swingml.event.EventHandler;
import org.swingml.model.JDesktopPaneModel;
import org.swingml.system.*;
public class JDesktopPaneComponent extends JDesktopPane {
private EventHandler eventHandler = EventHandler.getInstance();
public JDesktopPaneComponent(JDesktopPaneModel aModel) {
try {
String theName = aModel.getName();
String theBorder = aModel.getBorder();
String theLayout = aModel.getLayout();
String theLookAndFeel = aModel.getLookAndFeel();
String theTooltip = aModel.getTooltip();
String theTitle = aModel.getTitle();
int theBevelType = aModel.getBevelType();
int theRows = aModel.getRows();
int theCols = aModel.getCols();
super.setName(theName);
super.setToolTipText(theTooltip);
super.setBackground(new Color(-1118482));
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));
}
}
if (theLayout.equalsIgnoreCase(Constants.FLOWLAYOUT)) {
super.setLayout(new FlowLayout());
}
if (theLayout.equalsIgnoreCase(Constants.GRIDLAYOUT)) {
super.setLayout(new GridLayout(theRows, theCols));
}
if (theLayout.equalsIgnoreCase(Constants.BORDERLAYOUT)) {
super.setLayout(new BorderLayout());
}
if (theLayout.equalsIgnoreCase(Constants.NONE)) {
super.setLayout(null);
}
if (theLookAndFeel != null) {
if (theLookAndFeel.equalsIgnoreCase(Constants.METAL)) {
UIManager.setLookAndFeel(Constants.METAL_LAF);
}
if (theLookAndFeel.equalsIgnoreCase(Constants.WINDOWS)) {
UIManager.setLookAndFeel(Constants.WINDOWS_LAF);
}
if (theLookAndFeel.equalsIgnoreCase(Constants.MOTIF)) {
UIManager.setLookAndFeel(Constants.MOTIF_LAF);
}
if (theLookAndFeel.equalsIgnoreCase(Constants.EXTERNAL)) {
String theExternalLaf = aModel.getExternalLookAndFeel();
if (theExternalLaf != null && theExternalLaf.length() > 0) {
/*
* Create an instance of the External Look and feel implementation.
*/
ExternalLookAndFeel laf = (ExternalLookAndFeel) Class.forName(aModel.getExternalLookAndFeel()).newInstance();
javax.swing.LookAndFeel newLaf = laf.getLookAndFeel();
UIManager.setLookAndFeel(newLaf);
}
}
}
} catch (ClassNotFoundException e) {
SwingMLLogger.getInstance().log(e);
} catch (IllegalAccessException e) {
SwingMLLogger.getInstance().log(e);
} catch (UnsupportedLookAndFeelException e) {
SwingMLLogger.getInstance().log(e);
} catch (InstantiationException e) {
SwingMLLogger.getInstance().log(e);
}
}
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 showDocument(String aUrl, String aTarget) {
SwingMLRenderer theSwingmlRenderer = ((SwingMLRenderer) super.getTopLevelAncestor());
theSwingmlRenderer.getAppletContext().showDocument(URLHandler.handle(aUrl), aTarget);
}
public void render(String aUrl, String aParent) {
Component theParentComponent = this.eventHandler.findActionTarget(super.getTopLevelAncestor(), aParent);
RenderingThread theThread = new RenderingThread(aUrl, (Container) theParentComponent);
theThread.start();
}
}