View Javadoc

1   /*
2    * @(#) NamePanel.java Oct 28, 2004
3    * 
4    * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
5    * Delft, the Netherlands. All rights reserved.
6    * 
7    * See for project information <a href="http://www.simulation.tudelft.nl/">
8    * www.simulation.tudelft.nl </a>.
9    * 
10   * The source code and binary code of this software is proprietary information
11   * of Delft University of Technology.
12   */
13  package org.gscg.gameleader.dialogs.actor.components;
14  
15  import info.clearthought.layout.TableLayout;
16  import info.clearthought.layout.TableLayoutConstants;
17  
18  import java.awt.Color;
19  import java.awt.Component;
20  import java.io.IOException;
21  import java.net.URL;
22  
23  import javax.swing.JEditorPane;
24  import javax.swing.JLabel;
25  import javax.swing.JPanel;
26  import javax.swing.SwingConstants;
27  
28  import nl.tudelft.simulation.actor.ActorInterface;
29  import nl.tudelft.simulation.language.io.URLResource;
30  import nl.tudelft.simulation.logger.Logger;
31  import nl.tudelft.simulation.supplychain.actor.SupplyChainActor;
32  
33  import org.gscg.gameleader.dialogs.components.AbstractPanel;
34  
35  /***
36   * The NamePanel is used to display the name of an actor.
37   * <p>
38   * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
39   * Delft, the Netherlands. All rights reserved.
40   * 
41   * See for project information <a href="http://www.simulation.tudelft.nl/">
42   * www.simulation.tudelft.nl </a>.
43   * 
44   * The source code and binary code of this software is proprietary information
45   * of Delft University of Technology.
46   * 
47   * @author <a
48   *         href="http://www.tbm.tudelft.nl/webstaf/stijnh/index.htm">Stijn-Pieter
49   *         van Houten </a>
50   * @version $Revision: 1.1 $ $Date: 2005/06/16 12:33:58 $
51   * @since 1.0.3
52   */
53  public class NamePanel extends AbstractPanel
54  {
55  	/*** the serial version uid */
56  	private static final long serialVersionUID = 11L;
57  
58  	/*** the actor */
59  	private ActorInterface actor = null;
60  
61  	/***
62  	 * constructs a new NamePanel
63  	 * 
64  	 * @param actor the actor
65  	 */
66  	public NamePanel(final Object actor)
67  	{
68  		super("general information");
69  		try
70  		{
71  			this.actor = (SupplyChainActor) actor;
72  		} catch (Exception exception)
73  		{
74  			// ignore, the Logger statement below will notify us
75  			exception = null;
76  		}
77  		if (this.actor != null)
78  		{
79  			this.initialize();
80  		} else
81  		{
82  			Logger.severe(this, "<init>",
83  					"Could not extract actor from received object of class: "
84  							+ actor.getClass());
85  		}
86  	}
87  
88  	/***
89  	 * @see org.gscg.gameleader.dialogs.components.AbstractPanel#initialize()
90  	 */
91  	protected void initialize()
92  	{
93  		JPanel nameLabelPanel = new JPanel();
94  		double[][] nameLabelPanelLayout = {
95  				{TableLayoutConstants.FILL, TableLayoutConstants.FILL}, {20}};
96  		nameLabelPanel.setLayout(new TableLayout(nameLabelPanelLayout));
97  		nameLabelPanel.setBackground(Color.WHITE);
98  
99  		JLabel label = super.getFormattedLabel("name");
100 		nameLabelPanel.add(label, "0,0,L,C");
101 
102 		JLabel actorNameLabel = super.getFormattedLabel(this.actor.getName());
103 		actorNameLabel.setHorizontalAlignment(SwingConstants.RIGHT);
104 		nameLabelPanel.add(actorNameLabel, "1,0,R,C");
105 
106 		// the information about the actor
107 		URL description = URLResource.getResource("/html/"
108 				+ this.actor.getName() + ".html");
109 		JEditorPane descriptionPane = null;
110 		try
111 		{
112 			descriptionPane = new JEditorPane(description);
113 		} catch (IOException exception)
114 		{
115 			description = URLResource.getResource("/general_info.html");
116 			try
117 			{
118 				descriptionPane = new JEditorPane(description);
119 			} catch (IOException exception2)
120 			{
121 				Logger.warning(this, "initialize", exception2);
122 				descriptionPane = new JEditorPane();
123 			}
124 		}
125 		descriptionPane.setAlignmentY(Component.CENTER_ALIGNMENT);
126 		descriptionPane.setAlignmentX(Component.CENTER_ALIGNMENT);
127 		descriptionPane.setEditable(false);
128 		descriptionPane.setFocusable(false);
129 		descriptionPane.setBackground(Color.WHITE);
130 		descriptionPane.setVisible(true);
131 
132 		// setup the panel
133 		double[][] panelLayout = {{TableLayoutConstants.FILL},
134 				{20, TableLayoutConstants.FILL}};
135 		super.setLayout(new TableLayout(panelLayout));
136 
137 		// add the components
138 		super.add(nameLabelPanel, "0,0,L,C");
139 		super.add(descriptionPane, "0,1,L,C");
140 
141 		// we need this to make sure the description pane
142 		// is visible at the first time a dialog is opened
143 		super.validate();
144 		super.doLayout();
145 	}
146 }