javax.swing.event.UndoableEditEvent Java Examples

The following examples show how to use javax.swing.event.UndoableEditEvent. 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: BezierLinerEditHandler.java    From openAGV with Apache License 2.0 6 votes vote down vote up
@Override
public void undoableEditHappened(UndoableEditEvent evt) {
  if (!(evt.getEdit() instanceof BezierLinerEdit)) {
    return;
  }
  BezierFigure owner = ((BezierLinerEdit) evt.getEdit()).getOwner();
  if (!(owner instanceof PathConnection)) {
    return;
  }

  PathConnection path = (PathConnection) owner;
  path.updateControlPoints();
  PathModel pathModel = path.getModel();
  pathModel.getPropertyPathControlPoints().markChanged();
  pathModel.propertiesChanged(path);
}
 
Example #2
Source File: CodeEditArea.java    From ApkToolPlus with Apache License 2.0 6 votes vote down vote up
public void undoableEditHappened(UndoableEditEvent e) {
	// Remember the edit and update the menus
	undo.addEdit(e.getEdit());
	if (undo.canUndo()) {
		((BrowserMDIFrame)internalFrame.getParentFrame()).actionUndo.setEnabled(true);
	} else  {
		((BrowserMDIFrame)internalFrame.getParentFrame()).actionUndo.setEnabled(false);
	}
	if (undo.canRedo()) {
		((BrowserMDIFrame)internalFrame.getParentFrame()).actionRedo.setEnabled(true);
	} else  {
		((BrowserMDIFrame)internalFrame.getParentFrame()).actionRedo.setEnabled(false);
	}
	/*
	 * internalFrame.getParentFrame(). undoAction.updateUndoState();
	 * redoAction.updateRedoState();
	 */

}
 
Example #3
Source File: DragManager.java    From PIPE with MIT License 6 votes vote down vote up
/**
 * Loops through each PlaceablePetriNetComponents start and ending coordinates (i.e. before and after translation)
 * and creates a {@link pipe.historyActions.component.MovePetriNetObject} undoEdit for each event
 *
 * It then creates an {@link pipe.historyActions.MultipleEdit} with all these undoEdits in and
 * registers this with the undoListener.
 * @param startingCoordinates of selected items before translation
 * @param translatedCoordinates of selected items after translation
 */
private void createMovedUndoItem(Map<String, Point2D> startingCoordinates,
                                 Map<PlaceablePetriNetComponent, Point2D> translatedCoordinates) {
    List<UndoableEdit> undoableEdits = new LinkedList<>();
    for (Map.Entry<PlaceablePetriNetComponent, Point2D> entry : translatedCoordinates.entrySet()) {
        PlaceablePetriNetComponent component = entry.getKey();
        Point2D starting = startingCoordinates.get(component.getId());
        Point2D translated = entry.getValue();
        if (!starting.equals(translated)) {
            undoableEdits.add(new MovePetriNetObject(component, starting, translated));
        }
    }
    if (!undoableEdits.isEmpty()) {
        petriNetController.getUndoListener().undoableEditHappened(new UndoableEditEvent(this, new MultipleEdit(undoableEdits)));
    }
}
 
Example #4
Source File: TextUndoManager.java    From groovy with Apache License 2.0 6 votes vote down vote up
public void undoableEditHappened(UndoableEditEvent uee) {
    UndoableEdit edit = uee.getEdit();
    boolean undoable = canUndo();

    long editTime = System.currentTimeMillis();

    if (firstModified == 0 ||
            editTime - compoundEdit.editedTime() > 700) {
        compoundEdit.end();
        compoundEdit = new StructuredEdit();
    }
    compoundEdit.addEdit(edit);

    firstModified = firstModified == 0 ?
            compoundEdit.editedTime() : firstModified;

    if (lastEdit() != compoundEdit) {
        boolean changed = hasChanged();
        addEdit(compoundEdit);
        firePropertyChangeEvent(UndoManager.UndoName, undoable, canUndo());
    }

}
 
Example #5
Source File: SQLPanelAPI.java    From bigtable-sql with Apache License 2.0 6 votes vote down vote up
public void undoableEditHappened(UndoableEditEvent e) {
    IApplication app = getSession().getApplication();
    SquirrelPreferences prefs = app.getSquirrelPreferences();
    
    if (fileOpened || fileSaved) {
        if (prefs.getWarnForUnsavedFileEdits()) {
            unsavedEdits = true;
        }
        getActiveSessionTabWidget().setUnsavedEdits(true);
        ActionCollection actions = 
            getSession().getApplication().getActionCollection();
        actions.enableAction(FileSaveAction.class, true);
    } else if (prefs.getWarnForUnsavedBufferEdits()) {
        unsavedEdits = true;
    }
}
 
Example #6
Source File: FormModel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public CompoundEdit endCompoundEdit(boolean commit) {
    if (compoundEdit != null) {
        t("ending compound edit: "+commit); // NOI18N
        compoundEdit.end();
        if (commit && undoRedoRecording && compoundEdit.isSignificant()) {
            if (!formModifiedLogged) {
                Logger logger = Logger.getLogger("org.netbeans.ui.metrics.form"); // NOI18N
                LogRecord rec = new LogRecord(Level.INFO, "USG_FORM_MODIFIED"); // NOI18N
                rec.setLoggerName(logger.getName());
                logger.log(rec);
                formModifiedLogged = true;
            }
            getUndoRedoManager().undoableEditHappened(
                new UndoableEditEvent(this, compoundEdit));
        }
        CompoundEdit edit = compoundEdit;
        compoundEdit = null;
        return edit;
    }
    return null;
}
 
Example #7
Source File: SyntaxDocument.java    From nextreports-designer with Apache License 2.0 6 votes vote down vote up
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());
            }
        }
        
    });
}
 
Example #8
Source File: UndoRedoTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void doUndoRedoTest(UndoRedo.Manager ur) {
    assertFalse("Nothing to undo", ur.canUndo());
    ur.addChangeListener(this);
    MyEdit me = new MyEdit();
    ur.undoableEditHappened(new UndoableEditEvent(this, me));
    assertChange("One change");
    assertTrue("Can undo now", ur.canUndo());
    ur.undo();
    assertFalse("Cannot undo", ur.canUndo());
    assertChange("Snd change");

    assertTrue("But redo", ur.canRedo());
    ur.redo();
    assertChange("Third change");
    assertEquals("One undo", 1, me.undo);
    assertEquals("One redo", 1, me.redo);
}
 
Example #9
Source File: ViewElementFilename.java    From Robot-Overlord-App with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Panel action, update entity
 */
@Override
public void actionPerformed(ActionEvent arg0) {
	JFileChooser chooser = new JFileChooser();
	if(filters.size()==0) return;  // @TODO: fail!
	if(filters.size()==1) chooser.setFileFilter(filters.get(0));
	else {
		Iterator<FileFilter> i = filters.iterator();
		while(i.hasNext()) {
			chooser.addChoosableFileFilter(i.next());
		}
	}
	if(lastPath!=null) chooser.setCurrentDirectory(new File(lastPath));
	int returnVal = chooser.showDialog(ro.getMainFrame(), Translator.get("Select"));
	if(returnVal == JFileChooser.APPROVE_OPTION) {
		String newFilename = chooser.getSelectedFile().getAbsolutePath();
		lastPath = chooser.getSelectedFile().getParent();

		ro.undoableEditHappened(new UndoableEditEvent(this,new ActionChangeString(e, newFilename) ) );
	}
}
 
Example #10
Source File: ViewElementInt.java    From Robot-Overlord-App with GNU General Public License v2.0 6 votes vote down vote up
protected void conditionalChange() {
	int newNumber;
	
	try {
		newNumber = Integer.valueOf(field.getText());
		field.setForeground(UIManager.getColor("Textfield.foreground"));
	} catch(NumberFormatException e1) {
		field.setForeground(Color.RED);
		newNumber = e.get();
	}
	
	if(lock.isLocked()) return;
	lock.lock();

	if(newNumber != e.get()) {
		ro.undoableEditHappened(new UndoableEditEvent(this,new ActionChangeInt(e, newNumber) ) );
	}
	lock.unlock();
}
 
Example #11
Source File: CompoundUndoManager.java    From jeveassets with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void undoableEditHappened(UndoableEditEvent e) {
	//  Start a new compound edit

	if (compoundEdit == null) {
		compoundEdit = startCompoundEdit(e.getEdit());
		return;
	}

	int offsetChange = textComponent.getCaretPosition() - lastOffset;
	int lengthChange = textComponent.getDocument().getLength() - lastLength;

	//  Check for an attribute change
	UndoableEdit edit = e.getEdit();
	if (edit instanceof AbstractDocument.DefaultDocumentEvent) {
		AbstractDocument.DefaultDocumentEvent event = (AbstractDocument.DefaultDocumentEvent) e.getEdit();
		if (event.getType().equals(DocumentEvent.EventType.CHANGE)) {
			if (offsetChange == 0) {
				compoundEdit.addEdit(e.getEdit());
				return;
			}
		}
	}

	//  Check for an incremental edit or backspace.
	//  The Change in Caret position and Document length should both be
	//  either 1 or -1.
	if (offsetChange == lengthChange
			&& Math.abs(offsetChange) == 1) {
		compoundEdit.addEdit(e.getEdit());
		lastOffset = textComponent.getCaretPosition();
		lastLength = textComponent.getDocument().getLength();
		return;
	}

	//  Not incremental edit, end previous edit and start a new one
	compoundEdit.end();
	compoundEdit = startCompoundEdit(e.getEdit());
}
 
Example #12
Source File: CutActionTest.java    From PIPE with MIT License 5 votes vote down vote up
@Test
public void doesNotUndoIfNoneSelected() {
    when(petriNetController.getSelectedComponents()).thenReturn(new HashSet<PetriNetComponent>());
    cutAction.addUndoableEditListener(listener);

    cutAction.actionPerformed(null);

    verify(listener, never()).undoableEditHappened(any(UndoableEditEvent.class));
}
 
Example #13
Source File: AbstractPetriNetComponentController.java    From PIPE with MIT License 5 votes vote down vote up
/**
 * Registers the edit with the listener
 *
 * @param edit to register 
 */
protected final void registerUndoableEdit(UndoableEdit edit) {
    if (registerMultipleEdits) {
        multipleEdits.add(edit);
    } else {
        listener.undoableEditHappened(new UndoableEditEvent(this, edit));
    }
}
 
Example #14
Source File: CopyPasteManager.java    From PIPE with MIT License 5 votes vote down vote up
/**
 * Creates a history item for the new components added to the petrinet
 *
 * @param createdComponents new components that have been created
 */
private void createPasteHistoryItem(Iterable<PetriNetComponent> createdComponents) {
    List<UndoableEdit> undoableEditList = new LinkedList<>();
    for (PetriNetComponent component : createdComponents) {
        AddPetriNetObject addAction = new AddPetriNetObject(component, petriNet);
        undoableEditList.add(addAction);
    }

    listener.undoableEditHappened(new UndoableEditEvent(this, new MultipleEdit(undoableEditList)));
}
 
Example #15
Source File: RepeatMenuItem.java    From Pixelitor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void undoableEditHappened(UndoableEditEvent e) {
    PixelitorEdit edit = (PixelitorEdit) e.getEdit();

    if (edit == null) { // happens when all images are closed
        setEnabled(false);
        getAction().putValue(Action.NAME, "Repeat");
        return;
    }

    setEnabled(edit.canRepeat());
    getAction().putValue(Action.NAME, "Repeat " + edit.getPresentationName());
}
 
Example #16
Source File: ViewElementColor.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void stateChanged(ChangeEvent arg0) {
	float [] newValues = new float[fields.length];
	float [] oldValues = ((ColorEntity)e).getFloatArray();
	
	float sum=0;
	for(int i=0;i<fields.length;++i) {
		newValues[i] = getField(i,oldValues[i]);
		sum += Math.abs( newValues[i] - oldValues[i] );
	}

	if(sum>1e-3) {
		ro.undoableEditHappened(new UndoableEditEvent(this,new ActionChangeColorRGBA(e,newValues) ) );
	}
}
 
Example #17
Source File: RateParameterControllerTest.java    From PIPE with MIT License 5 votes vote down vote up
@Test
public void setRateDoesCreatesUndoItemIfIdEqual() {
    String oldId = "id";
    String newId = "id";
    when(rateParameter.getId()).thenReturn(oldId);

    rateParameterController.setId(newId);

    verify(listener, never()).undoableEditHappened(any(UndoableEditEvent.class));
}
 
Example #18
Source File: ViewElementSlider.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void stateChanged(ChangeEvent arg0) {
	int oldValue = e.get();
	int newValue = field.getValue();
	
	if(newValue!=oldValue) {
		ro.undoableEditHappened(new UndoableEditEvent(this,new ActionChangeInt(e,newValue) ) );
	}
}
 
Example #19
Source File: ViewElementComboBox.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
/**
 * I have changed.  poke the entity
 */
@Override
public void actionPerformed(ActionEvent arg0) {
	int newIndex = field.getSelectedIndex();
	if(newIndex != e.get()) {
		ro.undoableEditHappened(new UndoableEditEvent(this,new ActionChangeComboBox(e, e.getName(), newIndex) ) );
	}
}
 
Example #20
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
@Override protected void fireUndoableEditUpdate(UndoableEditEvent e) {
  // FindBugs: UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR
  // if (Objects.nonNull(compoundEdit)) {
  //   compoundEdit.addEdit(e.getEdit());
  // } else {
  //   super.fireUndoableEditUpdate(e);
  // }
  Optional.ofNullable(compoundEdit).ifPresent(ce -> ce.addEdit(e.getEdit()));
  // JDK9:
  // Optional.ofNullable(compoundEdit)
  //     .ifPresentOrElse(ce -> ce.addEdit(e.getEdit()), () -> super.fireUndoableEditUpdate(e));
}
 
Example #21
Source File: CutActionTest.java    From PIPE with MIT License 5 votes vote down vote up
@Test
public void performsUndoItemIfSelected() {
    Set<PetriNetComponent> components = new HashSet<>();
    components.add(component);
    when(petriNetController.getSelectedComponents()).thenReturn(components);

    cutAction.addUndoableEditListener(listener);
    cutAction.actionPerformed(null);

    verify(listener).undoableEditHappened(any(UndoableEditEvent.class));

}
 
Example #22
Source File: RateParameterControllerTest.java    From PIPE with MIT License 5 votes vote down vote up
@Test
public void setRateDoesCreatesUndoItemIfRateEqual() throws InvalidRateException {
    String oldRate = "5";
    String newRate = "5";
    when(rateParameter.getExpression()).thenReturn(oldRate);
    rateParameterController.setRate(newRate);

    verify(listener, never()).undoableEditHappened(any(UndoableEditEvent.class));
}
 
Example #23
Source File: ROCEditorListener.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
@Override
public void undoableEditHappened(UndoableEditEvent ev) {
	UndoableEdit edit = ev.getEdit();
	if (edit instanceof AbstractDocument.DefaultDocumentEvent && ((AbstractDocument.DefaultDocumentEvent) edit)
			.getType() == AbstractDocument.DefaultDocumentEvent.EventType.CHANGE) {
		return;
	}
	manager.addEdit(edit);
}
 
Example #24
Source File: ViewElementSliderDouble.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void stateChanged(ChangeEvent arg0) {
	if(inUpdate) return;
	
	int oldValue = (int)Math.floor(e.get());
	int newValue = field.getValue();
	
	if(newValue!=oldValue) {
		ro.undoableEditHappened(new UndoableEditEvent(this,new ActionChangeDouble(e,(double)newValue) ) );
	}
}
 
Example #25
Source File: ViewElementString.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
/**
 * panel changed, poke entity
 */
@Override
public void changedUpdate(DocumentEvent arg0) {
	if(lock.isLocked()) return;
	lock.lock();

	String newValue = field.getText();
	if( !newValue.equals(e.get()) ) {
		ro.undoableEditHappened(new UndoableEditEvent(this,new ActionChangeString(e, newValue) ) );
	}
	lock.unlock();
}
 
Example #26
Source File: ViewElementBoolean.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
/**
 * the panel element has changed.  poke the entity.
 */
@Override
public void itemStateChanged(ItemEvent arg0) {
	boolean newValue = field.isSelected();
	if(e.get()!=newValue) {
		ro.undoableEditHappened(new UndoableEditEvent(this,new ActionChangeBoolean(e, newValue) ) );
	}
}
 
Example #27
Source File: Contains.java    From PIPE with MIT License 5 votes vote down vote up
@Override
public boolean matches(Object argument) {
    UndoableEditEvent event = (UndoableEditEvent) argument;
    UndoableEdit edit = event.getEdit();

    return edit.equals(expectedEdit);
}
 
Example #28
Source File: CommandRemoveEntity.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
public void actionPerformed(ActionEvent e) {
	Entity entity = ro.getPickedEntity();
	if(entity==null) {
		Log.error("RemoveEntity with no entity selected.");
		return;
	}
	ro.undoableEditHappened(new UndoableEditEvent(this,new ActionEntityRemove(ro,entity) ) );
}
 
Example #29
Source File: SyntaxDocument.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public SyntaxDocument(Lexer lexer) {
    super();
    putProperty(PlainDocument.tabSizeAttribute, 4);
    this.lexer = lexer;
    // Listen for undo and redo events
    addUndoableEditListener(new UndoableEditListener() {

        @Override
        public void undoableEditHappened(UndoableEditEvent evt) {
            if (evt.getEdit().isSignificant()) {
                undo.addEdit(evt.getEdit());
            }
        }
    });
}
 
Example #30
Source File: AbbrevDetection.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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);
        }
    }
}