use of edu.cmu.cs.hcii.cogtool.model.IWidget in project cogtool by cogtool.
the class FrameEditorUI method addFrameWidgetHandler.
/**
* Registers a listener that adjusts selection state in response to
* widget additions or removals
*/
protected void addFrameWidgetHandler() {
AlertHandler frameWidgetHandler = new AlertHandler() {
public void handleAlert(EventObject alert) {
Frame.WidgetChange chg = (Frame.WidgetChange) alert;
IWidget chgWidget = chg.getChangeElement();
if (chg != null) {
// Check what action was performed
switch(chg.action) {
// Switch the selection to the newly-added widget
case Frame.WidgetChange.ELEMENT_ADD:
{
GraphicalWidget<?> gw = frameUI.getWidgetFigure(chgWidget);
gw.addChangeHandler(widgetChangeHandler, Widget.WidgetChange.class);
gw.addChangeHandler(widgetChangeHandler, IAttributed.AttributeChange.class);
gw.addChangeHandler(widgetChangeHandler, IAttributed.AuthorityChange.class);
delayedWidgetSelection.addToSelection(chgWidget, gw);
view.requestRename();
break;
}
// Reflect the change in selection state
case Frame.WidgetChange.ELEMENT_DELETE:
{
// Cannot depend on the frameUI to have removed
// this widget's graphical version.
// Call deselect with the model itself.
selection.deselectElement(chgWidget);
delayedWidgetSelection.removeFromSelection(chgWidget);
// call to clean up any resize handles.
delayedRepainting.requestRepaint(REPAINT_SELECT_HANDLES);
break;
}
}
}
}
};
frame.addHandler(this, Frame.WidgetChange.class, frameWidgetHandler);
AlertHandler frameEltHandler = new AlertHandler() {
public void handleAlert(EventObject alert) {
delayedRepainting.requestRepaint(REPAINT_SELECT_HANDLES);
}
};
// Do the above for both widget and association changes!
frame.addHandler(this, Frame.ElementChange.class, frameEltHandler);
AlertHandler frameAssocHandler = new AlertHandler() {
public void handleAlert(EventObject alert) {
Frame.FrameEltGrpChange chg = (Frame.FrameEltGrpChange) alert;
if (chg.action == Frame.FrameEltGrpChange.ELEMENT_DELETE) {
selection.deselectElement(chg.getChangeElement());
} else if (chg.action == Frame.FrameEltGrpChange.ELEMENT_ADD) {
selection.setSelectedSelnFig(uiModel.getGroupHalo(chg.getChangeElement()));
}
}
};
frame.addHandler(this, Frame.FrameEltGrpChange.class, frameAssocHandler);
}
use of edu.cmu.cs.hcii.cogtool.model.IWidget in project cogtool by cogtool.
the class FrameEditorUI method updateView.
/**
* Update the visual contents based on the selected widgets.
*/
public void updateView() {
int selectionCount = selection.getElementSelectionCount();
// text boxes and pull downs with values.
if (selectionCount == 1) {
// preserve selected state if a whole text field is selected
Text text = WindowUtil.getFocusedText();
boolean restoreSel = false;
if ((text != null) && (text.getSelectionCount() == text.getCharCount())) {
restoreSel = true;
}
// get the selected item
Iterator<FrameElement> iter = selection.getSelectedElementsIterator();
// For each selected object, which there is only one.
FrameElement elt = iter.next();
if (elt instanceof IWidget) {
IWidget widget = (IWidget) elt;
view.useParameters(FrameEditorView.USE_SINGLE_SELECT);
view.updateWidgetProperties(widget);
} else if (elt instanceof FrameElementGroup) {
FrameElementGroup eltGroup = (FrameElementGroup) elt;
view.useParameters(FrameEditorView.USE_GROUP_SELECT);
view.updateEltGroupProperties(eltGroup);
}
// Restore the selection state
if (restoreSel) {
text.selectAll();
}
} else if (selectionCount > 1) {
// TODO: on multi selection, some values are left enabled
// We need to set these to something or disable them.
view.useParameters(FrameEditorView.USE_MULTI_SELECT);
} else {
view.useParameters(FrameEditorView.USE_NONE);
view.updateFrameProperties(frame, false);
}
}
use of edu.cmu.cs.hcii.cogtool.model.IWidget in project cogtool by cogtool.
the class FrameEditorUI method setUpDropImageSupport.
protected void setUpDropImageSupport(final Canvas editorSubstrate) {
ExternalImageDropTarget dropTarget = new ExternalImageDropTarget() {
protected GraphicalWidget<?> dropTargetWidget = null;
@Override
protected void cancelHighlight(DropTargetEvent evt) {
if (dropTargetWidget != null) {
dropTargetWidget.dynamicHighlight(false);
}
}
@Override
protected void highlight(DropTargetEvent evt) {
org.eclipse.swt.graphics.Point pt = editorSubstrate.toControl(evt.x, evt.y);
GraphicalWidget<?> widgetFig = widgetLocatedAtXY(pt.x, pt.y);
if (dropTargetWidget != widgetFig) {
cancelHighlight(evt);
if (widgetFig != null) {
widgetFig.dynamicHighlight(true);
}
dropTargetWidget = widgetFig;
}
}
@Override
protected Object buildParameters(DropTargetEvent evt, byte[] imgData) {
org.eclipse.swt.graphics.Point pt = editorSubstrate.toControl(evt.x, evt.y);
GraphicalWidget<?> widgetFig = widgetLocatedAtXY(pt.x, pt.y);
IWidget selectedWidget = (widgetFig != null) ? widgetFig.getModel() : null;
return new FrameEditorUI.CopyImageAsBackgroundParms(imgData, selectedWidget);
}
};
setUpDropImage(editorSubstrate, dropTarget);
}
Aggregations