View Javadoc

1   /*
2    * @(#) OrderBasedOnQuoteContentPanel.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.Bill;
35  import nl.tudelft.simulation.supplychain.content.Order;
36  import nl.tudelft.simulation.supplychain.content.OrderBasedOnQuote;
37  import nl.tudelft.simulation.supplychain.content.OrderConfirmation;
38  import nl.tudelft.simulation.supplychain.content.Payment;
39  import nl.tudelft.simulation.supplychain.content.Shipment;
40  
41  import org.gscg.gameleader.dialogs.components.AbstractPanel;
42  
43  /***
44   * The OrderBasedOnQuoteContentPanel is used to display the contents of an
45   * order.
46   * <p>
47   * 
48   * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
49   * Delft, the Netherlands. All rights reserved.
50   * 
51   * See for project information <a href="http://www.simulation.tudelft.nl/">
52   * www.simulation.tudelft.nl </a>.
53   * 
54   * The source code and binary code of this software is proprietary information
55   * of Delft University of Technology.
56   * 
57   * @author <a
58   *         href="http://www.tbm.tudelft.nl/webstaf/stijnh/index.htm">Stijn-Pieter
59   *         van Houten </a>
60   * @version $Revision: 1.1 $ $Date: 2005/06/16 12:33:57 $
61   * @since 1.0.3
62   */
63  public class OrderBasedOnQuoteContentPanel extends AbstractPanel
64  {
65  	/*** the serial version uid */
66  	private static final long serialVersionUID = 11L;
67  
68  	/*** the content */
69  	private Order content = null;
70  
71  	/*** the simulator to use */
72  	private SimulatorInterface simulator = null;
73  
74  	/***
75  	 * constructs a new OrderBasedOnQuoteContentPanel
76  	 * 
77  	 * @param content the content
78  	 * @param simulator the simulator
79  	 */
80  	public OrderBasedOnQuoteContentPanel(final Object content,
81  			final SimulatorInterface simulator)
82  	{
83  		super("order");
84  
85  		this.simulator = simulator;
86  
87  		if (OrderBasedOnQuote.class.isAssignableFrom(content.getClass()))
88  		{
89  			this.content = (Order) content;
90  		} else if (OrderConfirmation.class.isAssignableFrom(content.getClass()))
91  		{
92  			this.content = ((OrderConfirmation) content).getOrder();
93  		} else if (Shipment.class.isAssignableFrom(content.getClass()))
94  		{
95  			this.content = (OrderBasedOnQuote) ((Shipment) content).getOrder();
96  		} else if (Bill.class.isAssignableFrom(content.getClass()))
97  		{
98  			this.content = (OrderBasedOnQuote) ((Bill) content).getOrder();
99  		} else if (Payment.class.isAssignableFrom(content.getClass()))
100 		{
101 			this.content = (OrderBasedOnQuote) ((Payment) content).getBill()
102 					.getOrder();
103 		}
104 
105 		if (this.content != null)
106 		{
107 			this.initialize();
108 		} else
109 		{
110 			Logger.severe(this, "<init>",
111 					"Could not extract content from received content of class: "
112 							+ content.getClass());
113 		}
114 	}
115 
116 	/***
117 	 * @see org.gscg.gameleader.dialogs.components.AbstractPanel#initialize()
118 	 */
119 	protected void initialize()
120 	{
121 		JPanel labelPanel = new JPanel();
122 		// col1, row1, col2, row2, hAlign, vAlign
123 		double[][] nameLabelPanelLayout = {
124 				{TableLayoutConstants.FILL, TableLayoutConstants.FILL},
125 				{20, 20, 20, 20, 20, 20}};
126 		labelPanel.setLayout(new TableLayout(nameLabelPanelLayout));
127 		labelPanel.setBackground(Color.WHITE);
128 
129 		JLabel senderLabel = super.getFormattedLabel("sender name");
130 		labelPanel.add(senderLabel, "0,0,L,C");
131 		JLabel senderNameLabel = super.getFormattedLabel(this.content
132 				.getSender().getName());
133 		senderNameLabel.setHorizontalAlignment(SwingConstants.RIGHT);
134 		labelPanel.add(senderNameLabel, "1,0,R,C");
135 
136 		JLabel receiverLabel = super.getFormattedLabel("receiver name");
137 		labelPanel.add(receiverLabel, "0,1,L,C");
138 		JLabel receiverNameLabel = super.getFormattedLabel(this.content
139 				.getReceiver().getName());
140 		receiverNameLabel.setHorizontalAlignment(SwingConstants.RIGHT);
141 		labelPanel.add(receiverNameLabel, "1,1,R,C");
142 
143 		JLabel productLabel = super.getFormattedLabel("product name");
144 		labelPanel.add(productLabel, "0,2,L,C");
145 		JLabel productNameLabel = super.getFormattedLabel(this.content
146 				.getProduct().getName());
147 		productNameLabel.setHorizontalAlignment(SwingConstants.RIGHT);
148 		labelPanel.add(productNameLabel, "1,2,R,C");
149 
150 		JLabel amountLabel = super.getFormattedLabel("amount");
151 		labelPanel.add(amountLabel, "0,3,L,C");
152 		JLabel amountNameLabel = super.getFormattedLabel(this.content
153 				.getAmount()
154 				+ "");
155 		amountNameLabel.setHorizontalAlignment(SwingConstants.RIGHT);
156 		labelPanel.add(amountNameLabel, "1,3,R,C");
157 
158 		JLabel priceLabel = super.getFormattedLabel("price");
159 		labelPanel.add(priceLabel, "0,4,L,C");
160 		JLabel priceNameLabel = super.getFormattedLabel(this.content.getPrice()
161 				+ "");
162 		priceNameLabel.setHorizontalAlignment(SwingConstants.RIGHT);
163 		labelPanel.add(priceNameLabel, "1,4,R,C");
164 
165 		JLabel earliestDeliveryLabel = super.getFormattedLabel("date");
166 		labelPanel.add(earliestDeliveryLabel, "0,5,L,C");
167 		JLabel earliestDeliveryNameLabel = super
168 				.getFormattedLabel(ContentUtilities.parseDateToDateString(
169 						this.content.getDeliveryDate(), this.simulator));
170 		earliestDeliveryNameLabel.setHorizontalAlignment(SwingConstants.RIGHT);
171 		labelPanel.add(earliestDeliveryNameLabel, "1,5,R,C");
172 
173 		// the information about the content
174 		URL description = URLResource.getResource("/"
175 				+ this.content.getClass().getName().substring(
176 						this.content.getClass().getName().lastIndexOf(".") + 1)
177 				+ ".html");
178 		JEditorPane descriptionPane = null;
179 		try
180 		{
181 			descriptionPane = new JEditorPane(description);
182 		} catch (IOException exception)
183 		{
184 			description = URLResource.getResource("/general_info.html");
185 			try
186 			{
187 				descriptionPane = new JEditorPane(description);
188 			} catch (IOException exception2)
189 			{
190 				Logger.warning(this, "initialize", exception2);
191 				descriptionPane = new JEditorPane();
192 			}
193 		}
194 		descriptionPane.setAlignmentY(Component.CENTER_ALIGNMENT);
195 		descriptionPane.setAlignmentX(Component.TOP_ALIGNMENT);
196 		descriptionPane.setEditable(false);
197 		descriptionPane.setFocusable(false);
198 		descriptionPane.setBackground(Color.WHITE);
199 		descriptionPane.setVisible(true);
200 
201 		JScrollPane scrollPane = new JScrollPane(descriptionPane);
202 		scrollPane
203 				.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
204 		scrollPane
205 				.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
206 
207 		// setup the panel
208 		double[][] panelLayout = {{TableLayoutConstants.FILL},
209 				{120, TableLayoutConstants.FILL}};
210 		super.setLayout(new TableLayout(panelLayout));
211 
212 		// add the components
213 		super.add(labelPanel, "0,0,L,C");
214 		super.add(scrollPane, "0,1,L,T");
215 
216 		// we need this to make sure the description pane
217 		// is visible at the first time a dialog is opened
218 		super.validate();
219 		super.doLayout();
220 	}
221 }