public void paint(Graphics g) { super.paint(g); List<PDOperation> operations = null; operations = new ArrayList<PDOperation>(history.getOperations()); Collections.sort(operations, new OperationComparatorByTime()); System.out.println(operations.size() + " operations retrieved"); editor.wordList.clear(); editor.wordList.add(new WordAndPos(editor.originator, 0)); if (operations != null) { for (PDOperation o : operations) { // System.out.println(o.toString()); PDInstance superParameter = o.getSuperParameter(); String command = o.getCommand(); if (command == editor.COPY) { PDCopy c = (PDCopy) superParameter; for (WordAndPos wp : editor.wordList) { if (wp.word.getId() == c.getToAfter().getId()) { editor.wordList.add( new WordAndPos(c.getNewWord(), wp.caretPos + wp.word.getText().length())); textArea.setText( textArea.getText().substring(0, wp.caretPos + wp.word.getText().length()) + c.getNewWord().getText() + textArea.getText().substring(wp.word.getText().length())); break; } } } else if (command == editor.DELETE || command == editor.CUT) { PDDelete d = (PDDelete) superParameter; for (WordAndPos wp : editor.wordList) { if (wp.word.getId() == d.getWord().getId()) { editor.wordList.remove(wp); textArea.setText( textArea.getText().substring(0, wp.caretPos) + textArea.getText().substring(wp.caretPos + wp.word.getText().length())); break; } } } else if (command == editor.INSERT) { PDInsert i = (PDInsert) superParameter; for (WordAndPos wp : editor.wordList) { if (wp.word.getId() == i.getAfter().getId()) { editor.wordList.add( new WordAndPos(i.getWord(), wp.caretPos + wp.word.getText().length())); textArea.setText( textArea.getText().substring(0, wp.caretPos + wp.word.getText().length()) + i.getWord().getText() + textArea.getText().substring(wp.word.getText().length())); break; } } } /*else if(command == MOVE){ PDMove m = (PDMove)superParameter; }*/ } ArrayList<PDOperation> parseOperations = new ArrayList<PDOperation>(); for (PDOperation operation : operations) { if (operation.toString() != null) { parseOperations.add(operation); } } list.setListData(parseOperations.toArray()); } }