use of edu.cmu.cs.hcii.cogtool.util.RcvrImageException in project cogtool by cogtool.
the class ProjectController method createImportAction.
protected IListenerAction createImportAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectSelectionState.class;
}
public boolean performAction(Object prms) {
boolean computeScripts = CogToolPref.COMPSCR.getBoolean();
if (importFile == null) {
importFile = interaction.selectXMLFile(true, null);
} else {
computeScripts = importFileComputes;
}
if (importFile == null) {
return false;
}
CompoundUndoableEdit editSeq = new CompoundUndoableEdit(importXMLPresentation, ProjectLID.ImportXML);
Map<Design, Collection<Demonstration>> parsedDesigns = null;
Set<AUndertaking> newUndertakings = null;
TaskParent parent = project;
try {
if (CogToolPref.HCIPA.getBoolean()) {
TaskGroup importGroup = new TaskGroup(importFile.getName(), GroupNature.SUM);
parent = importGroup;
project.addUndertaking(importGroup);
editSeq.addEdit(createNewTaskUndo(project, Project.AT_END, importGroup, ProjectLID.ImportXML, importXMLPresentation));
}
ImportCogToolXML importer = new ImportCogToolXML();
if (!importer.importXML(importFile, parent, MODELGEN_ALG) || (importer.getDesigns().size() == 0)) {
List<String> errors = importer.getObjectFailures();
if ((errors != null) && (errors.size() > 0)) {
interaction.reportProblems(importXMLPresentation, errors);
} else {
interaction.reportProblem(importXMLPresentation, xmlParseFailed);
}
return false;
}
List<String> warnings = importer.getGenerationWarnings();
if (warnings.size() > 0) {
interaction.reportWarnings(importXMLPresentation, warnings);
}
parsedDesigns = importer.getDesigns();
newUndertakings = importer.getNewUndertakings();
} catch (ImportCogToolXML.ImportFailedException ex) {
throw new RcvrXMLParsingException("Missing XML component", ex);
} catch (GraphicsUtil.ImageException ex) {
throw new RcvrImageException("Image error during loading XML", ex);
} catch (IOException ex) {
throw new RcvrXMLParsingException("IO error loading XML", ex);
} catch (SAXException ex) {
throw new RcvrXMLParsingException("Error parsing XML", ex);
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
importFile = null;
importFileComputes = false;
}
for (AUndertaking u : newUndertakings) {
parent.addUndertaking(u);
final AUndertaking uu = u;
final TaskParent pp = parent;
editSeq.addEdit(new AUndoableEdit(ProjectLID.ImportXML) {
@Override
public void redo() {
super.redo();
pp.addUndertaking(uu);
}
@Override
public void undo() {
super.undo();
pp.removeUndertaking(uu);
}
});
}
Iterator<Map.Entry<Design, Collection<Demonstration>>> designDemos = parsedDesigns.entrySet().iterator();
while (designDemos.hasNext()) {
Map.Entry<Design, Collection<Demonstration>> entry = designDemos.next();
importDesign(parent, (DesignSelectionState) prms, entry.getKey(), entry.getValue(), newUndertakings, editSeq);
}
editSeq.end();
undoMgr.addEdit(editSeq);
if (computeScripts) {
//compute predictions for imported project
ProjectContextSelectionState seln = new ProjectContextSelectionState(project);
seln.addSelectedDesigns(project.getDesigns());
ui.selectAllTasks();
recomputeScripts(seln);
ui.deselectAllTasks();
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.RcvrImageException in project cogtool by cogtool.
the class FrameEditorController method setBackgroundImage.
/**
* Sets the background image for the frame
*
* @param imageData the new image, or null if none
*/
private void setBackgroundImage(final byte[] imageData, final String imagePath) {
try {
// compute the size of the new image.
final DoubleRectangle imageSize = GraphicsUtil.getImageBounds(imageData);
// Get existing image
final byte[] previousImageData = model.getBackgroundImage();
final DoubleRectangle previmageSize = model.getBackgroundBounds();
final String oldPath = (String) model.getAttribute(WidgetAttributes.IMAGE_PATH_ATTR);
// Perform operation
model.setBackgroundImage(imageData, imageSize);
model.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, imagePath);
CogToolLID lid = (imageData == null) ? FrameEditorLID.RemoveBackgroundImage : FrameEditorLID.SetBackgroundImage;
// Add the undo edit
IUndoableEdit edit = new AUndoableEdit(lid) {
@Override
public String getPresentationName() {
return (imageData == null) ? REMOVE_BKG_IMG : SET_BKG_IMG;
}
@Override
public void redo() {
super.redo();
try {
model.setBackgroundImage(imageData, imageSize);
model.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, imagePath);
} catch (GraphicsUtil.ImageException ex) {
throw new RcvrImageException("Redo set background image failed", ex);
}
}
@Override
public void undo() {
super.undo();
try {
model.setBackgroundImage(previousImageData, previmageSize);
model.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, oldPath);
} catch (GraphicsUtil.ImageException ex) {
throw new RcvrImageException("Undo set background image failed", ex);
}
}
};
undoMgr.addEdit(edit);
} catch (GraphicsUtil.ImageException e) {
interaction.protestInvalidImageFile();
}
}
Aggregations