use of edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException in project cogtool by cogtool.
the class ProjectController method createCutTaskAction.
// Action for CutTask
protected IListenerAction createCutTaskAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return TaskSelectionState.class;
}
public boolean performAction(Object prms) {
TaskSelectionState selection = (TaskSelectionState) prms;
AUndertaking[] selectedTasks = selection.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
// Can only cut if one or more tasks are currently selected.
if ((selectedTasks != null) && (selectedTasks.length > 0)) {
try {
ObjectSaver saver = CogToolClipboard.startClipboardSave(CogToolClipboard.CopyTasks, CogToolClipboard.SAVE_TO_CLIPBOARD);
deleteTasks(selectedTasks, saver, undoMgr);
// flush!
saver.finish();
return true;
} catch (IOException e) {
throw new RcvrClipboardException("Could not execute cut", e);
} catch (OutOfMemoryError error) {
throw new RcvrOutOfMemoryException("Cutting Tasks", error);
}
} else {
interaction.protestNoSelection();
}
return false;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException in project cogtool by cogtool.
the class DesignEditorController method createPasteAction.
protected IListenerAction createPasteAction() {
return new AListenerAction() {
public boolean performAction(Object prms) {
try {
Collection<Object> objects = CogToolClipboard.fetchCogToolObjects();
if ((objects != null) && (objects.size() > 0)) {
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(L10N.get("UNDO.Paste", "Paste"), DesignEditorLID.Paste);
Set<DeviceType> devTypes = design.getDeviceTypes();
int numPasted = 0;
Iterator<Object> objIt = objects.iterator();
while (objIt.hasNext()) {
Object o = objIt.next();
if (o instanceof Frame) {
Frame frame = (Frame) o;
makeFrameNameUnique(frame);
// Find an unoccupied starting position
// by cascading.
DoublePoint origin = frame.getFrameOrigin();
DesignUtil.findDistinctOrigin(design, origin, 16.0, 16.0);
// Union devices
Iterator<InputDevice> frameDevices = frame.getInputDevices().iterator();
while (frameDevices.hasNext()) {
InputDevice inputDevice = frameDevices.next();
DeviceType devType = inputDevice.getDeviceType();
if (!devTypes.contains(devType)) {
DesignCmd.addDevice(design, devType);
}
}
Iterator<DeviceType> designDevTypes = devTypes.iterator();
while (designDevTypes.hasNext()) {
DeviceType devType = designDevTypes.next();
if (frame.getInputDevice(devType) == null) {
frame.addInputDevice(devType);
}
}
addFrame(frame, editSequence);
numPasted++;
} else if (o instanceof Transition) {
Transition t = (Transition) o;
DeviceType device = t.getAction().getDefaultDeviceType();
if (!devTypes.contains(device)) {
DesignCmd.addDevice(design, device);
}
IUndoableEdit edit = DesignEditorCmd.addTransition(demoStateMgr, t);
editSequence.addEdit(edit);
numPasted++;
}
}
editSequence.end();
undoMgr.addEdit(editSequence);
interaction.setStatusMessage(numPasted + " " + pasteComplete);
} else {
interaction.setStatusMessage(nothingPasted);
}
} catch (IOException e) {
throw new RcvrClipboardException(e);
} catch (ParserConfigurationException e) {
throw new RcvrClipboardException(e);
} catch (SAXException e) {
throw new RcvrClipboardException(e);
} catch (ClipboardUtil.ClipboardException e) {
throw new RcvrClipboardException(e);
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException in project cogtool by cogtool.
the class FrameEditorController method createPasteAction.
// createSetFrameTemplateAction
/**
* The paste action for inserting copied information.
* Currently no checks are made to ensure that the paste is valid XML.
* @return
*/
private IListenerAction createPasteAction() {
return new AListenerAction() {
public boolean performAction(Object prms) {
try {
if (CogToolClipboard.hasCogToolObjects()) {
// Get the XML text from the clipboard
Collection<Object> objects = CogToolClipboard.fetchCogToolObjects();
if ((objects != null) && (objects.size() > 0)) {
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(PASTE, FrameEditorLID.Paste);
int numPasted = DesignEditorCmd.pasteElements(design, model, objects, demoStateMgr, editSequence);
if (numPasted > 0) {
editSequence.end();
undoMgr.addEdit(editSequence);
interaction.setStatusMessage(numPasted + " " + pasteComplete);
} else {
interaction.setStatusMessage(nothingPasted);
}
}
return true;
} else {
interaction.setStatusMessage(nothingPasted);
}
} catch (IOException e) {
throw new RcvrClipboardException(e);
} catch (ParserConfigurationException e) {
throw new RcvrClipboardException(e);
} catch (SAXException e) {
throw new RcvrClipboardException(e);
} catch (ClipboardUtil.ClipboardException e) {
throw new RcvrClipboardException(e);
}
return false;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException in project cogtool by cogtool.
the class ProjectController method createCopyDesignAction.
// Action for CopyDesign
protected IListenerAction createCopyDesignAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return DesignSelectionState.class;
}
public boolean performAction(Object prms) {
DesignSelectionState seln = (DesignSelectionState) prms;
Design design = seln.getSelectedDesign();
// Can only copy if a design is currently selected.
if (design != null) {
try {
ObjectSaver s = CogToolClipboard.startClipboardDesignSave(project, CogToolClipboard.SAVE_TO_CLIPBOARD);
saveDesignToClipboard(design, s);
s.finish();
interaction.setStatusMessage(DESIGN_COPIED);
return true;
} catch (IOException e) {
throw new RcvrClipboardException(e);
} catch (OutOfMemoryError error) {
throw new RcvrOutOfMemoryException("Copying Design", error);
}
} else {
interaction.protestNoSelection();
}
return false;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException in project cogtool by cogtool.
the class DesignEditorCmd method copyElements.
public static void copyElements(Design design, FrameElement[] selectedElts, Iterator<FrameElement> eltsToCopy, boolean saveToClipboard) {
try {
// Set up a clipboard saver. Indicate that no transitions
// should be copied.
CogToolClipboard.ClipboardClassSaver s = CogToolClipboard.startClipboardSave(CogToolClipboard.CopyWidgets, selectedElts, saveToClipboard);
// Iterate through the widgets and save the selected items.
while (eltsToCopy.hasNext()) {
FrameElement elt = eltsToCopy.next();
// get pasted.
if (!(elt instanceof ChildWidget)) {
s.saveObject(elt);
}
}
s.finish();
if (!saveToClipboard) {
FrameTemplateSupport.setFrameTemplate(design, s.getSavedString());
}
} catch (IOException e) {
throw new RcvrClipboardException(e);
} catch (OutOfMemoryError error) {
throw new RcvrOutOfMemoryException("Copying Widgets", error);
}
}
Aggregations