This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 103467
Collapse All | Expand All

(-)awt/src/org/openide/awt/UndoRedo.java (-1 / +180 lines)
Lines 93-99 Link Here
93
93
94
    /** An undo manager which fires a change event each time it consumes a new undoable edit.
94
    /** An undo manager which fires a change event each time it consumes a new undoable edit.
95
    */
95
    */
96
    public static class Manager extends UndoManager implements UndoRedo {
96
    public static class Manager extends UndoGroupManager implements UndoRedo {
97
        static final long serialVersionUID = 6721367974521509720L;
97
        static final long serialVersionUID = 6721367974521509720L;
98
98
99
        private final ChangeSupport cs = new ChangeSupport(this);
99
        private final ChangeSupport cs = new ChangeSupport(this);
Lines 251-255 Link Here
251
        public String getRedoPresentationName() {
251
        public String getRedoPresentationName() {
252
            return ""; // NOI18N
252
            return ""; // NOI18N
253
        }
253
        }
254
    }
255
256
    /** <code>UndoGroupManager</code> is an <code>UndoManager</code>
257
     * that allows explicit control of how
258
     * <code>UndoableEdit</code>s are coalesced into compound edits,
259
     * rather than using the rules defined by the edits themselves.
260
     * Other than the default usage, special handling is initiated by doing
261
     * <code>beginUndoGroup()</code>.
262
     * <p>
263
     * Three use cases are supported.
264
     * </p>
265
     * <ol>
266
     * <li> Default behavior is defined by {@link javax.swing.undo.UndoManager}.</li>
267
     * <li> <code>UnddoableEdit</code>s issued between <code>beginUndoGroup()</code>
268
     * and <code>endUndoGroup()</code> are placed into a single <code>CompoundEdit</code>.
269
     * Thus <code>undo()</code> and <code>redo()</code> treat them atomically.</li>
270
     * <li> Use <code>commitUndoGroup()</code> to place any accumulated
271
     * <code>UndoableEdit</code>s into a <code>CompoundEdit</code>;
272
     * the application does this at strategic points, such as EndOfLine
273
     * entry or cursor movement.</li>
274
     * </ol>
275
     * Note that certain methods, such as <code>undo()</code>, automatically issue
276
     * <code>commitUndoGroup()</code>.
277
     */
278
    public static class UndoGroupManager extends UndoManager {
279
        /** signals that edits should be accumulated */
280
        boolean buildUndoGroup;
281
        /** accumulate edits here in undoGroup */
282
        CompoundEdit undoGroup;
283
284
        public synchronized void beginUndoGroup() {
285
            commitUndoGroup();
286
            buildUndoGroup = true;
287
        }
288
289
        public synchronized void endUndoGroup() {
290
            buildUndoGroup = false;
291
            commitUndoGroup();
292
        }
293
294
        public synchronized void commitUndoGroup() {
295
            if(undoGroup == null) {
296
                return;
297
            }
298
            // super.addEdit may end up in this.addEdit,
299
            // so buildUndoGroup must be false
300
            boolean saveInUndoGroup = buildUndoGroup;
301
            buildUndoGroup = false;
302
303
            undoGroup.end();
304
            super.addEdit(undoGroup);
305
306
            undoGroup = null;
307
            buildUndoGroup = saveInUndoGroup;
308
        }
309
310
311
        public synchronized boolean addEdit(UndoableEdit anEdit) {
312
            if(!isInProgress())
313
                return false;
314
            if(buildUndoGroup) {
315
                if(undoGroup == null)
316
                    undoGroup = new CompoundEdit();
317
                return undoGroup.addEdit(anEdit);
318
            } else {
319
                return super.addEdit(anEdit);
320
            }
321
        }
322
323
        public synchronized void discardAllEdits() {
324
            commitUndoGroup();
325
            super.discardAllEdits();
326
        }
327
328
        //
329
        // TODO: limits
330
        //
331
332
        public synchronized void undoOrRedo() {
333
            commitUndoGroup();
334
            super.undoOrRedo();
335
        }
336
337
        public synchronized boolean canUndoOrRedo() {
338
            if(undoGroup != null)
339
                return true;
340
            return super.canUndoOrRedo();
341
        }
342
343
        public synchronized void undo() {
344
            commitUndoGroup();
345
            super.undo();
346
        }
347
348
        public synchronized boolean canUndo() {
349
            if(undoGroup != null)
350
                return true;
351
            return super.canUndo();
352
        }
353
354
        public synchronized void redo() {
355
            if(undoGroup != null)
356
                throw new CannotRedoException();
357
            super.redo();
358
        }
359
360
        public synchronized boolean canRedo() {
361
            if(undoGroup != null)
362
                return false;
363
            return super.canRedo();
364
        }
365
366
        public synchronized void end() {
367
            commitUndoGroup();
368
            super.end();
369
        }
370
371
        public synchronized String getUndoOrRedoPresentationName() {
372
            if(undoGroup != null)
373
                return undoGroup.getUndoPresentationName();
374
            return super.getUndoOrRedoPresentationName();
375
        }
376
377
        public synchronized String getUndoPresentationName() {
378
            if(undoGroup != null)
379
                return undoGroup.getUndoPresentationName();
380
            return super.getUndoPresentationName();
381
        }
382
383
        public synchronized String getRedoPresentationName() {
384
            if(undoGroup != null)
385
                return undoGroup.getRedoPresentationName();
386
            return super.getRedoPresentationName();
387
        }
388
389
        public boolean isSignificant() {
390
            if(undoGroup != null && undoGroup.isSignificant()) {
391
                return true;
392
            }
393
            return super.isSignificant();
394
        }
395
396
        public synchronized void die() {
397
            commitUndoGroup();
398
            super.die();
399
        }
400
401
        public String getPresentationName() {
402
            if(undoGroup != null)
403
                return undoGroup.getPresentationName();
404
            return super.getPresentationName();
405
        }
406
407
        /* since these protected methods are only accessed from
408
         * synchronized methods that commitUndoGroup,
409
         * they do not need to be in this class
410
        protected UndoableEdit editToBeUndone() {
411
            if(undoGroup != null)
412
                return null;
413
            return super.editToBeUndone();
414
        }
415
416
        protected UndoableEdit editToBeRedone() {
417
            if(undoGroup != null)
418
                return null;
419
            return super.editToBeRedone();
420
        }
421
422
        protected void undoTo(UndoableEdit edit) {
423
            if(undoGroup != null)
424
                throw new CannotUndoException();
425
            super.undoTo(edit);
426
        }
427
428
        protected void redoTo(UndoableEdit edit) {
429
            if(undoGroup != null)
430
                throw new CannotRedoException();
431
            super.redoTo(edit);
432
        }*/
254
    }
433
    }
255
}
434
}

Return to bug 103467