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