001    package videoautomat.gui;
002    
003    import java.util.Comparator;
004    
005    import javax.swing.Box;
006    import javax.swing.BoxLayout;
007    import javax.swing.JComponent;
008    import javax.swing.JLabel;
009    import javax.swing.JPanel;
010    
011    import sale.FormSheet;
012    import sale.FormSheetContentCreator;
013    import sale.UIGate;
014    import util.swing.TableEntryDescriptor;
015    import data.DataBasket;
016    import data.StoringStock;
017    import data.ooimpl.MoneyBagImpl;
018    import data.stdforms.SingleTableFormSheet;
019    import data.stdforms.TwoTableFormSheet;
020    import data.stdforms.twotableformsheet.SSSSStrategy;
021    
022    /**
023     * This class implements graphical-user-interface elements for the SaleProcessHandBack
024     */
025    public class HandBack {
026    
027            /**
028             * An ID to identify the <code>FormButton</code> give back
029             */
030            public static final int FB_GIVEBACK = 1;
031    
032            /**
033             * An ID to identify the <code>FormButton</code> cancel
034             */
035            public static final int FB_CANCEL = 2;
036    
037            /**
038             * @return a <code>TwoTableFormSheet</code> used to display the already rented videos.
039             * @param ss_source
040             *                  the source <code>Stock</code> containing the videos of the user
041             * @param ss_dest
042             *                  the destination <code>Stock</code>
043             * @param db
044             *                  the <code>DataBasket</code> used for the transactions
045             * @param uig
046             *                  the <code>UIGate</code> this <code>FormSheet</code> is displayed
047             * @param cmp_source
048             *                  the <code>Comparator</code> for the source <code>Stock</code>
049             * @param cmp_dest
050             *                  the <code>Comparator</code> for the destination <code>Stock</code>
051             * @param ted_source
052             *                  the <code>TableEntryDescriptor</code> for the source <code>Stock</code>
053             * @param ted_dest
054             *                  the <code>TableEntryDescriptor</code> for the destination <code>Stock</code>
055             * @param sssss
056             *                  the <code>SSSSStrategy</code> to be used
057             *  
058             */
059            public static TwoTableFormSheet getRentedVideosFormSheet(
060                    StoringStock ss_source,
061                    StoringStock ss_dest,
062                    DataBasket db,
063                    UIGate uig,
064                    Comparator cmp_source,
065                    Comparator cmp_dest,
066                    TableEntryDescriptor ted_source,
067                    TableEntryDescriptor ted_dest,
068                    SSSSStrategy sssss) {
069    
070                    TwoTableFormSheet ttfs =
071                            TwoTableFormSheet.create(
072                                    "Give back a video",
073                                    ss_source,
074                                    ss_dest,
075                                    db,
076                                    uig,
077                                    cmp_source,
078                                    cmp_dest,
079                                    ted_source,
080                                    ted_dest,
081                                    sssss);
082    
083                    ttfs.addContentCreator(new FormSheetContentCreator() {
084                            public void createFormSheetContent(FormSheet fs) {
085                                    fs.removeAllButtons();
086                                    fs.addButton("Give back", FB_GIVEBACK, null);
087                                    fs.addButton("Cancel", FB_CANCEL, null);
088                            }
089                    });
090                    return ttfs;
091            }
092    
093            /**
094             * @return a <code>FormSheet</code> used to display change the user gets back.
095             * @param mb_money
096             *                  the <code>MoneyBag</code> containing the change that has to be displayed
097             * @param uig
098             *                  the <code>UIGate</code> this <code>FormSheet</code> is displayed
099             * @param db
100             *                  the <code>DataBasket</code> used for the transactions
101             * @param value
102             *                  the <code>String</code> that will be displayed as the value that the user gets back
103             *  
104             */
105            public static FormSheet getChangeFormSheet(
106                    MoneyBagImpl mb_money,
107                    UIGate uig,
108                    DataBasket db,
109                    final String value) {
110                    SingleTableFormSheet stfs =
111                            SingleTableFormSheet.create("Here is your change!", mb_money, uig, db);
112                    stfs.addContentCreator(new FormSheetContentCreator() {
113                            public void createFormSheetContent(FormSheet fs) {
114                                    JComponent jc = new JPanel();
115                                    jc.setLayout(new BoxLayout(jc, BoxLayout.Y_AXIS));
116                                    jc.add(Box.createVerticalStrut(10));
117                                    jc.add(new JLabel("You get back: " + value));
118                                    jc.add(Box.createVerticalStrut(10));
119                                    jc.add(fs.getComponent());
120                                    fs.setComponent(jc);
121                                    fs.removeButton(FormSheet.BTNID_CANCEL);
122                            }
123                    });
124                    return stfs;
125            }
126    }