1   package org.wcb.gui.forms.wizard;
2   
3   import org.wcb.gui.component.JXTitlePanel;
4   import org.wcb.gui.dialog.file.ExportFileDialog;
5   import org.wcb.model.service.impl.ExportService;
6   import org.jdesktop.swingx.border.DropShadowBorder;
7   
8   import javax.swing.border.Border;
9   import javax.swing.border.CompoundBorder;
10  import javax.swing.border.EtchedBorder;
11  import javax.swing.*;
12  import java.awt.event.ActionListener;
13  import java.awt.event.ActionEvent;
14  import java.awt.*;
15  import java.io.File;
16  
17  /**
18   * <small>
19   * <p/>
20   * Copyright (C)  2006  wbogaardt.
21   * This library is free software; you can redistribute it and/or
22   * modify it under the terms of the GNU Lesser General Public
23   * License as published by the Free Software Foundation; either
24   * version 2.1 of the License, or (at your option) any later version.
25   * <p/>
26   * This library is distributed in the hope that it will be useful,
27   * but WITHOUT ANY WARRANTY; without even the implied warranty of
28   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
29   * Lesser General Public License for more details.
30   * <p/>
31   * You should have received a copy of the GNU Lesser General Public
32   * License along with this library; if not, write to the Free Software
33   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
34   * <p/>
35   * $File:  $ <br>
36   * $Change:  $ submitted by $Author: wbogaardt $ at $DateTime: Oct 26, 2006 2:43:12 PM $ <br>
37   * </small>
38   *
39   * @author wbogaardt
40   *        Page 2 save cvs file to a user selected location.
41   */
42  
43  public class Step2ofExportWizard extends JXTitlePanel implements ActionListener {
44  
45      public Step2ofExportWizard() {
46          super("Step 2 - Save to File", new Color(0x3779ff));
47          Border shadow = new DropShadowBorder(Color.BLACK, 1, 5, .3f, 15, true, true, true, true);
48          setBorder(new CompoundBorder(shadow, getBorder()));
49          initComponents();
50      }
51  
52      /** This method is called from within the constructor to
53       * initialize the form.
54       * WARNING: Do NOT modify this code. The content of this method is
55       * always regenerated by the Form Editor.
56       */
57      private void initComponents() {
58          fileName = new JTextField(System.getProperty("user.home") + File.separator + "pilotslog-export.csv");
59          fileLocationButton = new JButton("..");
60          fileLocationButton.addActionListener(this);
61          commaRb = new JRadioButton("Comma", true);
62          tabRb = new JRadioButton("Tab");
63          pipeRb = new JRadioButton("Pipe");
64          semicolonRb = new JRadioButton("Semicolon");
65          ButtonGroup groupFileSeps = new ButtonGroup();
66          groupFileSeps.add(commaRb);
67          groupFileSeps.add(tabRb);
68          groupFileSeps.add(pipeRb);
69          groupFileSeps.add(semicolonRb);
70  
71          setLayout(new BorderLayout());
72          JPanel messagePanel = new JPanel();
73          messagePanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
74          messagePanel.add(new JLabel("<html>The data export wizard allows you to get the data<br>" +
75                  "from this logbook software into other programs. The default format is<br>" +
76                  "comma delimted, which is a common way of importing into spreadsheet<br>" +
77                  "programs. If you want to move your logbook data to another machine and<br>" +
78                  "still use this program then read \"back-up\" your data."));
79          add(messagePanel, BorderLayout.NORTH);
80  
81          JPanel fileSelectionPanel = new JPanel(new GridBagLayout());
82          GridBagConstraints gridBagConstraints = new GridBagConstraints();
83          gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
84          gridBagConstraints.gridwidth = 3;
85          gridBagConstraints.insets = new Insets(0,5,5,0);
86          fileSelectionPanel.add(new JLabel("Once exported, the data will be available in the following file:"), gridBagConstraints);
87  
88          gridBagConstraints = new GridBagConstraints();
89          gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
90          gridBagConstraints.gridx = 0;
91          gridBagConstraints.gridy = 1;
92          gridBagConstraints.insets = new Insets(0,5,0,5);
93          fileSelectionPanel.add(new JLabel("File Name"), gridBagConstraints);
94  
95          gridBagConstraints = new GridBagConstraints();
96          gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
97          gridBagConstraints.gridx = 1;
98          gridBagConstraints.gridy = 1;
99          gridBagConstraints.insets = new Insets(0,0,0,3);
100         fileSelectionPanel.add(fileName, gridBagConstraints);
101 
102         gridBagConstraints = new GridBagConstraints();
103         gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
104         gridBagConstraints.gridx = 2;
105         gridBagConstraints.gridy = 1;
106         fileSelectionPanel.add(fileLocationButton, gridBagConstraints);
107 
108         gridBagConstraints = new GridBagConstraints();
109         gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
110         gridBagConstraints.gridwidth = 3;
111         gridBagConstraints.gridx = 0;
112         gridBagConstraints.gridy = 2;
113         gridBagConstraints.insets = new Insets(0,5,5,0);
114         fileSelectionPanel.add(new JLabel("Select a field delimiter:"), gridBagConstraints);
115 
116         JPanel radioButtonPanel = new JPanel();
117         radioButtonPanel.add(commaRb);
118         radioButtonPanel.add(tabRb);
119         radioButtonPanel.add(pipeRb);
120         radioButtonPanel.add(semicolonRb);
121 
122         gridBagConstraints = new GridBagConstraints();
123         gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
124         gridBagConstraints.gridwidth = 3;
125         gridBagConstraints.gridx = 0;
126         gridBagConstraints.gridy = 3;
127         gridBagConstraints.insets = new Insets(0,5,0,0);
128         gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
129         fileSelectionPanel.add(radioButtonPanel, gridBagConstraints);
130 
131 
132         add(fileSelectionPanel,BorderLayout.CENTER);
133     }
134 
135     /**
136      * The selected file path and name the user wants this file saved as.
137      * @return the filename and path.
138      */
139     public String getFilePathName() {
140         return fileName.getText();
141     }
142 
143     /**
144      * Gets the user specified file delimiter.
145      * @return the int value indicates the selection look at ExportService.
146      */
147     public int getFieldDelimiter() {
148         if (tabRb.isSelected()) {
149             return ExportService.TAB;
150         }
151         if (pipeRb.isSelected()) {
152             return ExportService.PIPE;
153         }
154         if (semicolonRb.isSelected()) {
155             return ExportService.SEMICOLON;
156         }
157         return ExportService.COMMA;
158     }
159 
160     public void actionPerformed(ActionEvent evt) {
161         ExportFileDialog exportDialog = new ExportFileDialog();
162         String filePath = exportDialog.getFilePath();
163         if(filePath != null && !filePath.equals("")) {
164             fileName.setText(filePath);
165         }
166     }
167 
168 
169     // Variables declaration - do not modify
170 
171     private JTextField fileName;
172     private JButton fileLocationButton;
173     private JRadioButton commaRb;
174     private JRadioButton tabRb;
175     private JRadioButton pipeRb;
176     private JRadioButton semicolonRb;
177 
178     // End of variables declaration
179 
180 }