Skip to content

Commit

Permalink
0.2.5.0
Browse files Browse the repository at this point in the history
released!
  • Loading branch information
leocarbon committed Nov 13, 2014
1 parent 665b8a8 commit 9dbb1be
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
14 changes: 13 additions & 1 deletion src/leocarbon/pnf/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.text.*;
Expand Down Expand Up @@ -135,7 +136,7 @@ public Options() {
add(info,c);
setBorder(BorderFactory.createEmptyBorder(16,16,16,16));
}

@Override
public void actionPerformed(ActionEvent AE) {
switch (AE.getActionCommand()) {
Expand Down Expand Up @@ -174,6 +175,7 @@ public void actionPerformed(ActionEvent AE) {
WriteToFile = false;
} break;
case "choosefile":
choosefile();
break;
case "alert":
if(alert.isSelected()){
Expand All @@ -186,4 +188,14 @@ public void actionPerformed(ActionEvent AE) {
break;
}
}

public void choosefile(){
FileDialog fd = new FileDialog(new JFrame(), "Choose File", FileDialog.SAVE);
fd.setFile("*.txt");
fd.setVisible(true);

if(fd.getFile() != null){
PNF.output = new File(fd.getDirectory()+"/"+fd.getFile());
}
}
}
23 changes: 16 additions & 7 deletions src/leocarbon/pnf/PrimeNumberFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,12 @@ public void start(){
out.setText(null);
}
try {
output = new File("Prime Numbers.txt");
if (!output.exists()) output.createNewFile();
filer = new FileWriter(output.getAbsoluteFile());
writer = new BufferedWriter(filer);
if(options.fileout.isSelected()){
if(output == null) options.choosefile();
if(!output.exists()) output.createNewFile();
filer = new FileWriter(output.getAbsoluteFile());
writer = new BufferedWriter(filer);
}
} catch (IOException IOE) {
Logger.getLogger(PrimeNumberFinder.class.getName()).warn(IOE);
}
Expand All @@ -209,7 +211,11 @@ public void start(){

options.autoscroll.setEnabled(true);
options.fileout.setEnabled(true);
options.filechoose.setEnabled(true);
if(options.fileout.isSelected()) options.filechoose.setEnabled(true);

output = null;
filer = null;
writer = null;

toggle.setActionCommand("start");
toggle.setText("Start");
Expand Down Expand Up @@ -290,7 +296,7 @@ protected Integer doInBackground() {
if(isPrime(j)){
++k;
try {
writer.append(Integer.toString(j) + "\n");
if(writer != null) writer.append(Integer.toString(j) + "\n");
} catch (IOException IOE) {
if(dologging) Logger.getLogger(PrimeNumberFinder.class.getName()).error(IOE);
}
Expand Down Expand Up @@ -332,7 +338,10 @@ public void done() {
stop();

try {
writer.close();
if(writer != null){
writer.flush();
writer.close();
}
} catch (IOException IOE) {
if(dologging) Logger.getLogger(FindPrimeNumbers.class.getName()).warn(IOE);
}
Expand Down
6 changes: 6 additions & 0 deletions version.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
version.md
---

Releases
--------------
######0.2.5.0 (11.13.14)
* actually usable
* output prime numbers to a (text) file of your choice.

Beta(β)
--------------
######0.β2.4.0 (11.9.14)
Expand Down
6 changes: 6 additions & 0 deletions version.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ Prime Number Finder

version.txt

Releases
--------------
0.2.5.0 (11.13.14)
- actually usable
- output prime numbers to a (text) file of your choice.

Beta(β)
--------------

0.β2.4.0 (11.9.14)
- many optimizations and cleanups.

Expand Down

0 comments on commit 9dbb1be

Please sign in to comment.