1   package org.wcb.gui.forms.report;
2   
3   import org.wcb.gui.table.model.Faa8710Model;
4   import org.wcb.gui.renderer.ColorRowsTableCellRender;
5   import org.wcb.gui.util.TableUtils;
6   import org.wcb.model.util.SpringUtil;
7   import org.wcb.model.service.IServicesConstants;
8   
9   import javax.swing.*;
10  import java.awt.*;
11  import java.awt.print.PrinterException;
12  import java.text.MessageFormat;
13  import java.util.logging.Logger;
14  import java.util.logging.Level;
15  
16  /**
17   * <small>
18   * <p/>
19   * Copyright (c)  2006  wbogaardt.
20   * This library is free software; you can redistribute it and/or
21   * modify it under the terms of the GNU Lesser General Public
22   * License as published by the Free Software Foundation; either
23   * version 2.1 of the License, or (at your option) any later version.
24   *
25   * This library is distributed in the hope that it will be useful,
26   * but WITHOUT ANY WARRANTY; without even the implied warranty of
27   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
28   * Lesser General Public License for more details.
29   *
30   * You should have received a copy of the GNU Lesser General Public
31   * License along with this library; if not, write to the Free Software
32   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
33   * <p/>
34   * $File:  $ <br>
35   * $Change:  $ submitted by $Author: wbogaardt $ at $DateTime: Aug 31, 2006 1:14:50 PM $ <br>
36   * </small>
37   *
38   * @author wbogaardt
39   *        This panel displays a jtable which has the figures for
40   * the current 2006 FAA 8710 form.
41   */
42  
43  public class Faa8710Form extends JPanel {
44  
45      private JTable jTableReport;
46      private Faa8710Model tableModel;
47      private Logger LOG = Logger.getLogger(Faa8710Form.class.getName());
48  
49      public Faa8710Form() {
50          initComponents();
51      }
52  
53      public void refresh() {
54          tableModel.refreshModel();
55      }
56  
57      private void initComponents() {
58  
59          tableModel = (Faa8710Model) SpringUtil.getApplicationContext().getBean(IServicesConstants.SWING_FAA8710_MODEL);
60          tableModel.refreshModel();
61  
62          jTableReport = new JTable(tableModel);
63          jTableReport.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
64          jTableReport.setPreferredSize(new Dimension(750,270));
65          jTableReport.setPreferredScrollableViewportSize(new Dimension(700,260));
66          ColorRowsTableCellRender colorizeRows = new ColorRowsTableCellRender();
67          colorizeRows.setOddRowColor(new Color(255,255,204));
68  
69          jTableReport.setDefaultRenderer(String.class, colorizeRows);
70          jTableReport.getColumnModel().getColumn(0).setMinWidth(193); //description
71          jTableReport.getColumnModel().getColumn(1).setMinWidth(60); //Airplanes
72          jTableReport.getColumnModel().getColumn(2).setMinWidth(60); //Rotocraft
73          jTableReport.getColumnModel().getColumn(3).setMinWidth(80); //PoweredLift
74          jTableReport.getColumnModel().getColumn(4).setMinWidth(50); //Glider
75          jTableReport.getColumnModel().getColumn(5).setMinWidth(90); //Lighter than air
76          jTableReport.getColumnModel().getColumn(6).setMinWidth(60); //Simulator
77          jTableReport.getColumnModel().getColumn(7).setMinWidth(90); //Training device
78          jTableReport.getColumnModel().getColumn(8).setMinWidth(90); //PCATD Device
79          JScrollPane jscrolling = new JScrollPane(jTableReport);//, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
80          TableUtils.setColumnWidths(jTableReport, jTableReport.getInsets(), true, false);
81          add(jscrolling);
82  
83      }
84  
85      public void print() {
86          SwingUtilities.invokeLater(new Runnable() {
87              public void run() {
88                  try {
89                      jTableReport.print(JTable.PrintMode.FIT_WIDTH, new MessageFormat("FAA 8710 Totals"), new MessageFormat("Page {0, number}"));
90                  } catch(PrinterException pe) {
91                      LOG.log(Level.WARNING, "Unable to print ", pe);
92                  }
93              }
94          });
95      }
96  
97  }