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 * ID for serialization. 033 */ 034 private static final long serialVersionUID = -303500994550641437L; 035 036 /** 037 * @param ciss the precomputed statistics to be displayed. 038 */ 039 public FSManagerArticleStatsDetail(final CISalesStats ciss) { 040 super("Artikelstatistik - Details", new FormSheetContentCreator() { 041 private static final long serialVersionUID = 4584811976140771653L; 042 public void createFormSheetContent(final FormSheet fs) { 043 final CIArticle cia = SMarket.getArticleCatalog().get(ciss.getArticleID()); 044 final EvaluateStatistics es = new EvaluateStatistics(ciss); 045 JPanel jpMain = new JPanel(); 046 JPanel jpData = new JPanel(); 047 JPanel jpTables = new JPanel(); 048 JPanel jpLeftTable = new JPanel(); 049 JPanel jpRightTable = new JPanel(); 050 JPanel jpDataLabel1 = new JPanel(); 051 JPanel jpDataLabel2 = new JPanel(); 052 JPanel jpValueLabel1 = new JPanel(); 053 JPanel jpValueLabel2 = new JPanel(); 054 JScrollPane jsc1 = new JScrollPane(); 055 JScrollPane jsc2 = new JScrollPane(); 056 JTable jt1 = new JTable(); 057 JTable jt2 = new JTable(); 058 Dimension tableDimension = new Dimension(250, 150); 059 GridBagConstraints c = new GridBagConstraints(); 060 GridBagLayout gridbag = new GridBagLayout(); 061 jpMain.setLayout(gridbag); 062 c.gridy = 0; 063 c.weightx = 1; 064 c.weighty = 0.1; 065 c.insets = new Insets(10,0,0,0); 066 c.anchor = GridBagConstraints.NORTH; 067 gridbag.setConstraints(jpData, c); 068 c.gridy = 1; 069 c.weightx = 1; 070 c.weighty = 0.9; 071 c.insets = new Insets(10,0,0,0); 072 c.anchor = GridBagConstraints.CENTER; 073 gridbag.setConstraints(jpTables, c); 074 075 jpData.setLayout(new BoxLayout(jpData, BoxLayout.X_AXIS)); 076 jpData.setBorder(ComponentFactory.createInsetBorder("Statistik für " + cia.getArticleName())); 077 jpData.add(jpDataLabel1); 078 jpDataLabel1.setLayout(new GridLayout(4,1)); 079 jpDataLabel1.add(new JLabel("Auf Lager:")); 080 jpDataLabel1.add(new JLabel("Einkaufspreis:")); 081 jpDataLabel1.add(new JLabel("Durchschn. Verkaufspreis:")); 082 jpDataLabel1.add(new JLabel("Durchschn. Gewinn:")); 083 jpData.add(jpValueLabel1); 084 jpValueLabel1.setLayout(new GridLayout(4,1)); 085 jpValueLabel1.add(ComponentFactory.createTextField(SMarket.getOffer().countItems( 086 ciss.getArticleID(), null), 7, false, ComponentFactory.RIGHT, false)); 087 jpValueLabel1.add(ComponentFactory.createTextField(Conversions.doubleToCurrency( 088 cia.getOffer()), 7, false, ComponentFactory.RIGHT, false)); 089 jpValueLabel1.add(ComponentFactory.createTextField(Conversions.doubleToCurrency( 090 es.getAveragePrice()), 7, false, ComponentFactory.RIGHT, false)); 091 jpValueLabel1.add(ComponentFactory.createTextField(Conversions.doubleToCurrency( 092 es.getAveragePrice() - cia.getOffer()), 7, false, ComponentFactory.RIGHT, false)); 093 jpData.add(Box.createHorizontalStrut(25)); 094 jpData.add(jpDataLabel2); 095 jpDataLabel2.setLayout(new GridLayout(4,1)); 096 jpDataLabel2.add(new JLabel("Gesamt verkauft:")); 097 jpDataLabel2.add(new JLabel("Durchschn. Verkauf pro Tag:")); 098 jpDataLabel2.add(new JLabel("Durchschn. Bestellmenge:")); 099 jpDataLabel2.add(new JLabel("Bestellabstand:")); 100 jpData.add(jpValueLabel2); 101 jpValueLabel2.setLayout(new GridLayout(4,1)); 102 jpValueLabel2.add(ComponentFactory.createTextField(es.getAmount(), 103 7, false, ComponentFactory.RIGHT, false)); 104 jpValueLabel2.add(ComponentFactory.createTextField( 105 Conversions.round(es.getAverageItemsSold(), 3), 106 7, false, ComponentFactory.RIGHT, false)); 107 jpValueLabel2.add(ComponentFactory.createTextField( 108 Conversions.round(es.getAverageOrderAmount(), 1), 109 7, false, ComponentFactory.RIGHT, false)); 110 jpValueLabel2.add(ComponentFactory.createTextField( 111 Conversions.round(es.getAverageDaysBetweenOrders(), 1), 112 7, false, ComponentFactory.RIGHT, false)); 113 jpTables.setLayout(new BoxLayout(jpTables, BoxLayout.X_AXIS)); 114 jpTables.add(jpLeftTable); 115 jpLeftTable.setLayout(new BoxLayout(jpLeftTable, BoxLayout.Y_AXIS)); 116 jpLeftTable.add(new JLabel("Preisverlauf:")); 117 jpLeftTable.add(Box.createVerticalStrut(10)); 118 jpLeftTable.add(jsc1); 119 jsc1.setViewportView(jt1); 120 jt1.setPreferredScrollableViewportSize(tableDimension); 121 jt1.setModel(new HistoryEntryModel(es.getPriceHistory(), 122 HistoryEntryModel.PRICE_HISTORY)); 123 jpTables.add(Box.createHorizontalStrut(25)); 124 jpTables.add(jpRightTable); 125 jpRightTable.setLayout(new BoxLayout(jpRightTable, BoxLayout.Y_AXIS)); 126 jpRightTable.add(new JLabel("Nachbestellungen:")); 127 jpRightTable.add(Box.createVerticalStrut(10)); 128 jpRightTable.add(jsc2); 129 jsc2.setViewportView(jt2); 130 jt2.setPreferredScrollableViewportSize(tableDimension); 131 jt2.setModel(new HistoryEntryModel(es.getOrderHistory(), 132 HistoryEntryModel.ORDER_HISTORY)); 133 jpMain.add(jpData); 134 jpMain.add(jpTables); 135 fs.setComponent(jpMain); 136 fs.removeAllButtons(); 137 fs.addButton("Zurück", ButtonIDs.BTN_BACK, null); 138 } 139 }, false); 140 } 141 }