|
|
|
@ -26,7 +26,7 @@ import javax.swing.text.DefaultCaret; |
|
|
|
|
public class GUI extends javax.swing.JFrame { |
|
|
|
|
|
|
|
|
|
private final int zup; |
|
|
|
|
private final double unit = 40.2; |
|
|
|
|
private final double unit; |
|
|
|
|
private int feed; |
|
|
|
|
|
|
|
|
|
private JFileChooser fc; |
|
|
|
@ -38,10 +38,10 @@ public class GUI extends javax.swing.JFrame { |
|
|
|
|
initComponents(); |
|
|
|
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
|
|
|
|
setLocationRelativeTo(null); |
|
|
|
|
setTitle("HPGL to GCode converter v1.0"); |
|
|
|
|
setTitle("HPGL to GCode converter v1.1"); |
|
|
|
|
|
|
|
|
|
zup = 5; |
|
|
|
|
|
|
|
|
|
unit = 40.2; |
|
|
|
|
feed = 30000; |
|
|
|
|
fc = new JFileChooser(); |
|
|
|
|
|
|
|
|
@ -102,7 +102,7 @@ public class GUI extends javax.swing.JFrame { |
|
|
|
|
jLabel3.setText("GCode output"); |
|
|
|
|
|
|
|
|
|
jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
|
|
|
|
jLabel4.setText("HPGL to GCode converter v1.0"); |
|
|
|
|
jLabel4.setText("HPGL to GCode converter v1.1"); |
|
|
|
|
|
|
|
|
|
jButton2.setText("Flush all"); |
|
|
|
|
jButton2.addActionListener(new java.awt.event.ActionListener() { |
|
|
|
@ -206,9 +206,7 @@ public class GUI extends javax.swing.JFrame { |
|
|
|
|
appendGCODE("G1 Z"+zup+" F"+feed); |
|
|
|
|
|
|
|
|
|
String lines[] = jTextArea1.getText().split("\\r?\\n"); |
|
|
|
|
jProgressBar1.setMaximum(lines.length/1000); |
|
|
|
|
jProgressBar1.setMinimum(0); |
|
|
|
|
enableProgress(); |
|
|
|
|
enableProgress(lines.length/1000, 0); |
|
|
|
|
|
|
|
|
|
new Thread() { |
|
|
|
|
public void run() { |
|
|
|
@ -249,20 +247,35 @@ public class GUI extends javax.swing.JFrame { |
|
|
|
|
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
|
|
|
|
|
int returnVal = fc.showOpenDialog(GUI.this); |
|
|
|
|
if (returnVal == JFileChooser.APPROVE_OPTION) { |
|
|
|
|
try { |
|
|
|
|
File f = new File(fc.getSelectedFile().getAbsolutePath()); |
|
|
|
|
if (!f.isDirectory()) { |
|
|
|
|
FileInputStream fs = new FileInputStream(fc.getSelectedFile().getAbsolutePath()); |
|
|
|
|
BufferedReader br = new BufferedReader(new InputStreamReader(fs)); |
|
|
|
|
String strLine; |
|
|
|
|
jTextArea1.setText(""); |
|
|
|
|
while((strLine = br.readLine()) != null) { |
|
|
|
|
jTextArea1.append(strLine+"\r\n"); |
|
|
|
|
} |
|
|
|
|
br.close(); |
|
|
|
|
File f = new File(fc.getSelectedFile().getAbsolutePath()); |
|
|
|
|
if (!f.isDirectory()) { |
|
|
|
|
//System.out.println("File");
|
|
|
|
|
try { |
|
|
|
|
new Thread() { |
|
|
|
|
public void run() { |
|
|
|
|
FileInputStream fs; |
|
|
|
|
try { |
|
|
|
|
fs = new FileInputStream(fc.getSelectedFile().getAbsolutePath()); |
|
|
|
|
BufferedReader br = new BufferedReader(new InputStreamReader(fs)); |
|
|
|
|
String strLine; |
|
|
|
|
enableProgress((int)f.length()/8,0); |
|
|
|
|
clearHPGL(); |
|
|
|
|
int i = 0; |
|
|
|
|
while((strLine = br.readLine()) != null) { |
|
|
|
|
i = i + (strLine.length()/5); |
|
|
|
|
updateProgress(i); |
|
|
|
|
//System.out.println((int)((double)i/((int)f.length()/8)*100)+": "+strLine);
|
|
|
|
|
appendHPGL(strLine); |
|
|
|
|
} |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}.start(); |
|
|
|
|
} |
|
|
|
|
catch (Exception e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}//GEN-LAST:event_jButton3ActionPerformed
|
|
|
|
@ -270,19 +283,26 @@ public class GUI extends javax.swing.JFrame { |
|
|
|
|
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
|
|
|
|
|
int returnVal = fc.showSaveDialog(GUI.this); |
|
|
|
|
if (returnVal == JFileChooser.APPROVE_OPTION) { |
|
|
|
|
try { |
|
|
|
|
File f = new File(fc.getSelectedFile().getAbsolutePath()); |
|
|
|
|
if (!f.isDirectory()) { |
|
|
|
|
PrintWriter writer = new PrintWriter(fc.getSelectedFile().getAbsolutePath(), "UTF-8"); |
|
|
|
|
String lines[] = jTextArea2.getText().split("\\r?\\n"); |
|
|
|
|
for (int i=0; i < lines.length; i++) { |
|
|
|
|
writer.println(lines[i]); |
|
|
|
|
new Thread() { |
|
|
|
|
public void run() { |
|
|
|
|
try { |
|
|
|
|
File f = new File(fc.getSelectedFile().getAbsolutePath()); |
|
|
|
|
if (!f.isDirectory()) { |
|
|
|
|
PrintWriter writer = new PrintWriter(fc.getSelectedFile().getAbsolutePath(), "UTF-8"); |
|
|
|
|
String lines[] = jTextArea2.getText().split("\\r?\\n"); |
|
|
|
|
enableProgress(lines.length, 0); |
|
|
|
|
for (int i=0; i < lines.length; i++) { |
|
|
|
|
writer.println(lines[i]); |
|
|
|
|
updateProgress(i); |
|
|
|
|
} |
|
|
|
|
disableProgress(); |
|
|
|
|
writer.close(); |
|
|
|
|
} |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
writer.close(); |
|
|
|
|
} |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
}.start(); |
|
|
|
|
} |
|
|
|
|
}//GEN-LAST:event_jButton4ActionPerformed
|
|
|
|
|
|
|
|
|
@ -293,7 +313,9 @@ public class GUI extends javax.swing.JFrame { |
|
|
|
|
jProgressBar1.setValue(0); |
|
|
|
|
jProgressBar1.setEnabled(false); |
|
|
|
|
} |
|
|
|
|
public void enableProgress() { |
|
|
|
|
public void enableProgress(int max, int min) { |
|
|
|
|
jProgressBar1.setMaximum(max); |
|
|
|
|
jProgressBar1.setMinimum(min); |
|
|
|
|
jProgressBar1.setValue(0); |
|
|
|
|
jProgressBar1.setEnabled(true); |
|
|
|
|
} |
|
|
|
@ -305,6 +327,14 @@ public class GUI extends javax.swing.JFrame { |
|
|
|
|
public void appendGCODE(String l) { |
|
|
|
|
jTextArea2.append(l+"\r\n"); |
|
|
|
|
} |
|
|
|
|
public void clearHPGL() { |
|
|
|
|
jTextArea1.setText(""); |
|
|
|
|
DefaultCaret caret = (DefaultCaret) jTextArea1.getCaret(); |
|
|
|
|
caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); |
|
|
|
|
} |
|
|
|
|
public void appendHPGL(String l) { |
|
|
|
|
jTextArea1.append(l+"\r\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param args the command line arguments |
|
|
|
|