added progress when opening and saving file.

This commit is contained in:
Dominik Dancs 2017-01-15 15:59:17 +01:00
parent 20e7622cf9
commit fe051f15dc
13 changed files with 96 additions and 37 deletions

View File

@ -10,7 +10,36 @@
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal> <goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals> </goals>
<properties> <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> <exec.executable>java</exec.executable>
</properties> </properties>
</action> </action>

View File

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

View File

@ -162,7 +162,7 @@
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Tahoma" size="14" style="0"/> <Font name="Tahoma" size="14" style="0"/>
</Property> </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> </Properties>
</Component> </Component>
<Component class="javax.swing.JProgressBar" name="jProgressBar1"> <Component class="javax.swing.JProgressBar" name="jProgressBar1">

View File

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

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

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