View Javadoc

1   /*
2    *  Copyright (C) 2004  The Concord Consortium, Inc.,
3    *  10 Concord Crossing, Concord, MA 01742
4    *
5    *  Web Site: http://www.concord.org
6    *  Email: info@concord.org
7    *
8    *  This library is free software; you can redistribute it and/or
9    *  modify it under the terms of the GNU Lesser General Public
10   *  License as published by the Free Software Foundation; either
11   *  version 2.1 of the License, or (at your option) any later version.
12   *
13   *  This library is distributed in the hope that it will be useful,
14   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16   *  Lesser General Public License for more details.
17   *
18   *  You should have received a copy of the GNU Lesser General Public
19   *  License along with this library; if not, write to the Free Software
20   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21   *
22   * END LICENSE */
23  
24  package org.telscenter.pas.pedagogica;
25  
26  import java.awt.Component;
27  import java.io.IOException;
28  import java.net.MalformedURLException;
29  import java.net.URL;
30  
31  import javax.swing.JComponent;
32  
33  import org.concord.models.HyperModel;
34  
35  public class HyperModelComponent extends JComponent
36  {
37  	protected URL modelURL;
38  	protected HyperModel hyperModel = new HyperModel();
39  
40  	public HyperModelComponent()
41  	{
42  
43  	}
44  
45  	public void setModel(String urlString)
46  	{
47  		try
48  		{
49  			modelURL = new URL(urlString);
50  			hyperModel.restore(modelURL.openStream());
51  			Object value = hyperModel.getProperty("mainComponent");
52  			if (value instanceof Component)
53  			{
54  				if (value instanceof JComponent)
55  				{
56  					setPreferredSize(((JComponent) value).getPreferredSize());
57  				}
58  				setSize(((Component) value).getSize());
59  				add((Component) value);
60  			}
61  		}
62  		catch (MalformedURLException e)
63  		{
64  			// TODO Auto-generated catch block
65  			e.printStackTrace();
66  		}
67  		catch (IOException e)
68  		{
69  			// TODO Auto-generated catch block
70  			e.printStackTrace();
71  		}
72  	}
73  }