use of edu.cmu.cs.hcii.cogtool.util.AListenerAction in project cogtool by cogtool.
the class DesignEditorController method assignActions.
@Override
public void assignActions() {
super.assignActions();
ui.setAction(DesignEditorLID.ExportDesignToHTML, createExportDesignToHTMLAction());
ui.setAction(DesignEditorLID.ExportToXML, createExportDesignToXMLAction());
ui.setAction(DesignEditorLID.Undo, new UndoController.UndoAction(undoMgr, interaction));
ui.setAction(DesignEditorLID.Redo, new UndoController.RedoAction(undoMgr, interaction));
ui.setAction(DesignEditorLID.Paste, createPasteAction());
ui.setAction(DesignEditorLID.CopyFrame, createCopyFrameAction());
ui.setAction(DesignEditorLID.CutFrame, createCutFrameAction());
ui.setAction(DesignEditorLID.ClearFrameTemplate, new AListenerAction() {
public boolean performAction(Object prms) {
FrameTemplateSupport.clearFrameTemplate(design);
return true;
}
});
ui.setAction(DesignEditorLID.DeselectAll, new IListenerAction() {
public Class<?> getParameterClass() {
return SelectionState.class;
}
public boolean performAction(Object prms) {
SelectionState selection = (SelectionState) prms;
selection.deselectAll();
return true;
}
});
ui.setAction(DesignEditorLID.MoveFrames, new IListenerAction() {
public Class<?> getParameterClass() {
return DesignEditorUI.MoveParameters.class;
}
public boolean performAction(Object prms) {
DesignEditorUI.MoveParameters movePrms = (DesignEditorUI.MoveParameters) prms;
if (movePrms != null) {
return moveFrames(movePrms.dx, movePrms.dy, movePrms.selection);
} else {
throw new RcvrUIException("Cannot move frames without parameters.");
}
}
});
ui.setAction(DesignEditorLID.AddDesignDevices, createAddDevicesAction());
ui.setAction(DesignEditorLID.NewFrame, createNewFrameAction());
// Align selected frames
ui.setAction(DesignEditorLID.AlignTop, new FrameAlignmentAction(AlignmentAction.TOP));
ui.setAction(DesignEditorLID.AlignBottom, new FrameAlignmentAction(AlignmentAction.BOTTOM));
ui.setAction(DesignEditorLID.AlignLeft, new FrameAlignmentAction(AlignmentAction.LEFT));
ui.setAction(DesignEditorLID.AlignRight, new FrameAlignmentAction(AlignmentAction.RIGHT));
ui.setAction(DesignEditorLID.AlignCenter, new FrameAlignmentAction(AlignmentAction.CENTER));
ui.setAction(DesignEditorLID.AlignHorizCenter, new FrameAlignmentAction(AlignmentAction.HORIZ_CENTER));
ui.setAction(DesignEditorLID.AlignVertCenter, new FrameAlignmentAction(AlignmentAction.VERT_CENTER));
// Space selected frames equally
ui.setAction(DesignEditorLID.SpaceVertically, new IListenerAction() {
public Class<?> getParameterClass() {
return Map.class;
}
@SuppressWarnings("unchecked")
public boolean performAction(Object prms) {
Map<Frame, DoubleRectangle> frameMap = (Map<Frame, DoubleRectangle>) prms;
// Equally space the widgets in the
// vertical axis.
final boolean VERTICAL = true;
return spaceFramesEqually(frameMap, VERTICAL);
}
});
ui.setAction(DesignEditorLID.SpaceHorizontally, new IListenerAction() {
public Class<?> getParameterClass() {
return Map.class;
}
@SuppressWarnings("unchecked")
public boolean performAction(Object prms) {
Map<Frame, DoubleRectangle> frameMap = (Map<Frame, DoubleRectangle>) prms;
// Equally space the widgets in the
// horizontal axis.
final boolean HORIZONTAL = false;
return spaceFramesEqually(frameMap, HORIZONTAL);
}
});
ui.setAction(DesignEditorLID.InitiateFrameRename, createInitiateFrameRenameAction());
ui.setAction(DesignEditorLID.RenameFrame, new IListenerAction() {
public Class<?> getParameterClass() {
return DesignEditorUI.FrameRenameParameters.class;
}
public boolean performAction(Object prms) {
DesignEditorUI.FrameRenameParameters evt = (DesignEditorUI.FrameRenameParameters) prms;
return renameFrame(evt.frame, evt.newName);
}
});
ui.setAction(ProjectLID.RenameDesign, new IListenerAction() {
public Class<?> getParameterClass() {
return DesignEditorUI.DesignRenameParameters.class;
}
public boolean performAction(Object prms) {
DesignEditorUI.DesignRenameParameters evt = (DesignEditorUI.DesignRenameParameters) prms;
return renameDesign(evt.design, evt.newText);
}
});
ui.setAction(DesignEditorLID.NewTransition, createNewTransitionAction());
ui.setAction(DesignEditorLID.EditFrame, createEditFrameAction());
ui.setAction(DesignEditorLID.EditTransition, createEditTransitionAction());
ui.setAction(DesignEditorLID.DeleteFrame, createDeleteFrameAction());
ui.setAction(DesignEditorLID.DeleteTransition, createDeleteTransitionAction());
// Nudge selected frame(s)
ui.setAction(DesignEditorLID.NudgeLeft, new IListenerAction() {
public Class<?> getParameterClass() {
return FrameSelectionState.class;
}
public boolean performAction(Object prms) {
FrameSelectionState selection = (FrameSelectionState) prms;
double dx = -1.0 / ui.getZoom();
return moveFrames(dx, 0.0, selection);
}
});
ui.setAction(DesignEditorLID.NudgeRight, new IListenerAction() {
public Class<?> getParameterClass() {
return FrameSelectionState.class;
}
public boolean performAction(Object prms) {
FrameSelectionState selection = (FrameSelectionState) prms;
double dx = 1.0 / ui.getZoom();
return moveFrames(dx, 0.0, selection);
}
});
ui.setAction(DesignEditorLID.NudgeUp, new IListenerAction() {
public Class<?> getParameterClass() {
return FrameSelectionState.class;
}
public boolean performAction(Object prms) {
FrameSelectionState selection = (FrameSelectionState) prms;
double dy = -1.0 / ui.getZoom();
return moveFrames(0.0, dy, selection);
}
});
ui.setAction(DesignEditorLID.NudgeDown, new IListenerAction() {
public Class<?> getParameterClass() {
return FrameSelectionState.class;
}
public boolean performAction(Object prms) {
FrameSelectionState selection = (FrameSelectionState) prms;
double dy = 1.0 / ui.getZoom();
return moveFrames(0.0, dy, selection);
}
});
ui.setAction(DesignEditorLID.SelectAll, new AListenerAction() {
public boolean performAction(Object prms) {
ui.selectAllFrames();
return true;
}
});
ui.setAction(DesignEditorLID.ChangeTarget, createChangeTargetAction());
ui.setAction(DesignEditorLID.ChangeSource, createChangeSourceAction());
// The following 6 are also functionality in FrameEditorController
ui.setAction(DesignEditorLID.SetBackgroundImage, createSetBackgroundImageAction());
ui.setAction(DesignEditorLID.RemoveBackgroundImage, createRemoveBackgroundImageAction());
ui.setAction(DesignEditorLID.CopyImageAsBackground, createCopyImageAsBkgAction());
ui.setAction(DesignEditorLID.PasteBackgroundImage, createPasteBackgroundImageAction());
ui.setAction(DesignEditorLID.SetWidgetColor, createSetWidgetColorAction());
// Skins!
ui.setAction(DesignEditorLID.SkinWireFrame, createSetSkinAction(SkinType.WireFrame, DesignEditorLID.SkinWireFrame));
ui.setAction(DesignEditorLID.SkinMacOSX, createSetSkinAction(SkinType.MacOSX, DesignEditorLID.SkinMacOSX));
ui.setAction(DesignEditorLID.SkinWinXP, createSetSkinAction(SkinType.WinXP, DesignEditorLID.SkinWinXP));
ui.setAction(DesignEditorLID.SkinPalm, createSetSkinAction(SkinType.Palm, DesignEditorLID.SkinPalm));
ui.setAction(CogToolLID.RenderAll, createRenderAllAction(true, CogToolLID.RenderAll));
ui.setAction(CogToolLID.UnRender, createRenderAllAction(false, CogToolLID.UnRender));
ui.setAction(DesignEditorLID.ImportImageDirectory, createImportImageDirectory());
IListenerAction action = createChangeActionAction();
ui.setAction(DesignEditorLID.ChangeWidgetAction, action);
ui.setAction(DesignEditorLID.ChangeDeviceAction, action);
ui.setAction(DesignEditorLID.DuplicateFrame, createDuplicateFrameAction());
ui.setAction(DesignEditorLID.ChangeDelay, createChangeDelayAction());
}
use of edu.cmu.cs.hcii.cogtool.util.AListenerAction in project cogtool by cogtool.
the class FrameEditorController method createNewWidgetAction.
/**
* Create a ListenerAction to handle creating a new Widget.
*
*/
private IListenerAction createNewWidgetAction() {
return new AListenerAction() {
public boolean performAction(Object prms) {
// TODO: Should we provide more input to this default widget?
// Dialog box with option?
// Current/last palette setting
// TODO: Bonnie wanted to have new widgets show up under the
// mouse. To do that we need to do something like
// getCursorLocation() (from display)
// offset based on the (0,0) of the window
// Might want to get that based on GetCursorControl().
// If working with the control, you need to walk the tree to
// get the actual offset from 0,0, in the display.
//
// Alternatively, in specialize, get the mouse pointer position
// from mousestate (but that would require tracking the mouse
// state -- on hover at least).
// Instantiate the appropriate widget. If the class was passed
// a prms, use that to dictate what to do.
Widget widget = null;
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(NEW_WIDGET, FrameEditorLID.NewWidget);
if (prms instanceof FrameEditorUI.NewWidgetParameters) {
FrameEditorUI.NewWidgetParameters nwp = (FrameEditorUI.NewWidgetParameters) prms;
// widget
if (nwp.parent != null) {
if (nwp.type == WidgetType.MenuItem) {
// Create menu item; may become a submenu through
// user interaction later
widget = new MenuItem((AMenuWidget) nwp.parent, nwp.bounds, nwp.widgetTitle);
} else if (nwp.type == WidgetType.PullDownItem) {
widget = new PullDownItem((PullDownHeader) nwp.parent, nwp.bounds, nwp.widgetTitle);
boolean rendered = nwp.parent.isRendered();
SimpleWidgetGroup group = widget.getParentGroup();
group.setAttribute(WidgetAttributes.IS_RENDERED_ATTR, Boolean.valueOf(rendered));
}
} else // widget group
if (nwp.parentGroup != null) {
if (nwp.type == WidgetType.Menu) {
widget = new MenuHeader(nwp.parentGroup, nwp.bounds, nwp.widgetTitle);
} else if (nwp.type == WidgetType.ListBoxItem) {
widget = new ListItem(nwp.parentGroup, nwp.bounds, nwp.widgetTitle);
} else if (nwp.type == WidgetType.Radio) {
widget = new RadioButton((RadioButtonGroup) nwp.parentGroup, nwp.bounds, nwp.widgetTitle);
} else if (nwp.type == WidgetType.Check) {
widget = new CheckBox((GridButtonGroup) nwp.parentGroup, nwp.bounds, nwp.widgetTitle);
}
} else {
widget = createWidget(nwp.type, nwp.bounds, nwp.widgetTitle, nwp.isAutomatic);
}
if (nwp.isSeparator) {
frameSetAttribute(widget, WidgetAttributes.IS_SEPARATOR_ATTR, WidgetAttributes.IS_SEPARATOR, editSequence);
}
}
// if (widget.getWidgetType() == WidgetType.TextBox) {
// widget.setAttribute(WidgetAttributes.IS_STANDARD_ATTR,
// WidgetAttributes.IS_CUSTOM);
// }
// Auto-generate a unique name for the widget
widget.setName(generateUniqueWidgetName());
// Build the widget: check for uniqueness and add to the frame
boolean result = addCreatedWidget(widget, editSequence);
editSequence.end();
undoMgr.addEdit(editSequence);
return result;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.AListenerAction 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;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.AListenerAction in project cogtool by cogtool.
the class DesignEditorController method createSetSkinAction.
protected IListenerAction createSetSkinAction(final SkinType newSkin, final CogToolLID lid) {
return new AListenerAction() {
public boolean performAction(Object prms) {
final SkinType oldSkin = design.getSkin();
design.setSkin(newSkin);
undoMgr.addEdit(new AUndoableEdit(lid) {
@Override
public String getPresentationName() {
return changeSkin;
}
@Override
public void redo() {
super.redo();
design.setSkin(newSkin);
}
@Override
public void undo() {
super.undo();
design.setSkin(oldSkin);
}
});
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.AListenerAction in project cogtool by cogtool.
the class ZoomableController 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();
final ZoomableUI ui = getZoomableUI();
if (ui != null) {
ui.setAction(CogToolLID.SetZoom, new IListenerAction() {
public Class<?> getParameterClass() {
return Double.class;
}
public boolean performAction(Object prm) {
double zoom = ((Double) prm).doubleValue();
ui.setZoom(zoom);
return true;
}
});
ui.setAction(CogToolLID.ZoomToFit, new AListenerAction() {
public boolean performAction(Object prms) {
ui.zoomToFit();
return true;
}
});
ui.setAction(CogToolLID.ZoomNormal, new AListenerAction() {
public boolean performAction(Object prms) {
ui.zoomToActual();
return true;
}
});
ui.setAction(CogToolLID.ZoomIn, new AListenerAction() {
public boolean performAction(Object prms) {
ui.zoomIn();
return true;
}
});
ui.setAction(CogToolLID.ZoomOut, new AListenerAction() {
public boolean performAction(Object prms) {
ui.zoomOut();
return true;
}
});
}
}
Aggregations