Search in sources :

Example 1 with AListenerAction

use of edu.cmu.cs.hcii.cogtool.util.AListenerAction in project cogtool by cogtool.

the class SEDemoController method createShowModelVisualizationAction.

protected IListenerAction createShowModelVisualizationAction() {
    return new AListenerAction() {

        public boolean performAction(Object prms) {
            CognitiveModelGenerator modelGen = script.getModelGenerator();
            IPredictionAlgo activeAlgo = taskApplication.determineActiveAlgorithm(project);
            if (taskApplication.getResult(modelGen, activeAlgo) != null) {
                PERTChartController c = PERTChartController.openController(taskApplication, modelGen, activeAlgo, project, -1, interaction);
                return (c != null);
            }
            return false;
        }
    };
}
Also used : IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) AListenerAction(edu.cmu.cs.hcii.cogtool.util.AListenerAction) CognitiveModelGenerator(edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator)

Example 2 with AListenerAction

use of edu.cmu.cs.hcii.cogtool.util.AListenerAction in project cogtool by cogtool.

the class Controller method createExitAction.

// The action for ExitApplication
protected IListenerAction createExitAction() {
    return new AListenerAction() {

        public boolean performAction(Object prms) {
            // Take advantage of dual policy implementation; by
            // temporarily ensuring that "project manages others", the user
            // is presented with a ProjectController when asked to save
            // each modified and unsaved project.
            boolean oldProjectManagesOthers = CogTool.projectManagesOthers;
            // Eliminate all windows where the associated
            // ProjectController still exists.
            CogTool.projectManagesOthers = true;
            Set<Project> projectSet = CogTool.controllerNexus.getControllerNexuses();
            Object[] projects = projectSet.toArray();
            for (Object project : projects) {
                Controller projectController = ControllerRegistry.ONLY.findOpenController(project);
                // was canceled.
                if ((projectController != null) && !projectController.requestClose()) {
                    // Restore the original policy
                    CogTool.projectManagesOthers = oldProjectManagesOthers;
                    return false;
                }
            }
            // Restore the original policy
            CogTool.projectManagesOthers = oldProjectManagesOthers;
            // Find remaining open windows that are not ProjectControllers;
            // Note we only get here if the current policy is that
            // "projects do NOT manage others"!
            projectSet = CogTool.controllerNexus.getControllerNexuses();
            projects = projectSet.toArray();
            // any modified but unsaved projects.
            for (Object project2 : projects) {
                Project project = (Project) project2;
                if (!CogTool.controllerNexus.closeControllers(project, true)) {
                    return false;
                }
            }
            // All the windows are closed (except possibly the "invisible"
            // root window when executing on a Mac); time to exit!
            System.exit(0);
            // Kind of superfluous (Java!)
            return true;
        }
    };
}
Also used : Project(edu.cmu.cs.hcii.cogtool.model.Project) AListenerAction(edu.cmu.cs.hcii.cogtool.util.AListenerAction)

Example 3 with AListenerAction

use of edu.cmu.cs.hcii.cogtool.util.AListenerAction in project cogtool by cogtool.

the class DefaultController method assignActions.

/**
     * Registers the set of <code>IListenerAction</code> instances
     * that implement the semantic actions that are possible.
     * <p>
     * For this class, this consists of the actions that all CogTool
     * model editing windows support.
     *
     * @author mlh
     */
@Override
protected void assignActions() {
    super.assignActions();
    UI ui = getUI();
    final Interaction interaction = getUI().getStandardInteraction();
    if (ui != null) {
        // Set "save as" action
        ui.setAction(CogToolLID.SaveProjectAs, new AListenerAction() {

            public boolean performAction(Object prms) {
                return saveAs();
            }
        });
        // Set "save" action
        ui.setAction(CogToolLID.SaveProject, new AListenerAction() {

            public boolean performAction(Object prms) {
                return forceSave();
            }
        });
        ui.setAction(CogToolLID.CloseWindow, createCloseWindowAction());
        ui.setAction(CogToolLID.CloseProject, new AListenerAction() {

            public boolean performAction(Object prms) {
                return closeProject(project, true);
            }
        });
        ui.setAction(CogToolLID.Properties, new AListenerAction() {

            public boolean performAction(Object prms) {
                return showProperties();
            }
        });
        ui.setAction(CogToolLID.SetAttribute, new IListenerAction() {

            public Class<?> getParameterClass() {
                return UI.SetAttributeParameters.class;
            }

            public boolean performAction(Object prms) {
                UI.SetAttributeParameters p = (UI.SetAttributeParameters) prms;
                return DefaultCmd.setAttribute(p.target, null, p.attrName, p.value, interaction, undoMgr);
            }
        });
    }
}
Also used : UI(edu.cmu.cs.hcii.cogtool.ui.UI) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) Interaction(edu.cmu.cs.hcii.cogtool.ui.Interaction) AListenerAction(edu.cmu.cs.hcii.cogtool.util.AListenerAction)

Example 4 with AListenerAction

use of edu.cmu.cs.hcii.cogtool.util.AListenerAction 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 5 with AListenerAction

use of edu.cmu.cs.hcii.cogtool.util.AListenerAction in project cogtool by cogtool.

the class DesignEditorController method createExportDesignToXMLAction.

protected IListenerAction createExportDesignToXMLAction() {
    return new AListenerAction() {

        public boolean performAction(Object actionParms) {
            String defaultFilename = design.getName() + ".xml";
            File exportFile = interaction.selectXMLFile(false, defaultFilename);
            if (exportFile == null) {
                return false;
            }
            OutputStream oStream = null;
            try {
                try {
                    oStream = new FileOutputStream(exportFile);
                    Writer xmlWriter = new BufferedWriter(new OutputStreamWriter(oStream, "UTF-8"));
                    Map<ITaskDesign, TaskApplication> designTAs = project.taskApplicationsForDesign(design);
                    ExportCogToolXML.exportXML(design, designTAs, xmlWriter, "UTF-8");
                    xmlWriter.flush();
                } finally {
                    if (oStream != null) {
                        oStream.close();
                    }
                }
            } catch (IllegalArgumentException e) {
                throw new RcvrIllegalStateException("Invalid argument exporting to XML", e);
            } catch (IllegalStateException e) {
                throw new RcvrIllegalStateException("Exporting to XML", e);
            } catch (IOException e) {
                throw new RcvrIOSaveException("Exporting to XML", e);
            } catch (Exception e) {
                throw new RecoverableException("Exporting to XML", e);
            }
            interaction.setStatusMessage(L10N.get("PC.DesignExportedToXML", "Design exported to XML:") + " " + exportFile.getName());
            return true;
        }
    };
}
Also used : RcvrIllegalStateException(edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) AListenerAction(edu.cmu.cs.hcii.cogtool.util.AListenerAction) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) IOException(java.io.IOException) RcvrIOSaveException(edu.cmu.cs.hcii.cogtool.util.RcvrIOSaveException) RcvrClipboardException(edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException) RcvrImageException(edu.cmu.cs.hcii.cogtool.util.RcvrImageException) RcvrOutOfMemoryException(edu.cmu.cs.hcii.cogtool.util.RcvrOutOfMemoryException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) SAXException(org.xml.sax.SAXException) RcvrIllegalStateException(edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException) RcvrUIException(edu.cmu.cs.hcii.cogtool.util.RcvrUIException) IOException(java.io.IOException) RecoverableException(edu.cmu.cs.hcii.cogtool.util.RecoverableException) RcvrIOSaveException(edu.cmu.cs.hcii.cogtool.util.RcvrIOSaveException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) BufferedWriter(java.io.BufferedWriter) RcvrIllegalStateException(edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) File(java.io.File) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter) RecoverableException(edu.cmu.cs.hcii.cogtool.util.RecoverableException)

Aggregations

AListenerAction (edu.cmu.cs.hcii.cogtool.util.AListenerAction)21 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)7 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)6 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)4 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)4 IOException (java.io.IOException)4 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)3 RcvrClipboardException (edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 SAXException (org.xml.sax.SAXException)3 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)2 ChildWidget (edu.cmu.cs.hcii.cogtool.model.ChildWidget)2 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)2 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)2 SkinType (edu.cmu.cs.hcii.cogtool.model.SkinType)2 DesignEditorUI (edu.cmu.cs.hcii.cogtool.ui.DesignEditorUI)2 FrameEditorUI (edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI)2 ProjectSelectionState (edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState)2 UI (edu.cmu.cs.hcii.cogtool.ui.UI)2 ZoomableUI (edu.cmu.cs.hcii.cogtool.ui.ZoomableUI)2