View Javadoc

1   /*
2    * @(#) OrderConfirmationContentPanel.java Oct 28, 2004
3    * 
4    * 
5    * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
6    * Delft, the Netherlands. All rights reserved.
7    * 
8    * See for project information <a href="http://www.simulation.tudelft.nl/">
9    * www.simulation.tudelft.nl </a>.
10   * 
11   * The source code and binary code of this software is proprietary information
12   * of Delft University of Technology.
13   */
14  package org.gscg.gameleader.dialogs.content.components;
15  
16  import info.clearthought.layout.TableLayout;
17  import info.clearthought.layout.TableLayoutConstants;
18  
19  import java.awt.Color;
20  import java.awt.Component;
21  import java.io.IOException;
22  import java.net.URL;
23  
24  import javax.swing.JEditorPane;
25  import javax.swing.JLabel;
26  import javax.swing.JPanel;
27  import javax.swing.JScrollPane;
28  import javax.swing.ScrollPaneConstants;
29  import javax.swing.SwingConstants;
30  
31  import nl.tudelft.simulation.language.io.URLResource;
32  import nl.tudelft.simulation.logger.Logger;
33  import nl.tudelft.simulation.supplychain.content.OrderConfirmation;
34  
35  import org.gscg.gameleader.dialogs.components.AbstractPanel;
36  
37  /***
38   * The OrderConfirmationContentPanel is used to display the contents of an order
39   * confirmation.
40   * <p>
41   * 
42   * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
43   * Delft, the Netherlands. All rights reserved.
44   * 
45   * See for project information <a href="http://www.simulation.tudelft.nl/">
46   * www.simulation.tudelft.nl </a>.
47   * 
48   * The source code and binary code of this software is proprietary information
49   * of Delft University of Technology.
50   * 
51   * @author <a
52   *         href="http://www.tbm.tudelft.nl/webstaf/stijnh/index.htm">Stijn-Pieter
53   *         van Houten </a>
54   * @version $Revision: 1.1 $ $Date: 2005/06/16 12:33:57 $
55   * @since 1.0.3
56   */
57  public class OrderConfirmationContentPanel extends AbstractPanel
58  {
59  	/*** the serial version uid */
60  	private static final long serialVersionUID = 11L;
61  
62  	/*** the content */
63  	private OrderConfirmation content = null;
64  
65  	/***
66  	 * constructs a new NamePanel
67  	 * 
68  	 * @param content the content
69  	 */
70  	public OrderConfirmationContentPanel(final Object content)
71  	{
72  		super("order confirmation");
73  
74  		if (OrderConfirmation.class.isAssignableFrom(content.getClass()))
75  		{
76  			this.content = (OrderConfirmation) content;
77  		}
78  		if (this.content != null)
79  		{
80  			this.initialize();
81  		} else
82  		{
83  			Logger.severe(this, "<init>",
84  					"Could not extract content from received content of class: "
85  							+ content.getClass());
86  		}
87  	}
88  
89  	/***
90  	 * @see org.gscg.gameleader.dialogs.components.AbstractPanel#initialize()
91  	 */
92  	protected void initialize()
93  	{
94  		JPanel labelPanel = new JPanel();
95  		// col1, row1, col2, row2, hAlign, vAlign
96  		double[][] nameLabelPanelLayout = {
97  				{TableLayoutConstants.FILL, TableLayoutConstants.FILL},
98  				{20, 20, 20, 20, 20, 20}};
99  		labelPanel.setLayout(new TableLayout(nameLabelPanelLayout));
100 		labelPanel.setBackground(Color.WHITE);
101 
102 		JLabel senderLabel = super.getFormattedLabel("sender name");
103 		labelPanel.add(senderLabel, "0,0,L,C");
104 		JLabel senderNameLabel = super.getFormattedLabel(this.content
105 				.getSender().getName());
106 		senderNameLabel.setHorizontalAlignment(SwingConstants.RIGHT);
107 		labelPanel.add(senderNameLabel, "1,0,R,C");
108 
109 		JLabel receiverLabel = super.getFormattedLabel("receiver name");
110 		labelPanel.add(receiverLabel, "0,1,L,C");
111 		JLabel receiverNameLabel = super.getFormattedLabel(this.content
112 				.getReceiver().getName());
113 		receiverNameLabel.setHorizontalAlignment(SwingConstants.RIGHT);
114 		labelPanel.add(receiverNameLabel, "1,1,R,C");
115 
116 		JLabel productLabel = super.getFormattedLabel("product name");
117 		labelPanel.add(productLabel, "0,2,L,C");
118 		JLabel productNameLabel = super.getFormattedLabel(this.content
119 				.getProduct().getName());
120 		productNameLabel.setHorizontalAlignment(SwingConstants.RIGHT);
121 		labelPanel.add(productNameLabel, "1,2,R,C");
122 
123 		JLabel statusLabel = super.getFormattedLabel("status");
124 		labelPanel.add(statusLabel, "0,3,L,C");
125 		JLabel statusNameLabel = super.getFormattedLabel(this.content
126 				.getStatusString()
127 				+ "");
128 		statusNameLabel.setHorizontalAlignment(SwingConstants.RIGHT);
129 		labelPanel.add(statusNameLabel, "1,3,R,C");
130 
131 		// the information about the content
132 		URL description = URLResource.getResource("/"
133 				+ this.content.getClass().getName().substring(
134 						this.content.getClass().getName().lastIndexOf(".") + 1)
135 				+ ".html");
136 		JEditorPane descriptionPane = null;
137 		try
138 		{
139 			descriptionPane = new JEditorPane(description);
140 		} catch (IOException exception)
141 		{
142 			description = URLResource.getResource("/general_info.html");
143 			try
144 			{
145 				descriptionPane = new JEditorPane(description);
146 			} catch (IOException exception2)
147 			{
148 				Logger.warning(this, "initialize", exception2);
149 				descriptionPane = new JEditorPane();
150 			}
151 		}
152 		descriptionPane.setAlignmentY(Component.CENTER_ALIGNMENT);
153 		descriptionPane.setAlignmentX(Component.TOP_ALIGNMENT);
154 		descriptionPane.setEditable(false);
155 		descriptionPane.setFocusable(false);
156 		descriptionPane.setBackground(Color.WHITE);
157 		descriptionPane.setVisible(true);
158 
159 		JScrollPane scrollPane = new JScrollPane(descriptionPane);
160 		scrollPane
161 				.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
162 		scrollPane
163 				.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
164 
165 		// setup the panel
166 		double[][] panelLayout = {{TableLayoutConstants.FILL},
167 				{80, TableLayoutConstants.FILL}};
168 		super.setLayout(new TableLayout(panelLayout));
169 
170 		// add the components
171 		super.add(labelPanel, "0,0,L,C");
172 		super.add(scrollPane, "0,1,L,T");
173 
174 		// we need this to make sure the description pane
175 		// is visible at the first time a dialog is opened
176 		super.validate();
177 		super.doLayout();
178 	}
179 }