Search in sources :

Example 6 with RcvrClipboardException

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;
        }
    };
}
Also used : ObjectSaver(edu.cmu.cs.hcii.cogtool.util.ObjectSaver) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) RcvrOutOfMemoryException(edu.cmu.cs.hcii.cogtool.util.RcvrOutOfMemoryException) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskSelectionState(edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState) RcvrClipboardException(edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException)

Example 7 with RcvrClipboardException

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;
        }
    };
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame) InputDevice(edu.cmu.cs.hcii.cogtool.model.InputDevice) AListenerAction(edu.cmu.cs.hcii.cogtool.util.AListenerAction) RcvrClipboardException(edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) IOException(java.io.IOException) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) SAXException(org.xml.sax.SAXException) DeviceType(edu.cmu.cs.hcii.cogtool.model.DeviceType) ClipboardUtil(edu.cmu.cs.hcii.cogtool.util.ClipboardUtil) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) Transition(edu.cmu.cs.hcii.cogtool.model.Transition) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 8 with RcvrClipboardException

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;
        }
    };
}
Also used : ClipboardUtil(edu.cmu.cs.hcii.cogtool.util.ClipboardUtil) AListenerAction(edu.cmu.cs.hcii.cogtool.util.AListenerAction) RcvrClipboardException(edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) SAXException(org.xml.sax.SAXException)

Example 9 with RcvrClipboardException

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;
        }
    };
}
Also used : Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) ObjectSaver(edu.cmu.cs.hcii.cogtool.util.ObjectSaver) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) RcvrOutOfMemoryException(edu.cmu.cs.hcii.cogtool.util.RcvrOutOfMemoryException) RcvrClipboardException(edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) DesignSelectionState(edu.cmu.cs.hcii.cogtool.ui.DesignSelectionState)

Example 10 with RcvrClipboardException

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);
    }
}
Also used : RcvrOutOfMemoryException(edu.cmu.cs.hcii.cogtool.util.RcvrOutOfMemoryException) CogToolClipboard(edu.cmu.cs.hcii.cogtool.CogToolClipboard) RcvrClipboardException(edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) IOException(java.io.IOException) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget)

Aggregations

RcvrClipboardException (edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException)11 IOException (java.io.IOException)11 RcvrIOException (edu.cmu.cs.hcii.cogtool.util.RcvrIOException)9 RcvrOutOfMemoryException (edu.cmu.cs.hcii.cogtool.util.RcvrOutOfMemoryException)6 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)5 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)5 ObjectSaver (edu.cmu.cs.hcii.cogtool.util.ObjectSaver)5 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)4 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)4 Design (edu.cmu.cs.hcii.cogtool.model.Design)3 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)3 ClipboardUtil (edu.cmu.cs.hcii.cogtool.util.ClipboardUtil)3 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 SAXException (org.xml.sax.SAXException)3 CogToolClipboard (edu.cmu.cs.hcii.cogtool.CogToolClipboard)2 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)2 DesignSelectionState (edu.cmu.cs.hcii.cogtool.ui.DesignSelectionState)2 TaskSelectionState (edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState)2 AListenerAction (edu.cmu.cs.hcii.cogtool.util.AListenerAction)2