private void formAncestorAdded(final javax.swing.event.AncestorEvent evt) {// GEN-FIRST:event_formAncestorAdded if (addedUndoListener) { return; } addedUndoListener = true; if (evt.getComponent() instanceof Container) { Container anc = evt.getComponent(); while ((anc != null) && (anc instanceof Container)) { if (anc instanceof UndoableEditListener) { editSupport.addUndoableEditListener((UndoableEditListener) anc); break; } anc = anc.getParent(); } } }
private void formAncestorAdded(javax.swing.event.AncestorEvent evt) {// GEN-FIRST:event_formAncestorAdded if (addedUndoListener) { return; } addedUndoListener = true; if (evt.getComponent() instanceof Container) { Container anc = evt.getComponent(); while ((anc != null) && (anc instanceof Container)) { if (anc instanceof UndoableEditListener) { editSupport.addUndoableEditListener((UndoableEditListener) anc); break; } anc = anc.getParent(); } } }
private void formAncestorAdded(javax.swing.event.AncestorEvent evt) {//GEN-FIRST:event_formAncestorAdded if (addedUndoListener) { return; } addedUndoListener = true; if (evt.getComponent() instanceof Container) { Container anc = (Container) evt.getComponent(); while (anc != null && anc instanceof Container) { if (anc instanceof UndoableEditListener) { editSupport.addUndoableEditListener((UndoableEditListener) anc); break; } anc = anc.getParent(); } } }
private void formAncestorAdded(javax.swing.event.AncestorEvent evt) {//GEN-FIRST:event_formAncestorAdded if ( addedUndoListener ){ return; } addedUndoListener = true; if ( evt.getComponent() instanceof Container ){ Container anc = (Container)evt.getComponent(); while ( anc != null && anc instanceof Container ){ if ( anc instanceof UndoableEditListener ){ editSupport.addUndoableEditListener((UndoableEditListener)anc); break; } anc = anc.getParent(); } } }
/** Creates a new instance of XMLEditorPane */ public XMLTextEditor() { super(); XMLEditorKit kit = new XMLEditorKit(); setEditorKitForContentType(XMLEditorKit.XML_MIME_TYPE, kit); setContentType(XMLEditorKit.XML_MIME_TYPE); setBackground(Color.white); //setFont(new Font("Monospaced", Font.PLAIN, 12)); // add undoable edit undoManager = new UndoManager(); UndoableEditListener undoableEditHandler = new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent e) { undoManager.addEdit(e.getEdit()); } }; getDocument().addUndoableEditListener(undoableEditHandler); }
/** Creates new form SemanticAnnotation */ public SemanticAnnotation(String inputFile) { this.inputFile = inputFile; initComponents(); readInputFile(); spinner.setValue(0); selectButton.doClick(); splitPane.setDividerLocation(0.5); outText.getDocument().addUndoableEditListener( new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent e) { undoManager.addEdit(e.getEdit()); } }); }
/** * The setters on the DSType uses a different method to set properties than the * one used in testUndoAndRedo. This confirms that the setters do create undo and * redo edits. */ public void testUndoOnSetters() throws Exception { final JDBCDataSourceType dsType = new JDBCDataSourceType(); class TestUndoableEditListener implements UndoableEditListener { private int editCount = 0; public void undoableEditHappened(UndoableEditEvent e) { editCount++; } public int getEditCount() { return editCount; } } TestUndoableEditListener undoableEditListener = new TestUndoableEditListener(); dsType.addUndoableEditListener(undoableEditListener); dsType.setComment("comment"); dsType.setDDLGeneratorClass("class"); dsType.setName("name"); assertEquals(3, undoableEditListener.getEditCount()); }
/** * This method is called from within the constructor to initialise the undo * manager for the text pane. */ private void initUndoManager() { undoF = new UndoManager(); undoF.setLimit(5000); doc.addUndoableEditListener(new UndoableEditListener() { @Override public void undoableEditHappened(UndoableEditEvent evt) { undoF.addEdit(evt.getEdit()); // adding a "*" to the file name, when the file has changed but not saved if (jframe.getFileTabCount() != 0 && jframe.getSelectedPath().indexOf("*") == -1) { jframe.setSelectedTitle(subPath + "*"); jframe.setTitle(jframe.getJifVersion() + " - " + jframe.getSelectedPath()); } } }); }
private void init() { basusSyntaxDocument = new BasusSyntaxDocument(); setStyledDocument(basusSyntaxDocument); undoManager = new UndoManager(); getDocument().addUndoableEditListener(new UndoableEditListener() { @Override public void undoableEditHappened(final UndoableEditEvent e) { if (!basusSyntaxDocument.isHighlighting()) { undoManager.addEdit(e.getEdit()); notifyProvider(); } } }); getDocument().addDocumentListener(this); addKeyListener(this); final ActionMap am = getActionMap(); am.put(DefaultEditorKit.insertBreakAction, new AutoIndentAction()); }
public SyntaxDocument(Lexer lexer) { super(); putProperty(PlainDocument.tabSizeAttribute, 4); // outside ?! this.lexer = lexer; // Listen for undo and redo events addUndoableEditListener(new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent event) { if (event.getEdit().isSignificant()) { undo.addEdit(event.getEdit()); } } }); }
/** * Creates actions for editing the petri net * * @param controller PIPE application controller */ public ComponentEditorManager(PipeApplicationController controller) { copyAction = new CopyAction(controller); pasteAction = new PasteAction(controller); cutAction = new CutAction(controller); deleteAction = new DeleteAction(controller); undoAction = new UndoAction(controller); redoAction = new RedoAction(controller, undoAction); undoAction.registerRedoAction(redoAction); undoAction.setEnabled(false); redoAction.setEnabled(false); UndoableEditListener listener = new SimpleUndoListener(redoAction, undoAction, controller); deleteAction.addUndoableEditListener(listener); copyAction.addUndoableEditListener(listener); cutAction.addUndoableEditListener(listener); pasteAction.addUndoableEditListener(listener); storeEnabledStatus(); }
/** * Constructor * @param model underlying Petri net * @param undoListener undo listener for tool bar buttons undo actions * @param animator Petri net animator * @param copyPasteManager copy paste manager for the Petri net * @param zoomController zoom controller for the Petri net * @param petriNetTab tab this Petri net is displayed on */ public PetriNetController(PetriNet model, UndoableEditListener undoListener, GUIAnimator animator, CopyPasteManager copyPasteManager, ZoomController zoomController, PetriNetTab petriNetTab) { petriNet = model; this.undoListener = undoListener; this.petriNetTab = petriNetTab; selectionManager = new SelectionManager(this); lastSavedNet = ClonePetriNet.clone(model); this.zoomController = zoomController; this.animator = animator; this.copyPasteManager = copyPasteManager; if (model.getTokens().size() > 0) { selectedToken = model.getTokens().iterator().next().getId(); } placeNamer = new PlaceNamer(model); transitionNamer = new TransitionNamer(model); }
/** * Register the tab to the Petri net * @param net Petri net * @param tab tab which houses the graphical petri net components * @param historyObserver listener for stepback/forward events in animation * @param undoListener listener for undo/redo events * @param zoomListener listener for zoom events */ //TODO: THIS IS RATHER UGLY, too many params but better than what was here before public void registerTab(PetriNet net, PetriNetTab tab, Observer historyObserver, UndoableEditListener undoListener, PropertyChangeListener zoomListener) { AnimationHistoryImpl animationHistory = new AnimationHistoryImpl(); animationHistory.addObserver(historyObserver); GUIAnimator animator = new GUIAnimator(new PetriNetAnimator(net), animationHistory, this); CopyPasteManager copyPasteManager = new CopyPasteManager(undoListener, tab, net, this); ZoomController zoomController = new ZoomController(100); tab.addZoomListener(zoomController); PetriNetController petriNetController = new PetriNetController(net, undoListener, animator, copyPasteManager, zoomController, tab); netControllers.put(tab, petriNetController); tab.updatePreferredSize(); PropertyChangeListener changeListener = new PetriNetChangeListener(applicationModel, tab, petriNetController); net.addPropertyChangeListener(changeListener); setActiveTab(tab); initialiseNet(net, changeListener); }
public UndoableList(List<T> list) { this.list = list; this.parent = null; this.offset = 0; this.editProtection = new boolean[]{ false }; this.editListeners = new ArrayList<UndoableEditListener>(); this.listDataListeners = new ArrayList<ListDataListener>(); }
private void addEdit(UndoableEdit edit) { if (compoundEdits.isEmpty()) { UndoableEditEvent editEvent = new UndoableEditEvent(getMainList(), edit); for (UndoableEditListener l : editListeners) { l.undoableEditHappened(editEvent); } } else { compoundEdits.peek().addEdit(edit); } }
public static void main(String[] args) { final LinkedList<UndoableEdit> edits = new LinkedList<UndoableEdit>(); UndoableEditListener editListener = new UndoableEditListener() { @Override public void undoableEditHappened(UndoableEditEvent e) { System.out.println(e.getEdit()); edits.addFirst(e.getEdit()); } }; UndoableList<Integer> list = new UndoableList<Integer>(new LinkedList<Integer>()); list.addUndoableEditListener(editListener); for (int i = 1; i < 10; i++) { list.add(2*i); } System.out.println(list); list.add(6, 13); System.out.println(list); list.set(3, 7); System.out.println(list); List<Integer> subList = list.subList(3, 6); System.out.println(subList); subList.set(0, 8); System.out.println(list); System.out.println(subList); subList.remove(1); System.out.println("----------------------------------"); for (UndoableEdit edit : edits) { System.out.println("Undo " + edit); edit.undo(); System.out.println(list); } }
@Override public void addUndoableEditListener(UndoableEditListener listener) { super.addUndoableEditListener(listener); if (LOG.isLoggable(Level.FINE)) { UndoableEditListener[] listeners = getUndoableEditListeners(); if (listeners.length > 1) { // Having two UE listeners may be dangerous - for example // having two undo managers attached at once will lead to strange errors // since only one of the UMs will work normally while processing // in the other one will be (typically silently) failing. LOG.log(Level.INFO, "Two or more UndoableEditListeners attached", new Exception()); // NOI18N } } }
public void testRecursiveUndoableEdits() throws Exception { final BaseDocument doc = new BaseDocument(false, "text/plain"); class UEL implements UndoableEditListener, Runnable { boolean undo; @Override public void undoableEditHappened(UndoableEditEvent e) { //doc.runAtomic(this); doc.render(this); undo = e.getEdit().canUndo(); } @Override public void run() { } } UEL uel = new UEL(); doc.addUndoableEditListener(uel); class Atom implements Runnable { @Override public void run() { try { doc.insertString(0, "Ahoj", null); } catch (BadLocationException ex) { throw new IllegalStateException(ex); } } } doc.runAtomicAsUser(new Atom()); assertTrue("Can undo now", uel.undo); }
void sendUndoableEdit(Document d, UndoableEdit ue) { if(d instanceof AbstractDocument) { UndoableEditListener[] uels = ((AbstractDocument)d).getUndoableEditListeners(); UndoableEditEvent ev = new UndoableEditEvent(d, ue); for(UndoableEditListener uel : uels) { uel.undoableEditHappened(ev); } } }
static void sendUndoableEdit(Document d, UndoableEdit ue) { if(d instanceof AbstractDocument) { UndoableEditListener[] uels = ((AbstractDocument)d).getUndoableEditListeners(); UndoableEditEvent ev = new UndoableEditEvent(d, ue); for(UndoableEditListener uel : uels) { uel.undoableEditHappened(ev); } } }
private static void sendUndoableEdit(Document d, UndoableEdit ue) { if(d instanceof AbstractDocument) { UndoableEditListener[] uels = ((AbstractDocument)d).getUndoableEditListeners(); UndoableEditEvent ev = new UndoableEditEvent(d, ue); for(UndoableEditListener uel : uels) { uel.undoableEditHappened(ev); } } }
@Override public synchronized void addUndoableRefactorListener(UndoableEditListener uel) { // savedUndoableEditListeners = ues.getUndoableEditListeners(); if (savedUndoableEditListeners != null) { for (UndoableEditListener saved : savedUndoableEditListeners) { if (saved instanceof UndoManager) { ((UndoManager)saved).discardAllEdits(); } } } ues = new ModelUndoableEditSupport(); ues.addUndoableEditListener(uel); }
@Override public synchronized void removeUndoableRefactorListener(UndoableEditListener uel) { // ues.removeUndoableEditListener(uel); if (savedUndoableEditListeners != null) { ues = new ModelUndoableEditSupport(); for (UndoableEditListener saved : savedUndoableEditListeners) { ues.addUndoableEditListener(saved); } savedUndoableEditListeners = null; } }
public void switchDocument(Object container, Object keyObj, String contents) { this.currentUndoManager = null; String key = container.getClass().getName() + "_" + container.hashCode() + "_" + keyObj.getClass().getName() + keyObj.hashCode(); UndoableJTextField.UndoableDocument ud = (UndoableJTextField.UndoableDocument) this.undoableDocumentMap .get(key); if (ud == null) { ud = new UndoableJTextField.UndoableDocument(); ud.undoManager = new UndoManager(); ud.document = new PlainDocument(); try { ud.document.insertString(0, contents, (AttributeSet) null); } catch (BadLocationException var7) { ; } this.undoableDocumentMap.put(key, ud); ud.document.addUndoableEditListener(new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent e) { if (UndoableJTextField.this.currentUndoManager != null) { UndoableEdit ue = e.getEdit(); UndoableJTextField.this.currentUndoManager.addEdit(ue); } } }); } this.setDocument(ud.document); this.currentUndoManager = ud.undoManager; }
private void formAncestorAdded(javax.swing.event.AncestorEvent evt) {//GEN-FIRST:event_formAncestorAdded if(addedUndoListener) return; addedUndoListener=true; if (evt.getComponent() instanceof Container) { Container anc = (Container) evt.getComponent(); while (anc != null && anc instanceof Container) { if (anc instanceof UndoableEditListener) { editSupport.addUndoableEditListener((UndoableEditListener) anc); // log.info("added undo listener "+anc); break; } anc = anc.getParent(); } } }
/** * @return a List of any missing font families as Strings. Will return an empty List if all * fonts encountered were available. */ public List open(File selectedFile, UndoableEditListener designatedUndoableEditListener) throws SAXException, IOException { setFile(selectedFile); List missingFontFamilies = open(designatedUndoableEditListener); if (changeListener!=null) changeListener.stateChanged(CHANGE_EVENT); return missingFontFamilies; }
private UndoManager undoMan() { // Listener for undo and redo functions to document undo = new UndoManager(); textArea.getDocument().addUndoableEditListener(new UndoableEditListener() { @Override public void undoableEditHappened(UndoableEditEvent e) { undo.addEdit(e.getEdit()); } }); return undo; }
protected void fireUndoableEditUpdate(UndoableEditEvent e) { UndoableEditListener[] listeners = getUndoableEditListeners(); if(listeners != null){ for (int i = 0; i < listeners.length; i++) { listeners[i].undoableEditHappened(e); } } }