From 9c478183bfbc1717a80a2b81bf5d10b5884056f9 Mon Sep 17 00:00:00 2001 From: Tom Copeland Date: Wed, 13 Aug 2003 19:47:22 +0000 Subject: [PATCH] Made the report saving process a bit nicer git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@2189 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd/etc/changelog.txt | 1 + pmd/src/net/sourceforge/pmd/cpd/GUI.java | 33 ++++++++++++------------ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index 8ff2bfbe93..12674b5e10 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -6,6 +6,7 @@ Fixed bug 781393 - VariableNameDeclaration no longer throws ClassCastExpression Tweaked CPD time display field Made CPD text fields uneditable Added more error checking to CPD GUI input +Added "dialog cancelled" check to CPD "Save" function TODO - fix it so tests and rules don't duplicate the xpath expressions August 1, 2003 - 1.2.1: diff --git a/pmd/src/net/sourceforge/pmd/cpd/GUI.java b/pmd/src/net/sourceforge/pmd/cpd/GUI.java index 72b7eeca6c..5c4e007025 100644 --- a/pmd/src/net/sourceforge/pmd/cpd/GUI.java +++ b/pmd/src/net/sourceforge/pmd/cpd/GUI.java @@ -54,24 +54,23 @@ public class GUI implements CPDListener { FileDialog fdlg = new FileDialog(GUI.this.frame, "Save", FileDialog.SAVE); fdlg.setVisible(true); String selected = fdlg.getDirectory() + System.getProperty("file.separator") + fdlg.getFile(); - if(selected !=null){ - if(!new File(selected).canWrite()){ - try{ - PrintWriter pw = new PrintWriter(new FileOutputStream(selected)); - String report = resultsTextArea.getText(); - pw.print(report); - pw.flush(); - pw.close(); - }catch(IOException e){ - error("Couldn't save file"+new File(selected).getAbsolutePath(), e); - } - }else{ - error("Could not write to file "+new File(selected).getAbsolutePath(), null); - - } - + if (fdlg.getFile() == null) { + return; + } + if(!new File(selected).canWrite()){ + try{ + PrintWriter pw = new PrintWriter(new FileOutputStream(selected)); + String report = resultsTextArea.getText(); + pw.print(report); + pw.flush(); + pw.close(); + JOptionPane.showMessageDialog(frame, "File saved"); + }catch(IOException e){ + error("Couldn't save file"+new File(selected).getAbsolutePath(), e); + } + }else{ + error("Could not write to file "+new File(selected).getAbsolutePath(), null); } - } private void error(String message, Exception e){