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

on:
push:
branches: [ "develop" ]
pull_request:
branches: [ "develop" ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 23
uses: actions/setup-java@v4
with:
java-version: '23'
distribution: 'temurin'
cache: maven
- name: Configure GitHub Packages credentials
run: |
mkdir -p ~/.m2
cat > ~/.m2/settings.xml <<EOF
<settings>
<servers>
<server>
<id>github</id>
<username>${GITHUB_ACTOR}</username>
<password>${GITHUB_TOKEN}</password>
</server>
</servers>
</settings>
EOF
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_ACTOR: ${{ github.actor }}
- name: Build entire project with Maven
run: mvn -B clean install --file pom.xml
- name: Run tests
run: mvn test --file pom.xml
9 changes: 9 additions & 0 deletions .maven-settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<settings>
<servers>
<server>
<id>github</id>
<username>${{ secrets.GITHUB_ACTOR }}</username>
<password>${{ secrets.GITHUB_TOKEN }}</password>
</server>
</servers>
</settings>
23 changes: 23 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Debug JHotDraw Draw Sample",
"request": "launch",
"mainClass": "org.jhotdraw.samples.draw.Main",
"projectName": "jhotdraw-samples-misc",
"classPaths": [
"${workspaceFolder}/jhotdraw-samples/jhotdraw-samples-misc/target/classes",
"${workspaceFolder}/jhotdraw-core/target/classes",
"${workspaceFolder}/jhotdraw-actions/target/classes",
"${workspaceFolder}/jhotdraw-app/target/classes",
"${workspaceFolder}/jhotdraw-api/target/classes",
"${workspaceFolder}/jhotdraw-gui/target/classes",
"${workspaceFolder}/jhotdraw-utils/target/classes",
"${workspaceFolder}/jhotdraw-xml/target/classes",
"${workspaceFolder}/jhotdraw-datatransfer/target/classes"
]
}
]
}
14 changes: 0 additions & 14 deletions README.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -98,43 +98,9 @@ protected boolean importData(final JComponent comp, Transferable t, final HashSe
SearchLoop: for (InputFormat format : drawing.getInputFormats()) {
for (DataFlavor flavor : transferFlavors) {
if (format.isDataFlavorSupported(flavor)) {
LinkedList<Figure> existingFigures = new LinkedList<>(drawing.getChildren());
try {
format.read(t, drawing, false);
final LinkedList<Figure> importedFigures = new LinkedList<>(drawing.
getChildren());
importedFigures.removeAll(existingFigures);
view.clearSelection();
view.addToSelection(importedFigures);
transferFigures.addAll(importedFigures);
moveToDropPoint(comp, transferFigures, dropPoint);
drawing.fireUndoableEditHappened(new AbstractUndoableEdit() {
private static final long serialVersionUID = 1L;

@Override
public String getPresentationName() {
ResourceBundleUtil labels = ResourceBundleUtil.getBundle(
"org.jhotdraw.draw.Labels");
return labels.getString("edit.paste.text");
}

@Override
public void undo() throws CannotUndoException {
super.undo();
drawing.removeAll(importedFigures);
}

@Override
public void redo() throws CannotRedoException {
super.redo();
drawing.addAll(importedFigures);
}
});
if (importTransferData(comp, t, transferFigures, dropPoint, view, drawing, format)) {
retValue = true;
break SearchLoop;
} catch (IOException e) {
e.printStackTrace();
// failed to read transferalbe, try with next InputFormat
}
}
}
Expand All @@ -144,43 +110,9 @@ public void redo() throws CannotRedoException {
SearchLoop: for (DataFlavor flavor : transferFlavors) {
for (InputFormat format : drawing.getInputFormats()) {
if (format.isDataFlavorSupported(flavor)) {
LinkedList<Figure> existingFigures = new LinkedList<>(drawing.getChildren());
try {
format.read(t, drawing, false);
final LinkedList<Figure> importedFigures = new LinkedList<>(drawing.
getChildren());
importedFigures.removeAll(existingFigures);
view.clearSelection();
view.addToSelection(importedFigures);
transferFigures.addAll(importedFigures);
moveToDropPoint(comp, transferFigures, dropPoint);
drawing.fireUndoableEditHappened(new AbstractUndoableEdit() {
private static final long serialVersionUID = 1L;

@Override
public String getPresentationName() {
ResourceBundleUtil labels = ResourceBundleUtil.getBundle(
"org.jhotdraw.draw.Labels");
return labels.getString("edit.paste.text");
}

@Override
public void undo() throws CannotUndoException {
super.undo();
drawing.removeAll(importedFigures);
}

@Override
public void redo() throws CannotRedoException {
super.redo();
drawing.addAll(importedFigures);
}
});
if (importTransferData(comp, t, transferFigures, dropPoint, view, drawing, format)) {
retValue = true;
break SearchLoop;
} catch (IOException e) {
e.printStackTrace();
// failed to read transferalbe, try with next InputFormat
}
}
}
Expand Down Expand Up @@ -218,28 +150,7 @@ protected void done() {
view.addToSelection(importedFigures);
transferFigures.addAll(importedFigures);
moveToDropPoint(comp, transferFigures, dropPoint);
drawing.fireUndoableEditHappened(new AbstractUndoableEdit() {
private static final long serialVersionUID = 1L;

@Override
public String getPresentationName() {
ResourceBundleUtil labels = ResourceBundleUtil.getBundle(
"org.jhotdraw.draw.Labels");
return labels.getString("edit.paste.text");
}

@Override
public void undo() throws CannotUndoException {
super.undo();
drawing.removeAll(importedFigures);
}

@Override
public void redo() throws CannotRedoException {
super.redo();
drawing.addAll(importedFigures);
}
});
firePasteUndoableEdit(drawing, importedFigures);
}

view.getEditor().setEnabled(true);
Expand All @@ -260,10 +171,54 @@ public void redo() throws CannotRedoException {
return retValue;
}

private boolean importTransferData(final JComponent comp, Transferable t, final HashSet<Figure> transferFigures,
final Point dropPoint, final DrawingView view, final Drawing drawing,
InputFormat format) throws UnsupportedFlavorException {
LinkedList<Figure> existingFigures = new LinkedList<>(drawing.getChildren());
try {
format.read(t, drawing, false);
final LinkedList<Figure> importedFigures = new LinkedList<>(drawing.getChildren());
importedFigures.removeAll(existingFigures);
view.clearSelection();
view.addToSelection(importedFigures);
transferFigures.addAll(importedFigures);
moveToDropPoint(comp, transferFigures, dropPoint);
firePasteUndoableEdit(drawing, importedFigures);
return true;
} catch (IOException e) {
e.printStackTrace();
// Failed to read transferable; try with the next InputFormat.
return false;
}
}

private void firePasteUndoableEdit(final Drawing drawing, final LinkedList<Figure> importedFigures) {
drawing.fireUndoableEditHappened(new AbstractUndoableEdit() {
private static final long serialVersionUID = 1L;

@Override
public String getPresentationName() {
ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.draw.Labels");
return labels.getString("edit.paste.text");
}

@Override
public void undo() throws CannotUndoException {
super.undo();
drawing.removeAll(importedFigures);
}

@Override
public void redo() throws CannotRedoException {
super.redo();
drawing.addAll(importedFigures);
}
});
}

protected void moveToDropPoint(JComponent component, HashSet<Figure> transferFigures, Point dropPoint) {
if (dropPoint == null) {
// This ugly code sequence is needed to ensure that the drawing view
// repaints the area which contains the dropped figures.
// Ensure that the drawing view repaints the area containing the dropped figures.
for (Figure fig : transferFigures) {
fig.willChange();
fig.changed();
Expand Down Expand Up @@ -493,10 +448,6 @@ public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) {
return retValue;
}

private void getDrawing() {
throw new UnsupportedOperationException("Not yet implemented");
}

/**
* This is the default drag handler for drag and drop operations that use
* the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
import java.util.*;

/**
* ComoositeTransferable.
* CompositeTransferable.
*
* @author Werner Randelshofer
*/
public class CompositeTransferable implements Transferable, ClipboardOwner {

private HashMap<DataFlavor, Transferable> transferables = new HashMap<>();
private LinkedList<DataFlavor> flavors = new LinkedList<>();
private final HashMap<DataFlavor, Transferable> transferables = new HashMap<>();
private final LinkedList<DataFlavor> flavors = new LinkedList<>();

/**
* Creates a new instance of CompositeTransferable
Expand Down Expand Up @@ -74,7 +74,7 @@ public DataFlavor[] getTransferDataFlavors() {
* this object.
*
* @param flavor the requested flavor for the data
* @return boolean indicating wjether or not the data flavor is supported
* @return boolean indicating whether or not the data flavor is supported
*/
@Override
public boolean isDataFlavorSupported(DataFlavor flavor) {
Expand Down
Loading