Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: CI
on:
pull_request:
branches: ["develop"]

jobs:
build-and-test:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Build and run tests
run: mvn clean verify -B
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# jhotdraw

* maven build process
* restructured project layout
* introduced submodules
## Install and Run
Install (**in project root**):
* mvn clean install -DskipTests

## License
Run (**in jhotdraw-samples-misc**):
* mvn exec:java "-Dexec.mainClass=org.jhotdraw.samples.svg.Main"

## License
* LGPL V2.1
* Creative Commons Attribution 2.5 License

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.jhotdraw.undo;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.util.logging.Logger;

public abstract class AbstractUndoRedoAction extends AbstractAction {

private static final long serialVersionUID = 1L;
private final UndoRedoManager manager;

protected final Logger logger = Logger.getLogger(this.getClass().getName());

AbstractUndoRedoAction(UndoRedoManager undoRedoManager, String id) {
this.manager = undoRedoManager;
UndoRedoManager.getLabels().configureAction(this, "edit." + id);
setEnabled(false);
}
@Override
public void actionPerformed(ActionEvent evt) {
performAction();
}

protected abstract void performAction();

protected UndoRedoManager getManager() {
return this.manager;
}
}
24 changes: 24 additions & 0 deletions jhotdraw-utils/src/main/java/org/jhotdraw/undo/RedoAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.jhotdraw.undo;

import javax.swing.undo.CannotUndoException;
import java.util.logging.Level;

/**
* Redo Action for use in a menu bar.
*/
class RedoAction extends AbstractUndoRedoAction {
public RedoAction(UndoRedoManager undoRedoManger) {
super(undoRedoManger, "redo");
}
/**
* Invoked when an action occurs.
*/
@Override
protected void performAction() {
try {
super.getManager().redo();
} catch (CannotUndoException e) {
logger.log(Level.SEVERE, "Cannot redo: ", e);
}
}
}
25 changes: 25 additions & 0 deletions jhotdraw-utils/src/main/java/org/jhotdraw/undo/UndoAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.jhotdraw.undo;

import javax.swing.undo.CannotUndoException;
import java.util.logging.Level;

/**
* Undo Action for use in a menu bar.
*/
class UndoAction extends AbstractUndoRedoAction {

public UndoAction(UndoRedoManager undoRedoManger) {
super(undoRedoManger, "undo");
}
/**
* Invoked when an action occurs.
*/
@Override
protected void performAction() {
try {
super.getManager().undo();
} catch (CannotUndoException e) {
logger.log(Level.SEVERE, "Cannot undo: ", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,55 +65,7 @@ public boolean canRedo() {
/**
* Undo Action for use in a menu bar.
*/
private class UndoAction
extends AbstractAction {

private static final long serialVersionUID = 1L;

public UndoAction() {
labels.configureAction(this, "edit.undo");
setEnabled(false);
}

/**
* Invoked when an action occurs.
*/
@Override
public void actionPerformed(ActionEvent evt) {
try {
undo();
} catch (CannotUndoException e) {
System.err.println("Cannot undo: " + e);
e.printStackTrace();
}
}
}

/**
* Redo Action for use in a menu bar.
*/
private class RedoAction
extends AbstractAction {

private static final long serialVersionUID = 1L;

public RedoAction() {
labels.configureAction(this, "edit.redo");
setEnabled(false);
}

/**
* Invoked when an action occurs.
*/
@Override
public void actionPerformed(ActionEvent evt) {
try {
redo();
} catch (CannotRedoException e) {
System.out.println("Cannot redo: " + e);
}
}
}
/**
* The undo action instance.
*/
Expand All @@ -135,8 +87,8 @@ public static ResourceBundleUtil getLabels() {
*/
public UndoRedoManager() {
getLabels();
undoAction = new UndoAction();
redoAction = new RedoAction();
undoAction = new UndoAction(this);
redoAction = new RedoAction(this);
}

public void setLocale(Locale l) {
Expand Down Expand Up @@ -255,6 +207,7 @@ private void updateActions() {
@Override
public void undo()
throws CannotUndoException {
System.out.println("UndoCalled");
undoOrRedoInProgress = true;
try {
super.undo();
Expand Down Expand Up @@ -286,43 +239,21 @@ public void redo()
* The UndoRedoManager ignores all incoming UndoableEdit events,
* while undo or redo is in progress.
*/
@Override
public void undoOrRedo()
throws CannotUndoException, CannotRedoException {
undoOrRedoInProgress = true;
try {
super.undoOrRedo();
} finally {
undoOrRedoInProgress = false;
updateActions();
}
}


public void addPropertyChangeListener(PropertyChangeListener listener) {
propertySupport.addPropertyChangeListener(listener);
}

public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
propertySupport.addPropertyChangeListener(propertyName, listener);
}

// has a use
public void removePropertyChangeListener(PropertyChangeListener listener) {
propertySupport.removePropertyChangeListener(listener);
}

public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
propertySupport.removePropertyChangeListener(propertyName, listener);
}

// has a use
protected void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) {
propertySupport.firePropertyChange(propertyName, oldValue, newValue);
}

protected void firePropertyChange(String propertyName, int oldValue, int newValue) {
propertySupport.firePropertyChange(propertyName, oldValue, newValue);
}

protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
propertySupport.firePropertyChange(propertyName, oldValue, newValue);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.jhotdraw.undo;

import com.tngtech.jgiven.Stage;
import com.tngtech.jgiven.annotation.ProvidedScenarioState;
import com.tngtech.jgiven.junit.ScenarioTest;
import org.junit.Test;

import javax.swing.undo.AbstractUndoableEdit;

import static org.junit.Assert.assertTrue;

public class UndoMostRecentActionBddTest extends ScenarioTest<
UndoMostRecentActionBddTest.Given,
UndoMostRecentActionBddTest.When,
UndoMostRecentActionBddTest.Then> {

@Test
public void undo_the_most_recent_action() {
given().an_undo_manager_with_one_action();
when().the_user_clicks_undo();
then().the_action_is_undone_and_redo_is_available();
}

public static class Given extends Stage<Given> {
@ProvidedScenarioState UndoRedoManager manager;
@ProvidedScenarioState TestEdit edit;

public Given an_undo_manager_with_one_action() {
manager = new UndoRedoManager();
edit = new TestEdit();
manager.addEdit(edit);
return self();
}
}

public static class When extends Stage<When> {
@ProvidedScenarioState UndoRedoManager manager;

public When the_user_clicks_undo() {
manager.undo();
return self();
}
}

public static class Then extends Stage<Then> {
@ProvidedScenarioState UndoRedoManager manager;
@ProvidedScenarioState TestEdit edit;

public Then the_action_is_undone_and_redo_is_available() {
assertTrue("Undo should be called on the edit", edit.undoCalled);
assertTrue("Redo should be available after undo", manager.canRedo());
return self();
}
}

static class TestEdit extends AbstractUndoableEdit {
boolean undoCalled = false;

@Override
public void undo() {
super.undo();
undoCalled = true;
}

@Override
public boolean isSignificant() {
return true;
}
}
}
7 changes: 0 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@
<organization>
<name>JHotDraw</name>
</organization>
<repositories>
<repository>
<id>github</id>
<name>GitHub external Packages</name>
<url>https://maven.pkg.github.com/sweat-tek/MavenRepository</url>
</repository>
</repositories>
<licenses>
<license>
<name>GNU Library or Lesser General Public License (LGPL) V2.1</name>
Expand Down