Computational "Auto Size" of node images [message #1820612] |
Thu, 23 January 2020 21:33 |
Bernhard Edler Messages: 6 Registered: August 2014 |
Junior Member |
|
|
My Goal: I wish to have nodes in a container, the container being resizable. The nodes should be displayed as images with fixed size, but should still be movable within the container. Edit: I failed to mention, the images should depend on model properties, and I dont want to have dozens of conditional styles that need maintaining in my .odesign file.
My status quo: The nodes are fixed in size(resize disabled, move still allowed), the correct Images are loaded.
My problem: The Images I wish are 100 by 100 px, yet when I create a new node using the palette tool I defined in my .odesign-file, the node is only 20 by 20px in size (In the attached image, see the violet "T"-shape in the left container). Since resizing is disabled, I have to manually hit "Auto Size" from the toolbar to have it correctly displayed (like the rightmost image).
Is there a way to programmatically "autosize" the image upon creation? Or better, a way to have the images created correctly sized in the first place?
A few samples of what I did, hopefully insightful:
public class StyleEditPartProvider extends AbstractEditPartProvider {
@Override
protected Class getNodeEditPartClass(View view) {
if (view.getElement() instanceof CustomStyle) {
CustomStyle customStyle = (CustomStyle) view.getElement();
if (customStyle.getId().equals(AnlageStyleEditPart.ID)) {
return AnlageStyleEditPart.class;
}
}
}
}
public class AnlageStyleEditPart extends AbstractNotSelectableShapeNodeEditPart implements IStyleEditPart {
public static final String ID = "at.tb_gruber.designer.design.style.AnlageStyle";
protected IFigure contentPane;
protected ImageFigure primaryShape;
public AnlageStyleEditPart(View view) {
super(view);
// here my model listeners are registert via addListenerFilter(...)
}
private NodeFigure createNodePlate() {
DefaultSizeNodeFigure result = new AirStyleDefaultSizeNodeFigure(100, 100);
return result;
}
public ImageFigure getPrimaryShape() {
if (primaryShape == null) {
primaryShape = new ImageFigure();
}
return primaryShape;
}
/**
* react to model changes from the properties view
* @generated NOT
*/
@Override
public void notifyChanged(Notification notification) {
refreshVisuals();
super.notifyChanged(notification);
}
protected void refreshVisuals() {
Optional<Image> imageOpt = getImage();
if (imageOpt.isPresent()) {
Image image = imageOpt.get();
image.getBounds();
getPrimaryShape().setImage(image);
}
}
private Optional<Image> getImage() {
//loads the correct image from my images-folder depending on model properties
}
}
public class EditPolicyProvider implements IEditPolicyProvider {
@Override
public void createEditPolicies(EditPart editPart) {
if (editPart instanceof DNodeContainerViewNodeContainerCompartmentEditPart) {
editPart.removeEditPolicy(EditPolicy.LAYOUT_ROLE);
editPart.installEditPolicy(EditPolicy.LAYOUT_ROLE, new FixedSizeContainerEditPolicy());
}
}
}
public class FixedSizeContainerEditPolicy extends AirXYLayoutEditPolicy {
@Override
protected Command getResizeChildrenCommand(ChangeBoundsRequest request) {
if (isResize(request)) {
return DoNothingCommand.INSTANCE;
}
Command superCommand = super.getResizeChildrenCommand(request);
EditPart host = getHost();
if (host instanceof IGraphicalEditPart) {
TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) host).getEditingDomain();
CompositeTransactionalCommand ctc = new CompositeTransactionalCommand(editingDomain,
superCommand.getLabel());
ctc.add(new CommandProxy(superCommand));
ShiftEdgeIdentityAnchorOperation operation = new ShiftEdgeIdentityAnchorOperation(request);
ICommand command = CommandFactory.createICommand(editingDomain, operation);
ctc.add(command);
return new ICommandProxy(ctc);
}
return superCommand;
}
private boolean isResize(ChangeBoundsRequest request) {
return request.getSizeDelta().height != 0 || request.getSizeDelta().width != 0;
}
}
-
Attachment: editor.png
(Size: 40.51KB, Downloaded 60 times)
[Updated on: Fri, 24 January 2020 06:22] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.01903 seconds