use of edu.cmu.cs.hcii.cogtool.model.DoublePoint in project cogtool by cogtool.
the class FrameEditorMouseState method dealWithMouseDragged.
/**
* Parameterized mouse drags so they can be scaled programatically.
*
* Handles mouse drags: moves the viewable area as needed
*
* @param figure ignored
* @param mouseX the location the mouse is pointing to
* @param mouseY the location the mouse is pointing to
* @param button the buttons pressed
* @param state the modifiers being held down
*/
@Override
protected boolean dealWithMouseDragged(IFigure figure, int button, int mouseX, int mouseY, int state) {
boolean goForward = super.dealWithMouseDragged(figure, button, mouseX, mouseY, state);
if (goForward && isMouseDownValid) {
// Get the StandardEditor for handling visuals & scrolling
StandardDrawingEditor editor = ui.getViewEditor();
// Update VIEW to ensure mouse point is visible.
// If outside of the visible canvas, up-click should cancel!
stopMouseDragTimer = true;
stopDynamic = editor.movePointNearEdge(mouseX, mouseY, updateDelta);
double zoom = ui.getZoom();
// The current mouse down position (scaled)
double currentScaledX = mouseX / zoom;
double currentScaledY = mouseY / zoom;
Iterator<FrameEltSelnFig<?>> selectedEltFigs = selection.getSelectedFigures();
InteractionFigure drawLayer = ui.getViewEditor().getInteractionFigure();
// Else this is a new widget
switch(getMouseState()) {
// Perform move-related states
case PotentialMovingWidget:
case PotentialMovingSelection:
{
if (withinHysteresis(mouseX, mouseY)) {
return true;
}
ui.hideNondynamicSupport(false);
prevCursor = drawLayer.getCursor();
drawLayer.setCursor(SELECT_CURSOR);
setMouseState(MovingWidgets);
// fall through!
}
case MovingWidgets:
{
dynamicMoveWidgets(selectedEltFigs, currentScaledX, currentScaledY);
ui.repaintEditor();
break;
}
case PotentialReorderWidget:
{
if (withinHysteresis(mouseX, mouseY)) {
return true;
}
prevCursor = drawLayer.getCursor();
ui.hideNondynamicSupport(false, false);
setUpReorderFigures();
prevCursor = drawLayer.getCursor();
drawLayer.setCursor(SELECT_CURSOR);
setMouseState(ReorderWidget);
// fall through!
}
case ReorderWidget:
{
dynamicReorderWidget(mouseX, mouseY, false);
break;
}
case PotentialResizingWidget:
{
if (withinHysteresis(mouseX, mouseY)) {
return true;
}
ui.hideNondynamicSupport(true);
// Iterate through selected widgets XYZZY openChildren in a loop???
while (selectedEltFigs.hasNext()) {
FrameEltSelnFig<?> gw = selectedEltFigs.next();
if (gw instanceof GraphicalTraversableWidget<?>) {
if (gw instanceof GraphicalChildWidget<?, ?>) {
((GraphicalChildWidget<?, ?>) gw).getParentFigure().openChildren();
}
}
}
setMouseState(ResizingWidget);
// fall through!
}
// Perform a drag resize of selected widget
case ResizingWidget:
{
dynamicResizeWidgets(selectedEltFigs, currentScaledX, currentScaledY);
ui.repaintEditor();
break;
}
// Create a new widget
case PotentialCreatingWidget:
{
if (withinHysteresis(mouseX, mouseY)) {
return true;
}
setMouseState(CreatingWidget);
// fall through!
}
case CreatingWidget:
{
redrawTemporaryWidget(currentScaledX, currentScaledY, false);
break;
}
// Sweeping a region for toggling selection
case PotentialTogglingSelection:
{
if (withinHysteresis(mouseX, mouseY)) {
return true;
}
setMouseState(TogglingSelection);
// fall through!
}
case TogglingSelection:
{
redrawTemporaryWidget(currentScaledX, currentScaledY, true);
break;
}
case PotentialDuplicatingWidget:
{
if (withinHysteresis(mouseX, mouseY)) {
return true;
}
ui.hideNondynamicSupport(false, false);
duplicatingDynamic = new ArrayList<RectangleFigure>();
Iterator<FrameEltSelnFig<?>> selectedFigs = selection.getSelectedFigures();
while (selectedFigs.hasNext()) {
FrameEltSelnFig<?> currFig = selectedFigs.next();
if (currFig instanceof FrameEltGroupHalo) {
showSelectionArea(new RectangleFigure(), currFig.getBounds());
} else if (!(currFig instanceof GraphicalChildWidget<?, ?>)) {
Rectangle widgetBds = new Rectangle(currFig.getBounds());
// Must scale widget figure's bounds to zoom factor
widgetBds.height = PrecisionUtilities.round(widgetBds.height * zoom);
widgetBds.width = PrecisionUtilities.round(widgetBds.width * zoom);
widgetBds.x = PrecisionUtilities.round(widgetBds.x * zoom);
widgetBds.y = PrecisionUtilities.round(widgetBds.y * zoom);
//display the new rectangle object
showSelectionArea(new RectangleFigure(), widgetBds);
}
}
setMouseState(DuplicatingWidgets);
// fall through!
}
case DuplicatingWidgets:
{
updateDynamicDuplicate(mouseX, mouseY);
break;
}
case PotentialInsertDuplicateWidget:
{
if (withinHysteresis(mouseX, mouseY)) {
return true;
}
ui.hideNondynamicSupport(false, false);
prevCursor = drawLayer.getCursor();
setUpReorderFigures();
prevCursor = drawLayer.getCursor();
drawLayer.setCursor(DRAW_CURSOR);
setMouseState(InsertDuplicateWidget);
// fall through!
}
case InsertDuplicateWidget:
{
dynamicReorderWidget(mouseX, mouseY, true);
break;
}
case PotentialMovingGridButtons:
{
if (withinHysteresis(mouseX, mouseY)) {
return true;
}
GraphicalWidget<?> gw = ui.getPotentialFigureOwner();
GridButton owner = (GridButton) gw.getModel();
DoublePoint start = owner.getShape().getOrigin();
GridButtonGroup gbg = (GridButtonGroup) owner.getParentGroup();
movedGridButtons = gbg.getMovedButtons(moveIsVertical, start.x, start.y);
minX = start.x - owner.getHorizSpace();
minY = start.y - owner.getVertSpace();
prevCursor = drawLayer.getCursor();
if (moveIsVertical) {
drawLayer.setCursor(MOVE_VERT_CURSOR);
} else {
drawLayer.setCursor(MOVE_HORIZ_CURSOR);
}
setMouseState(MovingGridButtons);
// fall through!
}
case MovingGridButtons:
{
dynamicMoveGridButtons(currentScaledX, currentScaledY);
break;
}
}
// Repeating timer for causing events to repeat.
if ((updateDelta.x != 0) || (updateDelta.y != 0)) {
if (rootFigure == null) {
rootFigure = ui.getViewEditor().getInteractionFigure();
}
stopMouseDragTimer = false;
// Determine the new point the mouse "moved" too.
mouseDragTask.setNextMousePosition(mouseX + updateDelta.x, mouseY + updateDelta.y, button, state);
// Queue the event for 0.1 sec.
WindowUtil.GLOBAL_DISPLAY.timerExec(100, mouseDragTask);
}
}
lastX = mouseX;
lastY = mouseY;
updateDynamic();
return goForward;
}
use of edu.cmu.cs.hcii.cogtool.model.DoublePoint in project cogtool by cogtool.
the class DesignEditorController method createPasteAction.
protected IListenerAction createPasteAction() {
return new AListenerAction() {
public boolean performAction(Object prms) {
try {
Collection<Object> objects = CogToolClipboard.fetchCogToolObjects();
if ((objects != null) && (objects.size() > 0)) {
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(L10N.get("UNDO.Paste", "Paste"), DesignEditorLID.Paste);
Set<DeviceType> devTypes = design.getDeviceTypes();
int numPasted = 0;
Iterator<Object> objIt = objects.iterator();
while (objIt.hasNext()) {
Object o = objIt.next();
if (o instanceof Frame) {
Frame frame = (Frame) o;
makeFrameNameUnique(frame);
// Find an unoccupied starting position
// by cascading.
DoublePoint origin = frame.getFrameOrigin();
DesignUtil.findDistinctOrigin(design, origin, 16.0, 16.0);
// Union devices
Iterator<InputDevice> frameDevices = frame.getInputDevices().iterator();
while (frameDevices.hasNext()) {
InputDevice inputDevice = frameDevices.next();
DeviceType devType = inputDevice.getDeviceType();
if (!devTypes.contains(devType)) {
DesignCmd.addDevice(design, devType);
}
}
Iterator<DeviceType> designDevTypes = devTypes.iterator();
while (designDevTypes.hasNext()) {
DeviceType devType = designDevTypes.next();
if (frame.getInputDevice(devType) == null) {
frame.addInputDevice(devType);
}
}
addFrame(frame, editSequence);
numPasted++;
} else if (o instanceof Transition) {
Transition t = (Transition) o;
DeviceType device = t.getAction().getDefaultDeviceType();
if (!devTypes.contains(device)) {
DesignCmd.addDevice(design, device);
}
IUndoableEdit edit = DesignEditorCmd.addTransition(demoStateMgr, t);
editSequence.addEdit(edit);
numPasted++;
}
}
editSequence.end();
undoMgr.addEdit(editSequence);
interaction.setStatusMessage(numPasted + " " + pasteComplete);
} 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 true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.DoublePoint in project cogtool by cogtool.
the class FrameEditorController method deleteWidget.
/**
* This deletes a widget from the model and adds the action to the undo list.
*
* @param w is the widget to delete.
* @param moveSiblings is a flag - if it is true, the other widgets in the
* group will be moved to close up the space left by the deleted widget.
* @param editSequence is the compound edit to add this delete operation to.
*/
private void deleteWidget(IWidget w, boolean moveSiblings, FrameElementGroup fromGroup, IUndoableEditSequence editSequence) {
// If this is a remote label, delete the attribute indicating so
// from the point of view of its owner.
FrameElement remoteLabelOwner = (FrameElement) w.getAttribute(WidgetAttributes.REMOTE_LABEL_OWNER_ATTR);
if (remoteLabelOwner != null) {
DefaultCmd.unsetAttribute(remoteLabelOwner, demoStateMgr, WidgetAttributes.REMOTE_LABEL_ATTR, interaction, editSequence);
} else {
// Check if this widget is a remote label owner; if so, delete
// the remote label as well
deleteRemoteLabel(w, editSequence);
}
SimpleWidgetGroup parentGroup = w.getParentGroup();
int atIndex = (parentGroup != null) ? parentGroup.indexOf(w) : -1;
double deltaX = 0;
double deltaY = 0;
// since we know every item in them will be deleted.
if (w instanceof AParentWidget) {
AParentWidget pw = (AParentWidget) w;
while (pw.itemCount() > 0) {
deleteWidget(pw.getItem(0), false, fromGroup, editSequence);
}
}
// If the widget is the last object of the its root element,
// then the root element must be removed from any containing groups
// and, if the root element is the second to last member of any
// group, then the group should be removed as well.
// This must be done before the removeWidget call.
FrameElement rootElt = w.getRootElement();
// containing associations
if (rootElt == w) {
removeRootElement(DELETE_WIDGET, rootElt, fromGroup, editSequence);
} else if (rootElt instanceof SimpleWidgetGroup) {
// Otherwise, need to do the same only if the root element
// is a widget group that will become empty.
SimpleWidgetGroup rootGroup = (SimpleWidgetGroup) rootElt;
// remove it from containing associations
if (rootGroup.size() == 1) {
removeRootElement(DELETE_WIDGET, rootElt, fromGroup, editSequence);
}
}
model.removeWidget(w);
if (parentGroup != null) {
// Check if this parent group is a remote label owner; if so, delete
// the remote label as well
deleteRemoteLabel(parentGroup, editSequence);
if (moveSiblings) {
int myGroupNum = parentGroup.size();
if (parentGroup.getOrientation() == SimpleWidgetGroup.HORIZONTAL) {
deltaX = -w.getEltBounds().width;
} else if (parentGroup.getOrientation() == SimpleWidgetGroup.VERTICAL) {
deltaY = -w.getEltBounds().height;
}
// This loop will be ineffective for grid buttons
for (int i = atIndex + 1; i < myGroupNum; i++) {
IWidget curWidget = parentGroup.get(i);
curWidget.moveElement(deltaX, deltaY);
}
}
// Otherwise, remove it from its parent group.
if (w instanceof ChildWidget) {
ChildWidget child = (ChildWidget) w;
AParentWidget itemParent = child.getParent();
itemParent.removeItem(child);
} else {
parentGroup.remove(w);
}
if (parentGroup instanceof GridButtonGroup) {
GridButtonGroup gbg = (GridButtonGroup) parentGroup;
GridButton gb = (GridButton) w;
DoubleRectangle b = w.getEltBounds();
double x = b.x + b.width;
double y = b.y + b.height;
double newHoriz = gb.getHorizSpace();
double newVert = gb.getVertSpace();
ReadOnlyList<GridButton> movedButtons = null;
GridButton top = null;
double dx = 0.0;
double dy = 0.0;
if (gbg.getColumn(gb).size() == 0) {
// w was the only widget in the column; need to move next
// column over
movedButtons = gbg.getMovedButtons(false, x, b.y);
if (movedButtons.size() > 0) {
top = movedButtons.get(0);
DoublePoint p = top.getShape().getOrigin();
dx = b.x - p.x;
}
} else {
// need to move lower widgets up to fill the hole
movedButtons = gbg.getMovedButtons(true, b.x, y);
if (movedButtons.size() > 0) {
top = movedButtons.get(0);
DoublePoint p = top.getShape().getOrigin();
dy = b.y - p.y;
}
}
if (top != null) {
moveGridButton(FrameEditorLID.Delete, DELETE_WIDGET, top, dx, dy, newHoriz, newVert, editSequence);
}
}
}
DemoStateManager.IDesignUndoableEdit edit;
// Add the deletion to the undoable history
if (w instanceof ChildWidget) {
ChildWidget child = (ChildWidget) w;
final AParentWidget itemParent = child.getParent();
edit = new DeleteWidgetUndoableEdit(w, parentGroup, atIndex, deltaX, deltaY) {
@Override
public void redoHelper() {
itemParent.removeItem((ChildWidget) widget);
}
@Override
public void undoHelper() {
itemParent.addItem(atIndex, (ChildWidget) widget);
}
};
} else {
edit = new DeleteWidgetUndoableEdit(w, parentGroup, atIndex, deltaX, deltaY) {
@Override
public void redoHelper() {
parentGroup.remove(widget);
}
@Override
public void undoHelper() {
parentGroup.add(atIndex, widget);
}
};
}
demoStateMgr.noteWidgetEdit(w, edit);
editSequence.addEdit(edit);
}
use of edu.cmu.cs.hcii.cogtool.model.DoublePoint in project cogtool by cogtool.
the class FrameEditorController method moveGridButtonsEdit.
// moveWidgetGroup
private IDesignUndoableEdit moveGridButtonsEdit(ListenerIdentifier lid, final String presentationLabel, final ReadOnlyList<? extends GridButton> movedButtons, final double widgetMoveByX, final double widgetMoveByY, final double oldHoriz, final double oldVert, final double newHoriz, final double newVert, final GridButton gb) {
final GridButtonGroup gbg = (GridButtonGroup) gb.getParentGroup();
DemoStateManager.ObsoletingEdit edit = new DemoStateManager.ObsoletingEdit(lid, demoStateMgr) {
@Override
public String getPresentationName() {
return presentationLabel;
}
@Override
public void redo() {
super.redo();
for (int i = 0; i < movedButtons.size(); i++) {
GridButton g = movedButtons.get(i);
DoublePoint p = g.getShape().getOrigin();
double tempX = Math.max(p.x + widgetMoveByX, 0.0);
double tempY = Math.max(p.y + widgetMoveByY, 0.0);
g.setWidgetOrigin(tempX, tempY);
}
if (widgetMoveByX == 0) {
gb.setVertSpace(newVert);
} else {
List<GridButton> column = gbg.getColumn(gb);
for (int i = 0; i < column.size(); i++) {
GridButton g = column.get(i);
g.setHorizSpace(newHoriz);
}
}
noteEditCheckRegenerate(movedButtons, this);
}
@Override
public void undo() {
super.undo();
for (int i = 0; i < movedButtons.size(); i++) {
GridButton g = movedButtons.get(i);
DoublePoint p = g.getShape().getOrigin();
double tempX = Math.max(p.x - widgetMoveByX, 0.0);
double tempY = Math.max(p.y - widgetMoveByY, 0.0);
g.setWidgetOrigin(tempX, tempY);
}
if (widgetMoveByX == 0) {
gb.setVertSpace(oldVert);
} else {
List<GridButton> column = gbg.getColumn(gb);
for (int i = 0; i < column.size(); i++) {
GridButton g = column.get(i);
g.setHorizSpace(oldHoriz);
}
}
noteEditCheckRegenerate(movedButtons, this);
}
};
noteEditCheckRegenerate(movedButtons, edit);
return edit;
}
use of edu.cmu.cs.hcii.cogtool.model.DoublePoint in project cogtool by cogtool.
the class DesignEditorCmd method repositionChildren.
public static void repositionChildren(SimpleWidgetGroup group) {
if (group.size() > 0) {
DoublePoint startPos = group.get(0).getShape().getOrigin();
repositionChildren(group, startPos.x, startPos.y);
}
}
Aggregations