Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project Ported to Maven #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
9 changes: 4 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
classes
javadoc
*.jar
*.zip
bin
target
.project
.classpath
.settings

78 changes: 0 additions & 78 deletions build.xml

This file was deleted.

21 changes: 21 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>

<groupId>br.com.ingenieux.towel</groupId>
<artifactId>towel</artifactId>
<version>1.2.3-SNAPSHOT</version>
<name>towel</name>
<url>https://github.com/MarkyVasconcelos/Towel</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.swinglabs</groupId>
<artifactId>swing-layout</artifactId>
<version>1.0.3</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.towel.awt;
/**
* Defines what the {@link ActionManager} must to do when the associated
* AbstractButton has been pressed.
*
* @author Marcos A. Vasconcelos Junior
* @deprecated Replaced by annotation {@link com.towel.awt.ann.Action}.
*/
@Deprecated
public interface Action {
/**
* Code to execute when the associated button has been pressed.
*/
public void doAction();
}
package com.towel.awt;

/**
* Defines what the {@link ActionManager} must to do when the associated
* AbstractButton has been pressed.
*
* @author Marcos A. Vasconcelos Junior
* @deprecated Replaced by annotation {@link com.towel.awt.ann.Action}.
*/
@Deprecated
public interface Action {
/**
* Code to execute when the associated button has been pressed.
*/
public void doAction();
}
Original file line number Diff line number Diff line change
@@ -1,119 +1,119 @@
package com.towel.awt;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.swing.AbstractButton;
/**
* Manager that maps an {@link ActionListener} to a button.
*
* @author Marcos A. Vasconcelos Junior
*/
public class ActionListenerManager implements ActionListener {
private List<ActionListener> before, after;
private Map<AbstractButton, ActionListener> map;
/**
* Creates a new <code>ActionListenerManager</code>.
*/
public ActionListenerManager() {
map = new HashMap<AbstractButton, ActionListener>();
before = new ArrayList<ActionListener>();
after = new ArrayList<ActionListener>();
}
/**
* Associates a button with an <code>ActionListener</code>, that will have
* its {@link ActionListener#actionPerformed(ActionEvent) actionPerformed}
* method called when the button has been pressed.
*
* @param source
* the button
* @param action
* the listener that will be called
*/
public void manage(AbstractButton source, ActionListener action) {
map.put(source, action);
source.addActionListener(this);
}
/**
* Adds a new <code>ActionListener</code> that will be called when any
* mapped button is pressed. That <code>ActionListener</code>s will be
* called before the specific button's action.
*
* The <code>ActionListener</code>s registered with this method are called
* even if the specific button <code>ActionListener</code> fails to execute.
*
* @param action
* the <code>ActionListener</code> that will be called
*/
public void doBefore(ActionListener action) {
before.add(action);
}
/**
* Adds a new <code>ActionListener</code> that will be called when any
* mapped button is pressed. That <code>ActionListener</code>s will be
* called after the specific button's action.
*
* The <code>ActionListener</code>s registered with this method are called
* even if the specific button <code>ActionListener</code> fails to execute.
*
* @param action
* the <code>ActionListener</code> that will be called
*/
public void doAfter(ActionListener action) {
after.add(action);
}
@Override
public void actionPerformed(ActionEvent arg0) {
for (ActionListener action : before) {
action.actionPerformed(arg0);
}
try {
map.get(arg0.getSource()).actionPerformed(arg0);
} catch (StopException e) {
e.getCause().printStackTrace();
}
for (ActionListener act : after) {
act.actionPerformed(arg0);
}
}
/**
* Exception to encapsulate checked exceptions when implementing method
* {@link Action#doAction()}.
*
* @author Marcos A. Vasconcelos Junior
*/
@SuppressWarnings("serial")
public static class StopException extends RuntimeException {
/**
* The real cause of this exception.
*/
public Exception cause;
/**
* Creates a new unchecked exception that encapsulates the given
* exception.
*
* @param cause
* the real cause
*/
public StopException(Exception cause) {
this.cause = cause;
}
@Override
public Exception getCause() {
return cause;
}
}
}
package com.towel.awt;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.swing.AbstractButton;

/**
* Manager that maps an {@link ActionListener} to a button.
*
* @author Marcos A. Vasconcelos Junior
*/
public class ActionListenerManager implements ActionListener {
private List<ActionListener> before, after;
private Map<AbstractButton, ActionListener> map;

/**
* Creates a new <code>ActionListenerManager</code>.
*/
public ActionListenerManager() {
map = new HashMap<AbstractButton, ActionListener>();
before = new ArrayList<ActionListener>();
after = new ArrayList<ActionListener>();
}

/**
* Associates a button with an <code>ActionListener</code>, that will have
* its {@link ActionListener#actionPerformed(ActionEvent) actionPerformed}
* method called when the button has been pressed.
*
* @param source
* the button
* @param action
* the listener that will be called
*/
public void manage(AbstractButton source, ActionListener action) {
map.put(source, action);
source.addActionListener(this);
}

/**
* Adds a new <code>ActionListener</code> that will be called when any
* mapped button is pressed. That <code>ActionListener</code>s will be
* called before the specific button's action.
*
* The <code>ActionListener</code>s registered with this method are called
* even if the specific button <code>ActionListener</code> fails to execute.
*
* @param action
* the <code>ActionListener</code> that will be called
*/
public void doBefore(ActionListener action) {
before.add(action);
}

/**
* Adds a new <code>ActionListener</code> that will be called when any
* mapped button is pressed. That <code>ActionListener</code>s will be
* called after the specific button's action.
*
* The <code>ActionListener</code>s registered with this method are called
* even if the specific button <code>ActionListener</code> fails to execute.
*
* @param action
* the <code>ActionListener</code> that will be called
*/
public void doAfter(ActionListener action) {
after.add(action);
}

@Override
public void actionPerformed(ActionEvent arg0) {
for (ActionListener action : before) {
action.actionPerformed(arg0);
}
try {
map.get(arg0.getSource()).actionPerformed(arg0);
} catch (StopException e) {
e.getCause().printStackTrace();
}
for (ActionListener act : after) {
act.actionPerformed(arg0);
}
}

/**
* Exception to encapsulate checked exceptions when implementing method
* {@link Action#doAction()}.
*
* @author Marcos A. Vasconcelos Junior
*/
@SuppressWarnings("serial")
public static class StopException extends RuntimeException {
/**
* The real cause of this exception.
*/
public Exception cause;

/**
* Creates a new unchecked exception that encapsulates the given
* exception.
*
* @param cause
* the real cause
*/
public StopException(Exception cause) {
this.cause = cause;
}

@Override
public Exception getCause() {
return cause;
}
}
}
Loading