001 ///////////////////////////////////////////////// 002 // This file is part of Sears project. 003 // Subtitle Editor And Re-Synch 004 // A tool to easily modify and resynch movies subtitles. 005 ///////////////////////////////////////////////// 006 //This program is free software; 007 //you can redistribute it and/or modify it under the terms 008 //of the GNU General Public License 009 //as published by the Free Software Foundation; 010 //either version 2 of the License, or (at your option) any later version. 011 ///////////////////////////////////////////////// 012 //Sears project is available under sourceforge 013 // at adress: http://sourceforge.net/projects/sears/ 014 //Copyright (C) 2005 Booba Skaya 015 //Mail: booba.skaya@gmail.com 016 //////////////////////////////////////////////// 017 // $Id 018 //////////////////////////////////////////////// 019 020 package sears.gui.undo; 021 022 import java.util.ArrayList; 023 024 import javax.swing.undo.CannotRedoException; 025 import javax.swing.undo.CannotUndoException; 026 import javax.swing.undo.UndoableEdit; 027 028 import sears.file.Subtitle; 029 030 /** 031 * Class SearsSimpleUndoEdit 032 * This represents a simple subtitle edit 033 */ 034 public class SearsSimpleUndoEdit implements UndoableEdit{ 035 036 /** The subtitle before the edit.*/ 037 private Subtitle _oldSubtitle = null; 038 /** The subtitle after the edit.*/ 039 private Subtitle _newSubtitle = null; 040 /** The subtitle list*/ 041 private ArrayList<Subtitle> _subtitleList = null; 042 /** The row of the edit.*/ 043 private int _row; 044 045 /** 046 * Constructor of the SimpleUndoEdit 047 * @param subtitleList The list that contains the subtitles 048 * @param row The row of the edit 049 * @param oldSubtitle The subtitle before the edit 050 * @param newSubtitle The subtitle after the edit 051 */ 052 public SearsSimpleUndoEdit(ArrayList<Subtitle> subtitleList, int row, Subtitle oldSubtitle, Subtitle newSubtitle){ 053 _subtitleList = subtitleList; 054 _oldSubtitle = oldSubtitle; 055 _newSubtitle = newSubtitle; 056 _row = row; 057 } 058 059 @Override 060 public boolean addEdit(UndoableEdit anEdit) { 061 return false; 062 } 063 064 @Override 065 public boolean canRedo() { 066 return true; 067 } 068 069 @Override 070 public boolean canUndo() { 071 return true; 072 } 073 074 @Override 075 public void die() { 076 _oldSubtitle = null; 077 _newSubtitle = null; 078 } 079 080 @Override 081 public String getPresentationName() { 082 return _oldSubtitle+"=>"+_newSubtitle; 083 } 084 085 @Override 086 public String getRedoPresentationName() { 087 return "=>"+_newSubtitle; 088 } 089 090 @Override 091 public String getUndoPresentationName() { 092 return ""+_oldSubtitle+"<="; 093 } 094 095 @Override 096 public boolean isSignificant() { 097 return true; 098 } 099 100 @Override 101 public void redo() throws CannotRedoException { 102 _subtitleList.set(_row, _newSubtitle); 103 } 104 105 @Override 106 public boolean replaceEdit(UndoableEdit anEdit) { 107 return false; 108 } 109 110 @Override 111 public void undo() throws CannotUndoException { 112 _subtitleList.set(_row, _oldSubtitle); 113 } 114 }