001 package market.stdform; 002 003 import java.awt.Dimension; 004 import java.awt.GridBagConstraints; 005 import java.awt.GridBagLayout; 006 import java.awt.GridLayout; 007 import java.awt.Insets; 008 009 import javax.swing.Box; 010 import javax.swing.BoxLayout; 011 import javax.swing.JLabel; 012 import javax.swing.JPanel; 013 import javax.swing.JScrollPane; 014 import javax.swing.JTable; 015 016 import market.CIArticle; 017 import market.Conversions; 018 import market.SMarket; 019 import market.statistics.CISalesStats; 020 import market.statistics.EvaluateStatistics; 021 import market.swing.ComponentFactory; 022 import market.swing.HistoryEntryModel; 023 import sale.FormSheet; 024 import sale.FormSheetContentCreator; 025 026 /** 027 * This FormSheet displays detailed statistics of a chosen article during a chosen range of time. 028 */ 029 public class FSManagerArticleStatsDetail extends FormSheet { 030 031 /** 032 * @param ciss the precomputed statistics to be displayed. 033 */ 034 public FSManagerArticleStatsDetail(final CISalesStats ciss) { 035 super("Artikelstatistik - Details", new FormSheetContentCreator() { 036 public void createFormSheetContent(final FormSheet fs) { 037 final CIArticle cia = SMarket.getArticleCatalog().get(ciss.getArticleID()); 038 final EvaluateStatistics es = new EvaluateStatistics(ciss); 039 JPanel jpMain = new JPanel(); 040 JPanel jpData = new JPanel(); 041 JPanel jpTables = new JPanel(); 042 JPanel jpLeftTable = new JPanel(); 043 JPanel jpRightTable = new JPanel(); 044 JPanel jpDataLabel1 = new JPanel(); 045 JPanel jpDataLabel2 = new JPanel(); 046 JPanel jpValueLabel1 = new JPanel(); 047 JPanel jpValueLabel2 = new JPanel(); 048 JPanel jpEdit = new JPanel(); 049 JPanel jpEditLabel1 = new JPanel(); 050 JPanel jpEditValue1 = new JPanel(); 051 JPanel jpEditCurrency1 = new JPanel(); 052 JScrollPane jsc1 = new JScrollPane(); 053 JScrollPane jsc2 = new JScrollPane(); 054 JTable jt1 = new JTable(); 055 JTable jt2 = new JTable(); 056 Dimension tableDimension = new Dimension(250, 150); 057 GridBagConstraints c = new GridBagConstraints(); 058 GridBagLayout gridbag = new GridBagLayout(); 059 jpMain.setLayout(gridbag); 060 c.gridy = 0; 061 c.weightx = 1; 062 c.weighty = 0.1; 063 c.insets = new Insets(10,0,0,0); 064 c.anchor = GridBagConstraints.NORTH; 065 gridbag.setConstraints(jpData, c); 066 c.gridy = 1; 067 c.weightx = 1; 068 c.weighty = 0.9; 069 c.insets = new Insets(10,0,0,0); 070 c.anchor = GridBagConstraints.CENTER; 071 gridbag.setConstraints(jpTables, c); 072 073 jpData.setLayout(new BoxLayout(jpData, BoxLayout.X_AXIS)); 074 jpData.setBorder(ComponentFactory.createInsetBorder("Statistik für " + cia.getArticleName())); 075 jpData.add(jpDataLabel1); 076 jpDataLabel1.setLayout(new GridLayout(4,1)); 077 jpDataLabel1.add(new JLabel("Auf Lager:")); 078 jpDataLabel1.add(new JLabel("Einkaufspreis:")); 079 jpDataLabel1.add(new JLabel("Durchschn. Verkaufspreis:")); 080 jpDataLabel1.add(new JLabel("Durchschn. Gewinn:")); 081 jpData.add(jpValueLabel1); 082 jpValueLabel1.setLayout(new GridLayout(4,1)); 083 jpValueLabel1.add(ComponentFactory.createTextField(SMarket.getOffer().countItems( 084 ciss.getArticleID(), null), 7, false, ComponentFactory.RIGHT, false)); 085 jpValueLabel1.add(ComponentFactory.createTextField(Conversions.doubleToCurrency( 086 cia.getOffer()), 7, false, ComponentFactory.RIGHT, false)); 087 jpValueLabel1.add(ComponentFactory.createTextField(Conversions.doubleToCurrency( 088 es.getAveragePrice()), 7, false, ComponentFactory.RIGHT, false)); 089 jpValueLabel1.add(ComponentFactory.createTextField(Conversions.doubleToCurrency( 090 es.getAveragePrice() - cia.getOffer()), 7, false, ComponentFactory.RIGHT, false)); 091 jpData.add(Box.createHorizontalStrut(25)); 092 jpData.add(jpDataLabel2); 093 jpDataLabel2.setLayout(new GridLayout(4,1)); 094 jpDataLabel2.add(new JLabel("Gesamt verkauft:")); 095 jpDataLabel2.add(new JLabel("Durchschn. Verkauf pro Tag:")); 096 jpDataLabel2.add(new JLabel("Durchschn. Bestellmenge:")); 097 jpDataLabel2.add(new JLabel("Bestellabstand:")); 098 jpData.add(jpValueLabel2); 099 jpValueLabel2.setLayout(new GridLayout(4,1)); 100 jpValueLabel2.add(ComponentFactory.createTextField(es.getAmount(), 101 7, false, ComponentFactory.RIGHT, false)); 102 jpValueLabel2.add(ComponentFactory.createTextField( 103 Conversions.round(es.getAverageItemsSold(), 3), 104 7, false, ComponentFactory.RIGHT, false)); 105 jpValueLabel2.add(ComponentFactory.createTextField( 106 Conversions.round(es.getAverageOrderAmount(), 1), 107 7, false, ComponentFactory.RIGHT, false)); 108 jpValueLabel2.add(ComponentFactory.createTextField( 109 Conversions.round(es.getAverageDaysBetweenOrders(), 1), 110 7, false, ComponentFactory.RIGHT, false)); 111 jpTables.setLayout(new BoxLayout(jpTables, BoxLayout.X_AXIS)); 112 jpTables.add(jpLeftTable); 113 jpLeftTable.setLayout(new BoxLayout(jpLeftTable, BoxLayout.Y_AXIS)); 114 jpLeftTable.add(new JLabel("Preisverlauf:")); 115 jpLeftTable.add(Box.createVerticalStrut(10)); 116 jpLeftTable.add(jsc1); 117 jsc1.setViewportView(jt1); 118 jt1.setPreferredScrollableViewportSize(tableDimension); 119 jt1.setModel(new HistoryEntryModel(es.getPriceHistory(), 120 HistoryEntryModel.PRICE_HISTORY)); 121 jpTables.add(Box.createHorizontalStrut(25)); 122 jpTables.add(jpRightTable); 123 jpRightTable.setLayout(new BoxLayout(jpRightTable, BoxLayout.Y_AXIS)); 124 jpRightTable.add(new JLabel("Nachbestellungen:")); 125 jpRightTable.add(Box.createVerticalStrut(10)); 126 jpRightTable.add(jsc2); 127 jsc2.setViewportView(jt2); 128 jt2.setPreferredScrollableViewportSize(tableDimension); 129 jt2.setModel(new HistoryEntryModel(es.getOrderHistory(), 130 HistoryEntryModel.ORDER_HISTORY)); 131 jpMain.add(jpData); 132 jpMain.add(jpTables); 133 fs.setComponent(jpMain); 134 fs.removeAllButtons(); 135 fs.addButton("Zurück", ButtonIDs.BTN_BACK, null); 136 } 137 }, false); 138 } 139 }