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
64 changes: 64 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: CI

# Build and test on every push to the main development branches and on
# every pull request targeting them. The workflow runs the full Maven
# reactor build with all tests, then uploads Surefire and JGiven
# reports as artifacts so they are inspectable from the GitHub Actions
# run page.

on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
workflow_dispatch:

# A new push to the same branch cancels any in-progress run on that
# branch. Saves CI minutes when a contributor pushes a fix on top of a
# failing build.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
name: Build and test (JDK 11)
runs-on: ubuntu-latest
timeout-minutes: 30

steps:
- name: Check out source
uses: actions/checkout@v4

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

- name: Build and run all tests
run: mvn -B -ntp clean install
env:
# Swing classes used in tests (JColorChooser, JPopupMenu)
# require headless mode on the runner since no display is
# attached.
MAVEN_OPTS: -Djava.awt.headless=true

- name: Upload Surefire test reports
if: always()
uses: actions/upload-artifact@v4
with:
name: surefire-reports
path: '**/target/surefire-reports/'
retention-days: 14
if-no-files-found: ignore

- name: Upload JGiven BDD reports
if: always()
uses: actions/upload-artifact@v4
with:
name: jgiven-reports
path: '**/target/jgiven-reports/'
retention-days: 14
if-no-files-found: ignore
12 changes: 12 additions & 0 deletions jhotdraw-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@
<version>6.8.21</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jhotdraw-actions</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public class SelectionColorChooserHandler extends AbstractSelectedAction
protected JPopupMenu popupMenu;
protected int isUpdating;

//protected Map<AttributeKey, Object> attributes;
/**
* Creates a new instance.
*/
Expand All @@ -40,59 +39,55 @@ public SelectionColorChooserHandler(DrawingEditor editor, AttributeKey<Color> ke
this.key = key;
this.colorChooser = colorChooser;
this.popupMenu = popupMenu;
//colorChooser.addActionListener(this);
colorChooser.getSelectionModel().addChangeListener(this);
updateEnabledState();
}

@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
/*
if (evt.getActionCommand() == JColorChooser.APPROVE_SELECTION) {
applySelectedColorToFigures();
} else if (evt.getActionCommand() == JColorChooser.CANCEL_SELECTION) {
}*/
popupMenu.setVisible(false);
}

protected void applySelectedColorToFigures() {
final ArrayList<Figure> selectedFigures = new ArrayList<>(getView().getSelectedFigures());
final ArrayList<Object> restoreData = new ArrayList<>(selectedFigures.size());
Color selectedColor = colorChooser.getColor();
if (selectedColor != null && selectedColor.getAlpha() == 0) {
selectedColor = null;
final Color selectedColor = normalizeChosenColor(colorChooser.getColor());
final ArrayList<Object> restoreData = applyColorToFigures(selectedColor, selectedFigures);
getEditor().setDefaultAttribute(key, selectedColor);
fireUndoableEditHappened(createUndoableEdit(selectedColor, selectedFigures, restoreData));
}

public static Color normalizeChosenColor(Color color) {
if (color != null && color.getAlpha() == 0) {
return null;
}
for (Figure figure : selectedFigures) {
return color;
}

ArrayList<Object> applyColorToFigures(Color color, ArrayList<Figure> figures) {
ArrayList<Object> restoreData = new ArrayList<>(figures.size());
for (Figure figure : figures) {
restoreData.add(figure.getAttributesRestoreData());
figure.willChange();
figure.set(key, selectedColor);
figure.set(key, color);
figure.changed();
}
getEditor().setDefaultAttribute(key, selectedColor);
final Color undoValue = selectedColor;
UndoableEdit edit = new AbstractUndoableEdit() {
return restoreData;
}

UndoableEdit createUndoableEdit(final Color undoValue, final ArrayList<Figure> figures, final ArrayList<Object> restoreData) {
return new AbstractUndoableEdit() {
private static final long serialVersionUID = 1L;

@Override
public String getPresentationName() {
return AttributeKeys.FONT_FACE.getPresentationName();
/*
String name = (String) getValue(Actions.UNDO_PRESENTATION_NAME_KEY);
if (name == null) {
name = (String) getValue(AbstractAction.NAME);
}
if (name == null) {
ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.draw.Labels");
name = labels.getString("attribute.text");
}
return name;*/
}

@Override
public void undo() {
super.undo();
Iterator<Object> iRestore = restoreData.iterator();
for (Figure figure : selectedFigures) {
for (Figure figure : figures) {
figure.willChange();
figure.restoreAttributesTo(iRestore.next());
figure.changed();
Expand All @@ -102,15 +97,13 @@ public void undo() {
@Override
public void redo() {
super.redo();
for (Figure figure : selectedFigures) {
//restoreData.add(figure.getAttributesRestoreData());
for (Figure figure : figures) {
figure.willChange();
figure.set(key, undoValue);
figure.changed();
}
}
};
fireUndoableEditHappened(edit);
}

@Override
Expand All @@ -120,12 +113,10 @@ protected void updateEnabledState() {
colorChooser.setEnabled(getView().getSelectionCount() > 0);
popupMenu.setEnabled(getView().getSelectionCount() > 0);
isUpdating++;
if (getView().getSelectionCount() > 0 /*&& colorChooser.isShowing()*/) {
for (Figure f : getView().getSelectedFigures()) {
Color figureColor = f.get(key);
colorChooser.setColor(figureColor == null ? new Color(0, true) : figureColor);
break;
}
if (getView().getSelectionCount() > 0) {
Figure firstSelected = getView().getSelectedFigures().iterator().next();
Color figureColor = firstSelected.get(key);
colorChooser.setColor(figureColor == null ? new Color(0, true) : figureColor);
}
isUpdating--;
}
Expand Down
Loading
Loading