org.openide.awt.UndoRedo Java Examples

The following examples show how to use org.openide.awt.UndoRedo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NbDocument.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static <T extends UndoableEdit> T getEditToBeUndoneRedoneOfType(EditorCookie ec, Class<T> type, boolean redone) {
    UndoRedo ur;
    if (ec instanceof CloneableEditorSupport &&
            ((ur = ((CloneableEditorSupport)ec).getUndoRedo()) instanceof UndoRedoManager))
    {
        UndoRedoManager urManager = (UndoRedoManager) ur;
        UndoableEdit edit = urManager.editToBeUndoneRedone(redone);
        if (type.isInstance(edit)) {
            return type.cast(edit);
        } else if (edit instanceof List) {
            @SuppressWarnings("unchecked")
            List<UndoableEdit> listEdit = (List<UndoableEdit>) edit;
            for (int i = listEdit.size() -1; i >= 0; i--) { // Go from most wrapped back
                edit = listEdit.get(i);
                if (type.isInstance(edit)) {
                    @SuppressWarnings("unchecked") T inst = (T) edit;
                    return inst;
                }
            }
        }
    }
    return null;
}
 
Example #2
Source File: CloneableEditorSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
     * Gets the undo redo manager.
     * @return the manager
     */
    protected final synchronized UndoRedo.Manager getUndoRedo() {
        CloneableEditorSupport redirect = CloneableEditorSupportRedirector.findRedirect(this);
        if (redirect != null) {
            return redirect.getUndoRedo();
        }
        
        if (undoRedo == null) {
            UndoRedo.Manager mgr = createUndoRedoManager();
//            if (!(mgr instanceof UndoRedoManager)) {
//                ERR.info("createUndoRedoManager(): ignoring created instance of class " + // NOI18N
//                        mgr.getClass() + " since CloneableEditorSupport requires instance of " + // NOI18N"
//                        UndoRedoManager.class.getName() + "\n"); // NOI18N
//                mgr = new UndoRedoManager(this);
//            }
            undoRedo = mgr;
        }

        return undoRedo;
    }
 
Example #3
Source File: UndoAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Update status of action.
*/
static synchronized void updateStatus() {
    if (undoAction == null) {
        undoAction = findObject (UndoAction.class, false);
    }

    if (redoAction == null) {
        redoAction = findObject (RedoAction.class, false);
    }

    SwingUtilities.invokeLater(
        new Runnable() {
            public void run() {
                UndoRedo ur = getUndoRedo();

                if (undoAction != null) {
                    undoAction.setEnabled(ur.canUndo());
                }

                if (redoAction != null) {
                    redoAction.setEnabled(ur.canRedo());
                }
            }
        }
    );
}
 
Example #4
Source File: GraphNode.java    From constellation with Apache License 2.0 6 votes vote down vote up
/**
 * Private constructor: recommended pattern for using InstanceContent.
 *
 * @param content This object's Lookup.
 * @param graph The Graph.
 * @param gdo The GraphDataObject.
 * @param visual The visual interface to the graph.
 * @param tc The graph's TopComponent.
 */
private GraphNode(final InstanceContent content, final Graph graph, final GraphDataObject gdo, final TopComponent tc, final VisualManager visualManager) {
    super(Children.LEAF, new AbstractLookup(content));
    content.add(graph);
    content.add(this);
    this.graph = graph;
    this.visualManager = visualManager;
    this.gdo = gdo;
    this.undoRedoManager = new UndoRedo.Manager();
    this.tc = tc;

    graph.setUndoManager(undoRedoManager);

    GRAPHS.put(graph.getId(), GraphNode.this);

    for (GraphManagerListener listener : LISTENERS) {
        listener.graphOpened(graph);
    }

    MemoryManager.newObject(GraphNode.class);
}
 
Example #5
Source File: UndoAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void performAction() {
    try {
        UndoRedo undoRedo = getUndoRedo();

        if (undoRedo.canUndo()) {
            undoRedo.undo();
        }
    } catch (CannotUndoException ex) {
        UndoRedoAction.cannotUndoRedo(ex);
    }

    updateStatus();
}
 
Example #6
Source File: NavigatorTCTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Test for IZ feature #98125. It tests ability of NavigatorPanelWithUndo
 * implementors to provide UndoRedo support for their view through
 * navigator TopComponent.
 */
public void testFeature98125_UndoRedo () throws Exception {
    System.out.println("Testing feature #98125, providing UndoRedo...");

    InstanceContent ic = getInstanceContent();
    
    TestLookupHint undoHint = new TestLookupHint("undoRedo/tester");
    ic.add(undoHint);
        
    NavigatorTC navTC = NavigatorTC.getInstance();
    NavigatorTCHandle navTCH = new NavigatorTCHandle(navTC);
    try {
        navTCH.open();
        waitForProviders(navTC);

        NavigatorPanel selPanel = navTC.getSelectedPanel();
        assertNotNull("Selected panel should not be null", navTC.getSelectedPanel());
        assertTrue("Panel class not expected", selPanel instanceof UndoRedoProvider);
        UndoRedoProvider provider = (UndoRedoProvider)selPanel;

        UndoRedo panelUndo = provider.getUndoRedo();
        UndoRedo tcUndo = navTC.getUndoRedo();

        assertTrue("Expected undo manager " + panelUndo + ", but got " + tcUndo, panelUndo == tcUndo);
    } finally {        
        // cleanup
        navTCH.close();
        ic.remove(undoHint);
    }        
}
 
Example #7
Source File: SnapApp.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void productRemoved(ProductManager.Event event) {
    UndoRedo.Manager manager = undoManagers.remove(event.getProduct());
    if (manager != null) {
        manager.die();
    }
}
 
Example #8
Source File: OpenImageViewAction.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private void openDocumentWindow(final ProductSceneView view) {

        UndoRedo.Manager undoManager = SnapApp.getDefault().getUndoManager(view.getProduct());
        ProductSceneViewTopComponent productSceneViewWindow = new ProductSceneViewTopComponent(view, undoManager);

        DocumentWindowManager.getDefault().openWindow(productSceneViewWindow);
        productSceneViewWindow.requestSelected();
    }
 
Example #9
Source File: UndoRedoActionTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testUndoDeliversChangesWithTooManyEdits() {
    UndoRedo.Manager man = new UndoRedo.Manager() {
        @Override
        public boolean canUndo() {
            if (super.canUndo()) {
                undoableEditHappened(new UndoableEditEvent(UndoRedoActionTest.this, new MyEdit(true)));
            }
            return super.canUndo();
        }
    };
    doUndoRedoTest(man, false);
}
 
Example #10
Source File: IssueTopComponent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void redo() throws CannotRedoException {
    if(delegate != null) {
        delegate.redo();
    } else {
        UndoRedo.NONE.redo();
    }
}
 
Example #11
Source File: MultiViewCloneableTopComponent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Get the undo/redo support for this component.
 * The default implementation returns a dummy support that cannot
 * undo anything.
 *
 * @return undoable edit for this component
 */
public UndoRedo getUndoRedo() {
    UndoRedo retValue;
    retValue = peer.peerGetUndoRedo();
    if (retValue == null) {
        retValue = super.getUndoRedo();
    }
    return retValue;
}
 
Example #12
Source File: UndoRedoSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private UndoRedoSupport(FormModel model) {
    manager = (FormModel.UndoRedoManager)model.getUndoRedoManager();
    manager.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            if (manager.isUndoInProgress()) {
                undoableEdits--;
                redoableEdits++;
            } else if (manager.isRedoInProgress()) {
                undoableEdits++;
                redoableEdits--;
            } else {
                undoableEdits++;
                redoableEdits=0;
            }
            undoAction.updateEnabled();
            redoAction.updateEnabled();
        }
    });
    undoAction = new UndoAction(SystemAction.get(org.openide.actions.UndoAction.class));
    redoAction = new RedoAction(SystemAction.get(org.openide.actions.RedoAction.class));
    undoRedoLookup = Lookups.singleton(new UndoRedo.Provider() {
        @Override
        public UndoRedo getUndoRedo() {
            return manager;
        }
    });
}
 
Example #13
Source File: ComponentInspector.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public UndoRedo getUndoRedo() {
    if (formDesigner != null) {
        FormModel formModel = formDesigner.getFormModel();
        if (formModel != null) {
            UndoRedo ur = formModel.getUndoRedoManager();
            if (ur != null) {
                return ur;
            }
        }
    }
    return UndoRedo.NONE;
}
 
Example #14
Source File: MultiViewTopComponent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Get the undo/redo support for this component.
 * The default implementation returns a dummy support that cannot
 * undo anything.
 *
 * @return undoable edit for this component
 */
@Override
public UndoRedo getUndoRedo() {
    UndoRedo retValue;
    retValue = peer.peerGetUndoRedo();
    if (retValue == null) {
        retValue = super.getUndoRedo();
    }
    return retValue;
}
 
Example #15
Source File: DiagramScene.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private UndoRedo.Manager getUndoRedoManager() {
    if (undoRedoManager == null) {
        undoRedoManager = new UndoRedo.Manager();
        undoRedoManager.setLimit(UNDOREDO_LIMIT);
    }

    return undoRedoManager;
}
 
Example #16
Source File: ProductSceneViewTopComponent.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public ProductSceneViewTopComponent(ProductSceneView view, UndoRedo undoRedo) {
        super(view.getRaster());
        this.view = view;
        this.undoRedo = undoRedo != null ? undoRedo : UndoRedo.NONE;
        this.nodeRenameHandler = new NodeRenameHandler();
        this.selection = Selection.EMPTY;
        setToolTipText(view.getRaster().getDescription());
        setIcon(ImageUtilities.loadImage("org/esa/snap/rcp/icons/RsBandAsSwath.gif"));
        updateDisplayName();
        setName(getDisplayName());
/*
        // checkme - this is ugly and not wanted (nf), the node will either passed in or we'll have
        // a central node factory, e.g. via an ExtensionObject
        Node node = null;
        try {
            if (raster instanceof Mask) {
                node = new MNode((Mask) raster, undoRedo);
            } else if (raster instanceof Band) {
                node = new BNode((Band) raster, undoRedo);
            } else if (raster instanceof TiePointGrid) {
                node = new TPGNode((TiePointGrid) raster, undoRedo);
            }
        } catch (IntrospectionException e) {
            Exceptions.printStackTrace(e);
        }
        if (node != null) {
            setActivatedNodes(new Node[]{node});
        }
*/
        setLayout(new BorderLayout());
        add(new JLayer<>(this.view, new ProductSceneViewLayerUI()), BorderLayout.CENTER);
    }
 
Example #17
Source File: DelegatingUndoRedo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void setDiffView(JComponent componentDelegate) {
    if (componentDelegate == null) {
        setDelegate(UndoRedo.NONE);
    } else {
        if (comp != null) {
            comp.removePropertyChangeListener(this);
        }
        comp = componentDelegate;
        comp.addPropertyChangeListener(this);
        UndoRedo delegate = (UndoRedo) componentDelegate.getClientProperty(UndoRedo.class);
        if (delegate == null) delegate = UndoRedo.NONE; 
        setDelegate(delegate);
    }
}
 
Example #18
Source File: IssueTopComponent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public UndoRedo getUndoRedo() {
    if(delegatingUndoRedoManager == null) {
        delegatingUndoRedoManager = new DelegatingUndoRedoManager();
    }
    return delegatingUndoRedoManager;
}
 
Example #19
Source File: DiagramScene.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private UndoRedo.Manager getUndoRedoManager() {
    if (undoRedoManager == null) {
        undoRedoManager = new UndoRedo.Manager();
        undoRedoManager.setLimit(UNDOREDO_LIMIT);
    }

    return undoRedoManager;
}
 
Example #20
Source File: EditableDiffView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private UndoRedo.Manager getUndoRedo(EditorCookie cookie) {
    // TODO: working around #96543 
    try {
        Method method = CloneableEditorSupport.class.getDeclaredMethod("getUndoRedo"); // NOI18N
        method.setAccessible(true);
        return (UndoRedo.Manager) method.invoke(cookie);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #21
Source File: DelegatingUndoRedo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void setDelegate(UndoRedo newDelegate) {
    if (newDelegate == delegate) return;
    delegate.removeChangeListener(this);
    delegate = newDelegate;
    stateChanged(new ChangeEvent(this));
    delegate.addChangeListener(this);
}
 
Example #22
Source File: FormModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public UndoRedo.Manager getUndoRedoManager() {
//        if (undoRedoManager == null) {
//            undoRedoManager = new UndoRedoManager();
//            undoRedoManager.setLimit(50);
//        }
        return undoRedoManager;
    }
 
Example #23
Source File: DiffTopComponent.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public UndoRedo getUndoRedo () {
    return controller.getUndoRedo();
}
 
Example #24
Source File: UndoAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Finds current undo/redo.
*/
static UndoRedo getUndoRedo() {
    TopComponent el = WindowManager.getDefault().getRegistry().getActivated();

    return (el == null) ? UndoRedo.NONE : el.getUndoRedo();
}
 
Example #25
Source File: DiffTopComponent.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public UndoRedo getUndoRedo() {
    return panel.getUndoRedo();
}
 
Example #26
Source File: ProductSceneViewTopComponent.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public UndoRedo getUndoRedo() {
    return undoRedo;
}
 
Example #27
Source File: DiffSidebar.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public UndoRedo getUndoRedo() {
    UndoRedo undoredo = (UndoRedo) diffView.getClientProperty(UndoRedo.class);
    return undoredo == null ? UndoRedo.NONE : undoredo;
}
 
Example #28
Source File: EditorSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
final UndoRedo.Manager superUndoRedoManager() {
    return super.createUndoRedoManager ();
}
 
Example #29
Source File: EditorSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected UndoRedo.Manager createUndoRedoManager() {
    return EditorSupport.this.createUndoRedoManager ();
}
 
Example #30
Source File: EditToBeUndoneRedoneTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testUndoRedoUndoEdits() throws Exception {

        final StyledDocument d = support.openDocument();

        UndoRedo.Manager ur = support.getUndoRedo();
        UndoRedoManager urMgr = null;

        if (ur instanceof UndoRedoManager) {
            urMgr = (UndoRedoManager) ur;
        }

        d.insertString(d.getLength(), "a", null);
        final CompoundEdit bigEdit = new CompoundEdit();
        d.insertString(d.getLength(), "b", null);
        bigEdit.end();
        support.saveDocument();

        // setting the property to populate urMgr.onSaveTasksEdit field
        d.putProperty("beforeSaveRunnable", new Runnable() {

            public void run() {
                Runnable beforeSaveStart = (Runnable) d.getProperty("beforeSaveStart");
                if (beforeSaveStart != null) {
                    beforeSaveStart.run();
                    support.getUndoRedo().undoableEditHappened(new UndoableEditEvent(d, bigEdit));
                }
            }
        });

        urMgr.undo();
        support.saveDocument();
        d.putProperty("beforeSaveRunnable", null);
        assertEquals("after undo data", "a", d.getText(0, d.getLength()));

        urMgr.redo();
        support.saveDocument();
        assertEquals("after redo data", "ab", d.getText(0, d.getLength()));

        urMgr.undo();
        assertEquals("after redo data", "a", d.getText(0, d.getLength()));
    }