-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCf2dxf.java
221 lines (193 loc) · 10.3 KB
/
Cf2dxf.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package cf2dxf;
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileNameExtensionFilter;
/**
*
* @author master
*/
public class Cf2dxf extends javax.swing.JFrame {
/**
* Creates new form cf2dxfA
*/
public Cf2dxf() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
btnConvert = new javax.swing.JButton();
btnSelect = new javax.swing.JButton();
txtCf2File = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
txtNewFile = new javax.swing.JTextField();
BtnConvAllDir = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("CF2DXF Conversion v1.15");
btnConvert.setText("Convert to DXF");
btnConvert.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnConvertActionPerformed(evt);
}
});
btnSelect.setText("Select File to Convert");
btnSelect.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSelectActionPerformed(evt);
}
});
jLabel1.setText("File or Directory to Convert");
jLabel2.setText("Name of New File (Single File Mode)");
BtnConvAllDir.setText("Convert All CF2s in a Directory");
BtnConvAllDir.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BtnConvAllDirActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 130, Short.MAX_VALUE)
.addComponent(BtnConvAllDir, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(127, 127, 127))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtCf2File, javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(btnSelect, javax.swing.GroupLayout.PREFERRED_SIZE, 187, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnConvert, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(txtNewFile)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(17, 17, 17)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnSelect, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnConvert, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(35, 35, 35)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtCf2File, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtNewFile, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(24, 24, 24)
.addComponent(BtnConvAllDir, javax.swing.GroupLayout.DEFAULT_SIZE, 42, Short.MAX_VALUE)
.addGap(12, 12, 12))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void btnSelectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSelectActionPerformed
JFileChooser fileChooser = new JFileChooser();
fileChooser.setDialogTitle("Specify a file to save");
FileNameExtensionFilter filter = new FileNameExtensionFilter("CF2 Files", "CF2");
fileChooser.setFileFilter(filter);
String sfileIn = "";
fileChooser.setCurrentDirectory(new File(System.getProperty("user.home")));
int result = fileChooser.showOpenDialog(this);
if (result == JFileChooser.APPROVE_OPTION) {
File selectedFile = fileChooser.getSelectedFile();
sfileIn = fileChooser.getSelectedFile().getName();
//System.out.println("Selected file: " + sfileIn);
txtCf2File.setText(fileChooser.getSelectedFile().getPath().toString() );
txtNewFile.setText(txtCf2File.getText().replaceAll(".cf2", ".dxf"));
} else {
//System.out.println("Cancel Button pressed");
}
// JOptionPane.showMessageDialog(null, "Done");
// timJFrame.infoBox("YOUR INFORMATION HERE", "TITLE BAR MESSAGE");
}//GEN-LAST:event_btnSelectActionPerformed
private void btnConvertActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConvertActionPerformed
// lblWorking.setVisible(true);
convertCls oDxf = new convertCls();
oDxf.cf2File = txtCf2File.getText();
if (txtNewFile.getText().trim().length() < 3) {
txtNewFile.setText(txtCf2File.getText().toLowerCase().replace(".cf2", ".dxf"));
}
oDxf.dxfFile = txtNewFile.getText();
this.setTitle(this.getTitle() + " WORKING...");
oDxf.convertDxf();
this.setTitle(this.getTitle() + " DONE!");
}//GEN-LAST:event_btnConvertActionPerformed
private void BtnConvAllDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnConvAllDirActionPerformed
GetCf2FilesInDir cf = new GetCf2FilesInDir();
convertCls oDxf = new convertCls();
oDxf.cf2File = txtCf2File.getText();
oDxf.batch = true;
File[] elements = cf.getCf2FileList(txtCf2File.getText().toString()); //{ "a","a","a","a" };
for( int i = 0; i < elements.length; i++) {
System.out.println(elements[i].toString());
oDxf.cf2File = elements[i].toString();
oDxf.dxfFile = elements[i].toString().toLowerCase().replace(".cf2", ".dxf");
oDxf.convertDxf();
}
JOptionPane.showMessageDialog(null, "Complete", "Convert CF2 Directory" , JOptionPane.INFORMATION_MESSAGE);
}//GEN-LAST:event_BtnConvAllDirActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Cf2dxf.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Cf2dxf.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Cf2dxf.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Cf2dxf.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Cf2dxf().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton BtnConvAllDir;
private javax.swing.JButton btnConvert;
private javax.swing.JButton btnSelect;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JTextField txtCf2File;
private javax.swing.JTextField txtNewFile;
// End of variables declaration//GEN-END:variables
}