View Javadoc

1   /*
2    * @(#) PaymentContentPanel.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.dsol.simulators.SimulatorInterface;
32  import nl.tudelft.simulation.language.io.URLResource;
33  import nl.tudelft.simulation.logger.Logger;
34  import nl.tudelft.simulation.supplychain.content.Payment;
35  
36  import org.gscg.gameleader.dialogs.components.AbstractPanel;
37  
38  /***
39   * The PaymentContentPanel is used to display the contents of a payment.
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 PaymentContentPanel extends AbstractPanel
58  {
59  	/*** the serial version uid */
60  	private static final long serialVersionUID = 11L;
61  
62  	/*** the content */
63  	private Payment content = null;
64  
65  	/*** the simulator to use */
66  	private SimulatorInterface simulator = null;
67  
68  	/***
69  	 * constructs a new BillContentPanel
70  	 * 
71  	 * @param content the content
72  	 * @param simulator the simulator to use
73  	 */
74  	public PaymentContentPanel(final Object content,
75  			final SimulatorInterface simulator)
76  	{
77  		super("payment");
78  		this.simulator = simulator;
79  
80  		if (Payment.class.isAssignableFrom(content.getClass()))
81  		{
82  			this.content = (Payment) content;
83  		}
84  		if (this.content != null)
85  		{
86  			this.initialize();
87  		} else
88  		{
89  			Logger.severe(this, "<init>",
90  					"Could not extract content from received content of class: "
91  							+ content.getClass());
92  		}
93  	}
94  
95  	/***
96  	 * @see org.gscg.gameleader.dialogs.components.AbstractPanel#initialize()
97  	 */
98  	protected void initialize()
99  	{
100 		JPanel labelPanel = new JPanel();
101 		// col1, row1, col2, row2, hAlign, vAlign
102 		double[][] nameLabelPanelLayout = {
103 				{TableLayoutConstants.FILL, TableLayoutConstants.FILL},
104 				{20, 20, 20, 20, 20, 20, 20}};
105 		labelPanel.setLayout(new TableLayout(nameLabelPanelLayout));
106 		labelPanel.setBackground(Color.WHITE);
107 
108 		JLabel senderLabel = super.getFormattedLabel("sender name");
109 		labelPanel.add(senderLabel, "0,0,L,C");
110 		JLabel senderNameLabel = super.getFormattedLabel(this.content
111 				.getSender().getName());
112 		senderNameLabel.setHorizontalAlignment(SwingConstants.RIGHT);
113 		labelPanel.add(senderNameLabel, "1,0,R,C");
114 
115 		JLabel receiverLabel = super.getFormattedLabel("receiver name");
116 		labelPanel.add(receiverLabel, "0,1,L,C");
117 		JLabel receiverNameLabel = super.getFormattedLabel(this.content
118 				.getReceiver().getName());
119 		receiverNameLabel.setHorizontalAlignment(SwingConstants.RIGHT);
120 		labelPanel.add(receiverNameLabel, "1,1,R,C");
121 
122 		JLabel productLabel = super.getFormattedLabel("product name");
123 		labelPanel.add(productLabel, "0,2,L,C");
124 		JLabel productNameLabel = super.getFormattedLabel(this.content
125 				.getProduct().getName());
126 		productNameLabel.setHorizontalAlignment(SwingConstants.RIGHT);
127 		labelPanel.add(productNameLabel, "1,2,R,C");
128 
129 		JLabel paymentLabel = super.getFormattedLabel("payment");
130 		labelPanel.add(paymentLabel, "0,3,L,C");
131 		JLabel paymentNameLabel = super.getFormattedLabel(this.content
132 				.getPayment()
133 				+ "");
134 		paymentNameLabel.setHorizontalAlignment(SwingConstants.RIGHT);
135 		labelPanel.add(paymentNameLabel, "1,3,R,C");
136 
137 		JLabel paymentDateLabel = super.getFormattedLabel("payment date");
138 		labelPanel.add(paymentDateLabel, "0,4,L,C");
139 		JLabel paymentDateNameLabel = super.getFormattedLabel(ContentUtilities
140 				.parseDateToDateString(this.content.getPayment(),
141 						this.simulator));
142 		paymentDateNameLabel.setHorizontalAlignment(SwingConstants.RIGHT);
143 		labelPanel.add(paymentDateNameLabel, "1,4,R,C");
144 
145 		// the information about the content
146 		URL description = URLResource.getResource("/"
147 				+ this.content.getClass().getName().substring(
148 						this.content.getClass().getName().lastIndexOf(".") + 1)
149 				+ ".html");
150 		JEditorPane descriptionPane = null;
151 		try
152 		{
153 			descriptionPane = new JEditorPane(description);
154 		} catch (IOException exception)
155 		{
156 			description = URLResource.getResource("/general_info.html");
157 			try
158 			{
159 				descriptionPane = new JEditorPane(description);
160 			} catch (IOException exception2)
161 			{
162 				Logger.warning(this, "initialize", exception2);
163 				descriptionPane = new JEditorPane();
164 			}
165 		}
166 		descriptionPane.setAlignmentY(Component.CENTER_ALIGNMENT);
167 		descriptionPane.setAlignmentX(Component.TOP_ALIGNMENT);
168 		descriptionPane.setEditable(false);
169 		descriptionPane.setFocusable(false);
170 		descriptionPane.setBackground(Color.WHITE);
171 		descriptionPane.setVisible(true);
172 
173 		JScrollPane scrollPane = new JScrollPane(descriptionPane);
174 		scrollPane
175 				.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
176 		scrollPane
177 				.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
178 
179 		// setup the panel
180 		double[][] panelLayout = {{TableLayoutConstants.FILL},
181 				{100, TableLayoutConstants.FILL}};
182 		super.setLayout(new TableLayout(panelLayout));
183 
184 		// add the components
185 		super.add(labelPanel, "0,0,L,C");
186 		super.add(scrollPane, "0,1,L,T");
187 
188 		// we need this to make sure the description pane
189 		// is visible at the first time a dialog is opened
190 		super.validate();
191 		super.doLayout();
192 	}
193 }