Package org.eclipse.gef.examples.logicdesigner.model

Examples of org.eclipse.gef.examples.logicdesigner.model.LogicSubpart


  for(int i = 0; i < editparts.size(); i++){
    EditPart child = (EditPart)editparts.get(i);
    if(isAncestor(child,getHost()))
      command.add(UnexecutableCommand.INSTANCE);
    else {
      LogicSubpart childModel = (LogicSubpart)child.getModel();
      command.add(createCreateCommand(
            childModel,
            new Rectangle(new org.eclipse.draw2d.geometry.Point(),
              childModel.getSize()),
            index, "Reparent LogicSubpart"));//$NON-NLS-1$
    }
  }
  return command;
}
View Full Code Here


  }
  return command;
}

protected Command getCreateCommand(CreateRequest request){
  LogicSubpart child = (LogicSubpart)request.getNewObject();
  int index = findIndexOfTreeItemAt(request.getLocation());
  return createCreateCommand(child, null, index, "Create LogicSubpart");//$NON-NLS-1$
}
View Full Code Here

  policy.setResizeDirections(0);
  return policy;
}

protected Command createMoveChildCommand(EditPart child, EditPart after) {
  LogicSubpart childModel = (LogicSubpart)child.getModel();
  LogicDiagram parentModel = (LogicDiagram)getHost().getModel();
  int oldIndex = getHost().getChildren().indexOf(child);
  int newIndex = getHost().getChildren().indexOf(after);
  if (newIndex > oldIndex)
    newIndex--;
View Full Code Here

  return result;
}

protected Command createAddCommand(Request request, EditPart childEditPart,
    Object constraint) {
  LogicSubpart part = (LogicSubpart)childEditPart.getModel();
  Rectangle rect = (Rectangle)constraint;

  AddCommand add = new AddCommand();
  add.setParent((LogicDiagram)getHost().getModel());
  add.setChild(part);
View Full Code Here

}

protected Command createChangeConstraintCommand(ChangeBoundsRequest request,
                                                EditPart child, Object constraint) {
  SetConstraintCommand cmd = new SetConstraintCommand();
  LogicSubpart part = (LogicSubpart)child.getModel();
  cmd.setPart(part);
  cmd.setLocation((Rectangle)constraint);
  Command result = cmd;

  if ((request.getResizeDirection() & PositionConstants.NORTH_SOUTH) != 0) {
    Integer guidePos = (Integer)request.getExtendedData()
        .get(SnapToGuides.KEY_HORIZONTAL_GUIDE);
    if (guidePos != null) {
      result = chainGuideAttachmentCommand(request, part, result, true);
    } else if (part.getHorizontalGuide() != null) {
      // SnapToGuides didn't provide a horizontal guide, but this part is attached
      // to a horizontal guide.  Now we check to see if the part is attached to
      // the guide along the edge being resized.  If that is the case, we need to
      // detach the part from the guide; otherwise, we leave it alone.
      int alignment = part.getHorizontalGuide().getAlignment(part);
      int edgeBeingResized = 0;
      if ((request.getResizeDirection() & PositionConstants.NORTH) != 0)
        edgeBeingResized = -1;
      else
        edgeBeingResized = 1;
      if (alignment == edgeBeingResized)
        result = result.chain(new ChangeGuideCommand(part, true));
    }
  }
 
  if ((request.getResizeDirection() & PositionConstants.EAST_WEST) != 0) {
    Integer guidePos = (Integer)request.getExtendedData()
        .get(SnapToGuides.KEY_VERTICAL_GUIDE);
    if (guidePos != null) {
      result = chainGuideAttachmentCommand(request, part, result, false);
    } else if (part.getVerticalGuide() != null) {
      int alignment = part.getVerticalGuide().getAlignment(part);
      int edgeBeingResized = 0;
      if ((request.getResizeDirection() & PositionConstants.WEST) != 0)
        edgeBeingResized = -1;
      else
        edgeBeingResized = 1;
View Full Code Here

}

protected Command getCreateCommand(CreateRequest request) {
  CreateCommand create = new CreateCommand();
  create.setParent((LogicDiagram)getHost().getModel());
  LogicSubpart newPart = (LogicSubpart)request.getNewObject();
  create.setChild(newPart);
  Rectangle constraint = (Rectangle)getConstraintFor(request);
  create.setLocation(constraint);
  create.setLabel(LogicMessages.LogicXYLayoutEditPolicy_CreateCommandLabelText);
 
View Full Code Here

}
public void undo() {
  parent.addGuide(guide);
  Iterator iter = oldParts.keySet().iterator();
  while (iter.hasNext()) {
    LogicSubpart part = (LogicSubpart)iter.next();
    guide.attachPart(part, ((Integer)oldParts.get(part)).intValue());
  }
}
View Full Code Here

public void execute() {
  guide.setPosition(guide.getPosition() + pDelta);
  Iterator iter = guide.getParts().iterator();
  while (iter.hasNext()) {
    LogicSubpart part = (LogicSubpart)iter.next();
    Point location = part.getLocation().getCopy();
    if (guide.isHorizontal()) {
      location.y += pDelta;
    } else {
      location.x += pDelta;
    }
    part.setLocation(location);
  }
}
View Full Code Here

public void undo() {
  guide.setPosition(guide.getPosition() - pDelta);
  Iterator iter = guide.getParts().iterator();
  while (iter.hasNext()) {
    LogicSubpart part = (LogicSubpart)iter.next();
    Point location = part.getLocation().getCopy();
    if (guide.isHorizontal()) {
      location.y -= pDelta;
    } else {
      location.x -= pDelta;
    }
    part.setLocation(location);
  }
}
View Full Code Here

  indices.put(part, new Integer(index));
}

protected void clonePart(LogicSubpart oldPart, LogicDiagram newParent, Rectangle newBounds,
            List newConnections, Map connectionPartMap, int index) {
  LogicSubpart newPart = null;
 
  if (oldPart instanceof AndGate) {
    newPart = new AndGate();
  } else if (oldPart instanceof Circuit) {
    newPart = new Circuit();
  } else if (oldPart instanceof GroundOutput) {
    newPart = new GroundOutput();
  } else if (oldPart instanceof LED) {
    newPart = new LED();
    newPart.setPropertyValue(LED.P_VALUE, oldPart.getPropertyValue(LED.P_VALUE));
  } else if (oldPart instanceof LiveOutput) {
    newPart = new LiveOutput();
  } else if (oldPart instanceof LogicLabel) {
    newPart = new LogicLabel();
    ((LogicLabel)newPart).setLabelContents(((LogicLabel)oldPart).getLabelContents());
  } else if (oldPart instanceof OrGate) {
    newPart = new OrGate();
  } else if (oldPart instanceof LogicFlowContainer) {
    newPart = new LogicFlowContainer();
  } else if (oldPart instanceof XORGate) {
    newPart = new XORGate();
  }
 
  if (oldPart instanceof LogicDiagram) {
    Iterator i = ((LogicDiagram)oldPart).getChildren().iterator();
    while (i.hasNext()) {
      // for children they will not need new bounds
      clonePart((LogicSubpart)i.next(), (LogicDiagram)newPart, null,
          newConnections, connectionPartMap, -1);
    }
  }
 
  Iterator i = oldPart.getTargetConnections().iterator();
  while (i.hasNext()) {
    Wire connection = (Wire)i.next();
    Wire newConnection = new Wire();
    newConnection.setValue(connection.getValue());
    newConnection.setTarget(newPart);
    newConnection.setTargetTerminal(connection.getTargetTerminal());
    newConnection.setSourceTerminal(connection.getSourceTerminal());
    newConnection.setSource(connection.getSource());
 
    Iterator b = connection.getBendpoints().iterator();
    Vector newBendPoints = new Vector();
   
    while (b.hasNext()) {
      WireBendpoint bendPoint = (WireBendpoint)b.next();
      WireBendpoint newBendPoint = new WireBendpoint();
      newBendPoint.setRelativeDimensions(bendPoint.getFirstRelativeDimension(),
          bendPoint.getSecondRelativeDimension());
      newBendPoint.setWeight(bendPoint.getWeight());
      newBendPoints.add(newBendPoint);
    }
   
    newConnection.setBendpoints(newBendPoints);
    newConnections.add(newConnection);
  }
 
 
  if (index < 0) {
    newParent.addChild(newPart);
  } else {
    newParent.addChild(newPart, index);
  }
 
  newPart.setSize(oldPart.getSize());

 
  if (newBounds != null) {
    newPart.setLocation(newBounds.getTopLeft());
  } else {
    newPart.setLocation(oldPart.getLocation());
  }
 
  // keep track of the new parts so we can delete them in undo
  // keep track of the oldpart -> newpart map so that we can properly attach
  // all connections.
View Full Code Here

TOP

Related Classes of org.eclipse.gef.examples.logicdesigner.model.LogicSubpart

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.