Commit 8e042757 authored by Florian Hölzl's avatar Florian Hölzl

AF3: Component editor allows keyboard movement of sticky ports.

Issue-Ref: 3968
Issue-Url: https://af3-developer.fortiss.org/issues/3968Signed-off-by: Florian Hölzl's avatarFlorian Hoelzl <hoelzl@fortiss.org>
parent e5608adf
ComponentControllerFactory.java 57c48af3d6c2d51a9040a8b754a8b19b73525777 GREEN
ComponentControllerFactory.java a5feb78f57aee4a8206866ef2dc6ca13bb145305 YELLOW
ComponentModelFactory.java 9141373b9498b8e947ef1ca8921128bdf66ec308 GREEN
ComponentStructureFXEditor.java c9016fd1b30ee8ed98cace186615c03ccb894abc GREEN
ComponentStructureFXEditorBinding.java 19ca73be6a4ea974994d26db537329878748b20d GREEN
......
......@@ -15,21 +15,21 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.component.ui.editor.fx;
import org.fortiss.tooling.common.ui.javafx.lwfxef.controller.IController;
import org.fortiss.tooling.common.ui.javafx.lwfxef.controller.IControllerFactory;
import org.fortiss.tooling.common.ui.javafx.lwfxef.mvc.IContentAnchorageMVCBundle;
import org.fortiss.tooling.common.ui.javafx.lwfxef.mvc.IContentMVCBundle;
import org.fortiss.tooling.common.ui.javafx.lwfxef.mvc.IDiagramAnchorageMVCBundle;
import org.fortiss.tooling.common.ui.javafx.lwfxef.mvc.IDiagramMVCBundle;
import org.fortiss.tooling.common.ui.javafx.lwfxef.mvc.ILinkMVCBundle;
import org.fortiss.af3.component.model.Channel;
import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.component.model.Port;
import org.fortiss.af3.component.ui.editor.fx.controller.PortContentAnchorageController;
import org.fortiss.tooling.base.ui.editor.fx.controller.EObjectDiagramController;
import org.fortiss.tooling.base.ui.editor.fx.controller.LayoutedContentAnchorageController;
import org.fortiss.tooling.base.ui.editor.fx.controller.LayoutedDiagramAnchorageController;
import org.fortiss.tooling.base.ui.editor.fx.controller.LayoutedLineLinkBendPointController;
import org.fortiss.tooling.base.ui.editor.fx.controller.LayoutedRectangularResizableContentController;
import org.fortiss.tooling.common.ui.javafx.lwfxef.controller.IController;
import org.fortiss.tooling.common.ui.javafx.lwfxef.controller.IControllerFactory;
import org.fortiss.tooling.common.ui.javafx.lwfxef.mvc.IContentAnchorageMVCBundle;
import org.fortiss.tooling.common.ui.javafx.lwfxef.mvc.IContentMVCBundle;
import org.fortiss.tooling.common.ui.javafx.lwfxef.mvc.IDiagramAnchorageMVCBundle;
import org.fortiss.tooling.common.ui.javafx.lwfxef.mvc.IDiagramMVCBundle;
import org.fortiss.tooling.common.ui.javafx.lwfxef.mvc.ILinkMVCBundle;
/**
* The implementation of the {@link IControllerFactory} for the component editor.
......@@ -53,7 +53,7 @@ public final class ComponentControllerFactory implements IControllerFactory {
/** {@inheritDoc} */
@Override
public IController createContentAnchorageController(IContentAnchorageMVCBundle modelBundle) {
return new LayoutedContentAnchorageController<>(modelBundle, Port.class);
return new PortContentAnchorageController(modelBundle);
}
/** {@inheritDoc} */
......
PortContentAnchorageController.java 39be36e3ff4a4d1d629e9a630b8a7fb96648f426 YELLOW
/*-------------------------------------------------------------------------+
| Copyright 2020 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.component.ui.editor.fx.controller;
import static java.lang.Math.max;
import static java.lang.Math.min;
import static javafx.scene.input.KeyCode.DOWN;
import static javafx.scene.input.KeyCode.LEFT;
import static javafx.scene.input.KeyCode.RIGHT;
import static javafx.scene.input.KeyCode.UP;
import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_CONNECTOR_SIZE;
import static org.fortiss.tooling.base.layout.LayoutKeyConstants.CONNECTOR_OFFSET_ORIENTATION;
import static org.fortiss.tooling.base.model.layout.EOrientation.EAST;
import static org.fortiss.tooling.base.model.layout.EOrientation.NORTH;
import static org.fortiss.tooling.base.model.layout.EOrientation.SOUTH;
import static org.fortiss.tooling.base.model.layout.EOrientation.WEST;
import static org.fortiss.tooling.base.ui.utils.LayoutDataUIUtils.getConnectorOffsetOrientation;
import static org.fortiss.tooling.base.utils.LayoutDataUtils.getNodeBounds;
import static org.fortiss.tooling.base.utils.OffsetOrientationUtils.setOffsetOrientation;
import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.component.model.Port;
import org.fortiss.tooling.base.model.layout.EOrientation;
import org.fortiss.tooling.base.model.layout.OffsetOrientation;
import org.fortiss.tooling.base.model.layout.Rectangle;
import org.fortiss.tooling.base.ui.editor.fx.controller.LayoutedContentAnchorageController;
import org.fortiss.tooling.common.ui.javafx.lwfxef.change.Change;
import org.fortiss.tooling.common.ui.javafx.lwfxef.mvc.IContentAnchorageMVCBundle;
import javafx.scene.input.KeyCode;
/**
* {@link LayoutedContentAnchorageController} for implementing the keyboard move behavior.
*
* @author hoelzl
*/
public class PortContentAnchorageController extends LayoutedContentAnchorageController<Port> {
/** Constructor. */
public PortContentAnchorageController(IContentAnchorageMVCBundle mvcb) {
super(mvcb, Port.class);
}
/** {@inheritDoc} */
@Override
protected Change keyMove(KeyCode code) {
final Component parent = ((Port)getLayoutedME()).getComponent();
final Rectangle bounds = getNodeBounds(parent);
final OffsetOrientation oo = getConnectorOffsetOrientation(getLayoutedME());
final EOrientation orient = oo.getOrientation();
final int offset = oo.getOffset();
final int step = DEFAULT_CONNECTOR_SIZE / 2;
final int maxX = bounds.getWidth() - 2 * step;
final int maxY = bounds.getHeight() - 2 * step;
int newOffset = -1;
EOrientation newOrient = null;
if(orient == NORTH) {
if(code == LEFT && offset > step) {
newOrient = NORTH;
newOffset = max(offset - step, step);
} else if(code == RIGHT && offset < maxX) {
newOrient = NORTH;
newOffset = min(offset + step, maxX);
} else if(code == DOWN) {
newOrient = (offset < maxX - offset) ? WEST : EAST;
newOffset = step;
}
} else if(orient == SOUTH) {
if(code == LEFT && offset > step) {
newOrient = SOUTH;
newOffset = max(offset - step, step);
} else if(code == RIGHT && offset < maxX) {
newOrient = SOUTH;
newOffset = min(offset + step, maxX);
} else if(code == UP) {
newOrient = (offset < maxX - offset) ? WEST : EAST;
newOffset = maxY;
}
} else if(orient == WEST) {
if(code == UP && offset > step) {
newOrient = WEST;
newOffset = max(offset - step, step);
} else if(code == DOWN && offset < maxY) {
newOrient = WEST;
newOffset = min(offset + step, maxY);
} else if(code == RIGHT) {
newOrient = (offset < maxY - offset) ? NORTH : SOUTH;
newOffset = step;
}
} else if(orient == EAST) {
if(code == UP && offset > step) {
newOrient = EAST;
newOffset = max(offset - step, step);
} else if(code == DOWN && offset < maxY) {
newOrient = EAST;
newOffset = min(offset + step, maxY);
} else if(code == LEFT) {
newOrient = (offset < maxY - offset) ? NORTH : SOUTH;
newOffset = maxX;
}
}
if(newOrient != null) {
final int newOffsetFinal = newOffset;
final EOrientation newOrientFinal = newOrient;
return () -> {
setOffsetOrientation(getLayoutedME(), CONNECTOR_OFFSET_ORIENTATION, newOffsetFinal,
newOrientFinal);
};
}
return null;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment