use of edu.cmu.cs.hcii.cogtool.util.IListenerAction in project cogtool by cogtool.
the class ProjectController method createSetBackgroundComputeAction.
protected IListenerAction createSetBackgroundComputeAction(final Boolean bkg, final ProjectLID lid, final String actionName) {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectSelectionState.class;
}
public boolean performAction(Object actionParms) {
ProjectSelectionState selState = (ProjectSelectionState) actionParms;
Design design = selState.getSelectedDesign();
AUndertaking[] tasks = selState.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
// iterate through tasks and get set of TaskApplications
final TaskApplication[] taskApps = new TaskApplication[tasks.length];
final Boolean[] oldBkgSettings = new Boolean[tasks.length];
DemoStateManager demoMgr = DemoStateManager.getStateManager(project, design);
for (int i = 0; i < tasks.length; i++) {
// Make sure that the task application exists, and create it
// if it does not. No need to ensure a script.
TaskApplication ta = ensureTaskApplication(tasks[i], design, null, demoMgr);
taskApps[i] = ta;
oldBkgSettings[i] = ta.getComputeInBackground();
// now set the compute in background flag
ta.setComputeInBackground(bkg);
}
undoMgr.addEdit(new AUndoableEdit(lid) {
@Override
public String getPresentationName() {
return actionName;
}
@Override
public void redo() {
super.redo();
for (TaskApplication taskApp : taskApps) {
taskApp.setComputeInBackground(bkg);
}
}
@Override
public void undo() {
super.undo();
for (int i = 0; i < taskApps.length; i++) {
taskApps[i].setComputeInBackground(oldBkgSettings[i]);
}
}
});
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.IListenerAction in project cogtool by cogtool.
the class FrameEditorController method createUngroupElementsAction.
private IListenerAction createUngroupElementsAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return FrameEditorSelectionState.class;
}
public boolean performAction(Object prms) {
FrameEditorSelectionState selection = (FrameEditorSelectionState) prms;
Iterator<FrameElement> selectedElts = selection.getSelectedElementsIterator();
final Set<FrameElementGroup> selectedGroups = new HashSet<FrameElementGroup>();
while (selectedElts.hasNext()) {
FrameElement elt = selectedElts.next();
if (elt instanceof FrameElementGroup) {
selectedGroups.add((FrameElementGroup) elt);
} else {
selectedGroups.addAll(elt.getRootElement().getEltGroups());
}
}
if (selectedGroups.size() > 0) {
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(UNGROUP_ELEMENTS, FrameEditorLID.Ungroup);
Iterator<FrameElementGroup> groups = selectedGroups.iterator();
while (groups.hasNext()) {
FrameElementGroup group = groups.next();
ungroup(group, editSequence);
removeRootElement(UNGROUP_ELEMENTS, group, null, editSequence);
}
IUndoableEdit edit = new AUndoableEdit(FrameEditorLID.Ungroup) {
@Override
public String getPresentationName() {
return UNGROUP_ELEMENTS;
}
@Override
public void redo() {
super.redo();
Iterator<FrameElementGroup> groups = selectedGroups.iterator();
while (groups.hasNext()) {
FrameElementGroup group = groups.next();
ungroup(group, null);
}
}
@Override
public void undo() {
super.undo();
Iterator<FrameElementGroup> groups = selectedGroups.iterator();
while (groups.hasNext()) {
FrameElementGroup group = groups.next();
regroup(group);
}
}
};
editSequence.addEdit(edit);
// Commit the edit
editSequence.end();
// Only add this edit if it is significant
if (editSequence.isSignificant()) {
undoMgr.addEdit(editSequence);
}
return true;
}
interaction.protestNoSelection();
return false;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.IListenerAction in project cogtool by cogtool.
the class FrameEditorController method createChangeShapeAction.
/**
* Create a listener for changing the shape of a widget.
*
* @return
*/
private IListenerAction createChangeShapeAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return FrameEditorUI.ShapeChangeParameters.class;
}
public boolean performAction(Object prms) {
// Get the parameters to change the shape into
final FrameEditorUI.ShapeChangeParameters p = (FrameEditorUI.ShapeChangeParameters) prms;
Iterator<IWidget> selected = p.selection.getSelectedWidgetsIterator();
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(CHG_WIDGET_SHAPE, FrameEditorLID.ChangeShapeProperty);
// Loop through all selected widgets.
while (selected.hasNext()) {
final IWidget w = selected.next();
final ShapeType oldShapeType = w.getShape().getShapeType();
final ShapeType newShapeType = p.newShapeType;
// Don't make a non-changing edit!
if (!oldShapeType.equals(newShapeType)) {
w.setShapeType(newShapeType);
DemoStateManager.ObsoletingEdit edit = new DemoStateManager.ObsoletingEdit(FrameEditorLID.ChangeShapeProperty, demoStateMgr) {
@Override
public String getPresentationName() {
return CHG_WIDGET_SHAPE;
}
@Override
public void redo() {
super.redo();
w.setShapeType(p.newShapeType);
noteEditCheckRegenerate(w, this);
}
@Override
public void undo() {
super.undo();
w.setShapeType(oldShapeType);
noteEditCheckRegenerate(w, this);
}
};
noteEditCheckRegenerate(w, edit);
editSequence.addEdit(edit);
}
}
editSequence.end();
// Don't add empty edits!
if (editSequence.isSignificant()) {
undoMgr.addEdit(editSequence);
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.IListenerAction in project cogtool by cogtool.
the class ProjectController method createImportWebCrawlAction.
protected IListenerAction createImportWebCrawlAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return DesignSelectionState.class;
}
public boolean performAction(Object prms) {
DesignSelectionState selection = (DesignSelectionState) prms;
ProjectInteraction.IWebCrawlImport importParms = interaction.requestWebCrawlParms(project, WebCrawler.DEFAULT_MAX_TO_CRAWL);
if (importParms != null) {
String designName = importParms.getDesignName();
Design design;
if (designName == null) {
ProjectInteraction.DesignRequestData requestData = requestNewDesignParms(false);
if (requestData == null) {
// canceled!
return false;
}
design = new Design(requestData.designName, requestData.deviceTypes);
} else {
design = project.getDesign(designName);
}
int defaultDepth = importParms.getDefaultDepth();
List<URLCrawlEntry> urls = importParms.getURLsToCrawl();
if ((urls == null) || (urls.size() == 0)) {
interaction.reportProblem(ImportWebCrawlThread.IMPORT_WEB_CRAWL, noURLsToCrawlError);
return false;
}
// If new, indicate that the work thread should add the
// new design to the project when it completes;
// -1 indicates that the design is *not* new.
int beforeIndex = ImportWebCrawlThread.EXISTING_DESIGN;
if (designName == null) {
Design selectedDesign = selection.getSelectedDesign();
beforeIndex = (selectedDesign != null) ? (project.getDesigns().indexOf(selectedDesign) + 1) : project.getDesigns().size();
}
ImportWebCrawlThread workThread = new ImportWebCrawlThread(interaction, undoMgr, project, design, beforeIndex, importParms.getMaxPages(), defaultDepth, urls, importParms.pruneSameURLs(), importParms.getBrowserWidth(), importParms.getBrowserHeight(), importParms.captureImages());
ThreadManager.startNewThread(workThread);
return true;
}
return false;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.IListenerAction in project cogtool by cogtool.
the class ProjectController method createExportDesignToHTMLAction.
protected IListenerAction createExportDesignToHTMLAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectSelectionState.class;
}
public boolean performAction(Object actionParms) {
ProjectSelectionState selection = (ProjectSelectionState) actionParms;
Design d = selection.getSelectedDesign();
if (d == null) {
interaction.protestNoSelection();
return false;
}
return ExportToHTMLWorkThread.exportDesignToHTML(d, interaction);
}
};
}
Aggregations