View Javadoc

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