Search in sources :

Example 16 with AListenerAction

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

the class DictionaryEditorController method assignActions.

@Override
public void assignActions() {
    super.assignActions();
    // Enable undo & redo
    ui.setAction(FrameEditorLID.Undo, new UndoController.UndoAction(undoMgr, interaction));
    ui.setAction(FrameEditorLID.Redo, new UndoController.RedoAction(undoMgr, interaction));
    ui.setAction(DictionaryEditorLID.StartNewEntry, createAddNewTermAction());
    ui.setAction(DictionaryEditorLID.SetGoalString, createSetStringAction(0));
    ui.setAction(DictionaryEditorLID.SetSearchString, createSetStringAction(1));
    ui.setAction(DictionaryEditorLID.CreateNewEntry, createAddNewEntryAction());
    ui.setAction(DictionaryEditorLID.SetSimilarity, createSetSimilarityAction());
    ui.setAction(DictionaryEditorLID.ComputeSimilarity, createComputeSimilarityAction());
    ui.setAction(DictionaryEditorLID.SetAlgorithm, createSetAlgorithmAction());
    ui.setAction(DictionaryEditorLID.Delete, createDeleteEntryAction());
    ui.setAction(ProjectLID.ExportDictToCSV, new AListenerAction() {

        public boolean performAction(Object actionParms) {
            return DictionaryEditorCmd.exportDictionaryToCSV(dictionary, interaction);
        }
    });
    ui.setAction(ProjectLID.ImportDict, new AListenerAction() {

        public boolean performAction(Object actionParms) {
            return DictionaryEditorCmd.importDictionary(design, dictionary, WidgetAttributes.NO_DICTIONARY, interaction, undoMgr, null);
        }
    });
    ui.setAction(CogToolLID.SelectAll, new AListenerAction() {

        public boolean performAction(Object actionParms) {
            ui.selectAll();
            return true;
        }
    });
}
Also used : AListenerAction(edu.cmu.cs.hcii.cogtool.util.AListenerAction)

Example 17 with AListenerAction

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

the class FrameEditorController method newSetWidgetColorAction.

/**
     * Returns a new anonymous IListenerAction for widget color changes.
     * @return
     */
private IListenerAction newSetWidgetColorAction() {
    return new AListenerAction() {

        public boolean performAction(Object prms) {
            final int oldColor = model.getWidgetColor();
            // Ask the user to get the color.
            Integer newColorChoice = interaction.selectColor(oldColor, SELECT_WIDGET_COLOR);
            // if the color is not the flag value, set it and add the undo.
            if (newColorChoice != null) {
                final int newColor = newColorChoice.intValue();
                model.setWidgetColor(newColor);
                undoMgr.addEdit(new AUndoableEdit(FrameEditorLID.SetWidgetColor) {

                    @Override
                    public String getPresentationName() {
                        return SET_WIDGET_COLOR;
                    }

                    @Override
                    public void redo() {
                        super.redo();
                        model.setWidgetColor(newColor);
                    }

                    @Override
                    public void undo() {
                        super.undo();
                        model.setWidgetColor(oldColor);
                    }
                });
                return true;
            }
            return false;
        }
    };
}
Also used : AListenerAction(edu.cmu.cs.hcii.cogtool.util.AListenerAction) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 18 with AListenerAction

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

the class ProjectController method createCopyResultsAction.

// Action for copying results to clipboard; uses TAB as separator!
protected IListenerAction createCopyResultsAction() {
    return new AListenerAction() {

        public boolean performAction(Object prms) {
            StringBuilder buffer = exportResults(CLIPBOARD_SEPARATOR, new Date());
            ClipboardUtil.copyTextData(buffer.toString());
            interaction.setStatusMessage(L10N.get("PS.ResultDataCopied", "Result data copied."));
            return true;
        }
    };
}
Also used : AListenerAction(edu.cmu.cs.hcii.cogtool.util.AListenerAction) Date(java.util.Date)

Example 19 with AListenerAction

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

the class DesignEditorController method createImportImageDirectory.

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

        public boolean performAction(Object actionParms) {
            // Ask for a directory of images
            String filePath = interaction.askForImageDir();
            if (filePath != null) {
                File dir = new File(filePath);
                if (dir.isDirectory()) {
                    final File[] files = dir.listFiles(new FileFilter() {

                        public boolean accept(File pathname) {
                            String name = pathname.getName();
                            Matcher imageFileNameMatcher = IMAGE_FILE_NAME.matcher(name);
                            if (imageFileNameMatcher.matches()) {
                                // Test for Mac resource forks
                                if (name.startsWith("._")) {
                                    String realName = name.substring(2);
                                    String fullPath = pathname.getParent() + FileUtil.FILE_SEP + realName;
                                    return !new File(fullPath).exists();
                                }
                                return true;
                            }
                            return false;
                        }
                    });
                    // Find an unoccupied starting position by cascading.
                    DoublePoint origin = new DoublePoint(10.0, 10.0);
                    // Check if only the default frame is present;
                    // if so, and it hasn't been significantly modified or
                    // used, indicate that it should be deleted when
                    // the images are imported.
                    Frame frameToDelete = design.getFrame(DesignEditorController.INITIAL_FRAME_NAME);
                    if ((frameToDelete == null) || (design.getFrames().size() > 1) || (frameToDelete.getWidgets().size() > 0) || (frameToDelete.getBackgroundImage() != null)) {
                        frameToDelete = null;
                    }
                    ImportImageDirThread workThread = new ImportImageDirThread(files, origin.x, origin.y, frameToDelete);
                    ThreadManager.startNewThread(workThread);
                }
            }
            return true;
        }
    };
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame) Matcher(java.util.regex.Matcher) AListenerAction(edu.cmu.cs.hcii.cogtool.util.AListenerAction) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) FileFilter(java.io.FileFilter) File(java.io.File)

Example 20 with AListenerAction

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

the class Controller 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 windows support.
     *
     * @author mlh
     */
protected void assignActions() {
    UI ui = getUI();
    if (ui != null) {
        ui.setAction(CogToolLID.About, ui.popAboutBox());
        // Set "open" action
        ui.setAction(CogToolLID.OpenProject, new AListenerAction() {

            public boolean performAction(Object prms) {
                // open expects null in that case.
                if (!(prms instanceof DoublePoint)) {
                    prms = null;
                }
                // Ask the user to select a CogTool project to open
                File[] openLocs = getUI().getStandardInteraction().selectFileSources();
                return open((DoublePoint) prms, openLocs);
            }
        });
        ui.setAction(CogToolLID.OpenProjectFile, new IListenerAction() {

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

            public boolean performAction(Object actionParms) {
                File[] openLoc = { new File((String) actionParms) };
                return open(null, openLoc);
            }
        });
        // Set "new project" action
        ui.setAction(CogToolLID.NewProject, createNewProjectAction());
        // Set "quit/exit" action
        ui.setAction(CogToolLID.ExitApplication, createExitAction());
        ui.setAction(CogToolLID.ClearRecent, new AListenerAction() {

            public boolean performAction(Object actionParms) {
                CogToolPref.clearRecent();
                Interaction interaction = getUI().getStandardInteraction();
                interaction.setStatusMessage(L10N.get("AC.RecentClear", "Recent file data cleared."));
                return true;
            }
        });
    }
}
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) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) File(java.io.File)

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