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: *
022: */
023:
024: package org.swingml.component;
025:
026: import java.awt.BorderLayout;
027: import java.awt.Color;
028: import java.awt.Component;
029: import java.awt.Container;
030: import java.awt.FlowLayout;
031: import java.awt.GridLayout;
032:
033: import javax.swing.JDesktopPane;
034: import javax.swing.UIManager;
035: import javax.swing.UnsupportedLookAndFeelException;
036: import javax.swing.border.BevelBorder;
037: import javax.swing.border.EtchedBorder;
038: import javax.swing.border.TitledBorder;
039:
040: import org.swingml.Constants;
041: import org.swingml.ExternalLookAndFeel;
042: import org.swingml.RenderingThread;
043: import org.swingml.SubmittingThread;
044: import org.swingml.SwingMLRenderer;
045: import org.swingml.URLHandler;
046: import org.swingml.event.EventHandler;
047: import org.swingml.model.JDesktopPaneModel;
048: import org.swingml.system.*;
049:
050: public class JDesktopPaneComponent extends JDesktopPane {
051:
052: private EventHandler eventHandler = EventHandler.getInstance();
053:
054: public JDesktopPaneComponent(JDesktopPaneModel aModel) {
055: try {
056: String theName = aModel.getName();
057: String theBorder = aModel.getBorder();
058: String theLayout = aModel.getLayout();
059: String theLookAndFeel = aModel.getLookAndFeel();
060: String theTooltip = aModel.getTooltip();
061: String theTitle = aModel.getTitle();
062: int theBevelType = aModel.getBevelType();
063: int theRows = aModel.getRows();
064: int theCols = aModel.getCols();
065: super .setName(theName);
066: super .setToolTipText(theTooltip);
067: super .setBackground(new Color(-1118482));
068: if (theBorder.equalsIgnoreCase(Constants.ETCHEDBORDER)) {
069: if (theTitle == null) {
070: super .setBorder(new EtchedBorder());
071: } else {
072: super .setBorder(new TitledBorder(
073: new EtchedBorder(), theTitle));
074: }
075: }
076: if (theBorder.equalsIgnoreCase(Constants.BEVELBORDER)) {
077: if (theTitle == null) {
078: super .setBorder(new BevelBorder(theBevelType));
079: } else {
080: super .setBorder(new TitledBorder(new BevelBorder(
081: theBevelType), theTitle));
082: }
083: }
084: if (theLayout.equalsIgnoreCase(Constants.FLOWLAYOUT)) {
085: super .setLayout(new FlowLayout());
086: }
087: if (theLayout.equalsIgnoreCase(Constants.GRIDLAYOUT)) {
088: super .setLayout(new GridLayout(theRows, theCols));
089: }
090: if (theLayout.equalsIgnoreCase(Constants.BORDERLAYOUT)) {
091: super .setLayout(new BorderLayout());
092: }
093: if (theLayout.equalsIgnoreCase(Constants.NONE)) {
094: super .setLayout(null);
095: }
096: if (theLookAndFeel != null) {
097: if (theLookAndFeel.equalsIgnoreCase(Constants.METAL)) {
098: UIManager.setLookAndFeel(Constants.METAL_LAF);
099: }
100: if (theLookAndFeel.equalsIgnoreCase(Constants.WINDOWS)) {
101: UIManager.setLookAndFeel(Constants.WINDOWS_LAF);
102: }
103: if (theLookAndFeel.equalsIgnoreCase(Constants.MOTIF)) {
104: UIManager.setLookAndFeel(Constants.MOTIF_LAF);
105: }
106: if (theLookAndFeel.equalsIgnoreCase(Constants.EXTERNAL)) {
107: String theExternalLaf = aModel
108: .getExternalLookAndFeel();
109: if (theExternalLaf != null
110: && theExternalLaf.length() > 0) {
111: /*
112: * Create an instance of the External Look and feel implementation.
113: */
114: ExternalLookAndFeel laf = (ExternalLookAndFeel) Class
115: .forName(
116: aModel.getExternalLookAndFeel())
117: .newInstance();
118: javax.swing.LookAndFeel newLaf = laf
119: .getLookAndFeel();
120: UIManager.setLookAndFeel(newLaf);
121: }
122: }
123: }
124: } catch (ClassNotFoundException e) {
125: SwingMLLogger.getInstance().log(e);
126: } catch (IllegalAccessException e) {
127: SwingMLLogger.getInstance().log(e);
128: } catch (UnsupportedLookAndFeelException e) {
129: SwingMLLogger.getInstance().log(e);
130: } catch (InstantiationException e) {
131: SwingMLLogger.getInstance().log(e);
132: }
133: }
134:
135: public void submit(String anAddress) {
136: SubmittingThread theThread = new SubmittingThread(anAddress,
137: this , this , true);
138: theThread.start();
139: }
140:
141: public void submit(String anAddress, String aTargetContainer,
142: boolean aRepaint) {
143: Component theTargetContainer = this .eventHandler
144: .findActionTarget(super .getTopLevelAncestor(),
145: aTargetContainer);
146: SubmittingThread theThread = new SubmittingThread(anAddress,
147: this , (Container) theTargetContainer, aRepaint);
148: theThread.start();
149: }
150:
151: public void showDocument(String aUrl, String aTarget) {
152: SwingMLRenderer theSwingmlRenderer = ((SwingMLRenderer) super
153: .getTopLevelAncestor());
154: theSwingmlRenderer.getAppletContext().showDocument(
155: URLHandler.handle(aUrl), aTarget);
156: }
157:
158: public void render(String aUrl, String aParent) {
159: Component theParentComponent = this .eventHandler
160: .findActionTarget(super .getTopLevelAncestor(), aParent);
161: RenderingThread theThread = new RenderingThread(aUrl,
162: (Container) theParentComponent);
163: theThread.start();
164: }
165: }
|