1   package org.wcb.gui.dialog;
2   
3   import org.wcb.gui.forms.report.*;
4   import org.wcb.gui.component.JXTitlePanel;
5   import org.wcb.gui.component.WaveButton;
6   import org.wcb.gui.util.PrintUtilities;
7   import org.wcb.gui.util.UIHelper;
8   import org.wcb.resources.MessageResourceRegister;
9   import org.wcb.resources.MessageKey;
10  import org.jdesktop.swingx.border.DropShadowBorder;
11  
12  import javax.swing.*;
13  import javax.swing.border.Border;
14  import javax.swing.border.CompoundBorder;
15  import java.awt.event.ActionListener;
16  import java.awt.event.ActionEvent;
17  import java.awt.*;
18  
19  /**
20   * <small>
21   * Copyright (c)  2006  wbogaardt.
22   * This library is free software; you can redistribute it and/or
23   * modify it under the terms of the GNU Lesser General Public
24   * License as published by the Free Software Foundation; either
25   * version 2.1 of the License, or (at your option) any later version.
26   *
27   * This library is distributed in the hope that it will be useful,
28   * but WITHOUT ANY WARRANTY; without even the implied warranty of
29   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
30   * Lesser General Public License for more details.
31   *
32   * You should have received a copy of the GNU Lesser General Public
33   * License along with this library; if not, write to the Free Software
34   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
35   * <p/>
36   * $File:  $ <br>
37   * $Change:  $ submitted by $Author: wbogaardt $ at $DateTime: Mar 29, 2006 3:35:03 PM $ <br>
38   * </small>
39   *
40   * @author wbogaardt
41   * @version 1
42   *          Date: Mar 29, 2006
43   *          Time: 3:35:03 PM
44   */
45  
46  public class ReportDisplayDialog extends JDialog implements ActionListener{
47  
48      private JButton closeButton;
49      private JButton printButton;
50      private JPanel form;
51      private String optionValue;
52  
53      public ReportDisplayDialog(int rType) {
54          this(rType, null);
55      }
56  
57      public ReportDisplayDialog(int rType, String sVal) {
58          setTitle("Logbook Report");
59          setModal(true);
60          setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
61          this.optionValue = sVal;
62          initForm(rType);
63          initComponents();
64      }
65  
66      public void addActionListener(ActionListener listener) {
67          closeButton.addActionListener(listener);
68      }
69  
70      public void refresh() {
71          ((ReportRefresh) form).refresh();
72      }
73  
74      private void initForm(int rType) {
75          switch(rType)
76          {
77              case 0:
78                  form = new TotalTimeReportForm();
79                  break;
80              case 1:
81                  form = new TotalTimeAircraftReportForm(optionValue);
82                  break;
83              case 2:
84                  form = new TotalTimeInstrumentReportForm();
85                  break;
86              case 3:
87                  form = new TotalTakeoffLandingsReportForm();
88                  break;
89              case 4:
90                  form = new AircraftMakeModelReportForm();
91                  break;
92              default:
93                  form = new TotalTimeReportForm();
94          }
95      }
96  
97      /**
98       * Init the componets in the dialog.
99       */
100     private void initComponents() {
101         closeButton = new WaveButton(MessageResourceRegister.getInstance().getValue(MessageKey.BUTTON_CLOSE));
102         printButton = new WaveButton(MessageResourceRegister.getInstance().getValue(MessageKey.BUTTON_PRINT));
103         printButton.addActionListener(this);
104         getContentPane().setLayout(new BorderLayout());
105 
106         JPanel mainPanel = new JXTitlePanel("Pilot Logbook Report", new Color(0x522aec));
107         Border shadow = new DropShadowBorder(Color.BLACK, 1, 10, .5f, 15, false, true, true, true);
108         mainPanel.setBorder(new CompoundBorder(shadow, mainPanel.getBorder()));
109         mainPanel.setLayout(new GridBagLayout());
110         GridBagConstraints gridBagConstraints;
111 
112         gridBagConstraints = new GridBagConstraints();
113         gridBagConstraints.gridx = 0;
114         gridBagConstraints.gridy = 0;
115         gridBagConstraints.anchor = GridBagConstraints.CENTER;
116         mainPanel.add(form, gridBagConstraints);
117 
118         gridBagConstraints = new GridBagConstraints();
119         gridBagConstraints.gridx = 0;
120         gridBagConstraints.gridy = 1;
121         gridBagConstraints.anchor = GridBagConstraints.WEST;
122         mainPanel.add(closeButton, gridBagConstraints);
123 
124         gridBagConstraints = new GridBagConstraints();
125         gridBagConstraints.gridx = 1;
126         gridBagConstraints.gridy = 1;
127         gridBagConstraints.anchor = GridBagConstraints.WEST;
128         mainPanel.add(printButton, gridBagConstraints);
129 
130         getContentPane().add(mainPanel, BorderLayout.CENTER);
131         pack();
132         UIHelper.centerDialogToScreen(this);
133     }
134 
135     public void actionPerformed(ActionEvent evt) {
136         PrintUtilities.printComponent(form);
137     }
138 }