use of edu.cmu.cs.hcii.cogtool.uimodel.GraphicalWidget in project cogtool by cogtool.
the class FrameEditorMouseState method dynamicResizeWidgets.
/**
* Utility to help with dynamic resize of selected widgets.
*
* @param selectedWFs the set of selected graphical widget figures
* @param currentScaledX scaled X location of the current mouse position
* @param currentScaledY scaled Y location of the current mouse position
* @author mlh/alex
*/
protected void dynamicResizeWidgets(Iterator<FrameEltSelnFig<?>> selectedWFs, double currentScaledX, double currentScaledY) {
// an origin less then 0.0,0.0
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 newWidth = Math.abs(currentScaledX - mouseFixedResizeX);
double newHeight = Math.abs(currentScaledY - mouseFixedResizeY);
double newLeft = Math.min(currentScaledX, mouseFixedResizeX);
double newTop = Math.min(currentScaledY, mouseFixedResizeY);
double ratioX = newWidth / initialResizeArea.width;
double ratioY = newHeight / initialResizeArea.height;
// Iterate through selected widgets
while (selectedWFs.hasNext()) {
FrameEltSelnFig<?> f = selectedWFs.next();
if (f instanceof GraphicalWidget<?>) {
GraphicalWidget<?> gw = (GraphicalWidget<?>) f;
IWidget w = gw.getModel();
SimpleWidgetGroup group = w.getParentGroup();
if ((w instanceof TraversableWidget) && (group != null)) {
dynamicResizeGroup(group, ratioX, ratioY, newLeft, newTop, false);
} else {
dynamicResizeWidget(w, gw, ratioX, ratioY, newLeft, newTop);
}
} else if (f instanceof FrameEltGroupHalo) {
dynamicResizeGroup(((FrameEltGroupHalo) f).getModel(), ratioX, ratioY, newLeft, newTop, true);
}
}
}
use of edu.cmu.cs.hcii.cogtool.uimodel.GraphicalWidget 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.uimodel.GraphicalWidget 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