From 977b77da1342af1763b7c52d0690f9ff998a421b Mon Sep 17 00:00:00 2001 From: Andre Dietisheim Date: Tue, 16 Mar 2010 23:59:21 +0000 Subject: [256624] [UI] Create a Commit History ViewPart https://bugs.eclipse.org/bugs/show_bug.cgi?id=256624 started to implement custom #fitWithinBounds --- .../emf/cdo/ui/internal/branch/BranchViewPart.java | 4 + .../ui/internal/branch/geometry/GeometryUtils.java | 113 +++++++-- .../internal/branch/item/BranchPointNodeUtils.java | 213 ++++++++++++++++ .../ui/internal/branch/item/BranchTreeUtils.java | 182 -------------- .../layout/AbstractBranchViewLayoutStrategy.java | 5 +- .../ui/internal/branch/layout/BranchContainer.java | 2 +- .../branch/layout/BranchTreeLayoutAlgorithm.java | 276 +-------------------- .../cdo/ui/internal/branch/layout/BranchView.java | 51 +--- .../branch/layout/BranchViewLayoutStrategy.java | 35 +++ .../emf/cdo/ui/internal/branch/layout/Deque.java | 2 + 10 files changed, 373 insertions(+), 510 deletions(-) create mode 100644 plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/item/BranchPointNodeUtils.java delete mode 100644 plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/item/BranchTreeUtils.java (limited to 'plugins/org.eclipse.emf.cdo.ui.branch') diff --git a/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/BranchViewPart.java b/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/BranchViewPart.java index b6914e8400..7b32744c3f 100644 --- a/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/BranchViewPart.java +++ b/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/BranchViewPart.java @@ -124,6 +124,7 @@ public class BranchViewPart extends ViewPart CDOBranch subBranch1_1 = subBranch1.createBranch("1-1", subBranch1.getBase().getTimeStamp() + 30000000); CDOBranch subBranch2 = mainBranch.createBranch("2", subBranch1.getBase().getTimeStamp() + 30000000); CDOBranch subBranch2_1 = subBranch1.createBranch("2-1", subBranch2.getBase().getTimeStamp() + 30000000); + CDOBranch subBranch2_2 = subBranch1.createBranch("2-2", subBranch2_1.getBase().getTimeStamp() + 30000000); CDOBranch subBranch3 = mainBranch.createBranch("3", subBranch2.getBase().getTimeStamp() + 30000000); RootNode rootNode = new RootNode(mainBranch.getBase(), graph, SWT.NONE, new TreeRootFigure()); @@ -135,6 +136,8 @@ public class BranchViewPart extends ViewPart "branch point 2")); BranchPointNode branchNode2_1 = new BranchPointNode(subBranch2_1.getBase(), graph, SWT.NONE, new BranchPointFigure( "branch point 2-1")); + BranchPointNode branchNode2_2 = new BranchPointNode(subBranch2_2.getBase(), graph, SWT.NONE, new BranchPointFigure( + "branch point 2-2")); BranchPointNode branchNode3 = new BranchPointNode(subBranch3.getBase(), graph, SWT.NONE, new BranchPointFigure( "branch point 3")); @@ -143,6 +146,7 @@ public class BranchViewPart extends ViewPart new SameBranchConnection(graph, SWT.NONE, branchNode1, branchNode2); new SameBranchConnection(graph, SWT.NONE, branchNode2, branchNode3); new NewBranchConnection(graph, SWT.NONE, branchNode2, branchNode2_1); + new SameBranchConnection(graph, SWT.NONE, branchNode2_1, branchNode2_2); } diff --git a/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/geometry/GeometryUtils.java b/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/geometry/GeometryUtils.java index cdbfca19bd..d9dd77cf50 100644 --- a/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/geometry/GeometryUtils.java +++ b/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/geometry/GeometryUtils.java @@ -18,6 +18,7 @@ import org.eclipse.zest.layouts.dataStructures.DisplayIndependentRectangle; */ public class GeometryUtils { + /** * Unifies both given dimensions. * @@ -25,15 +26,12 @@ public class GeometryUtils * the this dimension * @param thatDimension * the that dimension - * @return the display independent dimension */ - public static DisplayIndependentDimension union(DisplayIndependentDimension thisDimension, - DisplayIndependentDimension thatDimension) + public static void union(DisplayIndependentDimension thisDimension, DisplayIndependentDimension thatDimension) { DisplayIndependentDimension union = new DisplayIndependentDimension(thisDimension); union.width += thatDimension.width; union.height += thatDimension.height; - return union; } /** @@ -52,6 +50,37 @@ public class GeometryUtils rectangle.y += yOffset; } + /** + * Returns the dimension needed to translate the given rectangle to the given location . + * + * @param rectangleToTranslate + * the rectangle to translate + * @param x + * the x coordinate to translate the rectangle to + * @param y + * the y coordinate to translate the rectangle to + * @return the translation + */ + public static DisplayIndependentDimension getTranslation(DisplayIndependentRectangle rectangleToTranslate, double x, + double y) + { + return new DisplayIndependentDimension(x - rectangleToTranslate.x, y - rectangleToTranslate.y); + } + + /** + * Gets the translation necessary to move the source coordinate to the target coordinate. + * + * @param sourceCoordinate + * the source x + * @param targetCoordinate + * the target x + * @return the translation + */ + public static double getTranslation(double sourceCoordinate, double targetCoordinate) + { + return targetCoordinate - sourceCoordinate; + } + /** * Answers whether the bottom of the first rectangle ends before the second rectangle's top starts (y coordinate). * @@ -81,28 +110,29 @@ public class GeometryUtils * the width (starting at the x coordinate) to expand the rectangle to * @param height * the height (starting at the y coordinate) to expand the rectangle to - * @return this for convenience + * @return */ public static DisplayIndependentRectangle union(DisplayIndependentRectangle rectangle, double x, double y, double width, double height) { + DisplayIndependentRectangle bounds = new DisplayIndependentRectangle(); double right = Math.max(rectangle.x + rectangle.width, x + width); double bottom = Math.max(rectangle.y + rectangle.height, y + height); - rectangle.x = Math.min(rectangle.x, x); - rectangle.y = Math.min(rectangle.y, y); - rectangle.width = right - rectangle.x; - rectangle.height = bottom - rectangle.y; - return rectangle; + bounds.x = Math.min(rectangle.x, x); + bounds.y = Math.min(rectangle.y, y); + bounds.width = right - rectangle.x; + bounds.height = bottom - rectangle.y; + return bounds; } /** - * Expands the given first rectangle to the minimum size which can hold both this Rectangle and the second rectangle + * Expands the given first rectangle to the minimum size which can hold both this Rectangle and the second rectangle. * * @param thisRectangle * the rectangle to expand * @param thatRectangle * the rectangle to include in the first one - * @return the display independent rectangle + * @return the new bounds */ public static DisplayIndependentRectangle union(DisplayIndependentRectangle thisRectangle, DisplayIndependentRectangle thatRectangle) @@ -111,16 +141,59 @@ public class GeometryUtils } /** - * Gets the translation necessar to translate the source coordinate to the target coordinate. + * Scales the given rectangle by the given factors. * - * @param sourceCoordinate - * the source x - * @param targetCoordinate - * the target x - * @return the translation + * @param width + * the width + * @param height + * the height + * @param bounds + * the bounds */ - public static double getTranslation(double sourceCoordinate, double targetCoordinate) + public static void scaleRectangle(double width, double height, DisplayIndependentRectangle bounds) { - return targetCoordinate - sourceCoordinate; + bounds.width *= width; + bounds.height *= height; + } + + /** + * Subtracts the given height and width from the given rectangle. + * + * @param dimension + * the dimension + * @param rectangle + * the rectangle + */ + public static DisplayIndependentRectangle substract(DisplayIndependentDimension dimension, + DisplayIndependentRectangle rectangle) + { + DisplayIndependentRectangle newRectangle = new DisplayIndependentRectangle(); + newRectangle.x = dimension.width; + newRectangle.y = dimension.height; + newRectangle.width = rectangle.width - dimension.width; + newRectangle.height = rectangle.height - dimension.height; + return newRectangle; + } + + /** + * Centers the given rectangle on the bounds of the given other rectangle. + * + * @param rectangleToCenter + * the rectangle to center + * @param rectangle + * the rectangle + */ + public static void center(DisplayIndependentRectangle rectangleToCenter, DisplayIndependentRectangle rectangle) + { + if (rectangle == null) + { + rectangleToCenter.x -= rectangleToCenter.width / 2; + rectangleToCenter.y -= rectangleToCenter.height / 2; + } + else + { + rectangleToCenter.x = rectangle.x + (rectangleToCenter.width - rectangle.width) / 2; + rectangleToCenter.y = rectangle.y + (rectangleToCenter.height - rectangle.height) / 2; + } } } diff --git a/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/item/BranchPointNodeUtils.java b/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/item/BranchPointNodeUtils.java new file mode 100644 index 0000000000..2bdfd2d3a6 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/item/BranchPointNodeUtils.java @@ -0,0 +1,213 @@ +/** + * Copyright (c) 2004 - 2010 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andre Dietisheim - initial API and implementation + */ +package org.eclipse.emf.cdo.ui.internal.branch.item; + +import org.eclipse.zest.layouts.dataStructures.DisplayIndependentRectangle; +import org.eclipse.zest.layouts.dataStructures.InternalNode; + +/** + * Various utility methods that help to deal with the manipulations needed to build a BranchTree. + * + * @author Andre Dietisheim + */ +public class BranchPointNodeUtils +{ + /** + * returns a BranchGraphNode for a given internal Node + * + * @param internalNode + * the internal node + * @return the branch graph node + * @see InternalNode + * @see AbstractBranchPointNode + */ + public static AbstractBranchPointNode getBranchPointNode(InternalNode internalNode) + { + AbstractBranchPointNode branchGraphNode = null; + Object graphData = internalNode.getLayoutEntity().getGraphData(); + if (graphData != null && graphData instanceof AbstractBranchPointNode) + { + branchGraphNode = (AbstractBranchPointNode)graphData; + } + return branchGraphNode; + } + + /** + * Returns an internal node for a given branch graph node. + * + * @param branchPointNode + * the branch graph node + * @return the internal node + * @see AbstractBranchPointNode + * @see InternalNode + */ + public static InternalNode getInternalNode(AbstractBranchPointNode branchPointNode) + { + InternalNode internalNode = null; + Object layoutInformation = branchPointNode.getLayoutEntity().getLayoutInformation(); + if (layoutInformation instanceof InternalNode) + { + internalNode = (InternalNode)layoutInformation; + } + return internalNode; + } + + /** + * Returns the center of the given node on the x-axis. + * + * @param node + * the node to get the x-center from + * @return the center of the given node on the x-axis + */ + public static double getCenterX(AbstractBranchPointNode node) + { + InternalNode internalNode = getInternalNode(node); + return internalNode.getInternalX() + internalNode.getInternalWidth() / 2; + } + + /** + * Centers the x coordinate of the given target node compared to the given source node and returns the result. If + * source node is null, the target node is translated to the right by the half of its own width (centered on + * its own location). + * + * @param nodeToCenter + * the node to center + * @param nodeToCenterOn + * the node to center on + * @return the centered x + */ + public static double getCenteredX(InternalNode nodeToCenter, InternalNode nodeToCenterOn) + { + if (nodeToCenterOn == null) + { + return nodeToCenter.getInternalX() - nodeToCenter.getInternalWidth() / 2; + } + + return nodeToCenterOn.getInternalX() + (nodeToCenterOn.getInternalWidth() - nodeToCenter.getInternalWidth()) / 2; + } + + /** + * Centers the x coordinate of the given target node. + * + * @param sourceInternalNode + * the internal node to center on the x-axis + * @return the centered x + */ + public static double getCenteredX(InternalNode sourceInternalNode) + { + return getCenteredX(sourceInternalNode, null); + } + + /** + * Sets the internal size of the internal node that displays the given branch tree node. + * + * @param node + * the branch tree nodes whose internal node shall be set in (internal) size + * @see InternalNode + * @see InternalNode#setInternalSize(double, double) + * @see AbstractBranchPointNode#getSize() + */ + public static void setInternalSize(AbstractBranchPointNode node) + { + InternalNode internalNode = getInternalNode(node); + internalNode.setInternalSize(node.getSize().preciseWidth(), node.getSize().preciseHeight()); + } + + /** + * Translates the internal location of the internal node that displays the given branch tree node + * + * @param node + * the node whose internal node shall be translated + * @param deltaX + * the delta x + * @param deltaY + * the delta y + * @see InternalNode + * @see InternalNode#getInternalX() + * @see InternalNode#getInternalY() + * @see InternalNode#setInternalLocation(double, double) + */ + public static void translateInternalLocation(AbstractBranchPointNode node, double deltaX, double deltaY) + { + InternalNode internalNode = getInternalNode(node); + internalNode.setInternalLocation(internalNode.getInternalX() + deltaX, internalNode.getInternalY() + deltaY); + } + + /** + * Sets the internal location of the internal node which displays the given branch tree node. + * + * @param node + * the node whose internal node's internal location shall be set + * @param x + * the x + * @param y + * the y + */ + public static void setInternalLocation(AbstractBranchPointNode node, double x, double y) + { + InternalNode internalNode = getInternalNode(node); + internalNode.setInternalLocation(x, y); + } + + /** + * Centers the internal node (which displays the given branch tree node) horizontally relatively to the (internal node + * that displays) the given source node. + * + * @param nodeToBeCentered + * the node to be centered + * @param sourcePositionNode + * the source node + * @param y + * the y coordinate to apply + */ + public static void centerHorizontally(AbstractBranchPointNode nodeToBeCentered, + AbstractBranchPointNode sourcePositionNode, double y) + { + + InternalNode internalNode = getInternalNode(nodeToBeCentered); + double x = getCenteredX(internalNode, getInternalNode(sourcePositionNode)); + internalNode.setInternalLocation(x, y); + } + + /** + * Centers the internal node (which displays the given branch tree node) horizontally. It gets shifted to the right by + * the half of its own width. + * + * @param nodeToBeCentered + * the node to be centered + * @param y + * the y coordinate to apply + */ + public static void centerHorizontally(AbstractBranchPointNode nodeToBeCentered, double y) + { + InternalNode internalNode = getInternalNode(nodeToBeCentered); + double x = getCenteredX(internalNode); + internalNode.setInternalLocation(x, y); + } + + /** + * Returns the bounds of the given node. + * + * @param node + * the node to get the bounds of + * @return the bounds of the given node + */ + public static DisplayIndependentRectangle getBounds(AbstractBranchPointNode node) + { + return getBounds(getInternalNode(node)); + } + + private static DisplayIndependentRectangle getBounds(InternalNode node) + { + return new DisplayIndependentRectangle(node.getInternalX(), node.getInternalY(), node.getInternalWidth(), node + .getInternalHeight()); + } +} diff --git a/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/item/BranchTreeUtils.java b/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/item/BranchTreeUtils.java deleted file mode 100644 index 5253e9ace1..0000000000 --- a/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/item/BranchTreeUtils.java +++ /dev/null @@ -1,182 +0,0 @@ -/** - * Copyright (c) 2004 - 2010 Eike Stepper (Berlin, Germany) and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Andre Dietisheim - initial API and implementation - */ -package org.eclipse.emf.cdo.ui.internal.branch.item; - -import org.eclipse.zest.layouts.dataStructures.InternalNode; - -/** - * Various utility methods that help to deal with the manipulations needed to build a BranchTree. - * - * @author Andre Dietisheim - */ -public class BranchTreeUtils -{ - /** - * returns a BranchGraphNode for a given internal Node - * - * @param internalNode - * the internal node - * @return the branch graph node - * @see InternalNode - * @see AbstractBranchPointNode - */ - public static AbstractBranchPointNode getBranchTreeNode(InternalNode internalNode) - { - AbstractBranchPointNode branchGraphNode = null; - Object graphData = internalNode.getLayoutEntity().getGraphData(); - if (graphData != null && graphData instanceof AbstractBranchPointNode) - { - branchGraphNode = (AbstractBranchPointNode)graphData; - } - return branchGraphNode; - } - - /** - * Returns an internal node for a given branch graph node. - * - * @param branchGraphNode - * the branch graph node - * @return the internal node - * @see AbstractBranchPointNode - * @see InternalNode - */ - public static InternalNode getInternalNode(AbstractBranchPointNode branchGraphNode) - { - InternalNode internalNode = null; - Object layoutInformation = branchGraphNode.getLayoutEntity().getLayoutInformation(); - if (layoutInformation instanceof InternalNode) - { - internalNode = (InternalNode)layoutInformation; - } - return internalNode; - } - - /** - * Centers the x coordinate of the given target node compared to the given source node. If source node is - * null, the target node is translated to the right by the half of its own width (centered on its own - * location) - * - * @param targetNode - * the target node - * @param sourceNode - * the source node - * @return the centered x - */ - private static double getCenteredX(InternalNode targetInternalNode, InternalNode sourceInternalNode) - { - if (sourceInternalNode == null) - { - return targetInternalNode.getInternalX() - targetInternalNode.getInternalWidth() / 2; - } - - return sourceInternalNode.getInternalX() - + (sourceInternalNode.getInternalWidth() - targetInternalNode.getInternalWidth()) / 2; - } - - /** - * Centers the x coordinate of the given target node. - * - * @param sourceNode - * the source node - * @return the centered x - */ - private static double getCenteredX(InternalNode sourceInternalNode) - { - return getCenteredX(sourceInternalNode, null); - } - - /** - * Sets the internal size of the internal node that displays the given branch tree node. - * - * @param node - * the branch tree nodes whose internal node shall be set in (internal) size - * @see InternalNode - * @see InternalNode#setInternalSize(double, double) - * @see AbstractBranchPointNode#getSize() - */ - public static void setInternalSize(AbstractBranchPointNode node) - { - InternalNode internalNode = getInternalNode(node); - internalNode.setInternalSize(node.getSize().preciseWidth(), node.getSize().preciseHeight()); - } - - /** - * Translates the internal location of the internal node that displays the given branch tree node - * - * @param node - * the node whose internal node shall be translated - * @param deltaX - * the delta x - * @param deltaY - * the delta y - * @see InternalNode - * @see InternalNode#getInternalX() - * @see InternalNode#getInternalY() - * @see InternalNode#setInternalLocation(double, double) - */ - public static void translateInternalLocation(AbstractBranchPointNode node, double deltaX, double deltaY) - { - InternalNode internalNode = getInternalNode(node); - internalNode.setInternalLocation(internalNode.getInternalX() + deltaX, internalNode.getInternalY() + deltaY); - } - - /** - * Sets the internal location of the internal node which displays the given branch tree node. - * - * @param node - * the node whose internal node's internal location shall be set - * @param x - * the x - * @param y - * the y - */ - public static void setInternalLocation(AbstractBranchPointNode node, double x, double y) - { - InternalNode internalNode = getInternalNode(node); - internalNode.setInternalLocation(x, y); - } - - /** - * Centers the internal node (which displays the given branch tree node) horizontally relatively to the (internal node - * that displays) the given source node. - * - * @param nodeToBeCentered - * the node to be centered - * @param sourcePositionNode - * the source node - * @param y - * the y coordinate to apply - */ - public static void centerHorizontally(AbstractBranchPointNode nodeToBeCentered, - AbstractBranchPointNode sourcePositionNode, double y) - { - - InternalNode internalNode = getInternalNode(nodeToBeCentered); - double x = getCenteredX(internalNode, getInternalNode(sourcePositionNode)); - internalNode.setInternalLocation(x, y); - } - - /** - * Centers the internal node (which displays the given branch tree node) horizontally. It gets shifted to the right by - * the half of its own width. - * - * @param nodeToBeCentered - * the node to be centered - * @param y - * the y coordinate to apply - */ - public static void centerHorizontally(AbstractBranchPointNode nodeToBeCentered, double y) - { - InternalNode internalNode = getInternalNode(nodeToBeCentered); - double x = getCenteredX(internalNode); - internalNode.setInternalLocation(x, y); - } -} diff --git a/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/AbstractBranchViewLayoutStrategy.java b/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/AbstractBranchViewLayoutStrategy.java index e9df346547..fecf78745b 100644 --- a/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/AbstractBranchViewLayoutStrategy.java +++ b/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/AbstractBranchViewLayoutStrategy.java @@ -176,9 +176,8 @@ public abstract class AbstractBranchViewLayoutStrategy implements BranchViewLayo DisplayIndependentRectangle bounds = branchView.getBounds(); DisplayIndependentDimension scaling = new DisplayIndependentDimension(bounds.width / targetBounds.width, bounds.height / targetBounds.height); - branchView.getLayoutStrategy().scale(branchView, scaling); - branchView.getLayoutStrategy().translateBy(branchView, - GeometryUtils.getTranslation(branchView.getBounds(), targetBounds.x, targetBounds.y)); + scale(branchView, scaling); + translateBy(branchView, GeometryUtils.getTranslation(branchView.getBounds(), targetBounds.x, targetBounds.y)); } protected void scaleSameBranchNodes(BranchView branchView, DisplayIndependentDimension scaling) diff --git a/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/BranchContainer.java b/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/BranchContainer.java index 3ff9382e8e..9adeb9ffa5 100644 --- a/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/BranchContainer.java +++ b/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/BranchContainer.java @@ -61,7 +61,7 @@ public class BranchContainer public void union(InternalNode node) { nodeList.add(node); - GeometryUtils.union(bounds, node.getInternalX(), node.getInternalY(), node.getInternalWidth(), node + bounds = GeometryUtils.union(bounds, node.getInternalX(), node.getInternalY(), node.getInternalWidth(), node .getInternalHeight()); } } diff --git a/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/BranchTreeLayoutAlgorithm.java b/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/BranchTreeLayoutAlgorithm.java index 65adc14377..35dea90e8c 100644 --- a/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/BranchTreeLayoutAlgorithm.java +++ b/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/BranchTreeLayoutAlgorithm.java @@ -10,15 +10,14 @@ */ package org.eclipse.emf.cdo.ui.internal.branch.layout; +import org.eclipse.emf.cdo.ui.internal.branch.geometry.GeometryUtils; import org.eclipse.emf.cdo.ui.internal.branch.item.AbstractBranchPointNode; -import org.eclipse.emf.cdo.ui.internal.branch.item.BranchTreeUtils; +import org.eclipse.emf.cdo.ui.internal.branch.item.BranchPointNodeUtils; import org.eclipse.emf.cdo.ui.internal.branch.item.RootNode; import org.eclipse.zest.layouts.LayoutStyles; import org.eclipse.zest.layouts.algorithms.AbstractLayoutAlgorithm; -import org.eclipse.zest.layouts.dataStructures.BendPoint; import org.eclipse.zest.layouts.dataStructures.DisplayIndependentDimension; -import org.eclipse.zest.layouts.dataStructures.DisplayIndependentPoint; import org.eclipse.zest.layouts.dataStructures.DisplayIndependentRectangle; import org.eclipse.zest.layouts.dataStructures.InternalNode; import org.eclipse.zest.layouts.dataStructures.InternalRelationship; @@ -38,7 +37,7 @@ public class BranchTreeLayoutAlgorithm extends AbstractLayoutAlgorithm private DisplayIndependentRectangle layoutBounds = null; - private double widthToHeightRatio; + private DisplayIndependentDimension borders = new DisplayIndependentDimension(60, 60); /** * Constructs a new TreeLayoutAlgorithm object. @@ -96,7 +95,7 @@ public class BranchTreeLayoutAlgorithm extends AbstractLayoutAlgorithm { for (InternalNode internalNode : entitiesToLayout) { - AbstractBranchPointNode node = BranchTreeUtils.getBranchTreeNode(internalNode); + AbstractBranchPointNode node = BranchPointNodeUtils.getBranchPointNode(internalNode); if (node != null) { if (node instanceof RootNode) @@ -114,12 +113,19 @@ public class BranchTreeLayoutAlgorithm extends AbstractLayoutAlgorithm if (entitiesToLayout.length > 0) { - buildBranch(rootNode); + BranchView branchView = buildBranch(rootNode); fireProgressEvent(1, LAYOUT_STEPS); - defaultFitWithinBounds(entitiesToLayout, layoutBounds); + // defaultFitWithinBounds(entitiesToLayout, layoutBounds); + fitWithinBounds(branchView); } } + private void fitWithinBounds(BranchView branchView) + { + DisplayIndependentRectangle boundsWithBorder = GeometryUtils.substract(borders, layoutBounds); + branchView.getLayoutStrategy().scale(branchView, boundsWithBorder); + } + private BranchView buildBranch(AbstractBranchPointNode branchRootNode) { return new BranchView(branchRootNode, new VerticallyDistributedSubBranches()); @@ -154,260 +160,4 @@ public class BranchTreeLayoutAlgorithm extends AbstractLayoutAlgorithm return false; } - - /** - * @COPIED methods - */ - - /** - * Find an appropriate size for the given nodes, then fit them into the given bounds. The relative locations of the - * nodes to each other must be preserved. Child classes should set flag reresizeEntitiesAfterLayout to false if they - * want to preserve node sizes. - */ - @Override - protected void defaultFitWithinBounds(InternalNode[] entitiesToLayout, InternalRelationship[] relationships, - DisplayIndependentRectangle realBounds) - { - - DisplayIndependentRectangle layoutBounds; - - if (resizeEntitiesAfterLayout) - { - layoutBounds = getLayoutBounds(entitiesToLayout, false); - - // Convert node x,y to be in percent rather than absolute coords - convertPositionsToPercentage(entitiesToLayout, relationships, layoutBounds, false /* do not update size */); - - // Resize and shift nodes - resizeAndShiftNodes(entitiesToLayout); - } - - // Recalculate layout, allowing for the node width, which we now know - layoutBounds = getLayoutBounds(entitiesToLayout, true); - - // adjust node positions again, to the new coordinate system (still as a percentage) - convertPositionsToPercentage(entitiesToLayout, relationships, layoutBounds, true /* update node size */); - - DisplayIndependentRectangle screenBounds = calcScreenBounds(realBounds, layoutBounds); - - // Now convert to real screen coordinates - convertPositionsToCoords(entitiesToLayout, relationships, screenBounds); - } - - /** - * Convert all node positions into a percentage of the screen. If includeNodeSize is true then this also updates the - * node's internal size. - * - * @param entitiesToLayout - */ - private void convertPositionsToPercentage(InternalNode[] entitiesToLayout, InternalRelationship[] relationships, - DisplayIndependentRectangle layoutBounds, boolean includeNodeSize) - { - - // Adjust node positions and sizes - for (int i = 0; i < entitiesToLayout.length; i++) - { - InternalNode node = entitiesToLayout[i]; - DisplayIndependentPoint location = node.getInternalLocation().convertToPercent(layoutBounds); - node.setInternalLocation(location.x, location.y); - if (includeNodeSize) - { // adjust node sizes - double width = node.getInternalWidth() / layoutBounds.width; - double height = node.getInternalHeight() / layoutBounds.height; - node.setInternalSize(width, height); - } - } - - // Adjust bendpoint positions - for (int i = 0; i < relationships.length; i++) - { - InternalRelationship rel = relationships[i]; - for (int j = 0; j < rel.getBendPoints().size(); j++) - { - BendPoint bp = (BendPoint)rel.getBendPoints().get(j); - DisplayIndependentPoint toPercent = bp.convertToPercent(layoutBounds); - bp.setX(toPercent.x); - bp.setY(toPercent.y); - } - } - } - - /** - * Convert the positions from a percentage of bounds area to fixed coordinates. NOTE: ALL OF THE POSITIONS OF NODES - * UNTIL NOW WERE FOR THE CENTER OF THE NODE - Convert it to the left top corner. - * - * @param entitiesToLayout - * @param relationships - * @param realBounds - */ - private void convertPositionsToCoords(InternalNode[] entitiesToLayout, InternalRelationship[] relationships, - DisplayIndependentRectangle screenBounds) - { - - // Adjust node positions and sizes - for (int i = 0; i < entitiesToLayout.length; i++) - { - InternalNode node = entitiesToLayout[i]; - double width = node.getInternalWidth() * screenBounds.width; - double height = node.getInternalHeight() * screenBounds.height; - DisplayIndependentPoint location = node.getInternalLocation().convertFromPercent(screenBounds); - node.setInternalLocation(location.x - width / 2, location.y - height / 2); - if (resizeEntitiesAfterLayout) - { - adjustNodeSizeAndPos(node, height, width); - } - else - { - node.setInternalSize(width, height); - } - } - - // Adjust bendpoint positions and shift based on source node size - for (int i = 0; i < relationships.length; i++) - { - InternalRelationship rel = relationships[i]; - for (int j = 0; j < rel.getBendPoints().size(); j++) - { - BendPoint bp = (BendPoint)rel.getBendPoints().get(j); - DisplayIndependentPoint fromPercent = bp.convertFromPercent(screenBounds); - bp.setX(fromPercent.x); - bp.setY(fromPercent.y); - } - } - } - - /** - * Adjust node size to take advantage of space. Reset position to top left corner of node. - * - * @param node - * @param height - * @param width - */ - private void adjustNodeSizeAndPos(InternalNode node, double height, double width) - { - double widthUsingHeight = height * widthToHeightRatio; - if (widthToHeightRatio <= 1.0 && widthUsingHeight <= width) - { - double widthToUse = height * widthToHeightRatio; - double leftOut = width - widthToUse; - node.setInternalSize(Math.max(height * widthToHeightRatio, MIN_ENTITY_SIZE), Math.max(height, MIN_ENTITY_SIZE)); - node.setInternalLocation(node.getInternalX() + leftOut / 2, node.getInternalY()); - - } - else - { - double heightToUse = height / widthToHeightRatio; - double leftOut = height - heightToUse; - - node.setInternalSize(Math.max(width, MIN_ENTITY_SIZE), Math.max(width / widthToHeightRatio, MIN_ENTITY_SIZE)); - node.setInternalLocation(node.getInternalX(), node.getInternalY() + leftOut / 2); - } - } - - /** - * Find and set the node size - shift the nodes to the right and down to make room for the width and height. - * - * @param entitiesToLayout - * @param relationships - */ - private void resizeAndShiftNodes(InternalNode[] entitiesToLayout) - { - // get maximum node size as percent of screen dimmensions - double nodeSize = getNodeSize(entitiesToLayout); - double halfNodeSize = nodeSize / 2; - - // Resize and shift nodes - for (int i = 0; i < entitiesToLayout.length; i++) - { - InternalNode node = entitiesToLayout[i]; - node.setInternalSize(nodeSize, nodeSize); - node.setInternalLocation(node.getInternalX() + halfNodeSize, node.getInternalY() + halfNodeSize); - } - } - - /** - * Returns the maximum possible node size as a percentage of the width or height in current coord system. - */ - private double getNodeSize(InternalNode[] entitiesToLayout) - { - double width, height; - if (entitiesToLayout.length == 1) - { - width = 0.8; - height = 0.8; - } - else - { - DisplayIndependentDimension minimumDistance = getMinimumDistance(entitiesToLayout); - width = 0.8 * minimumDistance.width; - height = 0.8 * minimumDistance.height; - } - return Math.max(width, height); - } - - /** - * minDistance is the closest that any two points are together. These two points become the center points for the two - * closest nodes, which we wish to make them as big as possible without overlapping. This will be the maximum of - * minDistanceX and minDistanceY minus a bit, lets say 20% We make the recommended node size a square for convenience. - * _______ | | | | | + | | |\ | |___|_\_|_____ | | \ | | | \ | +-|---+ | | | |_______| - */ - private DisplayIndependentDimension getMinimumDistance(InternalNode[] entitiesToLayout) - { - DisplayIndependentDimension horAndVertdistance = new DisplayIndependentDimension(Double.MAX_VALUE, Double.MAX_VALUE); - double minDistance = Double.MAX_VALUE; // the minimum distance between all the nodes - // TODO: Very Slow! - for (int i = 0; i < entitiesToLayout.length; i++) - { - InternalNode layoutEntity1 = entitiesToLayout[i]; - double x1 = layoutEntity1.getInternalX(); - double y1 = layoutEntity1.getInternalY(); - for (int j = i + 1; j < entitiesToLayout.length; j++) - { - InternalNode layoutEntity2 = entitiesToLayout[j]; - double x2 = layoutEntity2.getInternalX(); - double y2 = layoutEntity2.getInternalY(); - double distanceX = Math.abs(x1 - x2); - double distanceY = Math.abs(y1 - y2); - double distance = Math.sqrt(Math.pow(distanceX, 2) + Math.pow(distanceY, 2)); - - if (distance < minDistance) - { - minDistance = distance; - horAndVertdistance.width = distanceX; - horAndVertdistance.height = distanceY; - } - } - } - return horAndVertdistance; - } - - /** - * Calculate the screen bounds, maintaining the - * - * @param realBounds - * @return - */ - private DisplayIndependentRectangle calcScreenBounds(DisplayIndependentRectangle realBounds, - DisplayIndependentRectangle layoutBounds) - { - if (resizeEntitiesAfterLayout) - { // OK to alter aspect ratio - double borderWidth = Math.min(realBounds.width, realBounds.height) / 10.0; // use 10% for the border - 5% on each - // side - return new DisplayIndependentRectangle(realBounds.x + borderWidth / 2.0, realBounds.y + borderWidth / 2.0, - realBounds.width - borderWidth, realBounds.height - borderWidth); - } - - // retain layout aspect ratio - double heightAdjustment = realBounds.height / layoutBounds.height; - double widthAdjustment = realBounds.width / layoutBounds.width; - double ratio = Math.min(heightAdjustment, widthAdjustment); - double adjustedHeight = layoutBounds.height * ratio; - double adjustedWidth = layoutBounds.width * ratio; - double adjustedX = realBounds.x + (realBounds.width - adjustedWidth) / 2.0; - double adjustedY = realBounds.y + (realBounds.height - adjustedHeight) / 2.0; - double borderWidth = Math.min(adjustedWidth, adjustedHeight) / 10.0; // use 10% for the border - 5% on each side - return new DisplayIndependentRectangle(adjustedX + borderWidth / 2.0, adjustedY + borderWidth / 2.0, adjustedWidth - - borderWidth, adjustedHeight - borderWidth); - } } diff --git a/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/BranchView.java b/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/BranchView.java index 33caabd2a6..68982b3f09 100644 --- a/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/BranchView.java +++ b/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/BranchView.java @@ -11,12 +11,9 @@ package org.eclipse.emf.cdo.ui.internal.branch.layout; import org.eclipse.emf.cdo.common.branch.CDOBranch; -import org.eclipse.emf.cdo.ui.internal.branch.geometry.GeometryUtils; import org.eclipse.emf.cdo.ui.internal.branch.item.AbstractBranchPointNode; import org.eclipse.emf.cdo.ui.internal.branch.item.BranchPointNode; -import org.eclipse.emf.cdo.ui.internal.branch.item.BranchTreeUtils; -import org.eclipse.zest.layouts.dataStructures.DisplayIndependentDimension; import org.eclipse.zest.layouts.dataStructures.DisplayIndependentRectangle; import java.util.Collection; @@ -145,44 +142,6 @@ public class BranchView this.bounds = bounds; } - /** - * Translates the given branch view by the given dimension. - * - * @param dimension - * the dimension the x- and y-offset - */ - public void translate(DisplayIndependentDimension dimension) - { - translateNodesOnSameBranch(dimension); - translateSubBranches(dimension); - GeometryUtils.translateRectangle(dimension.width, dimension.height, getBounds()); - } - - /** - * Translates all sub branches of the given branch. - * - * @param dimension - * the dimension to translate this branch by - */ - private void translateSubBranches(DisplayIndependentDimension dimension) - { - for (BranchView branch : getSubBranchViews()) - { - branch.translate(dimension); - } - } - - /** - * Translates all the sibling nodes in this branch view. Applies the given horizontal and vertical offset. - */ - private void translateNodesOnSameBranch(DisplayIndependentDimension dimension) - { - for (AbstractBranchPointNode node : getNodes()) - { - BranchTreeUtils.translateInternalLocation(node, dimension.width, dimension.height); - } - } - /** * Returns not the last, but the one before the last sub branch view. If none is present, null is returned. * @@ -207,4 +166,14 @@ public class BranchView { return subBranchViews; } + + public void resetBounds() + { + bounds = null; + } + + public boolean areBoundsSet() + { + return bounds != null; + } } diff --git a/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/BranchViewLayoutStrategy.java b/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/BranchViewLayoutStrategy.java index 45d384a756..ce06dc00e1 100644 --- a/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/BranchViewLayoutStrategy.java +++ b/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/BranchViewLayoutStrategy.java @@ -13,6 +13,9 @@ package org.eclipse.emf.cdo.ui.internal.branch.layout; import org.eclipse.emf.cdo.ui.internal.branch.item.AbstractBranchPointNode; import org.eclipse.emf.cdo.ui.internal.branch.item.BranchPointNode; +import org.eclipse.zest.layouts.dataStructures.DisplayIndependentDimension; +import org.eclipse.zest.layouts.dataStructures.DisplayIndependentRectangle; + /** * @author Eike Stepper */ @@ -46,4 +49,36 @@ public interface BranchViewLayoutStrategy */ public abstract void layoutSubBranchView(BranchView branchView, BranchView subBranchView, BranchPointNode branchPointNode); + + /** + * Translates the given branch view by the given dimension. + * + * @param offsets + * the dimension the x- and y-offset + * @param branchView + * the branch view to translate + */ + public void translateBy(BranchView branchView, DisplayIndependentDimension offsets); + + /** + * Scales the given branch view by the given factor on the x- and on the y-axis and translates it to the given x and y + * coordinates. + * + * @param branchView + * the branch view + * @param targetBounds + * the target bounds + */ + public void scale(BranchView branchView, DisplayIndependentRectangle targetBounds); + + /** + * Scales the given branch view by the given factor on the x- and on the y-axis. + * + * @param branchView + * the branch view to scale + * @param scaling + * the scaling + */ + public void scale(BranchView branchView, DisplayIndependentDimension scaling); + } diff --git a/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/Deque.java b/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/Deque.java index 9daa190def..f272ffd905 100644 --- a/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/Deque.java +++ b/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/Deque.java @@ -9,6 +9,7 @@ public final class Deque extends LinkedList { private static final long serialVersionUID = 1L; + @Override public E peekFirst() { if (isEmpty()) @@ -19,6 +20,7 @@ public final class Deque extends LinkedList return getFirst(); } + @Override public E peekLast() { if (isEmpty()) -- cgit v1.2.3