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

on:
pull_request:
branches: [ "develop"]
push:
branches: [ "GerardasAlutis_Undo/Redo" ]

jobs:
build:
runs-on: ubuntu-latest

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

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

- name: Build and test with Maven
run: mvn --batch-mode --update-snapshots verify --settings .maven-settings.xml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
12 changes: 12 additions & 0 deletions .maven-settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>github</id>
<username>${env.GITHUB_ACTOR}</username>
<password>${env.GITHUB_TOKEN}</password>
</server>
</servers>
</settings>
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* @(#)AbstractUndoRedoAction.java
*
* Copyright (c) 1996-2010 The authors and contributors of JHotDraw.
* You may not use, copy or modify this file, except in compliance with the
* accompanying license terms.
*/
package org.jhotdraw.action.edit;

import java.awt.event.*;
import java.beans.*;
import javax.swing.*;
import org.jhotdraw.action.AbstractViewAction;
import org.jhotdraw.api.app.Application;
import org.jhotdraw.api.app.View;
import org.jhotdraw.util.ResourceBundleUtil;

/**
* Abstract base for {@link UndoAction} and {@link RedoAction}.
* <p>
* Both actions share identical listener management, enabled-state tracking,
* and delegation logic. The only variation is the action ID, supplied by
* subclasses via {@link #getActionId()}.
*/
abstract class AbstractUndoRedoAction extends AbstractViewAction {

private static final long serialVersionUID = 1L;
protected final ResourceBundleUtil labels =
ResourceBundleUtil.getBundle("org.jhotdraw.action.Labels");

private final PropertyChangeListener actionPropertyListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
String name = evt.getPropertyName();
if ((name == null && AbstractAction.NAME == null)
|| (name != null && name.equals(AbstractAction.NAME))) {
putValue(AbstractAction.NAME, evt.getNewValue());
} else if ("enabled".equals(name)) {
updateEnabledState();
}
}
};

public AbstractUndoRedoAction(Application app, View view) {
super(app, view);
}

/**
* Returns the action map key that identifies this action within a view
* (e.g. {@code "edit.undo"} or {@code "edit.redo"}).
*/
protected abstract String getActionId();

protected void updateEnabledState() {
Action realAction = getRealAction();
setEnabled(realAction != null && realAction != this && realAction.isEnabled());
}

@Override
protected void updateView(View oldValue, View newValue) {
super.updateView(oldValue, newValue);
if (newValue != null
&& newValue.getActionMap().get(getActionId()) != null
&& newValue.getActionMap().get(getActionId()) != this) {
putValue(AbstractAction.NAME,
newValue.getActionMap().get(getActionId()).getValue(AbstractAction.NAME));
updateEnabledState();
}
}

@Override
protected void installViewListeners(View p) {
super.installViewListeners(p);
Action actionInView = p.getActionMap().get(getActionId());
if (actionInView != null && actionInView != this) {
actionInView.addPropertyChangeListener(actionPropertyListener);
}
}

@Override
protected void uninstallViewListeners(View p) {
super.uninstallViewListeners(p);
Action actionInView = p.getActionMap().get(getActionId());
if (actionInView != null && actionInView != this) {
actionInView.removePropertyChangeListener(actionPropertyListener);
}
}

@Override
public void actionPerformed(ActionEvent e) {
Action realAction = getRealAction();
if (realAction != null && realAction != this) {
realAction.actionPerformed(e);
}
}

private Action getRealAction() {
return (getActiveView() == null) ? null : getActiveView().getActionMap().get(getActionId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,110 +7,37 @@
*/
package org.jhotdraw.action.edit;

import java.awt.event.*;
import java.beans.*;
import javax.swing.*;
import org.jhotdraw.action.AbstractViewAction;
import org.jhotdraw.api.app.Application;
import org.jhotdraw.api.app.View;
import org.jhotdraw.util.*;

/**
* Redoes the last user action on the active view.
* <p>
* This action requires that the View returns a project
* specific redo action when invoking getActionMap("redo") on a View.
* This action requires that the View returns a project specific redo action
* when invoking getActionMap("edit.redo") on a View.
* <p>
* This action is called when the user selects the Redo item in the Edit
* menu. The menu item is automatically created by the application.
* This action is called when the user selects the Redo item in the Edit menu.
* The menu item is automatically created by the application.
* <p>
* If you want this behavior in your application, you have to create an action
* with this ID and put it in your {@code ApplicationModel} in method
* {@link org.jhotdraw.app.ApplicationModel#initApplication}.
*
*
* @author Werner Randelshofer
* @version $Id$
*/
public class RedoAction extends AbstractViewAction {
public class RedoAction extends AbstractUndoRedoAction {

private static final long serialVersionUID = 1L;
public static final String ID = "edit.redo";
private ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.action.Labels");
private PropertyChangeListener redoActionPropertyListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
String name = evt.getPropertyName();
if ((name == null && AbstractAction.NAME == null) || (name != null && name.equals(AbstractAction.NAME))) {
putValue(AbstractAction.NAME, evt.getNewValue());
} else if ("enabled".equals(name)) {
updateEnabledState();
}
}
};

/**
* Creates a new instance.
*/
public RedoAction(Application app, View view) {
super(app, view);
labels.configureAction(this, ID);
}

protected void updateEnabledState() {
boolean isEnabled = false;
Action realRedoAction = getRealRedoAction();
if (realRedoAction != null && realRedoAction != this) {
isEnabled = realRedoAction.isEnabled();
}
setEnabled(isEnabled);
}

@Override
protected void updateView(View oldValue, View newValue) {
super.updateView(oldValue, newValue);
if (newValue != null
&& newValue.getActionMap().get(ID) != null
&& newValue.getActionMap().get(ID) != this) {
putValue(AbstractAction.NAME, newValue.getActionMap().get(ID).
getValue(AbstractAction.NAME));
updateEnabledState();
}
}

/**
* Installs listeners on the view object.
*/
@Override
protected void installViewListeners(View p) {
super.installViewListeners(p);
Action redoActionInView = p.getActionMap().get(ID);
if (redoActionInView != null && redoActionInView != this) {
redoActionInView.addPropertyChangeListener(redoActionPropertyListener);
}
}

/**
* Installs listeners on the view object.
*/
@Override
protected void uninstallViewListeners(View p) {
super.uninstallViewListeners(p);
Action redoActionInView = p.getActionMap().get(ID);
if (redoActionInView != null && redoActionInView != this) {
redoActionInView.removePropertyChangeListener(redoActionPropertyListener);
}
}

@Override
public void actionPerformed(ActionEvent e) {
Action realAction = getRealRedoAction();
if (realAction != null && realAction != this) {
realAction.actionPerformed(e);
}
}

private Action getRealRedoAction() {
return (getActiveView() == null) ? null : getActiveView().getActionMap().get(ID);
protected String getActionId() {
return ID;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,17 @@
*/
package org.jhotdraw.action.edit;

import java.awt.event.*;
import java.beans.*;
import javax.swing.*;
import org.jhotdraw.action.AbstractViewAction;
import org.jhotdraw.api.app.Application;
import org.jhotdraw.api.app.View;
import org.jhotdraw.util.*;

/**
* Undoes the last user action.
* <p>
* This action requires that the View returns a project
* specific undo action when invoking getActionMap("redo") on a View.
* This action requires that the View returns a project specific undo action
* when invoking getActionMap("edit.undo") on a View.
* <p>
* This action is called when the user selects the Undo item in the Edit
* menu. The menu item is automatically created by the application.
* This action is called when the user selects the Undo item in the Edit menu.
* The menu item is automatically created by the application.
* <p>
* If you want this behavior in your application, you have to create an action
* with this ID and put it in your {@code ApplicationModel} in method
Expand All @@ -31,85 +26,18 @@
* @author Werner Randelshofer
* @version $Id$
*/
public class UndoAction extends AbstractViewAction {
public class UndoAction extends AbstractUndoRedoAction {

private static final long serialVersionUID = 1L;
public static final String ID = "edit.undo";
private ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.action.Labels");
private PropertyChangeListener redoActionPropertyListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
String name = evt.getPropertyName();
if ((name == null && AbstractAction.NAME == null) || (name != null && name.equals(AbstractAction.NAME))) {
putValue(AbstractAction.NAME, evt.getNewValue());
} else if ("enabled".equals(name)) {
updateEnabledState();
}
}
};

/**
* Creates a new instance.
*/
public UndoAction(Application app, View view) {
super(app, view);
labels.configureAction(this, ID);
}

protected void updateEnabledState() {
boolean isEnabled = false;
Action realAction = getRealUndoAction();
if (realAction != null && realAction != this) {
isEnabled = realAction.isEnabled();
}
setEnabled(isEnabled);
}

@Override
protected void updateView(View oldValue, View newValue) {
super.updateView(oldValue, newValue);
if (newValue != null
&& newValue.getActionMap().get(ID) != null
&& newValue.getActionMap().get(ID) != this) {
putValue(AbstractAction.NAME, newValue.getActionMap().get(ID).
getValue(AbstractAction.NAME));
updateEnabledState();
}
}

/**
* Installs listeners on the view object.
*/
@Override
protected void installViewListeners(View p) {
super.installViewListeners(p);
Action undoActionInView = p.getActionMap().get(ID);
if (undoActionInView != null && undoActionInView != this) {
undoActionInView.addPropertyChangeListener(redoActionPropertyListener);
}
}

/**
* Installs listeners on the view object.
*/
@Override
protected void uninstallViewListeners(View p) {
super.uninstallViewListeners(p);
Action undoActionInView = p.getActionMap().get(ID);
if (undoActionInView != null && undoActionInView != this) {
undoActionInView.removePropertyChangeListener(redoActionPropertyListener);
}
}

@Override
public void actionPerformed(ActionEvent e) {
Action realUndoAction = getRealUndoAction();
if (realUndoAction != null && realUndoAction != this) {
realUndoAction.actionPerformed(e);
}
}

private Action getRealUndoAction() {
return (getActiveView() == null) ? null : getActiveView().getActionMap().get(ID);
protected String getActionId() {
return ID;
}
}
Loading