001    package market.stdform;
002    
003    import java.awt.GridBagConstraints;
004    import java.awt.GridBagLayout;
005    import java.awt.GridLayout;
006    
007    import javax.swing.Box;
008    import javax.swing.BoxLayout;
009    import javax.swing.JLabel;
010    import javax.swing.JPanel;
011    
012    import market.Conversions;
013    import market.SMarket;
014    import market.VCPositiveDouble;
015    import market.VCPositiveInteger;
016    import market.swing.ComponentFactory;
017    import market.swing.JTFCheckable;
018    import sale.FormSheet;
019    import sale.FormSheetContentCreator;
020    
021    /**
022     * This FormSheet is used by the manager to set special calculation variables such as the maximal discount
023     * for customers or the monthly costs of the market.
024     */
025    public class FSManagerOptions extends FormSheet {
026    
027        public static final int JTFC_DISCOUNT_RANGE = 0;
028        public static final int JTFC_DISCOUNT_VALUE = 1;
029        public static final int JTFC_MAX_DISCOUNT = 2;
030        public static final int JTFC_FRACTION_OF_WAGES = 3;
031        public static final int JTFC_SENIORITY = 4;
032        public static final int JTFC_COSTS = 5;
033    
034        private JTFCheckable jtfcDiscountRange = new JTFCheckable(
035                JTFC_DISCOUNT_RANGE, new VCPositiveInteger("Anrechnung"), 10);
036        private JTFCheckable jtfcDiscountValue = new JTFCheckable(
037                JTFC_DISCOUNT_VALUE, new VCPositiveInteger("Umsatz"), 10);
038        private JTFCheckable jtfcMaxDiscount = new JTFCheckable(
039                JTFC_MAX_DISCOUNT, new VCPositiveDouble("Maximaler Rabatt"), 10);
040        private JTFCheckable jtfcFractionOfWages = new JTFCheckable(
041                JTFC_FRACTION_OF_WAGES, new VCPositiveDouble("Lohnanteil"), 10);
042        private JTFCheckable jtfcSeniority = new JTFCheckable(
043                JTFC_SENIORITY, new VCPositiveDouble("Betriebszugehörigkeit"), 10);
044        private JTFCheckable jtfcCosts = new JTFCheckable(
045                JTFC_COSTS, new VCPositiveDouble("Sonstige Kosten"), 10);
046    
047        public FSManagerOptions() {
048            super("Einstellungen", null);
049            addContentCreator(new FormSheetContentCreator() {protected void createFormSheetContent(FormSheet fs) {
050                //define components
051                JPanel jpMain = new JPanel();
052                JPanel jpData = new JPanel();
053                JPanel jpDiscount = new JPanel();
054                JPanel jpEmployees = new JPanel();
055                JPanel jpCostCentres = new JPanel();
056                GridBagLayout gridBag = new GridBagLayout();
057                GridBagConstraints c = new GridBagConstraints();
058                jpMain.setLayout(gridBag);
059                    c.weighty = 1;
060                    c.anchor = GridBagConstraints.CENTER;
061                gridBag.setConstraints(jpData, c);
062    
063                jpMain.add(jpData);
064                    jpData.setLayout(new BoxLayout(jpData, BoxLayout.Y_AXIS));
065                    jpData.add(jpDiscount);
066                        jpDiscount.setLayout(new BoxLayout(jpDiscount, BoxLayout.Y_AXIS));
067                        jpDiscount.setBorder(ComponentFactory.createInsetBorder("Kundenrabatt"));
068                        jpDiscount.setLayout(new GridLayout(3, 3));
069                        jpDiscount.add(new JLabel("Anrechnung:  "));
070                        jpDiscount.add(jtfcDiscountRange);
071                        jpDiscount.add(new JLabel("   Monate"));
072                        jpDiscount.add(new JLabel("Umsatz für 1% Rabatt:  "));
073                        jpDiscount.add(jtfcDiscountValue);
074                        jpDiscount.add(new JLabel("   Euro"));
075                        jpDiscount.add(new JLabel("Maximaler Rabatt:  "));
076                        jpDiscount.add(jtfcMaxDiscount);
077                        jpDiscount.add(new JLabel("   Prozent"));
078                    jpData.add(Box.createVerticalStrut(10));
079                    jpData.add(jpEmployees);
080                        jpEmployees.setLayout(new GridLayout(2, 3));
081                        jpEmployees.setBorder(ComponentFactory.createInsetBorder(
082                                "Faktoren zur Berechnung des Entlassungsausgleichs"));
083                        jpEmployees.add(new JLabel("Lohnanteil:  "));
084                        jpEmployees.add(jtfcFractionOfWages);
085                        jpEmployees.add(new JLabel("   Prozent"));
086                        jpEmployees.add(new JLabel("Betriebszugehörigkeit:  "));
087                        jpEmployees.add(jtfcSeniority);
088                        jpEmployees.add(new JLabel("   Prozent"));
089                    jpData.add(Box.createVerticalStrut(10));
090                    jpData.add(jpCostCentres);
091                        jpCostCentres.setBorder(ComponentFactory.createInsetBorder("Kostenstellen"));
092                        jpCostCentres.setLayout(new GridLayout(1, 3));
093                        jpCostCentres.add(new JLabel("Sonstige Kosten: "));
094                        jpCostCentres.add(jtfcCosts);
095                        jpCostCentres.add(new JLabel("   Euro"));
096    
097                fs.setComponent(jpMain);
098                fs.removeAllButtons();
099                fs.addButton("Übernehmen", ButtonIDs.BTN_ACCEPT, null);
100    
101                jtfcDiscountRange.setText(Integer.toString(SMarket.getOptions().getDiscountRange()));
102                jtfcDiscountValue.setText(Integer.toString(SMarket.getOptions().getDiscountValue()));
103                jtfcMaxDiscount.setText(Conversions.fixedDecimal(100 * SMarket.getOptions().getMaxDiscount(), 3));
104                jtfcFractionOfWages.setText(Conversions.fixedDecimal(100 * SMarket.getOptions().
105                        getFractionOfWages(), 3));
106                jtfcSeniority.setText(Conversions.fixedDecimal(100 * SMarket.getOptions().getTimeOfEmployment(), 3));
107                jtfcCosts.setText(Conversions.doubleToCurrency(SMarket.getMonthlySalesStats().getCosts()));
108            }});
109        }
110    
111    }