diff --git a/src/main/java/ui/TDiagramPanel.java b/src/main/java/ui/TDiagramPanel.java index 1704ae0812d9260ba2b97cdcc4311108c87efdf2..d657461cbc1e544c8379f61b787123954cf0c4a9 100644 --- a/src/main/java/ui/TDiagramPanel.java +++ b/src/main/java/ui/TDiagramPanel.java @@ -345,15 +345,17 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree { final int maxYPrev = maxY; maxX = (int) Math.round(zoomChange * maxX); maxY = (int) Math.round(zoomChange * maxY); + + // Issue #174: Also updated the minLimit to be consistent with + final int minLimitPrev = minLimit; + minLimit = (int) Math.round(zoomChange * minLimit); - if (maxXPrev != maxX || maxYPrev != maxY) { + if (maxXPrev != maxX || maxYPrev != maxY || minLimitPrev != minLimit ) { mgui.changeMade(this, DIAGRAM_RESIZED); updateSize(); } updateComponentsAfterZoom(); - - //TraceManager.addDev("end Setting zoom of " + getName() + " to " + zoom + " maxX=" + maxX + " maxY=" + maxY); } public boolean isDrawingMain() { @@ -1161,8 +1163,12 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree { // Multi-select public void setSelectingComponents(int x, int y) { - x = Math.min(Math.max((int) (Math.floor(minLimit * zoom)), x), (int) (Math.ceil(maxX * zoom))); - y = Math.min(Math.max((int) (Math.floor(minLimit * zoom)), y), (int) (Math.ceil(maxY * zoom))); + + // Issue #174: Diagram min and max values are scaled as the zoom is computed so should not be scaled again + x = Math.min( Math.max( minLimit, x ), maxX ); + y = Math.min( Math.max( minLimit, y ), maxY ); +// x = Math.min(Math.max((int) (Math.floor(minLimit * zoom)), x), (int) (Math.ceil(maxX * zoom))); +// y = Math.min(Math.max((int) (Math.floor(minLimit * zoom)), y), (int) (Math.ceil(maxY * zoom))); // x = Math.min(Math.max(minLimit*zoom, x), maxX*zoom); //y = Math.min(Math.max(minLimit*zoom, y), maxY*zoom); initSelectX = x; @@ -2387,45 +2393,46 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree { return mgui; } - - public int getRawMinX() { - return minLimit; - } - - public int getRawMaxX() { - return maxX; - } - - public int getRawMinY() { - return minLimit; - } - - public int getRawMaxY() { - return maxY; - } +// Issue #174: The size of components saved in the XML file are the scaled one so to be consistent, also store the scaled diagram dimensions +// public int getRawMinX() { +// return minLimit; +// } +// +// public int getRawMaxX() { +// return maxX; +// } +// +// public int getRawMinY() { +// return minLimit; +// } +// +// public int getRawMaxY() { +// return maxY; +// } public int getMaxX() { - //return maxX; - return (int) Math.ceil(maxX * zoom); + return maxX; // Issue #174: The maxX is updated after each zoom so no need to rescale it with the zoom factor + //return (int) Math.ceil(maxX * zoom); } public int getMinX() { - return (int) Math.floor(minLimit * zoom); + return minLimit; // Issue #174: The minLimit is updated after each zoom so no need to rescale it with the zoom factor + //return (int) Math.floor(minLimit * zoom); } public int getMinY() { - return (int) Math.floor(minLimit * zoom); + return minLimit; // Issue #174: The minLimit is updated after each zoom so no need to rescale it with the zoom factor +// return (int) Math.floor(minLimit * zoom); //return minLimit*zoom; } public int getMaxY() { - //return maxY; - return (int) Math.ceil(maxY * zoom); + return maxY; // Issue #174: The maxY is updated after each zoom so no need to rescale it with the zoom factor + //return (int) Math.ceil(maxY * zoom); } public void setMaxX(int x) { maxX = x; - } public void setMinX(int x) { @@ -2468,10 +2475,11 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree { } public String sizeParam() { - String s = " minX=\"" + getRawMinX() + "\""; - s += " maxX=\"" + getRawMaxX() + "\""; - s += " minY=\"" + getRawMinY() + "\""; - s += " maxY=\"" + getRawMaxY() + "\""; + // Issue #174: The size of components saved in the XML file are the scaled one so to be consistent, also store the scaled diagram dimensions + String s = " minX=\"" + getMinX()/*getRawMinX()*/ + "\""; + s += " maxX=\"" + getMaxX() /*getRawMaxX()*/ + "\""; + s += " minY=\"" + getMinY() /*getRawMinY()*/ + "\""; + s += " maxY=\"" + getMaxY() /*getRawMaxY()*/ + "\""; return s; } diff --git a/src/main/java/ui/TGComponent.java b/src/main/java/ui/TGComponent.java index f7578a188ca0a727153abd9012d847c3a32684c5..2dd13d6693a5f4e9c650924fecb9c7967606b3dc 100644 --- a/src/main/java/ui/TGComponent.java +++ b/src/main/java/ui/TGComponent.java @@ -2595,18 +2595,24 @@ public abstract class TGComponent extends AbstractCDElement implements /*CDElem // if it has a father, check that it is in its authorized area first if (father != null && drawingZoneRelativeToFather) { targetX = Math.min(maxX + father.getX(), Math.max(minX + father.getX(), targetX)); - } else { - if (x > targetX) - targetX = Math.max(Math.max(targetX, minX), Math.min(targetX, maxX - width)); - else - targetX = Math.min(Math.max(targetX, minX), Math.min(targetX, maxX - width)); + } + else { + + // Issue #174: Use the diagram min and max sizes when the component is not contained + final int minVal = Math.max( targetX, tdp.getMinX() ); + final int maxVal = Math.min( targetX, tdp.getMaxX() - width ); + targetX = x > targetX ? Math.max( minVal, maxVal ) : Math.min( minVal, maxVal ); +// if (x > targetX) +// targetX = Math.max(Math.max(targetX, minX), Math.min(targetX, maxX - width)); +// else +// targetX = Math.min(Math.max(targetX, minX), Math.min(targetX, maxX - width)); } // Issue #46: Added the else. // When we are moving a contained component, we should not check for the max of the diagram. This should be done for the father only // Issue #14: Do not check the diagram size // The problem is that this method is applied after a zoom and readjusts the targeted coordinate if it is outside the diagram area. - // However the check involves getting the size of the component, but taking into account the size of its childs (getCurrentMaxX) that + // However the check involves getting the size of the component, but taking into account the size of its children (getCurrentMaxX) that // have not been zoomed yet therefore leading to an erroneous calculation of size. Disable this verification for now. // else { // int currentWidthPos = Math.abs(getCurrentMaxX() - x); @@ -2621,11 +2627,17 @@ public abstract class TGComponent extends AbstractCDElement implements /*CDElem // if it has a father, check that it is in its authorized area first if ((father != null) && (drawingZoneRelativeToFather)) { targetY = Math.min(maxY + father.getY(), Math.max(minY + father.getY(), targetY)); - } else { - if (y > targetY) - targetY = Math.max(Math.max(targetY, minY), Math.min(targetY, maxY - height)); - else - targetY = Math.min(Math.max(targetY, minY), Math.min(targetY, maxY - height)); + } + else { + + // Issue #174: Use the diagram min and max sizes when the component is not contained + final int minVal = Math.max( targetY, tdp.getMinY() ); + final int maxVal = Math.min( targetY, tdp.getMaxY() - height ); + targetY = y > targetY ? Math.max( minVal, maxVal ) : Math.min( minVal, maxVal ); +// if (y > targetY) +// targetY = Math.max(Math.max(targetY, minY), Math.min(targetY, maxY - height)); +// else +// targetY = Math.min(Math.max(targetY, minY), Math.min(targetY, maxY - height)); } // Issues #46 and #14: See comment in verifyMoveCdX // else {