1   package org.wcb.gui.table;
2   
3   import org.wcb.gui.table.model.PrintableLogbookModel;
4   import org.wcb.gui.renderer.jtable.GroupableTableColumnModel;
5   import org.wcb.gui.renderer.jtable.GroupableTableHeader;
6   import org.wcb.gui.renderer.jtable.ColumnGroup;
7   import org.wcb.gui.util.TableUtils;
8   import org.wcb.gui.renderer.ColorRowsTableCellRender;
9   
10  import javax.swing.*;
11  import java.awt.*;
12  import java.util.Date;
13  
14  /**
15   * <small>
16   * <p>
17   * This library is free software; you can redistribute it and/or
18   * modify it under the terms of the GNU Lesser General Public
19   * License as published by the Free Software Foundation; either
20   * version 2.1 of the License, or (at your option) any later version.
21   *
22   * This library is distributed in the hope that it will be useful,
23   * but WITHOUT ANY WARRANTY; without even the implied warranty of
24   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
25   * Lesser General Public License for more details.
26   *
27   * You should have received a copy of the GNU Lesser General Public
28   * License along with this library; if not, write to the Free Software
29   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
30   * <p/>
31   * $File:  $ <br>
32   * $Change:  $ submitted by $Author: wbogaardt $ at $DateTime: Sep 12, 2006 11:33:51 AM $ <br>
33   * </small>
34   *
35   * @author wbogaardt
36   *         This is a printable table
37   */
38  
39  public class LogbookPrintableTable extends JTable {
40      private JDialog frame;
41  
42      public LogbookPrintableTable(PrintableLogbookModel tableEditModel) {
43          setColumnModel(new GroupableTableColumnModel());
44          setTableHeader(new GroupableTableHeader((GroupableTableColumnModel) getColumnModel()));
45          setModel(tableEditModel);
46  
47          GroupableTableColumnModel cm = (GroupableTableColumnModel)getColumnModel();
48          ColumnGroup routeofFlightGroup = new ColumnGroup("Route of Flight");
49          routeofFlightGroup.add(cm.getColumn(2));
50          routeofFlightGroup.add(cm.getColumn(3));
51          routeofFlightGroup.add(cm.getColumn(4));
52          ColumnGroup typesOfFlightGroup = new ColumnGroup("Type of Piloting Time");
53          typesOfFlightGroup.add(cm.getColumn(6));
54          typesOfFlightGroup.add(cm.getColumn(7));
55          typesOfFlightGroup.add(cm.getColumn(8));
56          typesOfFlightGroup.add(cm.getColumn(9));
57          typesOfFlightGroup.add(cm.getColumn(10));
58          typesOfFlightGroup.add(cm.getColumn(11));
59          typesOfFlightGroup.add(cm.getColumn(12));
60          ColumnGroup dayGroup = new ColumnGroup("Day");
61          dayGroup.add(cm.getColumn(13));
62          ColumnGroup nightGroup = new ColumnGroup("Night");
63          nightGroup.add(cm.getColumn(14));
64          ColumnGroup conditionsOfFlightGroup = new ColumnGroup("Conditions of Flight");
65          conditionsOfFlightGroup.add(cm.getColumn(16));
66          conditionsOfFlightGroup.add(cm.getColumn(17));
67          conditionsOfFlightGroup.add(cm.getColumn(18));
68          getTableHeader();
69          cm.addColumnGroup(routeofFlightGroup);
70          cm.addColumnGroup(typesOfFlightGroup);
71          cm.addColumnGroup(dayGroup);
72          cm.addColumnGroup(nightGroup);
73          cm.addColumnGroup(conditionsOfFlightGroup);
74  
75          setShowGrid(false);
76          setDefaultRenderer(String.class, new ColorRowsTableCellRender());
77          setDefaultRenderer(Double.class, new ColorRowsTableCellRender());
78          setDefaultRenderer(Integer.class, new ColorRowsTableCellRender());
79          setDefaultRenderer(Date.class, new ColorRowsTableCellRender());
80          TableUtils.setColumnWidths(this, this.getInsets(), true, false);
81          setUpJFrame();
82      }
83  
84  
85      // Table Frame common to all examples in this tip
86  
87      private void setUpJFrame() {
88          frame = new JDialog();
89          frame.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
90          frame.add( getTablePanel());
91          frame.pack();
92          frame.setVisible(true);
93      }
94  
95      /**
96       * Closes the frame
97       */
98      public void closeFrame() {
99          if (frame != null) {
100             frame.dispose();
101         }
102     }
103 
104     private JPanel getTablePanel(){
105         JPanel jPanel = new JPanel(new GridLayout(1,0));
106         jPanel.setOpaque(true);
107         //setPreferredScrollableViewportSize(new Dimension(600, 200));
108         setPreferredScrollableViewportSize(new Dimension(1000, 400));
109         jPanel.add(new JScrollPane(this));
110         return jPanel;
111     }
112 }