added progress when opening and saving file.

master
Dominik Dancs 6 years ago
parent 20e7622cf9
commit fe051f15dc
  1. 31
      nbactions.xml
  2. 2
      pom.xml
  3. 2
      src/main/java/info/moow/hpgl2gcode/GUI.form
  4. 94
      src/main/java/info/moow/hpgl2gcode/GUI.java
  5. BIN
      target/HPGL2GCODE-1.0.jar.original
  6. BIN
      target/HPGL2GCODE-1.1.jar
  7. BIN
      target/HPGL2GCODE-1.1.jar.original
  8. BIN
      target/classes/info/moow/hpgl2gcode/GUI$6.class
  9. BIN
      target/classes/info/moow/hpgl2gcode/GUI$7.class
  10. BIN
      target/classes/info/moow/hpgl2gcode/GUI$8.class
  11. BIN
      target/classes/info/moow/hpgl2gcode/GUI$9.class
  12. BIN
      target/classes/info/moow/hpgl2gcode/GUI.class
  13. 4
      target/maven-archiver/pom.properties

@ -10,7 +10,36 @@
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals>
<properties>
<exec.args>-classpath %classpath info.moow.hgpl2gcode.GUI</exec.args>
<exec.args>-classpath %classpath info.moow.hpgl2gcode.GUI</exec.args>
<exec.executable>java</exec.executable>
</properties>
</action>
<action>
<actionName>debug</actionName>
<packagings>
<packaging>jar</packaging>
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals>
<properties>
<exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath info.moow.hpgl2gcode.GUI</exec.args>
<exec.executable>java</exec.executable>
<jpda.listen>true</jpda.listen>
</properties>
</action>
<action>
<actionName>profile</actionName>
<packagings>
<packaging>jar</packaging>
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals>
<properties>
<exec.args>-classpath %classpath info.moow.hpgl2gcode.GUI</exec.args>
<exec.executable>java</exec.executable>
</properties>
</action>

@ -4,7 +4,7 @@
<groupId>info.moow</groupId>
<artifactId>HPGL2GCODE</artifactId>
<version>1.0</version>
<version>1.1</version>
<packaging>jar</packaging>
<name>HPGL2GCODE</name>

@ -162,7 +162,7 @@
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Tahoma" size="14" style="0"/>
</Property>
<Property name="text" type="java.lang.String" value="HPGL to GCode converter v1.0"/>
<Property name="text" type="java.lang.String" value="HPGL to GCode converter v1.1"/>
</Properties>
</Component>
<Component class="javax.swing.JProgressBar" name="jProgressBar1">

@ -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

@ -1,5 +1,5 @@
#Generated by Maven
#Sun Jan 15 15:02:51 CET 2017
version=1.0
#Sun Jan 15 15:58:42 CET 2017
version=1.1
groupId=info.moow
artifactId=HPGL2GCODE

Loading…
Cancel
Save