/** * Backs up the current state of the dataset, so the changes can be undone. * * @throws Exception if an error occurs */ public void addUndoPoint() throws Exception { if (!ExplorerDefaults.get("enableUndo", "true").equalsIgnoreCase("true")) { return; } if (m_Instances != null) { // create temporary file File tempFile = File.createTempFile("weka", SerializedInstancesLoader.FILE_EXTENSION); tempFile.deleteOnExit(); if (!ExplorerDefaults.get("undoDirectory", "%t").equalsIgnoreCase("%t")) { String dir = ExplorerDefaults.get("undoDirectory", "%t"); File undoDir = new File(dir); if (undoDir.exists()) { String fileName = tempFile.getName(); File newFile = new File(dir + File.separator + fileName); if (undoDir.canWrite()) { newFile.deleteOnExit(); tempFile = newFile; } else { System.err.println("Explorer: it doesn't look like we have permission" + " to write to the user-specified undo directory " + "'" + dir + "'"); } } else { System.err.println("Explorer: user-specified undo directory '" + dir + "' does not exist!"); } } ObjectOutputStream oos = new ObjectOutputStream( new BufferedOutputStream( new FileOutputStream(tempFile))); oos.writeObject(m_Instances); oos.flush(); oos.close(); // update undo file list if (m_tempUndoFiles[m_tempUndoIndex] != null) { // remove undo points that are too old m_tempUndoFiles[m_tempUndoIndex].delete(); } m_tempUndoFiles[m_tempUndoIndex] = tempFile; if (++m_tempUndoIndex >= m_tempUndoFiles.length) { // wrap pointer around m_tempUndoIndex = 0; } m_UndoBut.setEnabled(true); } }
/** * Adds an undo point. * * @return true if successfully added */ public boolean addUndoPoint() { boolean result; File tempFile; ObjectOutputStream oos; ArrayList data; if (m_Data == null) return false; tempFile = null; try { // create temporary file tempFile = File.createTempFile("meka", SerializedInstancesLoader.FILE_EXTENSION); tempFile.deleteOnExit(); data = new ArrayList(); data.add(m_CurrentFile); data.add(m_Data); // save data oos = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(tempFile))); oos.writeObject(data); oos.flush(); oos.close(); m_Undo.add(tempFile); result = true; } catch (Exception e) { result = false; System.err.println("Failed to save undo data to '" + tempFile + "':"); e.printStackTrace(); JOptionPane.showMessageDialog( this, "Failed to save undo data to '" + tempFile + "':\n" + e, "Error", JOptionPane.ERROR_MESSAGE); } updateMenu(); return result; }
/** * Backs up the current state of the dataset, so the changes can be undone. * * @throws Exception if an error occurs */ public void addUndoPoint() throws Exception { if (!ExplorerDefaults.get("enableUndo", "true").equalsIgnoreCase("true")) { return; } if (m_Instances != null) { // create temporary file File tempFile = File.createTempFile("weka/src/main/java/weka", SerializedInstancesLoader.FILE_EXTENSION); tempFile.deleteOnExit(); if (!ExplorerDefaults.get("undoDirectory", "%t").equalsIgnoreCase("%t")) { String dir = ExplorerDefaults.get("undoDirectory", "%t"); File undoDir = new File(dir); if (undoDir.exists()) { String fileName = tempFile.getName(); File newFile = new File(dir + File.separator + fileName); if (undoDir.canWrite()) { newFile.deleteOnExit(); tempFile = newFile; } else { System.err.println("Explorer: it doesn't look like we have permission" + " to write to the user-specified undo directory " + "'" + dir + "'"); } } else { System.err.println("Explorer: user-specified undo directory '" + dir + "' does not exist!"); } } ObjectOutputStream oos = new ObjectOutputStream( new BufferedOutputStream( new FileOutputStream(tempFile))); oos.writeObject(m_Instances); oos.flush(); oos.close(); // update undo file list if (m_tempUndoFiles[m_tempUndoIndex] != null) { // remove undo points that are too old m_tempUndoFiles[m_tempUndoIndex].delete(); } m_tempUndoFiles[m_tempUndoIndex] = tempFile; if (++m_tempUndoIndex >= m_tempUndoFiles.length) { // wrap pointer around m_tempUndoIndex = 0; } m_UndoBut.setEnabled(true); } }