Search in sources :

Example 6 with CogToolLID

use of edu.cmu.cs.hcii.cogtool.CogToolLID in project cogtool by cogtool.

the class FrameEditorController method setWidgetImages.

/**
     * Sets the images on a bunch of widgets
     * @param selected an iterator containing the IWidgets
     * @param imageData the new image, or null of none
     */
private void setWidgetImages(Iterator<IWidget> selected, final byte[] imageData, final String imageURL) {
    String undoRedoLabel = (imageData == null) ? REMOVE_WIDGET_IMG : SET_WIDGET_IMG;
    CogToolLID lid = (imageData == null) ? FrameEditorLID.RemoveImageProperty : FrameEditorLID.SetImageProperty;
    // Create the compound undo
    CompoundUndoableEdit editSequence = new CompoundUndoableEdit(undoRedoLabel, lid);
    // Change the images on all the selected widgets
    while (selected.hasNext()) {
        setWidgetImage(selected.next(), imageData, imageURL, lid, undoRedoLabel, editSequence);
    }
    // Commit the edit
    editSequence.end();
    // Only add this edit if it is significant
    if (editSequence.isSignificant()) {
        undoMgr.addEdit(editSequence);
    }
}
Also used : CogToolLID(edu.cmu.cs.hcii.cogtool.CogToolLID) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)

Example 7 with CogToolLID

use of edu.cmu.cs.hcii.cogtool.CogToolLID in project cogtool by cogtool.

the class MenuFactory method buildMenu.

// addWindowMenu
public static void buildMenu(MenuType[] neededMenus, Shell viewShell, final Listener selectionListener, ListenerIdentifierMap lIDMap, IWindowMenuData<?> menuData) {
    int windowMenuIndex = -1;
    int fileMenuIndex = -1;
    MenuUtil.CascadingMenuItemDefinition[] defn = new MenuUtil.CascadingMenuItemDefinition[neededMenus.length];
    for (int i = 0; i < neededMenus.length; i++) {
        defn[i] = menuDefns[neededMenus[i].getOrdering()];
        if (neededMenus[i] == MenuFactory.MenuType.FileMenu) {
            fileMenuIndex = i;
        } else if (neededMenus[i] == MenuFactory.MenuType.WindowMenu) {
            windowMenuIndex = i;
            defn[i].menuItems = menuData.getWindowMenuLeadItems();
        }
    }
    Menu newMenuBar = MenuUtil.createMenu(viewShell, SWT.BAR | SWT.LEFT_TO_RIGHT, defn, ListenerIdentifierMap.NORMAL, selectionListener, lIDMap);
    if (fileMenuIndex != -1) {
        final Menu fileMenu = newMenuBar.getItem(fileMenuIndex).getMenu();
        fileMenu.addMenuListener(new MenuAdapter() {

            @Override
            public void menuShown(MenuEvent evt) {
                for (MenuItem item : fileMenu.getItems()) {
                    //This menu item corresponds to the Open Recent submenu
                    if (item.getData() == RECENT_FLAG) {
                        Menu cascade = item.getMenu();
                        for (MenuItem subItem : cascade.getItems()) {
                            subItem.dispose();
                        }
                        char recentIndex = '0';
                        for (String pathName : CogToolPref.getRecent()) {
                            if (!(MenuFactory.UNSET_FILE.equals(pathName))) {
                                if (recentIndex != 0) {
                                    if (recentIndex != '9') {
                                        recentIndex++;
                                    } else {
                                        recentIndex = ' ';
                                    }
                                }
                                String safePathName = "&" + recentIndex + " " + pathName.replaceAll("&", "&&");
                                MenuItem mi = MenuUtil.addMenuItem(cascade, safePathName, SWT.PUSH);
                                CogToolLID lid = new CogToolLID.OpenRecentLID("OpenRecent", pathName);
                                mi.addListener(SWT.Selection, selectionListener);
                                mi.setData(lid);
                            }
                        }
                        boolean hasRecent = CogToolPref.hasRecent();
                        if (hasRecent) {
                            MenuUtil.addMenuItem(cascade, "", SWT.SEPARATOR);
                        }
                        MenuItem clearItem = MenuUtil.addMenuItem(cascade, L10N.get("MI.ClearItems", "Clear items"), SWT.PUSH);
                        clearItem.addListener(SWT.Selection, selectionListener);
                        clearItem.setData(CogToolLID.ClearRecent);
                        clearItem.setEnabled(hasRecent);
                    //break;
                    } else // TODO this is a mess and needs to be tidied up
                    if (item.getData() == IMPORT_OTHER_FLAG) {
                        Menu cascade = item.getMenu();
                        for (MenuItem subItem : cascade.getItems()) {
                            subItem.dispose();
                        }
                        File directory = null;
                        String directoryName = CogToolPref.CONVERTER_DIRECTORY.getString();
                        boolean researchMode = CogToolPref.RESEARCH.getBoolean();
                        if (directoryName != null && !directoryName.equals("")) {
                            directory = new File(directoryName);
                            URL[] urls = null;
                            try {
                                // TODO: fix this deprecated method
                                URL url = directory.toURL();
                                urls = new URL[] { url };
                            } catch (MalformedURLException e1) {
                                // TODO Auto-generated catch block
                                e1.printStackTrace();
                            }
                            if (directory.exists()) {
                                URLClassLoader classLoader = new URLClassLoader(urls);
                                String[] children = directory.list();
                                boolean firstMenuItem = true;
                                for (String resource : children) {
                                    System.out.println("Resource " + resource);
                                    resource = (resource.lastIndexOf(".") == -1) ? resource : resource.substring(0, resource.lastIndexOf('.'));
                                    try {
                                        Class<ImportConverter> translatorClass = (Class<ImportConverter>) classLoader.loadClass(resource);
                                        try {
                                            Object converter = null;
                                            try {
                                                converter = translatorClass.newInstance();
                                                Class[] nameMethodParameters = new Class[0];
                                                Method method = translatorClass.getMethod("name", nameMethodParameters);
                                                String name = (String) method.invoke(converter);
                                                if (!name.endsWith("...")) {
                                                    name = name + "...";
                                                }
                                                if (firstMenuItem) {
                                                    MenuUtil.addMenuItem(cascade, "", SWT.SEPARATOR);
                                                    firstMenuItem = false;
                                                }
                                                String menuItemName = "Import Designs from " + name;
                                                MenuItem mi = MenuUtil.addMenuItem(cascade, menuItemName, SWT.PUSH);
                                                CogToolLID lid = new CogToolLID.ConverterFilesLID("NewDesignFromImport");
                                                ((ConverterFilesLID) lid).setClassAttribute(translatorClass);
                                                mi.setData(lid);
                                                mi.addListener(SWT.Selection, selectionListener);
                                            } catch (Exception ex) {
                                                throw new RcvrImportException("The file " + resource + " can not be loaded as a class.");
                                            }//Interact with the user and display the message.
                                             catch (Error er) {
                                                System.out.println("Error was thrown!");
                                            //TODO: How to throw this recoverable exception but move on?
                                            //throw new RcvrImportException("The file " + resource + " can not be loaded as a class.");
                                            }
                                        } catch (Exception ex) {
                                            throw new RcvrImportException("The file " + resource + " is not a valid converter file.");
                                        } catch (Error er) {
                                            System.out.println("Error was thrown2!");
                                        //TODO: How to throw this recoverable exception but move on?
                                        //throw new RcvrImportException("The file " + resource + " can not be loaded as a class.");
                                        }
                                    } catch (Exception ex) {
                                        throw new RcvrImportException("The file " + resource + " cannot be loaded as a class.");
                                    } catch (Error er) {
                                        System.out.println("Error was thrown3!");
                                    //TODO: How to throw this recoverable exception but move on?
                                    //throw new RcvrImportException("The file " + resource + " can not be loaded as a class.");
                                    }
                                }
                                break;
                            }
                        }
                    }
                }
            }
        });
    }
    if (windowMenuIndex != -1) {
        // reset!
        defn[windowMenuIndex].menuItems = null;
        addWindowMenu(newMenuBar.getItem(windowMenuIndex).getMenu(), menuData);
    }
    viewShell.setMenuBar(newMenuBar);
}
Also used : MalformedURLException(java.net.MalformedURLException) ImportConverter(edu.cmu.cs.hcii.cogtool.model.ImportConverter) URL(java.net.URL) ConverterFilesLID(edu.cmu.cs.hcii.cogtool.CogToolLID.ConverterFilesLID) Menu(org.eclipse.swt.widgets.Menu) MenuEvent(org.eclipse.swt.events.MenuEvent) RcvrImportException(edu.cmu.cs.hcii.cogtool.util.RcvrImportException) MenuAdapter(org.eclipse.swt.events.MenuAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) Method(java.lang.reflect.Method) RcvrUIException(edu.cmu.cs.hcii.cogtool.util.RcvrUIException) MalformedURLException(java.net.MalformedURLException) RcvrImportException(edu.cmu.cs.hcii.cogtool.util.RcvrImportException) CascadingMenuItemDefinition(edu.cmu.cs.hcii.cogtool.util.MenuUtil.CascadingMenuItemDefinition) CogToolLID(edu.cmu.cs.hcii.cogtool.CogToolLID) URLClassLoader(java.net.URLClassLoader) File(java.io.File)

Example 8 with CogToolLID

use of edu.cmu.cs.hcii.cogtool.CogToolLID in project cogtool by cogtool.

the class ProjectUI method setViewEnabledState.

/**
     * Enables or disables LIDs as appropriate
     * @param sel the selection state on which to base enabling/disabling
     * @param availability NORMAL or CONTEXT
     * @see ListenerIdentifierMap
     */
protected void setViewEnabledState(ProjectSelectionState sel, Boolean availability) {
    boolean hasDesign = sel.getSelectedDesign() != null;
    setEnabled(CogToolLID.AddDesignDevices, availability, hasDesign);
    String scriptLabel = "";
    scriptLabel = hasMultipleScripts(sel) ? " " + SCRIPTS_LABEL : " " + SCRIPT_LABEL;
    String label = "";
    int selectedTaskCount = sel.getSelectedTaskCount();
    boolean isSnifActTask = snifActTasksSelected(sel, TaskSelectionState.PRUNE_SELECTION);
    boolean isSnifActGroup = snifActTasksSelected(sel, TaskSelectionState.TASK_GROUPS_ONLY);
    if (selectedTaskCount > 0) {
        AUndertaking[] tasks = sel.getSelectedTasks(TaskSelectionState.ORDER_SELECTION);
        boolean allGroups = true;
        for (int i = 0; i < tasks.length; i++) {
            if (!tasks[i].isTaskGroup()) {
                allGroups = false;
            }
        }
        if (allGroups) {
            label = (selectedTaskCount > 1) ? (" " + TASK_GROUPS_LABEL) : (" " + TASK_GROUP_LABEL);
        } else {
            label = (selectedTaskCount > 1) ? (" " + TASKS_LABEL) : (" " + TASK_LABEL);
        }
    }
    if (hasDesign) {
        label = " " + DESIGN_LABEL;
        setEnabled(CogToolLID.ExportToXML, ListenerIdentifierMap.ALL, MenuUtil.ENABLED, L10N.get("PR.ExportDesignXMLLabel", "Export Design to XML"));
    } else {
        setEnabled(CogToolLID.ExportToXML, ListenerIdentifierMap.ALL, MenuUtil.ENABLED, EXPORT_PROJECT_LABEL);
    }
    String cutCopyLabel = (editor.getEditor() != null) ? "" : label;
    String regenerateString = regenerateTitle;
    boolean requiresRegeneration = selectionRequiresRegeneration(sel);
    if (requiresRegeneration) {
        regenerateString += scriptLabel;
    }
    setEnabled(CogToolLID.RegenerateScript, availability, requiresRegeneration, regenerateString);
    AUndertaking[] tasks = sel.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
    boolean singleTask = selectedTaskCount == 1;
    boolean cellSelected = hasDesign && singleTask;
    boolean anySelection = hasDesign || (selectedTaskCount > 0);
    setEnabled(CogToolLID.ExportDesignToHTML, availability, hasDesign);
    setEnabled(ProjectLID.ExportDictToCSV, availability, hasDesign);
    setEnabled(ProjectLID.ImportDict, availability, hasDesign);
    setEnabled(CogToolLID.CaptureBehavior, availability, true);
    if (cellSelected) {
        setEnabled(CogToolLID.Paste, availability, false);
        setEnabled(CogToolLID.Duplicate, availability, false, MenuFactory.DUPLICATE_STRING);
        setEnabled(CogToolLID.Rename, availability, false, MenuFactory.RENAME_STRING);
        setEnabled(CogToolLID.Cut, availability, false, MenuFactory.CUT_STRING);
        setEnabled(CogToolLID.Copy, availability, false, MenuFactory.COPY_STRING);
        setEnabled(CogToolLID.Delete, availability, false, MenuFactory.DELETE_STRING);
        String editLabel = MenuFactory.EDIT_STRING + " " + SCRIPT_LABEL;
        boolean editEnabled = true;
        if (tasks[0].isTaskGroup()) {
            if (GroupNature.SUM.equals(((TaskGroup) tasks[0]).getNature())) {
                editLabel = VIEW_SCRIPTS;
            } else {
                editLabel = MenuFactory.EDIT_STRING;
                editEnabled = false;
            }
        }
        setEnabled(CogToolLID.Edit, availability, editEnabled, editLabel);
        if (isSnifActTask) {
            // If it's a task generated by a run of SNIF-ACT (and therefore
            // put in a group that has that attribute), the algorithm in its
            // cell should never be changed.
            setEnabled(ProjectLID.SetAlgorithmACTR6, availability, false);
            setEnabled(ProjectLID.SetAlgorithmSNIFACT, availability, false);
            setEnabled(ProjectLID.SetAlgorithmDefault, availability, false);
            setEnabled(ProjectLID.SetAlgorithmHuman, availability, false);
            setEnabled(ProjectLID.SetBackgroundComputationDefault, availability, false);
            setEnabled(ProjectLID.SetBackgroundComputationFalse, availability, false);
            setEnabled(ProjectLID.SetBackgroundComputationTrue, availability, false);
        }
    } else if (isSnifActTask) {
        setEnabled(CogToolLID.Paste, availability, false);
        setEnabled(CogToolLID.Duplicate, availability, false, MenuFactory.DUPLICATE_STRING);
        setEnabled(CogToolLID.Cut, availability, false, MenuFactory.CUT_STRING);
        setEnabled(CogToolLID.Copy, availability, false, MenuFactory.COPY_STRING);
        setEnabled(CogToolLID.Rename, availability, hasDesign || singleTask, MenuFactory.RENAME_STRING + label);
        setEnabled(CogToolLID.NewTask, availability, false);
        setEnabled(CogToolLID.NewTaskGroup, availability, false);
    } else {
        setEnabled(CogToolLID.NewTask, availability, true);
        setEnabled(CogToolLID.NewTaskGroup, availability, true);
        setEnabled(CogToolLID.Paste, availability, true);
        String dupString = MenuFactory.DUPLICATE_STRING;
        if (anySelection) {
            dupString += label;
        }
        setEnabled(CogToolLID.Duplicate, availability, anySelection, dupString);
        // Edit enabled if only a single design selected
        String editString = MenuFactory.EDIT_STRING;
        if (hasDesign) {
            editString += label;
        }
        setEnabled(CogToolLID.Edit, availability, hasDesign, editString);
        // Rename enabled if a single selection
        boolean enabled = hasDesign || singleTask;
        String renameString = MenuFactory.RENAME_STRING;
        if (enabled) {
            renameString += label;
        }
        setEnabled(CogToolLID.Rename, availability, enabled, renameString);
        // Cut, Copy, Delete, DeselectAll should be enabled
        //   if there is any selection (task or design)
        setEnabled(CogToolLID.Cut, availability, anySelection, MenuFactory.CUT_STRING + cutCopyLabel);
        setEnabled(CogToolLID.Copy, availability, anySelection, MenuFactory.COPY_STRING + cutCopyLabel);
        setEnabled(CogToolLID.Delete, availability, anySelection, MenuFactory.DELETE_STRING + label);
        setEnabled(CogToolLID.DeselectAll, availability, anySelection);
    }
    boolean showRecompute = anySelection && taskHasComputableScripts(sel);
    if (!showRecompute && hasDesign && sel.getSelectedTaskCount() == 1) {
        Design design = sel.getSelectedDesign();
        TaskApplication taskApp = project.getTaskApplication(sel.getSelectedTask(), design);
        if (taskApp != null && taskApp.getActiveAlgorithm() instanceof SNIFACTPredictionAlgo) {
            showRecompute = true;
        }
    }
    String recomputeString = recomputeTitle;
    if (showRecompute) {
        recomputeString += scriptLabel;
    }
    // If the user wants to call recompute let them.
    setEnabled(CogToolLID.RecomputeScript, availability, showRecompute, recomputeString);
    // The export trace is only available when a script is
    // computed && there are traces to export.
    boolean hasComputedResult = selectionHasComputedResult(sel);
    boolean showExport = anySelection && //hasComputedResult &&
    selectionHasTraces(sel);
    setEnabled(ProjectLID.ExportTraces, availability, showExport);
    setEnabled(ProjectLID.DisplayTraces, availability, showExport);
    setEnabled(ProjectLID.ExportForSanlab, availability, showExport);
    // Show Visualization should only be available when a script is
    // computed/valid && there are ResultSteps to visualize.
    boolean showVis = anySelection && hasComputedResult && selectionHasResultSteps(sel);
    setEnabled(ProjectLID.ShowModelVisualization, availability, showVis);
    // The export device and script lisp files
    // is only available when a script is valid
    // valid IE: not null, not invalid
    boolean showExportFiles = anySelection && selectionHasScripts(sel) && hasComputedResult;
    setEnabled(ProjectLID.ExportActrModelFile, availability, showExportFiles);
    // Default to off; fix if truly enabled
    setEnabled(ProjectLID.MoveTaskEarlier, ListenerIdentifierMap.ALL, false);
    setEnabled(ProjectLID.MoveTaskLater, ListenerIdentifierMap.ALL, false);
    setEnabled(ProjectLID.PromoteTask, ListenerIdentifierMap.ALL, false);
    setEnabled(ProjectLID.DemoteTask, ListenerIdentifierMap.ALL, false);
    // Allow "vertical" movement if effectively only one task is selected
    if ((tasks != null) && !hasDesign) {
        if (singleTask) {
            boolean spawned = tasks[0].isSpawned();
            TaskGroup parent = tasks[0].getTaskGroup();
            List<AUndertaking> siblings;
            if (parent != null) {
                setEnabled(ProjectLID.PromoteTask, ListenerIdentifierMap.ALL, !spawned);
                siblings = parent.getUndertakings();
            } else {
                siblings = project.getUndertakings();
            }
            int siblingCount = siblings.size();
            int atIndex = siblings.indexOf(tasks[0]);
            if (siblingCount > 1) {
                boolean notFirstChild = (atIndex > 0);
                setEnabled(ProjectLID.DemoteTask, ListenerIdentifierMap.ALL, notFirstChild && !spawned);
                setEnabled(ProjectLID.MoveTaskEarlier, ListenerIdentifierMap.ALL, notFirstChild && !spawned);
                setEnabled(ProjectLID.MoveTaskLater, ListenerIdentifierMap.ALL, (atIndex < siblingCount - 1) && !spawned);
            }
        } else if (tasks.length > 1) {
            // Too many tasks selected to check conditions;
            // let the controller handle the error cases.
            setEnabled(ProjectLID.PromoteTask, ListenerIdentifierMap.ALL, !isSnifActTask);
            setEnabled(ProjectLID.DemoteTask, ListenerIdentifierMap.ALL, !isSnifActTask);
        }
    }
    // Stuff that is enabled only when a script exists.
    boolean canExport = false;
    if (hasDesign) {
        Design design = sel.getSelectedDesign();
        for (AUndertaking task : tasks) {
            if (taskHasScripts(task, design)) {
                canExport = true;
            }
        }
    }
    setEnabled(CogToolLID.ExportScriptToCSV, availability, canExport);
    // Enable "Show XXX" options if any task groups are selected
    boolean enabled = false;
    int numTaskGroups = 0;
    TaskGroup group = null;
    for (AUndertaking task : tasks) {
        if (task.isTaskGroup()) {
            enabled = true;
            numTaskGroups++;
            group = (TaskGroup) task;
        }
    }
    setEnabled(ProjectLID.Ungroup, availability, enabled && !isSnifActGroup);
    setEnabled(CogToolLID.ShowSum, availability, enabled && !isSnifActGroup);
    setEnabled(CogToolLID.ShowMean, availability, enabled);
    setEnabled(CogToolLID.ShowMin, availability, enabled);
    setEnabled(CogToolLID.ShowMax, availability, enabled);
    setSelected(CogToolLID.ShowSum, availability, false);
    setSelected(CogToolLID.ShowMean, availability, false);
    setSelected(CogToolLID.ShowMin, availability, false);
    setSelected(CogToolLID.ShowMax, availability, false);
    if (enabled) {
        if (numTaskGroups == 1) {
            GroupNature nature = group.getNature();
            CogToolLID id = null;
            if (nature == GroupNature.SUM) {
                id = CogToolLID.ShowSum;
            } else if (nature == GroupNature.MEAN) {
                id = CogToolLID.ShowMean;
            } else if (nature == GroupNature.MIN) {
                id = CogToolLID.ShowMin;
            } else if (nature == GroupNature.MAX) {
                id = CogToolLID.ShowMax;
            }
            setSelected(id, availability, true);
        }
    }
    IPredictionAlgo defaultAlgo = project.getDefaultAlgo();
    // enabled state for default algorithm settings
    setSelected(ProjectLID.SetProjDefaultAlgoACTR, availability, defaultAlgo == ACTR6PredictionAlgo.ONLY);
    setSelected(ProjectLID.SetProjDefaultAlgoSNIFACT, availability, defaultAlgo == SNIFACTPredictionAlgo.ONLY);
    setSelected(ProjectLID.SetProjExecBackground, availability, project.getDefaultRunInBackground());
    setSelected(ProjectLID.SetProjExecForeground, availability, !project.getDefaultRunInBackground());
    // (TODO: same level/contiguous/subtrees for Group Tasks???)
    // if the user has named the task (created the group), he can export
    boolean canExportHCIPA = false;
    if ((tasks != null) && (tasks.length > 0)) {
        // Must have selected a top-level group
        for (AUndertaking task : tasks) {
            if (task.isTaskGroup() && (task.getTaskGroup() == null)) {
                canExportHCIPA = true;
            }
        }
    } else if (hasDesign) {
        // At least one top-level task must be a group
        Iterator<AUndertaking> allTasks = project.getUndertakings().iterator();
        while (allTasks.hasNext()) {
            AUndertaking u = allTasks.next();
            if (u.isTaskGroup()) {
                canExportHCIPA = true;
            }
        }
    }
    setEnabled(ProjectLID.ExportToHCIPA, availability, canExportHCIPA);
    if (hasDesign) {
        ISimilarityDictionary dict = (ISimilarityDictionary) sel.getSelectedDesign().getAttribute(WidgetAttributes.DICTIONARY_ATTR);
        String newLabel = NullSafe.equals(dict, WidgetAttributes.NO_DICTIONARY) ? L10N.get("WT.GenerateDictionary", "Generate Dictionary...") : L10N.get("WT.UpdateDictionary", "Update Dictionary...");
        setEnabled(ProjectLID.GenerateDictionary, availability, !isSnifActTask, newLabel);
    } else if (tasks.length > 0) {
        List<Design> designs = project.getDesigns();
        String newLabel = designs.size() > 1 ? L10N.get("WT.UpdateDictionaries", "Update Dictionaries...") : L10N.get("WT.UpdateDictionary", "Update Dictionary...");
        setEnabled(ProjectLID.GenerateDictionary, availability, !isSnifActTask, newLabel);
    }
}
Also used : IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) Point(org.eclipse.swt.graphics.Point) Design(edu.cmu.cs.hcii.cogtool.model.Design) CogToolLID(edu.cmu.cs.hcii.cogtool.CogToolLID) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) Iterator(java.util.Iterator) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) SNIFACTPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.SNIFACTPredictionAlgo) List(java.util.List) ISimilarityDictionary(edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup) GroupNature(edu.cmu.cs.hcii.cogtool.model.GroupNature)

Example 9 with CogToolLID

use of edu.cmu.cs.hcii.cogtool.CogToolLID in project cogtool by cogtool.

the class DesignEditorUI method setViewEnabledState.

/**
     * Enables or disables LIDs as appropriate
     * @param sel the selection state on which to base enabling/disabling
     * @param availability NORMAL or CONTEXT
     * @see ListenerIdentifierMap
     */
protected void setViewEnabledState(DesignEditorSelectionState sel, Boolean availability) {
    String label = "";
    int frameCount = sel.getSelectedFrameCount();
    if (frameCount > 0) {
        if (frameCount > 1) {
            label = " " + FRAMES_LABEL;
        } else {
            label = " " + FRAME_LABEL;
        }
    }
    int transitionCount = sel.getSelectedTransitionCount();
    if (transitionCount > 0) {
        if (transitionCount > 1) {
            label = " " + TRANSITIONS_LABEL;
        } else {
            label = " " + TRANSITION_LABEL;
        }
    }
    Text t = WindowUtil.getFocusedText();
    boolean editing = ((editor != null) && editor.getVisible());
    String cutCopyLabel = (editing || (t != null)) ? "" : label;
    boolean enabled = (frameCount > 0) || (transitionCount == 1);
    String editString = MenuFactory.EDIT_STRING;
    if (enabled) {
        editString += label;
    }
    setEnabled(CogToolLID.Edit, availability, enabled, editString);
    enabled = (frameCount > 0) || (transitionCount > 0);
    String deleteString = MenuFactory.DELETE_STRING + label;
    setEnabled(CogToolLID.Delete, availability, enabled, deleteString);
    // Enable move/reorder items if any frames are selected
    enabled = (frameCount > 0);
    String cutString = MenuFactory.CUT_STRING;
    if (enabled) {
        cutString += cutCopyLabel;
    }
    setEnabled(CogToolLID.Cut, availability, enabled, cutString);
    String copyString = MenuFactory.COPY_STRING;
    if (enabled) {
        copyString += cutCopyLabel;
    }
    setEnabled(CogToolLID.Copy, availability, enabled, copyString);
    setEnabled(CogToolLID.NudgeLeft, availability, enabled);
    setEnabled(CogToolLID.NudgeRight, availability, enabled);
    setEnabled(CogToolLID.NudgeDown, availability, enabled);
    setEnabled(CogToolLID.NudgeUp, availability, enabled);
    // TODO: For now, don't allow duplication of transitions
    String dupString = MenuFactory.DUPLICATE_STRING;
    if (enabled) {
        dupString += label;
    }
    setEnabled(CogToolLID.Duplicate, availability, enabled, dupString);
    // the following 3 menu items involve code snippets copied from
    // FrameEditor classes
    setEnabled(CogToolLID.SetBackgroundImage, availability, enabled, SET_FRAME_BKG_IMAGE);
    setEnabled(CogToolLID.SetWidgetColor, availability, enabled);
    // only enable RemoveBackgroundImage if there are selected frames
    if (enabled) {
        // and at least one of those frames has a background image
        boolean foundBackgroundImage = false;
        Frame[] selFrames = sel.getSelectedFrames();
        for (Frame selFrame : selFrames) {
            if (selFrame.getBackgroundImage() != null) {
                foundBackgroundImage = true;
                break;
            }
        }
        setEnabled(CogToolLID.RemoveBackgroundImage, availability, foundBackgroundImage, REMOVE_FRAME_BKG_IMAGE);
    } else {
        setEnabled(CogToolLID.RemoveBackgroundImage, availability, enabled, REMOVE_FRAME_BKG_IMAGE);
    }
    //        setEnabled(CogToolLID.BringToFront, availability, enabled);
    //        setEnabled(CogToolLID.BringForward, availability, enabled);
    //        setEnabled(CogToolLID.SendBackward, availability, enabled);
    //        setEnabled(CogToolLID.SendToBack, availability, enabled);
    // Enable alignment items if multiple frames are selected
    enabled = (frameCount > 1);
    setEnabled(CogToolLID.AlignTop, availability, enabled);
    setEnabled(CogToolLID.AlignBottom, availability, enabled);
    setEnabled(CogToolLID.AlignLeft, availability, enabled);
    setEnabled(CogToolLID.AlignRight, availability, enabled);
    setEnabled(CogToolLID.AlignCenter, availability, enabled);
    setEnabled(CogToolLID.AlignHorizCenter, availability, enabled);
    setEnabled(CogToolLID.AlignVertCenter, availability, enabled);
    // Enable spacing items if at least 3 frames are selected
    enabled = (frameCount >= 3);
    setEnabled(CogToolLID.SpaceVertically, availability, enabled);
    setEnabled(CogToolLID.SpaceHorizontally, availability, enabled);
    // Edit and Rename enabled if a single selection
    enabled = (frameCount == 1);
    String renameString = MenuFactory.RENAME_STRING;
    if (enabled) {
        renameString += label;
    }
    setEnabled(CogToolLID.Rename, availability, enabled, renameString);
    Design modelDesign = uiModel.getDesign();
    enabled = (modelDesign.getFrames().size() > 0);
    setEnabled(CogToolLID.SelectAll, availability, enabled, SELECT_ALL_FRAMES);
    // Draws the dot to indicate that the correct skin type is selected
    setSelected(CogToolLID.SkinNone, availability, false);
    setSelected(CogToolLID.SkinWireFrame, availability, false);
    setSelected(CogToolLID.SkinMacOSX, availability, false);
    setSelected(CogToolLID.SkinWinXP, availability, false);
    setSelected(CogToolLID.SkinPalm, availability, false);
    SkinType skin = modelDesign.getSkin();
    CogToolLID id = null;
    if (skin == SkinType.None) {
        id = CogToolLID.SkinNone;
    } else if (skin == SkinType.WireFrame) {
        id = CogToolLID.SkinWireFrame;
    } else if (skin == SkinType.MacOSX) {
        id = CogToolLID.SkinMacOSX;
    } else if (skin == SkinType.WinXP) {
        id = CogToolLID.SkinWinXP;
    } else if (skin == SkinType.Palm) {
        id = CogToolLID.SkinPalm;
    }
    if (id != null) {
        setSelected(id, availability, true);
    }
    setEnabled(CogToolLID.ClearFrameTemplate, ListenerIdentifierMap.ALL, FrameTemplateSupport.hasFrameTemplate(design));
}
Also used : Design(edu.cmu.cs.hcii.cogtool.model.Design) Frame(edu.cmu.cs.hcii.cogtool.model.Frame) DesignEditorFrame(edu.cmu.cs.hcii.cogtool.uimodel.DesignEditorFrame) CogToolLID(edu.cmu.cs.hcii.cogtool.CogToolLID) SkinType(edu.cmu.cs.hcii.cogtool.model.SkinType) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.draw2d.geometry.Point)

Aggregations

CogToolLID (edu.cmu.cs.hcii.cogtool.CogToolLID)9 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)4 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)3 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)3 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)3 Design (edu.cmu.cs.hcii.cogtool.model.Design)2 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)2 FrameElement (edu.cmu.cs.hcii.cogtool.model.FrameElement)2 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)2 SkinType (edu.cmu.cs.hcii.cogtool.model.SkinType)2 Point (org.eclipse.draw2d.geometry.Point)2 ConverterFilesLID (edu.cmu.cs.hcii.cogtool.CogToolLID.ConverterFilesLID)1 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)1 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)1 FrameElementGroup (edu.cmu.cs.hcii.cogtool.model.FrameElementGroup)1 GroupNature (edu.cmu.cs.hcii.cogtool.model.GroupNature)1 IPredictionAlgo (edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo)1 ISimilarityDictionary (edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary)1 DictEntry (edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary.DictEntry)1 ImportConverter (edu.cmu.cs.hcii.cogtool.model.ImportConverter)1