diff --git a/src/ui/TGCScalableWithInternalComponent.java b/src/ui/TGCScalableWithInternalComponent.java index acd4d97c5d0e7b9482189d458052633c908b2bfd..6f78bea06223e4976a500dd8f45d2542b9be1c8a 100755 --- a/src/ui/TGCScalableWithInternalComponent.java +++ b/src/ui/TGCScalableWithInternalComponent.java @@ -63,10 +63,17 @@ public abstract class TGCScalableWithInternalComponent extends TGCWithInternalCo dheight = (height + dheight) / oldScaleFactor * scaleFactor; dx = (dx + x) / oldScaleFactor * scaleFactor; dy = (dy + y) / oldScaleFactor * scaleFactor; + dMaxWidth = (maxWidth + dMaxWidth) / oldScaleFactor * scaleFactor; + dMaxHeight = (maxWidth + dMaxWidth) / oldScaleFactor * scaleFactor; + width = (int)(dwidth); dwidth = dwidth - width; height = (int)(dheight); dheight = dheight - height; + maxWidth = (int)(dMaxWidth); + maxHeight = (int)(dMaxHeight); + dMaxWidth = dMaxWidth - maxWidth; + dMaxHeight = dMaxHeight - maxHeight; x = (int)(dx); dx = dx - x; y = (int)(dy); @@ -101,6 +108,15 @@ public abstract class TGCScalableWithInternalComponent extends TGCWithInternalCo height = (int)(dheight); dheight = dheight - height; + dMaxWidth = defMaxWidth * oldScaleFactor; + dMaxHeight = defMaxHeight * oldScaleFactor; + + maxWidth = (int)defMaxWidth; + maxHeight = (int)defMaxHeight; + + dMaxWidth = dMaxWidth - maxWidth; + dMaxHeight = dMaxHeight - maxHeight; + rescaled = true; } diff --git a/src/ui/TGComponent.java b/src/ui/TGComponent.java index 58ddf2a242e98f8fe9e617d8352696c5a4e7d684..070694c35918a220de3bd12b2d2adba8166e102a 100755 --- a/src/ui/TGComponent.java +++ b/src/ui/TGComponent.java @@ -95,8 +95,10 @@ public abstract class TGComponent implements CDElement, GenericTree { protected int minDesiredHeight = 0; protected int minWidth = 0; protected int minHeight = 0; - protected int maxWidth = 1000; + protected int maxWidth = 2000; protected int maxHeight = 2000; + protected static int defMaxWidth = 2000; + protected static int defMaxHeight = 2000; protected TGComponent father; private boolean moveWithFather = true; @@ -180,7 +182,7 @@ public abstract class TGComponent implements CDElement, GenericTree { // Zoom - public double dx=0, dy=0, dwidth, dheight; + public double dx=0, dy=0, dwidth, dheight, dMaxWidth, dMaxHeight; //Constructor diff --git a/src/ui/atd/ATDAttack.java b/src/ui/atd/ATDAttack.java index fd2cbb91b42da5496142a70a638edce896f406af..b9a9241c38579cf96294c595796007a9ae38b191 100755 --- a/src/ui/atd/ATDAttack.java +++ b/src/ui/atd/ATDAttack.java @@ -69,8 +69,8 @@ public class ATDAttack extends TGCScalableWithInternalComponent implements Swall private String rootStereotype = "root attack"; private boolean isRootAttack = false; - private int maxFontSize = 12; - private int minFontSize = 4; + private static int maxFontSize = 14; + private static int minFontSize = 4; private int currentFontSize = -1; private boolean displayText = true; private int textX = 10; @@ -106,7 +106,7 @@ public class ATDAttack extends TGCScalableWithInternalComponent implements Swall value = "attack01"; description = "blah blah blah"; - currentFontSize = maxFontSize; + currentFontSize = -1; oldScaleFactor = tdp.getZoom(); myImageIcon = IconManager.imgic702; @@ -126,19 +126,23 @@ public class ATDAttack extends TGCScalableWithInternalComponent implements Swall setValue(value, g); } - if ((rescaled) && (!tdp.isScaled())) { - - if (currentFontSize == -1) { + + if (currentFontSize == -1) { currentFontSize = f.getSize(); } + + if ((rescaled) && (!tdp.isScaled())) { rescaled = false; + + + // Must set the font size .. // Find the biggest font not greater than max_font size // By Increment of 1 // Or decrement of 1 // If font is less than 4, no text is displayed - int maxCurrentFontSize = Math.max(0, Math.min(height, maxFontSize)); + /*int maxCurrentFontSize = Math.max(0, Math.min(height, maxFontSize)); int w0, w1, w2; f = f.deriveFont((float)maxCurrentFontSize); g.setFont(f); @@ -162,21 +166,29 @@ public class ATDAttack extends TGCScalableWithInternalComponent implements Swall displayText = true; f = f.deriveFont((float)currentFontSize); g.setFont(f); - } + }*/ + + float scale = (float)(f.getSize()*tdp.getZoom()); + scale = Math.min(maxFontSize, scale); + currentFontSize = (int)scale; + if (scale < minFontSize) { + displayText = false; + } else { + displayText = true; + setValue(value, g); + } } + // Core of the attack Color c = g.getColor(); g.draw3DRect(x, y, width, height, true); - //g.drawRoundRect(x, y, width, height, arc, arc); - if (isRootAttack) { g.setColor(ColorManager.ATD_ROOT_ATTACK); } else { g.setColor(ColorManager.ATD_ATTACK); } g.fill3DRect(x+1, y+1, width-1, height-1, true); - //g.fillRoundRect(x+1, y+1, width-1, height-1, arc, arc); g.setColor(c); // Strings @@ -186,7 +198,8 @@ public class ATDAttack extends TGCScalableWithInternalComponent implements Swall if (displayText) { f = f.deriveFont((float)currentFontSize); - Font f0 = g.getFont(); + g.setFont(f); + //Font f0 = g.getFont(); boolean cannotWriteAttack = (height < (2 * currentFontSize + (int)(textY1 * tdp.getZoom()))); //TraceManager.addDev("Zoom=" + tdp.getZoom() + " Cannot write attack=" + cannotWriteAttack + "Font=" + f0); @@ -211,9 +224,9 @@ public class ATDAttack extends TGCScalableWithInternalComponent implements Swall g.drawString(ster, x + (width - w)/2, y + h); cumulated = h; } - g.setFont(f0); + g.setFont(f); w = g.getFontMetrics().stringWidth(value); - h = cumulated + currentFontSize + (int)(textY1 * tdp.getZoom()); + h = cumulated + (int)currentFontSize + (int)(textY1 * tdp.getZoom()); if ((w < (2*textX + width)) && (h < height)) { //TraceManager.addDev("Drawing value=" + value); g.drawString(value, x + (width - w)/2, y + h); @@ -230,7 +243,7 @@ public class ATDAttack extends TGCScalableWithInternalComponent implements Swall } - public void setValue(String val, Graphics g) { + public void setValue(String val, Graphics g) { oldValue = value; String ster; if (isRootAttack) { @@ -238,6 +251,15 @@ public class ATDAttack extends TGCScalableWithInternalComponent implements Swall } else { ster = "<<" + stereotype + ">>"; } + + Font f0 = g.getFont(); + + if (currentFontSize != -1) { + if (currentFontSize != f0.getSize()) { + g.setFont(f0.deriveFont((float)currentFontSize)); + } + } + int w = Math.max(g.getFontMetrics().stringWidth(value), g.getFontMetrics().stringWidth(ster)); int w1 = Math.max((int)(minWidth*tdp.getZoom()), w + 2 * textX); @@ -246,6 +268,10 @@ public class ATDAttack extends TGCScalableWithInternalComponent implements Swall width = w1; resizeWithFather(); } + + + g.setFont(f0); + //System.out.println("width=" + width + " w1=" + w1 + " value=" + value); } diff --git a/src/ui/atd/ATDAttackConnector.java b/src/ui/atd/ATDAttackConnector.java index ac97285281f072f16642f4078280ae8e6ff84eb1..710e12431cbb683522703414b7f1c79ab085dd7e 100755 --- a/src/ui/atd/ATDAttackConnector.java +++ b/src/ui/atd/ATDAttackConnector.java @@ -63,7 +63,7 @@ import ui.window.*; public class ATDAttackConnector extends TGConnectorWithCommentConnectionPoints implements ScalableTGComponent { //protected int arrowLength = 10; //protected int widthValue, heightValue, maxWidthValue, h; - protected int c = 10; //square length + protected int c = 5; //square length protected double oldScaleFactor; protected int fontSize = 12; @@ -85,10 +85,59 @@ public class ATDAttackConnector extends TGConnectorWithCommentConnectionPoints //g.drawLine(x1, y1, x2, y2); int cz = (int)(tdp.getZoom() * c); - g.fillRect(x2-(cz/2), y2-(cz/2), cz, cz); - g.fillRect(p1.getX()-(cz/2), p1.getY()-(cz/2), cz, cz); - Point p = GraphicLib.intersectionRectangleSegment(x2-(cz/2), y2-(cz/2), cz, cz, x1, y1, x2, y2); + // white squares only if ATDConstraint + + TGConnectingPoint cp = p1; + CDElement comp = cp.getFather(); + int decX = 0; + int decY = 0; + // Origin = constraint? + if (comp instanceof ATDConstraint) { + if (comp.getX() == cp.getX()) { + decX = 0; + } else if (comp.getX() + comp.getWidth() == cp.getX()) { + decX = -cz; + } else { + decX = -cz/2; + } + + if (comp.getY() == cp.getY()) { + decY = 0; + } else if (comp.getY() + comp.getHeight() == cp.getY()) { + decY = -cz; + } else { + decY = -cz/2; + } + + g.drawRect(cp.getX() + decX, cp.getY() + decY, cz, cz); + } + cp = p2; + comp = cp.getFather(); + if (comp instanceof ATDConstraint) { + if (comp.getX() == cp.getX()) { + decX = 0; + } else if (comp.getX() + comp.getWidth() == cp.getX()) { + decX = -cz; + } else { + decX = -cz/2; + } + + if (comp.getY() == cp.getY()) { + decY = 0; + } else if (comp.getY() + comp.getHeight() == cp.getY()) { + decY = -cz; + } else { + decY = -cz/2; + } + g.drawRect(x2+decX, y2+decY, cz, cz); + } + + + /*g.fillRect(x2-(cz/2), y2-(cz/2), cz, cz); + g.fillRect(p1.getX()-(cz/2), p1.getY()-(cz/2), cz, cz);*/ + + Point p = new Point(x2, y2); if (p == null) { //System.out.println("null point"); } else { diff --git a/src/ui/atd/ATDConstraint.java b/src/ui/atd/ATDConstraint.java index be49bd9263a8239b8c777a561db5bfcb216f40f4..cb1f896959d22568dfca6515f9756620304420bd 100755 --- a/src/ui/atd/ATDConstraint.java +++ b/src/ui/atd/ATDConstraint.java @@ -64,8 +64,8 @@ public class ATDConstraint extends TGCScalableWithInternalComponent implements protected String oldValue = ""; - private int maxFontSize = 12; - private int minFontSize = 4; + private static int maxFontSize = 14; + private static int minFontSize = 4; private int currentFontSize = -1; private boolean displayText = true; private int textX = 1; @@ -105,7 +105,7 @@ public class ATDConstraint extends TGCScalableWithInternalComponent implements value = "<<OR>>"; equation = ""; - currentFontSize = maxFontSize; + currentFontSize = -1; oldScaleFactor = tdp.getZoom(); myImageIcon = IconManager.imgic1078; @@ -116,42 +116,22 @@ public class ATDConstraint extends TGCScalableWithInternalComponent implements Font f = g.getFont(); Font fold = f; - if ((rescaled) && (!tdp.isScaled())) { - - if (currentFontSize == -1) { + if (currentFontSize == -1) { currentFontSize = f.getSize(); } - rescaled = false; - // Must set the font size .. - // Find the biggest font not greater than max_font size - // By Increment of 1 - // Or decrement of 1 - // If font is less than 4, no text is displayed + + if ((rescaled) && (!tdp.isScaled())) { - int maxCurrentFontSize = Math.max(0, Math.min(height, maxFontSize)); - int w0, w1; - f = f.deriveFont((float)maxCurrentFontSize); - g.setFont(f); - //System.out.println("max current font size:" + maxCurrentFontSize); - while(maxCurrentFontSize > (minFontSize-1)) { - w0 = g.getFontMetrics().stringWidth(value); - if (w0 < (width - (2*textX))) { - break; - } - maxCurrentFontSize --; - f = f.deriveFont((float)maxCurrentFontSize); - g.setFont(f); - } - currentFontSize = maxCurrentFontSize; + rescaled = false; - if(currentFontSize <minFontSize) { + float scale = (float)(f.getSize()*tdp.getZoom()); + scale = Math.min(maxFontSize, scale); + currentFontSize = (int)scale; + if (scale < minFontSize) { displayText = false; } else { displayText = true; - f = f.deriveFont((float)currentFontSize); - g.setFont(f); } - } Color c = g.getColor(); @@ -168,7 +148,7 @@ public class ATDConstraint extends TGCScalableWithInternalComponent implements Font f0 = g.getFont(); if (displayText) { - f = f.deriveFont((float)currentFontSize); + f = f.deriveFont(currentFontSize); g.setFont(f.deriveFont(Font.BOLD)); int w = g.getFontMetrics().stringWidth(value); g.drawString(value, x + (width - w)/2, y + currentFontSize + (int)(textY1*tdp.getZoom()));