001 package videoautomat.gui; 002 import javax.swing.Box; 003 import javax.swing.BoxLayout; 004 import javax.swing.JComponent; 005 import javax.swing.JLabel; 006 import javax.swing.JPanel; 007 008 import sale.FormSheet; 009 import sale.FormSheetContentCreator; 010 import sale.UIGate; 011 import util.swing.TableEntryDescriptor; 012 import data.Catalog; 013 import data.CountingStock; 014 import data.DataBasket; 015 import data.DataBasketCondition; 016 import data.stdforms.SingleTableFormSheet; 017 import data.stdforms.TwoTableFormSheet; 018 import data.stdforms.twotableformsheet.CCSStrategy; 019 import data.stdforms.twotableformsheet.CSDBStrategy; 020 021 /** 022 * This class implements graphical-user-interface elements for the SaleProcessRent 023 */ 024 public class Rent { 025 026 /** 027 * An ID to identify the <code>FormButton</code> rent 028 */ 029 public static final int FB_RENT = 1; 030 /** 031 * An ID to identify the <code>FormButton</code> pay 032 */ 033 public static final int FB_PAY = 2; 034 /** 035 * An ID to identify the <code>FormButton</code> cancel 036 */ 037 public static final int FB_CANCEL = 3; 038 /** 039 * @return a <code>TwoTableFormSheet</code> used to select the videos of the offer. 040 * @param cs_source 041 * the source <code>Stock</code> containing the avaible videos 042 * @param db 043 * the destination <code>DataBasket</code> 044 * @param uigGate 045 * the <code>UIGate</code> this <code>FormSheet</code> is displayed 046 * @param cmp_source 047 * the <code>Comparator</code> for the <code>Stock</code> 048 * @param cmp_dest 049 * the <code>Comparator</code> for the <code>DataBasket</code> 050 * @param show_zeros 051 * if false, lines containing a '0' in the "Count" field of the <code>Stock</code> will be hidden. 052 * @param ted_source 053 * the <code>TableEntryDescriptor</code> for the <code>Stock</code> 054 * @param ted_dest 055 * the <code>TableEntryDescriptor</code> for the <code>DataBasket</code> 056 * @param csdbs 057 * the <code>CSDBStrategy</code> to be used 058 * 059 */ 060 public static TwoTableFormSheet getRentFormSheet( 061 CountingStock cs_source, 062 DataBasket db, 063 UIGate uigGate, 064 java.util.Comparator cmp_source, 065 java.util.Comparator cmp_dest, 066 boolean show_zeros, 067 TableEntryDescriptor ted_source, 068 TableEntryDescriptor ted_dest, 069 CSDBStrategy csdbs) { 070 071 TwoTableFormSheet ttfs = 072 TwoTableFormSheet.create( 073 "Choose your videos!", 074 cs_source, 075 db, 076 uigGate, 077 cmp_source, 078 cmp_dest, 079 show_zeros, 080 ted_source, 081 ted_dest, 082 csdbs); 083 084 ttfs.addContentCreator(new FormSheetContentCreator() { 085 public void createFormSheetContent(FormSheet fs) { 086 fs.removeAllButtons(); 087 fs.addButton("Rent", FB_RENT, null); 088 fs.addButton("Cancel", FB_CANCEL, null); 089 } 090 }); 091 092 return ttfs; 093 } 094 /** 095 * @return a <code>TwoTableFormSheet</code> used to select the money the user inserts in the automat. 096 * @param c_source 097 * the source <code>Catalog</code> containing the possible coins 098 * @param cs_dest 099 * the destination <code>Stock</code> 100 * @param db 101 * the <code>DataBasket</code> used for the transactions 102 * @param uig 103 * the <code>UIGate</code> this <code>FormSheet</code> is displayed 104 * @param cmp_source 105 * the <code>Comparator</code> for the <code>Catalog</code> 106 * @param cmp_dest 107 * the <code>Comparator</code> for the <code>Stock</code> 108 * @param show_zeros 109 * if false, lines containing a '0' in the "Count" field of the <code>Stock</code> will be hidden. 110 * @param ted_source 111 * the <code>TableEntryDescriptor</code> for the <code>Catalog</code> 112 * @param ted_dest 113 * the <code>TableEntryDescriptor</code> for the <code>Stock</code> 114 * @param ccss 115 * the <code>CCSStrategy</code> to be used 116 * @param value 117 * a <code>String</code> -representation of the value the user has to pay 118 * 119 */ 120 public static TwoTableFormSheet getPayFormSheet( 121 Catalog c_source, 122 CountingStock cs_dest, 123 DataBasket db, 124 UIGate uig, 125 java.util.Comparator cmp_source, 126 java.util.Comparator cmp_dest, 127 boolean show_zeros, 128 TableEntryDescriptor ted_source, 129 TableEntryDescriptor ted_dest, 130 CCSStrategy ccss, 131 final String value) { 132 133 TwoTableFormSheet ttfs = 134 TwoTableFormSheet.create( 135 "Throw the money in the slot, please.", 136 c_source, 137 cs_dest, 138 db, 139 uig, 140 cmp_source, 141 cmp_dest, 142 show_zeros, 143 ted_source, 144 ted_dest, 145 ccss); 146 147 ttfs.addContentCreator(new FormSheetContentCreator() { 148 public void createFormSheetContent(FormSheet fs) { 149 150 JComponent jc = new JPanel(); 151 jc.setLayout(new BoxLayout(jc, BoxLayout.Y_AXIS)); 152 jc.add(Box.createVerticalStrut(10)); 153 jc.add(new JLabel("You have to pay: " + value)); 154 jc.add(Box.createVerticalStrut(10)); 155 jc.add(fs.getComponent()); 156 157 fs.setComponent(jc); 158 fs.removeAllButtons(); 159 fs.addButton("Pay", FB_PAY, null); 160 fs.addButton("Cancel", FB_CANCEL, null); 161 } 162 }); 163 return ttfs; 164 } 165 /** 166 * @return a <code>FormSheet</code> which shows the rented videos and which money the user gets back 167 * @param db 168 * the <code>DataBasket</code> containig the rented videos 169 * @param dbc_videos 170 * a <code>DataBasketCondition</code> affecting that only the rented videos in the <code>DataBasket</code> 171 * are shown 172 * @param ted_videos 173 * the <code>TableEntryDescriptor</code> for the <code>DataBasket</code> 174 * @param cs_money 175 * the <code>Stock</code> containing the money 176 * @param uig 177 * the <code>UIGate</code> this <code>FormSheet</code> is displayed 178 * 179 */ 180 public static FormSheet getConfirmFormSheet( 181 final DataBasket db, 182 final DataBasketCondition dbc_videos, 183 final TableEntryDescriptor ted_videos, 184 final CountingStock cs_money, 185 final UIGate uig) { 186 SingleTableFormSheet stfs_videos = 187 SingleTableFormSheet.create( 188 "Confirm your transaction!", 189 db, 190 uig, 191 dbc_videos, 192 ted_videos); 193 194 stfs_videos.addContentCreator(new FormSheetContentCreator() { 195 public void createFormSheetContent(FormSheet fs) { 196 SingleTableFormSheet stfs_money = 197 SingleTableFormSheet.create("", cs_money, uig, db); 198 199 JComponent jc = new JPanel(); 200 jc.setLayout(new BoxLayout(jc, BoxLayout.Y_AXIS)); 201 jc.add(new JLabel("All your rented videos:")); 202 jc.add(fs.getComponent()); 203 jc.add(new JLabel("The money you`ll get back:")); 204 jc.add(stfs_money.getComponent()); 205 jc.add(new JLabel("Please, click Ok to confirm the transaction!")); 206 fs.setComponent(jc); 207 fs.removeButton(FormSheet.BTNID_CANCEL); 208 } 209 }); 210 211 return stfs_videos; 212 } 213 }