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
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
53
54
55
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
137
138
139 public String getFilePathName() {
140 return fileName.getText();
141 }
142
143
144
145
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
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
179
180 }