use of edu.cmu.cs.hcii.cogtool.model.FrameElementGroup in project cogtool by cogtool.
the class FrameEditorUI 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(FrameEditorSelectionState sel, Boolean availability) {
String label = "";
int widgetCount = sel.getWidgetSelectionCount();
int elementCount = sel.getElementSelectionCount();
IWidget selectedWidget = null;
FrameElement selectedElement = null;
if ((widgetCount > 0) || (elementCount > 0)) {
if (widgetCount == 1) {
label = " " + WIDGET_LABEL;
selectedWidget = sel.getSelectedIWidgets()[0];
selectedElement = selectedWidget;
} else {
label = " " + WIDGETS_LABEL;
if (elementCount == 1) {
selectedElement = sel.getSelectedIFrameElements()[0];
}
}
}
Text t = WindowUtil.getFocusedText();
boolean editing = ((editor != null) && editor.getVisible());
String cutCopyLabel = (editing || (t != null)) ? "" : label;
// Turn on rename support if selection is exactly 1
boolean enabled = (widgetCount == 1);
String renameString = MenuFactory.RENAME_STRING;
String relabelString = MenuFactory.RELABEL_STRING;
if (enabled) {
renameString += label;
relabelString += label;
}
setEnabled(CogToolLID.Rename, availability, enabled, renameString);
setEnabled(FrameEditorLID.Relabel, availability, enabled, relabelString);
setEnabled(CogToolLID.CopyPath, availability, enabled);
setEnabled(FrameEditorLID.RemoveImageProperty, availability, (selectedWidget != null) && (selectedWidget.getImage() != null));
setEnabled(FrameEditorLID.ToggleRenderSkin, availability, enabled, MenuFactory.RENDER_WIDGET_SKIN_LABEL, (selectedWidget != null) && selectedWidget.isRendered());
if (enabled && (selectedWidget != null)) {
enabled = selectedWidget.getAttribute(WidgetAttributes.REMOTE_LABEL_OWNER_ATTR) != null;
}
setEnabled(FrameEditorLID.SetRemoteLabelType, availability, enabled);
if (elementCount == 1) {
enabled = selectedElement.getRemoteLabelOwner() != null;
}
setEnabled(FrameEditorLID.SetRemoteLabelText, availability, enabled);
// Turn on these LIDs if the selection is > 0
enabled = (widgetCount > 0);
setEnabled(FrameEditorLID.SetImageProperty, availability, enabled);
setEnabled(FrameEditorLID.CaptureImageProperty, availability, enabled && view.isBackgroundAvailable());
enabled = (elementCount > 0);
String deleteString = MenuFactory.DELETE_STRING + label;
setEnabled(CogToolLID.Delete, availability, enabled, deleteString);
String dupString = MenuFactory.DUPLICATE_STRING + label;
setEnabled(CogToolLID.Duplicate, availability, enabled, dupString);
// For these, there must exist a non-IChildWidget selected widget
int nonchildWidgetCount = sel.getNonchildSelectionCount();
enabled = (nonchildWidgetCount > 0);
String cutString = MenuFactory.CUT_STRING + cutCopyLabel;
setEnabled(CogToolLID.Cut, availability, enabled, cutString);
String copyString = MenuFactory.COPY_STRING + cutCopyLabel;
setEnabled(CogToolLID.Copy, availability, enabled, copyString);
setEnabled(CogToolLID.SetFrameTemplate, availability, enabled);
setEnabled(CogToolLID.NudgeLeft, availability, enabled);
setEnabled(CogToolLID.NudgeRight, availability, enabled);
setEnabled(CogToolLID.NudgeDown, availability, enabled);
setEnabled(CogToolLID.NudgeUp, availability, enabled);
setEnabled(CogToolLID.BringToFront, availability, enabled);
setEnabled(CogToolLID.BringForward, availability, enabled);
setEnabled(CogToolLID.SendBackward, availability, enabled);
setEnabled(CogToolLID.SendToBack, availability, enabled);
// Grouping enabled only if multiple unrelated IFrameElements are selected
enabled = false;
FrameElement firstSelectedElt = null;
Iterator<FrameElement> selectedElts = sel.getSelectedElementsIterator();
while (selectedElts.hasNext()) {
FrameElement elt = selectedElts.next();
if (firstSelectedElt == null) {
firstSelectedElt = elt.getRootElement();
} else if (firstSelectedElt != elt.getRootElement()) {
enabled = true;
break;
}
}
setEnabled(CogToolLID.Group, availability, enabled);
enabled = false;
selectedElts = sel.getSelectedElementsIterator();
while (selectedElts.hasNext()) {
FrameElement elt = selectedElts.next();
enabled = enabled || (elt instanceof FrameElementGroup) || (elt.getRootElement().getEltGroups().size() > 0);
}
setEnabled(CogToolLID.Ungroup, availability, enabled);
// don't allow alignment if any of the selected widgets are part of a
// widget group (e.g. menu headers, list box items, grid buttons)
// TODO might want to allow it for grid buttons, with extra work in the
// controller to calculate horizontal and vertical space
boolean groupWidgetSelected = false;
IWidget[] widgets = sel.getSelectedIWidgets();
for (IWidget widget : widgets) {
if (widget.getParentGroup() != null) {
groupWidgetSelected = true;
}
}
// Enable alignment items if multiple non-child widgets are selected
enabled = (nonchildWidgetCount > 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 non-child widgets are selected
enabled = (nonchildWidgetCount >= 3) && !groupWidgetSelected;
setEnabled(CogToolLID.SpaceVertically, availability, enabled);
setEnabled(CogToolLID.SpaceHorizontally, availability, enabled);
// If there is at least one widget in the model, enable these.
enabled = (frame.getWidgets().size() > 0);
setEnabled(CogToolLID.SelectAll, availability, enabled, SELECT_ALL_WIDGETS);
// 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 = design.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));
}
use of edu.cmu.cs.hcii.cogtool.model.FrameElementGroup in project cogtool by cogtool.
the class FrameEditorMouseState method dealWithMouseReleased.
/**
* A mouse up event was called.
* Checks for context selection, then performs actions as dictated
* by the FSM.
*/
@Override
protected boolean dealWithMouseReleased(IFigure figure, int button, int x, int y, int state) {
boolean goForward = super.dealWithMouseReleased(figure, button, x, y, state);
// Clear any mouse drag timer, that may be running
stopMouseDragTimer = true;
if (goForward && isMouseDownValid) {
// Record the mouse down position
double zoom = ui.getZoom();
// The current mouse down position (scaled)
double currentScaledX = x / zoom;
double currentScaledY = y / zoom;
switch(getMouseState()) {
case PotentialCreatingWidget:
case PotentialMovingWidget:
case PotentialResizingWidget:
{
// Nothing to do; any action necessary was taken on "down".
break;
}
case PotentialReorderWidget:
case PotentialMovingSelection:
{
// Get whatever graphical widget under original down x,y
GraphicalWidget<?> wf = ui.widgetLocatedAtXY(mouseDownX, mouseDownY);
MoveHalo halo = null;
FrameElement data = null;
if (wf == null) {
halo = ui.moveHaloUnderXY(mouseDownX, mouseDownY);
if (halo != null) {
data = halo.getData();
if (data instanceof SimpleWidgetGroup) {
IWidget[] widgets = selection.getSelectedIWidgets();
SimpleWidgetGroup group = (SimpleWidgetGroup) data;
for (IWidget widget : widgets) {
if (widget.getParentGroup() != group) {
selection.deselectElement(widget);
}
}
break;
}
if (data instanceof IWidget) {
wf = ui.frameUI.getWidgetFigure((IWidget) data);
}
}
}
if (wf != null) {
selection.setSelectedSelnFig(wf);
} else {
if (halo == null) {
halo = ui.moveHaloUnderXY(mouseDownX, mouseDownY);
if (halo != null) {
data = halo.getData();
}
}
if ((data != null) && (data instanceof FrameElementGroup)) {
selection.setSelectedSelnFig((FrameEltGroupHalo) halo);
}
}
break;
}
case PotentialTogglingSelection:
{
// If mouse down on a widget, toggle selection.
GraphicalWidget<?> wf = ui.widgetLocatedAtXY(mouseDownX, mouseDownY);
MoveHalo halo = ui.moveHaloUnderXY(mouseDownX, mouseDownY);
FrameElement data = null;
if (halo != null) {
data = halo.getData();
}
if (wf == null) {
if (data instanceof IWidget) {
wf = ui.frameUI.getWidgetFigure((IWidget) data);
}
}
if (wf != null) {
// If the widget is already selected, unselect it.
if (selection.isSelectionFigureSelected(wf)) {
selection.deselectSelnFig(wf);
} else {
selection.selectSelnFig(wf);
}
} else if (data instanceof SimpleWidgetGroup) {
Iterator<IWidget> widgets = ((SimpleWidgetGroup) data).iterator();
while (widgets.hasNext()) {
IWidget w = widgets.next();
selection.deselectElement(w);
}
} else if ((halo instanceof FrameEltGroupHalo) && (data instanceof FrameElementGroup)) {
FrameEltGroupHalo groupHalo = (FrameEltGroupHalo) halo;
if (selection.isElementSelected(data)) {
selection.deselectSelnFig(groupHalo);
} else {
selection.selectSelnFig(groupHalo);
}
} else {
selection.deselectAll();
}
break;
}
// Move is complete, so apply changes to the model.
case MovingWidgets:
{
// Get selection, and use the difference between current
// and start location.
double moveByX = currentScaledX - scaledMouseDownX;
double moveByY = currentScaledY - scaledMouseDownY;
FrameEditorUI.MoveParameters prms = new FrameEditorUI.MoveParameters(moveByX, moveByY, selection);
ui.performAction(CogToolLID.MoveWidgets, prms);
break;
}
case ReorderWidget:
{
boolean reorder = reorderWidget(x, y, reorderParms);
ui.clearUISupport(true);
isReordering = false;
if (reorder) {
ui.performAction(FrameEditorLID.Reorder, reorderParms);
} else {
selection.deselectElement(lastClickedWidget);
}
InteractionDrawingEditor editor = ui.getViewEditor();
editor.removeInteractionFigure(reorderFigure);
editor.removeInteractionFigure(dividerLine);
break;
}
// since the user may have flipped the orientation.
case ResizingWidget:
{
// Switch to quality mode rendering for graphical widgets
setWidgetFastRenderMode(false);
if (currentScaledX < 0.0) {
currentScaledX = 0.0;
}
if (currentScaledY < 0.0) {
currentScaledY = 0.0;
}
// Deal with any anchoring issues
if (ui.resizeHandlesUIFig.isTopLeftAnchored()) {
switch(currentResizeHandleType) {
case FrameEditorUI.TOP_RIGHT:
{
// Cannot change Y position
currentScaledY = initialResizeArea.y;
break;
}
case FrameEditorUI.BOTTOM_LEFT:
{
// Cannot change X position
currentScaledX = initialResizeArea.x;
break;
}
default:
{
break;
}
}
// Cannot move left of top-left
if (currentScaledX < initialResizeArea.x) {
currentScaledX = initialResizeArea.x;
}
// Cannot move above of top-left
if (currentScaledY < initialResizeArea.y) {
currentScaledY = initialResizeArea.y;
}
}
double width = Math.abs(currentScaledX - mouseFixedResizeX);
double height = Math.abs(currentScaledY - mouseFixedResizeY);
FrameEditorUI.ResizeParameters prms = new FrameEditorUI.ResizeParameters(initialResizeArea.x, initialResizeArea.y, Math.min(currentScaledX, mouseFixedResizeX), Math.min(currentScaledY, mouseFixedResizeY), width / initialResizeArea.width, height / initialResizeArea.height, selection);
ui.performAction(CogToolLID.ResizeWidgets, prms);
break;
}
// Finished a mouse drag operation to create a new widget
case CreatingWidget:
{
if (currentScaledX < 0.0) {
currentScaledX = 0.0;
}
if (currentScaledY < 0.0) {
currentScaledY = 0.0;
}
double width = Math.abs(scaledMouseDownX - currentScaledX);
double height = Math.abs(scaledMouseDownY - currentScaledY);
double leftX = (scaledMouseDownX > currentScaledX) ? currentScaledX : scaledMouseDownX;
double topY = (scaledMouseDownY > currentScaledY) ? currentScaledY : scaledMouseDownY;
// Turn off the bounding box drawn.
ui.stopDrawingTemporaryFigure();
// Create a rectangle for the new region.
DoubleRectangle region = new DoubleRectangle(leftX, topY, width, height);
// width of 0. Probably this should be less then 2.
if ((region.width != 0.0) && (region.height != 0.0)) {
ui.performAction(CogToolLID.NewWidget, new FrameEditorUI.NewWidgetParameters(region, ui.getCurrentWidgetType(), ui.view.isAutomaticCreation()));
}
break;
}
// Finished a mouse drag operation to select a set of widgets
case TogglingSelection:
{
// Get the total area selected
double width = Math.abs(scaledMouseDownX - currentScaledX);
double height = Math.abs(scaledMouseDownY - currentScaledY);
// Get top left point.
double leftX = (scaledMouseDownX > currentScaledX) ? currentScaledX : scaledMouseDownX;
double topY = (scaledMouseDownY > currentScaledY) ? currentScaledY : scaledMouseDownY;
// Turn off the bounding box drawn.
ui.stopDrawingTemporaryFigure();
// Create the final region's area
DoubleRectangle region = new DoubleRectangle(leftX, topY, width, height);
// Loop through all figures and check for intersections
Iterator<GraphicalWidget<?>> gwFigures = ui.getFrameUI().getFigureListIterator();
while (gwFigures.hasNext()) {
GraphicalWidget<?> gw = gwFigures.next();
if (!(gw instanceof GraphicalChildWidget<?, ?>)) {
Rectangle bounds = gw.getBounds();
if (region.intersects(bounds.x, bounds.y, bounds.width, bounds.height)) {
// If the widget is already selected, deselect it.
if (selection.isSelectionFigureSelected(gw)) {
selection.deselectSelnFig(gw);
} else {
selection.selectSelnFig(gw);
}
}
}
}
break;
}
case PotentialInsertDuplicateWidget:
case PotentialDuplicatingWidget:
{
GraphicalWidget<?> widgetFig = ui.widgetLocatedAtXY(mouseDownX, mouseDownY);
selection.setSelectedSelnFig(widgetFig);
break;
}
case DuplicatingWidgets:
{
double dx = currentScaledX - scaledMouseDownX;
double dy = currentScaledY - scaledMouseDownY;
// Remove all the rectangle figures from the display, clear the list
clearRectFigures();
ui.performAction(FrameEditorLID.Duplicate, new FrameEditorUI.DuplicateParameters(dx, dy, selection));
break;
}
case InsertDuplicateWidget:
{
double dx = currentScaledX - scaledMouseDownX;
double dy = currentScaledY - scaledMouseDownY;
isReordering = false;
if (reorderWidget(x, y, insertDuplicateParms)) {
insertDuplicateParms.moveByX = dx;
insertDuplicateParms.moveByY = dy;
ui.performAction(FrameEditorLID.InsertDuplicate, insertDuplicateParms);
} else {
selection.deselectElement(lastClickedWidget);
}
InteractionDrawingEditor editor = ui.getViewEditor();
editor.removeInteractionFigure(reorderFigure);
editor.removeInteractionFigure(dividerLine);
break;
}
case PotentialMovingGridButtons:
{
if (movedGridButtons != null) {
movedGridButtons = NO_GRID_BUTTONS;
}
break;
}
case MovingGridButtons:
{
// Get selection, and use the difference between current
// and start location.
double moveByX;
double moveByY;
GraphicalWidget<?> gw = ui.getPotentialFigureOwner();
GridButton gb = (GridButton) gw.getModel();
DoublePoint start = gb.getShape().getOrigin();
if (moveIsVertical) {
moveByX = 0.0;
if (currentScaledY < minY) {
moveByY = (minY - start.y);
} else {
moveByY = currentScaledY - scaledMouseDownY;
}
} else {
moveByY = 0.0;
if (currentScaledX < minX) {
moveByX = (minX - start.x);
} else {
moveByX = currentScaledX - scaledMouseDownX;
}
}
if ((moveByX != 0.0) || (moveByY != 0.0)) {
FrameEditorUI.MoveParameters prms = new FrameEditorUI.MoveParameters(moveByX, moveByY, selection, false);
ui.performAction(CogToolLID.MoveWidgets, prms);
}
break;
}
}
// Clear the values used.
lastClickedWidget = null;
isMouseDownValid = false;
setMouseState(MouseUp);
}
cleanup();
return goForward;
}
use of edu.cmu.cs.hcii.cogtool.model.FrameElementGroup in project cogtool by cogtool.
the class DictEntryGenerator method generateEntries.
// TODO This whole mishmash of different flavors of progress bars, and
// Cancelables/Stoppables/Pausables is a mess. We shouldn't be using
// the type hierarchy to fiddle this stuff. Instead we should have a
// single interface for control of a background operation, subsuming
// all of Cancelable, Stoppable and Pausable, and a single ProgressBar
// type that takes a bunch of flags indicating what buttons it should
// display.
public void generateEntries(String goal, ITermSimilarity alg, Cancelable cancelable, Stoppable stoppable, boolean computeAll, List<String> computeErrors, ProgressCallback progressCallback) {
// TODO figure out how to deal with this for real, long term
// goal = clean(goal);
ISimilarityDictionary dict = (ISimilarityDictionary) design.getAttribute(WidgetAttributes.DICTIONARY_ATTR);
if (NullSafe.equals(dict, WidgetAttributes.NO_DICTIONARY)) {
dict = new SimilarityDictionary();
design.setAttribute(WidgetAttributes.DICTIONARY_ATTR, dict);
}
int initialSize = dict.size();
ITermSimilarity.Continuable cont = new ITermSimilarity.Continuable(cancelable, stoppable);
Iterator<Frame> frames = design.getFrames().iterator();
while (frames.hasNext() && cont.isContinuing()) {
Frame f = frames.next();
generateOneEntry(f.getSpeakerText(), goal, alg, cont, dict, computeAll, computeErrors, progressCallback);
Set<SimpleWidgetGroup> swGrps = new HashSet<SimpleWidgetGroup>();
Iterator<IWidget> widgets = f.getWidgets().iterator();
while (widgets.hasNext() && cont.isContinuing()) {
IWidget w = widgets.next();
generateOneEntry(w.getTitle(), goal, alg, cont, dict, computeAll, computeErrors, progressCallback);
if (!cont.isContinuing()) {
break;
}
generateOneEntry(w.getTextualCue(), goal, alg, cont, dict, computeAll, computeErrors, progressCallback);
SimpleWidgetGroup swg = w.getParentGroup();
if (swg != null) {
swGrps.add(swg);
}
}
Iterator<FrameElementGroup> groups = f.getEltGroups().iterator();
while (groups.hasNext() && cont.isContinuing()) {
generateOneEntry(groups.next().getTextualCue(), goal, alg, cont, dict, computeAll, computeErrors, progressCallback);
}
Iterator<SimpleWidgetGroup> swgIter = swGrps.iterator();
while (swgIter.hasNext() && cont.isContinuing()) {
generateOneEntry(swgIter.next().getTextualCue(), goal, alg, cont, dict, computeAll, computeErrors, progressCallback);
}
}
if (stoppable.isStopped()) {
// Clean out the last entry if we were stopped, as it may not be
// correct. But only if we've added something.
int n = dict.size();
if (n > initialSize) {
dict.removeEntry(n - 1);
}
}
}
use of edu.cmu.cs.hcii.cogtool.model.FrameElementGroup in project cogtool by cogtool.
the class FrameEditorController method createGroupElementsAction.
private IListenerAction createGroupElementsAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return FrameEditorSelectionState.class;
}
public boolean performAction(Object prms) {
FrameEditorSelectionState selection = (FrameEditorSelectionState) prms;
int selectedEltCount = selection.getElementSelectionCount();
if (selectedEltCount > 1) {
final FrameElementGroup newGroup = new FrameElementGroup();
assignUniqueEltGroupName(newGroup);
Iterator<FrameElement> selectedElts = selection.getSelectedElementsIterator();
while (selectedElts.hasNext()) {
FrameElement rootElt = selectedElts.next().getRootElement();
// that the element is a member of the group
if (!newGroup.contains(rootElt)) {
newGroup.add(rootElt);
}
}
model.addEltGroup(newGroup);
IUndoableEdit edit = new AUndoableEdit(FrameEditorLID.Group) {
@Override
public String getPresentationName() {
return GROUP_ELEMENTS;
}
@Override
public void redo() {
super.redo();
Iterator<FrameElement> groupElts = newGroup.iterator();
// back to the frame
while (groupElts.hasNext()) {
groupElts.next().addToEltGroup(newGroup);
}
model.addEltGroup(newGroup);
}
@Override
public void undo() {
super.undo();
model.removeEltGroup(newGroup);
Iterator<FrameElement> groupElts = newGroup.iterator();
// association from the element.
while (groupElts.hasNext()) {
groupElts.next().removeFromEltGroup(newGroup);
}
}
};
undoMgr.addEdit(edit);
return true;
}
if (selectedEltCount == 1) {
interaction.protestTooFewWidgets();
} else {
interaction.protestNoSelection();
}
return false;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.FrameElementGroup in project cogtool by cogtool.
the class FrameEditorController method deleteGroupMember.
private void deleteGroupMember(FrameElement elt, FrameElementGroup fromGroup, IUndoableEditSequence editSequence) {
if (elt instanceof IWidget) {
deleteWidget((IWidget) elt, false, fromGroup, editSequence);
} else if (elt instanceof FrameElementGroup) {
deleteFrameEltGroup((FrameElementGroup) elt, fromGroup, editSequence);
} else if (elt instanceof SimpleWidgetGroup) {
SimpleWidgetGroup parentGroup = (SimpleWidgetGroup) elt;
while (parentGroup.size() > 0) {
IWidget child = parentGroup.get(0);
// If the widget group is itself a remote label owner,
// its remote label will be deleted in the first call here.
deleteWidget(child, false, fromGroup, editSequence);
}
}
}
Aggregations