Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2485c0b
Extract Tool interfaces to fix Interface Segregation Principle violation
Seralyne Dec 27, 2025
48a8744
Things didn't migrate properly
Seralyne Dec 27, 2025
16452bc
Refactoring Work:
Seralyne Dec 27, 2025
2baee1e
More refactoring to Dependency Inversion Principle (Depending on
Seralyne Dec 27, 2025
c793fb3
Fixed regression exposed by my refactor causing broken event loops.
Seralyne Dec 28, 2025
d654e87
Changed TextCreationTool to work on mouseClicked since there was a re…
Seralyne Dec 28, 2025
fb1ec1b
Work for today: Finished refactoring of TextCreationTool and TextEdit…
Seralyne Dec 28, 2025
4d48d78
Some shit didn't add itself properly to last commit
Seralyne Dec 29, 2025
2008599
Removed class created while testing
Seralyne Dec 29, 2025
6619a11
Done a bunch of refactoring
Seralyne Dec 30, 2025
edec18e
Finished refactor
Seralyne Dec 30, 2025
52dabd4
Add CI/CD and finish refactor truly. Now to write tests
Seralyne Dec 30, 2025
4fc85d9
Added basic tests. See if it works in CI/CD too
Seralyne Dec 31, 2025
e5560f4
Started work on test suite
Seralyne Dec 31, 2025
b6edd6c
Test debugging
Seralyne Jan 1, 2026
2aa0671
Changed JDK version due to incompatibilities between Mockito and JDK 25
Seralyne Jan 1, 2026
2e2a17a
Fixed bug caused when refactoring endOverlay
Seralyne Jan 1, 2026
7aecbf8
Problems with worker
Seralyne Jan 1, 2026
9422ecc
Duplicate junit dependencies
Seralyne Jan 1, 2026
dd0323f
Forgot to update worker code to not pattern match
Seralyne Jan 1, 2026
c9ad060
Force maven to do both junit and testng for worker
Seralyne Jan 1, 2026
16bddbd
Test removal of testNG
Seralyne Jan 1, 2026
6afcee5
Okay so removing setLabelFor during my refactor was stupid
Seralyne Jan 1, 2026
0833829
Integration tests mostly done. Last one probably won't be finished un…
Seralyne Jan 3, 2026
3307bc0
Fixed small regression in which pressing escape no longer finishes
Seralyne Jan 3, 2026
7de0d0e
Fixed regression that was caused by dumbassery early in refactor. Als…
Seralyne Jan 3, 2026
72510ac
FINAL COMMIT FUCKING FINALLY
Seralyne Jan 3, 2026
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
42 changes: 42 additions & 0 deletions .github/workflows/maven-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: CI/CD with Maven and Tests

on:
push:
branches: ["develop", "mia"]
pull_request:
branches: ["main", "mia"]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Clone code to worker
uses: actions/checkout@v4

- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: temurin
cache: maven

- name: Install xvfb for BDD Tests
run: sudo apt-get update && sudo apt-get install -y xvfb

- name: Compile
run: mvn compile -Djava.awt.headless=true

- name: Run All Tests
run: >
xvfb-run mvn -B verify
-DfailIfNoTests=false

- name: Get Test Results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-reports
path: |
target/jgiven-reports/html
target/surefire-reports
target/failsafe-reports
52 changes: 50 additions & 2 deletions jhotdraw-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,59 @@
<artifactId>testng</artifactId>
<version>6.8.21</version>
<scope>test</scope>
</dependency>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.25.3</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-swing-junit</artifactId>
<version>3.17.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.tngtech.jgiven</groupId>
<artifactId>jgiven-junit</artifactId>
<version>1.3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jhotdraw-actions</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.4.1</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ public boolean isSelectionEmpty() {
return selectedFigures.isEmpty();
}


private class EventHandler implements FigureListener, CompositeFigureListener, HandleListener, FocusListener {

@Override
Expand Down Expand Up @@ -299,6 +300,7 @@ public void figureRemoved(FigureEvent e) {
public void figureRequestRemove(FigureEvent e) {
}
}

private final EventHandler eventHandler = new EventHandler();


Expand Down Expand Up @@ -1001,6 +1003,7 @@ public void duplicate() {
f.remap(originalToDuplicateMap, false);
}
addToSelection(duplicates);

drawing.fireUndoableEditHappened(new AbstractUndoableEdit() {
private static final long serialVersionUID = 1L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@

import org.jhotdraw.draw.figure.Figure;
import java.awt.*;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseWheelListener;
import java.awt.event.*;
import java.util.*;
import javax.swing.ActionMap;
import javax.swing.InputMap;
Expand All @@ -29,6 +25,7 @@
import org.jhotdraw.draw.action.*;
import org.jhotdraw.draw.event.ToolAdapter;
import org.jhotdraw.draw.event.ToolEvent;
import org.jhotdraw.draw.tool.BaseTool;
import org.jhotdraw.draw.tool.Tool;

/**
Expand All @@ -44,7 +41,7 @@ public class DefaultDrawingEditor extends AbstractBean implements DrawingEditor
private static final long serialVersionUID = 1L;
private HashMap<AttributeKey<?>, Object> defaultAttributes = new HashMap<>();
private HashMap<AttributeKey<?>, Object> handleAttributes = new HashMap<>();
private Tool tool;
private BaseTool tool;
private HashSet<DrawingView> views;
private DrawingView activeView;
private boolean isEnabled = true;
Expand Down Expand Up @@ -114,16 +111,16 @@ public DefaultDrawingEditor() {
}

@Override
public void setTool(Tool newValue) {
Tool oldValue = tool;
public void setTool(BaseTool newValue) {
BaseTool oldValue = tool;
if (newValue == tool) {
return;
}
if (tool != null) {
for (DrawingView v : views) {
v.removeMouseListener(tool);
v.removeMouseMotionListener(tool);
v.removeKeyListener(tool);
if (tool instanceof MouseListener) v.removeMouseListener((MouseListener) tool);
if (tool instanceof MouseMotionListener) v.removeMouseMotionListener((MouseMotionListener) tool);
if (tool instanceof KeyListener) v.removeKeyListener((KeyListener) tool);
if (tool instanceof MouseWheelListener) {
v.removeMouseWheelListener((MouseWheelListener) tool);
}
Expand All @@ -135,9 +132,9 @@ public void setTool(Tool newValue) {
if (tool != null) {
tool.activate(this);
for (DrawingView v : views) {
v.addMouseListener(tool);
v.addMouseMotionListener(tool);
v.addKeyListener(tool);
if (tool instanceof MouseListener) v.addMouseListener((MouseListener) tool);
if (tool instanceof MouseMotionListener) v.addMouseMotionListener((MouseMotionListener) tool);
if (tool instanceof KeyListener) v.addKeyListener((KeyListener) tool);
if (tool instanceof MouseWheelListener) {
v.addMouseWheelListener((MouseWheelListener) tool);
}
Expand All @@ -155,7 +152,7 @@ public void setActiveView(DrawingView newValue) {
}

@Override
public Tool getTool() {
public BaseTool getTool() {
return tool;
}

Expand Down Expand Up @@ -204,9 +201,9 @@ public void remove(DrawingView view) {
view.getComponent().removeFocusListener(focusHandler);
views.remove(view);
if (tool != null) {
view.removeMouseListener(tool);
view.removeMouseMotionListener(tool);
view.removeKeyListener(tool);
if (tool instanceof MouseListener) view.removeMouseListener((MouseListener) tool);
if (tool instanceof MouseMotionListener) view.removeMouseMotionListener((MouseMotionListener) tool);
if (tool instanceof KeyListener) view.removeKeyListener((KeyListener) tool);
}
view.removeNotify(this);
if (activeView == view) {
Expand All @@ -221,9 +218,9 @@ public void add(DrawingView view) {
view.addNotify(this);
view.getComponent().addFocusListener(focusHandler);
if (tool != null) {
view.addMouseListener(tool);
view.addMouseMotionListener(tool);
view.addKeyListener(tool);
if (tool instanceof MouseListener) view.addMouseListener((MouseListener) tool);
if (tool instanceof MouseMotionListener) view.addMouseMotionListener((MouseMotionListener) tool);
if (tool instanceof KeyListener) view.addKeyListener((KeyListener) tool);
}
updateActiveView();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ public DefaultDrawingView() {
setTransferHandler(new DefaultDrawingViewTransferHandler());
setBackground(new Color(0xb0b0b0));
setOpaque(true);
setName("drawingCanvas"); // For BDD Testing
}

protected EventHandler createEventHandler() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.util.*;
import javax.swing.ActionMap;
import javax.swing.InputMap;

import org.jhotdraw.draw.tool.BaseTool;
import org.jhotdraw.draw.tool.Tool;

/**
Expand Down Expand Up @@ -157,14 +159,14 @@ public interface DrawingEditor {
* <p>
* This is a bound property.
*/
void setTool(Tool t);
void setTool(BaseTool t);

/**
* Gets the current tool.
* <p>
* This is a bound property.
*/
Tool getTool();
BaseTool getTool();

/**
* Sets the cursor on the view(s) of the drawing editor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import javax.swing.ActionMap;
import javax.swing.InputMap;
import org.jhotdraw.beans.AbstractBean;
import org.jhotdraw.draw.tool.BaseTool;
import org.jhotdraw.draw.tool.Tool;

/**
Expand Down Expand Up @@ -105,12 +106,12 @@ public DrawingView getFocusedView() {
}

@Override
public void setTool(Tool t) {
public void setTool(BaseTool t) {
target.setTool(t);
}

@Override
public Tool getTool() {
public BaseTool getTool() {
return target.getTool();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ public void setUpdateEnabledState(boolean newValue) {
* Returns true, if this action automatically updates its enabled
* state to reflect the enabled state of the active {@code DrawingView}.
*/

//FIXME: Typo
public boolean isUpdatEnabledState() {
return eventHandler != null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ public interface FigureListener extends EventListener {
/**
* Sent when the drawing area used by the figure needs to be repainted.
*/
public void areaInvalidated(FigureEvent e);
default void areaInvalidated(FigureEvent e) {}

/**
* Sent when an attribute of the figure has changed.
*/
public void attributeChanged(FigureEvent e);
default void attributeChanged(FigureEvent e) {}

/**
* Sent when handles of a Figure have been added, removed or replaced.
Expand All @@ -51,25 +51,25 @@ public interface FigureListener extends EventListener {
* A Figure should not fire this event, if just the state or the location
* of Handle has changed.
*/
public void figureHandlesChanged(FigureEvent e);
default void figureHandlesChanged(FigureEvent e) {}

/**
* Sent when the geometry (for example the bounds) of the figure has changed.
*/
public void figureChanged(FigureEvent e);
default void figureChanged(FigureEvent e) {}

/**
* Sent when a figure was added to a drawing.
*/
public void figureAdded(FigureEvent e);
default void figureAdded(FigureEvent e) {}

/**
* Sent when a figure was removed from a drawing.
*/
public void figureRemoved(FigureEvent e);
void figureRemoved(FigureEvent e);

/**
* Sent when the figure requests to be removed from a drawing.
*/
public void figureRequestRemove(FigureEvent e);
default void figureRequestRemove(FigureEvent e) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.awt.*;
import java.util.*;
import org.jhotdraw.draw.*;
import org.jhotdraw.draw.tool.BaseTool;
import org.jhotdraw.draw.tool.Tool;

/**
Expand Down Expand Up @@ -38,7 +39,7 @@ public class ToolEvent extends EventObject {
/**
* Creates a new instance.
*/
public ToolEvent(Tool src, DrawingView view, Rectangle invalidatedArea) {
public ToolEvent(BaseTool src, DrawingView view, Rectangle invalidatedArea) {
super(src);
this.view = view;
this.invalidatedArea = invalidatedArea;
Expand All @@ -47,8 +48,8 @@ public ToolEvent(Tool src, DrawingView view, Rectangle invalidatedArea) {
/**
* Gets the tool which is the source of the event.
*/
public Tool getTool() {
return (Tool) getSource();
public BaseTool getTool() {
return (BaseTool) getSource();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.jhotdraw.draw.handle.BoundsOutlineHandle;
import org.jhotdraw.draw.handle.Handle;
import org.jhotdraw.draw.handle.ResizeHandleKit;
import org.jhotdraw.draw.tool.BaseTool;
import org.jhotdraw.draw.tool.Tool;
import org.jhotdraw.geom.Dimension2DDouble;

Expand Down Expand Up @@ -460,7 +461,7 @@ public Collection<Action> getActions(Point2D.Double p) {
* Returns null, if no specialized tool is available.
*/
@Override
public Tool getTool(Point2D.Double p) {
public BaseTool getTool(Point2D.Double p) {
return null;
}

Expand Down
Loading