Search in sources :

Example 81 with IListenerAction

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;
        }
    };
}
Also used : ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication)

Example 82 with IListenerAction

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;
        }
    };
}
Also used : IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) FrameEditorSelectionState(edu.cmu.cs.hcii.cogtool.ui.FrameEditorSelectionState) FrameElementGroup(edu.cmu.cs.hcii.cogtool.model.FrameElementGroup) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) HashSet(java.util.HashSet)

Example 83 with IListenerAction

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;
        }
    };
}
Also used : IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) ShapeType(edu.cmu.cs.hcii.cogtool.model.ShapeType) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) FrameEditorUI(edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 84 with IListenerAction

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;
        }
    };
}
Also used : Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) URLCrawlEntry(edu.cmu.cs.hcii.cogtool.model.URLCrawlEntry) ProjectInteraction(edu.cmu.cs.hcii.cogtool.ui.ProjectInteraction) DesignSelectionState(edu.cmu.cs.hcii.cogtool.ui.DesignSelectionState) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 85 with IListenerAction

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);
        }
    };
}
Also used : Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState)

Aggregations

IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)94 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)30 Design (edu.cmu.cs.hcii.cogtool.model.Design)29 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)29 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)23 ProjectSelectionState (edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState)23 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)21 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)19 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)17 IOException (java.io.IOException)14 RcvrIOException (edu.cmu.cs.hcii.cogtool.util.RcvrIOException)13 TaskSelectionState (edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState)12 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)10 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)10 DesignSelectionState (edu.cmu.cs.hcii.cogtool.ui.DesignSelectionState)10 FrameEditorSelectionState (edu.cmu.cs.hcii.cogtool.ui.FrameEditorSelectionState)9 FrameSelectionState (edu.cmu.cs.hcii.cogtool.ui.FrameSelectionState)9 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)8 FrameEditorUI (edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI)8 File (java.io.File)8