Author: chatellier Date: 2009-03-31 08:14:00 +0000 (Tue, 31 Mar 2009) New Revision: 131 Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPopupMenu.java Log: Fix NPE if user choose cancel option. Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPopupMenu.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPopupMenu.java 2009-03-24 15:33:41 UTC (rev 130) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPopupMenu.java 2009-03-31 08:14:00 UTC (rev 131) @@ -47,7 +47,7 @@ import org.codelutin.util.FileUtil; /** - * Ajout d'un menu contextuel sur la matrice dans l'editeur + * Ajout d'un menu contextuel sur la matrice dans l'editeur. * * Created: 22 mars 2006 12:11:46 * @@ -61,7 +61,7 @@ /** serialVersionUID. */ private static final long serialVersionUID = 3349189688987885915L; - + private MatrixEditor matrixEditor; private JFileChooser fileChooser; @@ -507,9 +507,11 @@ private void sendToFileAllCopyPerformed() { try { Writer writer = getFileChooserWriter(); - getMatrix().exportCSV(writer, withSemantics.getState()); - writer.close(); - matrixEditor.repaint(); + if (writer != null) { + getMatrix().exportCSV(writer, withSemantics.getState()); + writer.close(); + matrixEditor.repaint(); + } } catch (Exception e) { JOptionPane.showMessageDialog(matrixEditor, _("lutinmatrix.error.file.write"), _("lutinmatrix.error"), @@ -521,10 +523,12 @@ private void sendToFileAllPastePerformed() { try { Reader reader = getFileChooserReader(); - getMatrix().importCSV(reader, new int[] { 0, 0 }); - reader.close(); - matrixEditor.fireEvent(); - matrixEditor.repaint(); + if (reader != null) { // cancel + getMatrix().importCSV(reader, new int[] { 0, 0 }); + reader.close(); + matrixEditor.fireEvent(); + matrixEditor.repaint(); + } } catch (Exception e) { JOptionPane.showMessageDialog(matrixEditor, _("lutinmatrix.error.file.read"), _("lutinmatrix.error"), @@ -536,9 +540,11 @@ private void sendToFileSelectionCopyPerformed() { try { Writer writer = getFileChooserWriter(); - getSelectedMatrix().exportCSV(writer, withSemantics.getState()); - writer.close(); - matrixEditor.repaint(); + if (writer != null) { + getSelectedMatrix().exportCSV(writer, withSemantics.getState()); + writer.close(); + matrixEditor.repaint(); + } } catch (Exception e) { JOptionPane.showMessageDialog(matrixEditor, _("lutinmatrix.error.file.write"), _("lutinmatrix.error"), @@ -550,11 +556,13 @@ private void sendToFileCurrentPastePerformed() { try { Reader reader = getFileChooserReader(); - getMatrix().importCSV(reader, - getCoordinatesFirstCellSelectedMatrix()); - reader.close(); - matrixEditor.fireEvent(); - matrixEditor.repaint(); + if (reader != null) { // cancel + getMatrix().importCSV(reader, + getCoordinatesFirstCellSelectedMatrix()); + reader.close(); + matrixEditor.fireEvent(); + matrixEditor.repaint(); + } } catch (Exception e) { JOptionPane.showMessageDialog(matrixEditor, _("lutinmatrix.error.file.read"), _("lutinmatrix.error"),