Java Code Examples for org.openide.awt.UndoRedo#Manager

The following examples show how to use org.openide.awt.UndoRedo#Manager . 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: 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 2
Source File: CreateVectorDataNodeAction.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
public static VectorDataNode createDefaultVectorDataNode(Product product, String name, String description) {
    CoordinateReferenceSystem modelCrs = product.getSceneCRS();
    SimpleFeatureType type = PlainFeatureFactory.createDefaultFeatureType(modelCrs);
    VectorDataNode vectorDataNode = new VectorDataNode(name, type);
    vectorDataNode.setDescription(description);
    product.getVectorDataGroup().add(vectorDataNode);
    vectorDataNode.getPlacemarkGroup();
    String oldLayerId = selectVectorDataLayer(vectorDataNode);

    UndoRedo.Manager undoManager = SnapApp.getDefault().getUndoManager(product);
    if (undoManager != null) {
        undoManager.addEdit(new UndoableVectorDataNodeInsertion(product, vectorDataNode, oldLayerId));
    }

    return vectorDataNode;
}
 
Example 3
Source File: PlacemarkManagerTopComponent.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
void newPin() {
    Guardian.assertNotNull("product", product);
    String[] uniquePinNameAndLabel = PlacemarkNameFactory.createUniqueNameAndLabel(placemarkDescriptor, product);
    Placemark newPlacemark = Placemark.createPointPlacemark(placemarkDescriptor, uniquePinNameAndLabel[0],
                                                            uniquePinNameAndLabel[1],
                                                            "",
                                                            new PixelPos(0, 0), null,
                                                            product.getSceneGeoCoding());
    if (PlacemarkDialog.showEditPlacemarkDialog(
            SwingUtilities.getWindowAncestor(this), product, newPlacemark, placemarkDescriptor)) {
        makePlacemarkNameUnique(newPlacemark);
        UndoRedo.Manager undoManager = SnapApp.getDefault().getUndoManager(product);
        if (undoManager != null) {
            undoManager.addEdit(UndoablePlacemarkActionFactory.createUndoablePlacemarkInsertion(product, newPlacemark, placemarkDescriptor));
        }
        updateUIState();
    }
}
 
Example 4
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 5
Source File: UndoRedoActionTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void doUndoRedoTest(UndoRedo.Manager man, boolean testCounts) {
    me = new MyEdit();
    man.undoableEditHappened(new UndoableEditEvent(this, me));
    assertTrue("Can undo", man.canUndo());
    this.ur = man;
    
    InstanceContent ic = new InstanceContent();
    AbstractLookup lkp = new AbstractLookup(ic);
    Action u = undoAction(lkp);
    Action r = redoAction(lkp);

    assertFalse("Not enabled", u.isEnabled());
    assertFalse("Not enabledR", r.isEnabled());
    MyEdit lu = new MyEdit();
    MyEdit lr = new MyEdit();
    u.addPropertyChangeListener(lu);
    r.addPropertyChangeListener(lr);

    ic.add(this);

    assertTrue("Action is enabled", u.isEnabled());
    assertEquals("One change", 1, lu.cnt);
    assertEquals("No redo change", 0, lr.cnt);
    assertEquals("Undo presentation", "&Undo My Undo", u.getValue(Action.NAME));

    u.actionPerformed(new ActionEvent(this, 0, ""));
    if (testCounts) {
        assertEquals("my edit undone", 1, me.undo);

        assertFalse("No more undo", man.canUndo());
        assertTrue("But redo", man.canRedo());
        assertEquals("Another undo change", 2, lu.cnt);
        assertEquals("New redo change", 1, lr.cnt);
        assertTrue("Redo action enabled", r.isEnabled());
        assertEquals("Redo presentation correct", "&Redo My Redo", r.getValue(Action.NAME));
    }

    r.actionPerformed(new ActionEvent(this, 0, ""));
    assertFalse("Redo action no longer enabled", r.isEnabled());
}
 
Example 6
Source File: InsertPlacemarkInteractor.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private void insertPlacemark(ProductSceneView view) {
    Product product = view.getProduct();
    final String[] uniqueNameAndLabel = PlacemarkNameFactory.createUniqueNameAndLabel(placemarkDescriptor,
                                                                                      product);
    final String name = uniqueNameAndLabel[0];
    final String label = uniqueNameAndLabel[1];
    PixelPos rasterPos = new PixelPos(view.getCurrentPixelX() + 0.5f, view.getCurrentPixelY() + 0.5f);
    Point2D modelPos = view.getRaster().getImageToModelTransform().transform(rasterPos, new Point2D.Double());
    Point2D scenePos = new Point2D.Double();
    try {
        view.getRaster().getModelToSceneTransform().transform(modelPos, scenePos);
        final AffineTransform sceneToImage = Product.findImageToModelTransform(product.getSceneGeoCoding()).createInverse();
        rasterPos = (PixelPos) sceneToImage.transform(modelPos, new PixelPos());
    } catch (TransformException | NoninvertibleTransformException e) {
        Dialogs.showError("Could not place pin in image due to transformation exception: " + e.getMessage());
        return;
    }
    final Placemark newPlacemark = Placemark.createPointPlacemark(placemarkDescriptor, name, label, "",
                                                                  rasterPos, null, product.getSceneGeoCoding());
    PlacemarkGroup placemarkGroup = placemarkDescriptor.getPlacemarkGroup(product);
    String defaultStyleCss = placemarkGroup.getVectorDataNode().getDefaultStyleCss();
    if(newPlacemark.getStyleCss().isEmpty()) {
        newPlacemark.setStyleCss(defaultStyleCss);
    }
    placemarkGroup.add(newPlacemark);
    UndoRedo.Manager undoManager = SnapApp.getDefault().getUndoManager(product);
    if (undoManager != null) {
        undoManager.addEdit(UndoablePlacemarkActionFactory.createUndoablePlacemarkInsertion(product, newPlacemark, placemarkDescriptor));
    }
}
 
Example 7
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 8
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 9
Source File: DiagramScene.java    From openjdk-jdk8u 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 10
Source File: DiagramScene.java    From jdk8u60 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 11
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 12
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 13
Source File: PNNodeSupport.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
static <T extends ProductNode> void performUndoableProductNodeEdit(String name, T productNode, UndoableProductNodeEdit.Edit<T> action, UndoableProductNodeEdit.Edit<T> undo) {
    action.edit(productNode);
    Product product = productNode.getProduct();
    // be paranoid
    if (product != null) {
        UndoRedo.Manager undoManager = SnapApp.getDefault().getUndoManager(product);
        // be paranoid again
        if (undoManager != null) {
            undoManager.addEdit(new UndoableProductNodeEdit<>(name, productNode, undo, action));
        }
    }
}
 
Example 14
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 15
Source File: AttachPixelGeoCodingAction.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
private static void attachPixelGeoCoding(final Product product) {
    final SnapApp snapApp = SnapApp.getDefault();
    final Window mainFrame = snapApp.getMainFrame();
    final String dialogTitle = Bundle.CTL_AttachPixelGeoCodingDialogTitle();
    final PixelGeoCodingSetupDialog setupDialog = new PixelGeoCodingSetupDialog(mainFrame,
            dialogTitle,
            HELP_ID,
            product);
    if (setupDialog.show() != ModalDialog.ID_OK) {
        return;
    }

    final Band lonBand = setupDialog.getSelectedLonBand();
    final Band latBand = setupDialog.getSelectedLatBand();
    final String groundResString = setupDialog.getGroundResString();
    final double groundResInKm = Double.parseDouble(groundResString);
    final String msgPattern = "New Pixel Geo-Coding: lon = ''{0}'' ; lat = ''{1}'' ; ground resolution=''{2}''";
    snapApp.getLogger().log(Level.INFO, MessageFormat.format(msgPattern,
            lonBand.getName(), latBand.getName(),
            groundResString));

    final long requiredBytes = getRequiredMemory(product);
    final long requiredMegas = requiredBytes / ONE_MB;
    final long freeMegas = Runtime.getRuntime().freeMemory() / ONE_MB;
    if (freeMegas < requiredMegas) {
        final String message = MessageFormat.format("This operation requires to load at least {0} M\n" +
                        "of additional data into memory.\n\n" +
                        "Do you really want to continue?",
                requiredMegas);
        final Dialogs.Answer answer = Dialogs.requestDecision(dialogTitle, message, false, "load_latlon_band_data");
        if (answer != Dialogs.Answer.YES) {
            return;
        }
    }

    UIUtils.setRootFrameWaitCursor(mainFrame);
    final ProgressMonitorSwingWorker<Void, Void> swingWorker = new ProgressMonitorSwingWorker<Void, Void>(mainFrame, dialogTitle) {

        @Override
        protected Void doInBackground(ProgressMonitor pm) throws Exception {
            final double[] longitudes = RasterUtils.loadDataScaled(lonBand);
            final double[] latitudes = RasterUtils.loadDataScaled(latBand);
            final GeoRaster geoRaster = new GeoRaster(longitudes, latitudes, lonBand.getName(), latBand.getName(),
                    product.getSceneRasterWidth(), product.getSceneRasterHeight(), groundResInKm);
            final ForwardCoding forward = ComponentFactory.getForward(PixelForward.KEY);
            final InverseCoding inverse = ComponentFactory.getInverse(PixelQuadTreeInverse.KEY);

            final ComponentGeoCoding geoCoding = new ComponentGeoCoding(geoRaster, forward, inverse, GeoChecks.POLES);
            geoCoding.initialize();

            final GeoCoding oldGeoCoding = product.getSceneGeoCoding();
            product.setSceneGeoCoding(geoCoding);
            UndoRedo.Manager undoManager = SnapApp.getDefault().getUndoManager(product);
            if (undoManager != null) {
                undoManager.addEdit(new UndoableAttachGeoCoding(product, geoCoding, oldGeoCoding));
            }

            return null;
        }

        @Override
        public void done() {
            try {
                get();
                Dialogs.showInformation(dialogTitle, "Pixel geo-coding has been attached.", null);
            } catch (Exception e) {
                Throwable cause = e;
                if (e instanceof ExecutionException) {
                    cause = e.getCause();
                }
                String msg = "An internal error occurred:\n" + e.getMessage();
                if (cause instanceof IOException) {
                    msg = "An I/O error occurred:\n" + e.getMessage();
                }
                Dialogs.showError(dialogTitle, msg);
            } finally {
                UIUtils.setRootFrameDefaultCursor(mainFrame);
            }
        }
    };

    swingWorker.executeWithBlocking();
}
 
Example 16
Source File: NavigatorTCTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public UndoRedo getUndoRedo() {
    if (undo == null) {
        undo = new UndoRedo.Manager();
    } 
    return undo;
}
 
Example 17
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 18
Source File: NamedSelectionState.java    From constellation with Apache License 2.0 3 votes vote down vote up
/**
 * Update a graph's find state meta-attribute with this instance in an
 * undoable way.
 * <p>
 * To make find state undoable, the graph must be updated within a
 * GraphUndoableEdit. This is a convenience method to do that.
 *
 * @param graph The graph to update.
 * @param undoRedoManager The UndoRedo.Manager for the graph.
 * @param stateAttr The attribute id of the find_state attribute.
 * @param name The name of the undoable edit.
 * @param isSignificant Is this a significant edit?
 *
 * @throws java.lang.InterruptedException if the process was canceled during
 * execution.
 */
public void update(final Graph graph, final UndoRedo.Manager undoRedoManager, final int stateAttr,
        final String name, final boolean isSignificant) throws InterruptedException {
    WritableGraph wg = graph.getWritableGraph(name, isSignificant);
    try {
        wg.setObjectValue(stateAttr, 0, this);
    } finally {
        wg.commit();
    }
}
 
Example 19
Source File: CloneableEditorSupport.java    From netbeans with Apache License 2.0 2 votes vote down vote up
/** Create an undo/redo manager.
* This manager is then attached to the document, and listens to
* all changes made in it.
* <P>
* The default implementation uses improved <code>UndoRedo.Manager</code>,
* with support for various extensions (including {@link #BEGIN_COMMIT_GROUP}
* and {@link #END_COMMIT_GROUP}). It is not wise to override this
* method without delegating to <code>super.createUndoRedoManager</code>.
*
* @return the undo/redo manager
*/
protected UndoRedo.Manager createUndoRedoManager() {
    return new UndoRedoManager(this);
}
 
Example 20
Source File: EditorSupport.java    From netbeans with Apache License 2.0 2 votes vote down vote up
/** Create an undo/redo manager.
* This manager is then attached to the document, and listens to
* all changes made in it.
* <P>
* The default implementation simply uses <code>UndoRedo.Manager</code>.
*
* @return the undo/redo manager
*/
protected UndoRedo.Manager createUndoRedoManager () {
    return del.superUndoRedoManager ();
}