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