/** * Prompts the user to save a matrix, and attemps to save it. * */ private void saveMatrix() { int returnVal = m_fileChooser.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File selectedFile = m_fileChooser.getSelectedFile(); // append extension if not already present if (!selectedFile.getName().toLowerCase() .endsWith(CostMatrix.FILE_EXTENSION)) { selectedFile = new File(selectedFile.getParent(), selectedFile.getName() + CostMatrix.FILE_EXTENSION); } Writer writer = null; try { writer = new BufferedWriter(new FileWriter(selectedFile)); m_matrix.write(writer); writer.close(); } catch (Exception ex) { JOptionPane.showMessageDialog(this, "Error writing file '" + selectedFile.getName() + "':\n" + ex.getMessage(), "Save failed", JOptionPane.ERROR_MESSAGE); System.out.println(ex.getMessage()); } } } }
/** * Prompts the user to save a matrix, and attemps to save it. * */ private void saveMatrix() { int returnVal = m_fileChooser.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File selectedFile = m_fileChooser.getSelectedFile(); // append extension if not already present if (!selectedFile.getName().toLowerCase() .endsWith(CostMatrix.FILE_EXTENSION)) { selectedFile = new File(selectedFile.getParent(), selectedFile.getName() + CostMatrix.FILE_EXTENSION); } Writer writer = null; try { writer = new BufferedWriter(new FileWriter(selectedFile)); m_matrix.write(writer); writer.close(); } catch (Exception ex) { JOptionPane.showMessageDialog(this, "Error writing file '" + selectedFile.getName() + "':\n" + ex.getMessage(), "Save failed", JOptionPane.ERROR_MESSAGE); System.out.println(ex.getMessage()); } } } }
if (cost_matrix.length() != 0) { StringWriter writer = new StringWriter(); CostMatrix.parseMatlab(cost_matrix).write(writer); setCostMatrix(new CostMatrix(new StringReader(writer.toString()))); setCostMatrixSource(new SelectedTag(MATRIX_SUPPLIED,
if (cost_matrix.length() != 0) { StringWriter writer = new StringWriter(); CostMatrix.parseMatlab(cost_matrix).write(writer); setCostMatrix(new CostMatrix(new StringReader(writer.toString()))); setCostMatrixSource(new SelectedTag(MATRIX_SUPPLIED,