Skip to content

Commit

Permalink
Make monitors delegate to SWTMonitor when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
gabegorelick committed Apr 17, 2011
1 parent 8955e23 commit aecf9b4
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 32 deletions.
46 changes: 46 additions & 0 deletions src/edu/umd/cs/guitar/ripper/SWTMonitor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package edu.umd.cs.guitar.ripper;

import edu.umd.cs.guitar.event.EventManager;
import edu.umd.cs.guitar.event.GEvent;
import edu.umd.cs.guitar.model.SWTApplication;
import edu.umd.cs.guitar.model.SWTConstants;
import edu.umd.cs.guitar.util.GUITARLog;

/**
* Contains actions common to {@link SWTRipperMonitor} and
* {@link SWTReplayerMonitor}.
*
* @author Gabe Gorelick
*/
public class SWTMonitor {

private final SWTApplication application;

public SWTMonitor(SWTGuitarConfiguration config, SWTApplication app) {
this.application = app;
}

public void cleanUp() {
application.getDisplay().syncExec(new Runnable() {
@Override
public void run() {
application.getDisplay().dispose();
}
});
GUITARLog.log.info("Display disposed");
}

/**
* Register the default supported events.
*
* @see EventManager
* @see SWTConstants#DEFAULT_SUPPORTED_EVENTS
*/
public void registerEvents() {
EventManager em = EventManager.getInstance();

for (Class<? extends GEvent> event : SWTConstants.DEFAULT_SUPPORTED_EVENTS) {
em.registerEvent(event);
}
}
}
52 changes: 20 additions & 32 deletions src/edu/umd/cs/guitar/ripper/SWTRipperMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,20 @@
import edu.umd.cs.guitar.util.GUITARLog;

/**
* Monitor for {@link SWTRipper} to handle SWT specific features. Adapted from
* <code>JFCRipperMonitor</code>.
*
* Monitor for the ripper to handle SWT specific features
*
* @see GRipperMonitor
*
* @author Gabe Gorelick
* @author <a href="mailto:[email protected]"> Matt Kirn </a>
* @author <a href="mailto:[email protected]"> Alex Loeb </a>
*/
public class SWTRipperMonitor extends GRipperMonitor {

private SWTApplication application;
private SWTRipperConfiguration configuration;
private final SWTApplication application;
private final SWTRipperConfiguration configuration;

// monitor to delegate actions shared with replayer to
private final SWTMonitor monitor;

private List<String> sRootWindows = new ArrayList<String>();

Expand All @@ -58,19 +60,20 @@ public class SWTRipperMonitor extends GRipperMonitor {
/**
* Constructor
*
* @param configuration
* @param config
* ripper configuration
* @param app
*/
public SWTRipperMonitor(SWTRipperConfiguration configuration, SWTApplication app) {
public SWTRipperMonitor(SWTRipperConfiguration config, SWTApplication app) {
super();

if (configuration == null) {
configuration = new SWTRipperConfiguration();
if (config == null) {
config = new SWTRipperConfiguration();
}

this.configuration = configuration;
this.configuration = config;
this.application = app;
this.monitor = new SWTMonitor(configuration, app);

// don't store application.getDisplay because it's still null at this point
}
Expand Down Expand Up @@ -119,23 +122,15 @@ public void run() {
@Override
public void setUp() {

// Registering default supported events

monitor.registerEvents();
EventManager em = EventManager.getInstance();

for (Class<? extends GEvent> event : SWTConstants.DEFAULT_SUPPORTED_EVENTS) {
em.registerEvent(event);
}

// Registering customized supported event
// Class<? extends GEvent> gCustomizedEvents;

String[] sCustomizedEventList;
if (configuration.getCustomizedEventList() != null)
String[] sCustomizedEventList = new String[0];
if (configuration.getCustomizedEventList() != null) {
sCustomizedEventList = configuration.getCustomizedEventList()
.split(GUITARConstants.CMD_ARGUMENT_SEPARATOR);
else
sCustomizedEventList = new String[0];
}

for (String sEvent : sCustomizedEventList) {
try {
Expand All @@ -145,7 +140,6 @@ public void setUp() {
} catch (ClassNotFoundException e) {
GUITARLog.log.error(e);
}

}

// Set up parameters
Expand All @@ -157,13 +151,7 @@ public void setUp() {

@Override
public void cleanUp() {
application.getDisplay().syncExec(new Runnable() {
@Override
public void run() {
application.getDisplay().dispose();
}
});
GUITARLog.log.info("Display disposed");
monitor.cleanUp();
}

@Override
Expand Down

0 comments on commit aecf9b4

Please sign in to comment.