diff --git a/src/main/java/ui/atd/ATDConstraint.java b/src/main/java/ui/atd/ATDConstraint.java index b27038df77f1f9279b7bdc2bfcd687f7d29f5a72..c077702c60e04b057d738816d9157c11453ac095 100644 --- a/src/main/java/ui/atd/ATDConstraint.java +++ b/src/main/java/ui/atd/ATDConstraint.java @@ -37,8 +37,6 @@ */ - - package ui.atd; import myutil.GraphicLib; @@ -53,13 +51,14 @@ import javax.swing.*; import java.awt.*; /** - * Class ATDConstraint - * Constraint of SysML Parametric diagrams, adapted to attack trees - * Creation: 11/12/2009 - * @version 1.0 11/12/2009 - * @author Ludovic APVRILLE + * Class ATDConstraint + * Constraint of SysML Parametric diagrams, adapted to attack trees + * Creation: 11/12/2009 + * + * @author Ludovic APVRILLE + * @version 1.0 11/12/2009 */ -public class ATDConstraint extends TGCScalableWithInternalComponent implements SwallowedTGComponent, ConstraintListInterface { +public class ATDConstraint extends TGCScalableWithInternalComponent implements SwallowedTGComponent, ConstraintListInterface { private int textY1 = 5; //private int textY2 = 30; @@ -71,17 +70,17 @@ public class ATDConstraint extends TGCScalableWithInternalComponent implements private static int minFontSize = 4; private int currentFontSize = -1; private boolean displayText = true; - // private int textX = 1; + // private int textX = 1; private static int arc = 7; private String equation; - public ATDConstraint(int _x, int _y, int _minX, int _maxX, int _minY, int _maxY, boolean _pos, TGComponent _father, TDiagramPanel _tdp) { + public ATDConstraint(int _x, int _y, int _minX, int _maxX, int _minY, int _maxY, boolean _pos, TGComponent _father, TDiagramPanel _tdp) { super(_x, _y, _minX, _maxX, _minY, _maxY, _pos, _father, _tdp); - width = (int)(150* tdp.getZoom()); - height = (int)(50 * tdp.getZoom()); + width = (int) (150 * tdp.getZoom()); + height = (int) (50 * tdp.getZoom()); minWidth = 100; nbConnectingPoint = 12; @@ -117,7 +116,7 @@ public class ATDConstraint extends TGCScalableWithInternalComponent implements public void internalDrawing(Graphics g) { Font f = g.getFont(); - // Font fold = f; + // Font fold = f; if (currentFontSize == -1) { currentFontSize = f.getSize(); @@ -127,9 +126,9 @@ public class ATDConstraint extends TGCScalableWithInternalComponent implements rescaled = false; - float scale = (float)(f.getSize()*tdp.getZoom()); + float scale = (float) (f.getSize() * tdp.getZoom()); scale = Math.min(maxFontSize, scale); - currentFontSize = (int)scale; + currentFontSize = (int) scale; displayText = !(scale < minFontSize); } @@ -149,15 +148,15 @@ public class ATDConstraint extends TGCScalableWithInternalComponent implements if (displayText) { 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())); - g.setFont(f0.deriveFont(f0.getSize()-2).deriveFont(Font.ITALIC)); - w = g.getFontMetrics().stringWidth(equation); + int w = g.getFontMetrics().stringWidth(value); + g.drawString(value, x + (width - w) / 2, y + currentFontSize + (int) (textY1 * tdp.getZoom())); + g.setFont(f0.deriveFont(f0.getSize() - 2).deriveFont(Font.ITALIC)); + w = g.getFontMetrics().stringWidth(equation); if (w >= width) { - w = g.getFontMetrics().stringWidth("..."); - g.drawString("...", x + (width - w)/2, y + (2*currentFontSize) + (int)(textY1*tdp.getZoom())); + w = g.getFontMetrics().stringWidth("..."); + g.drawString("...", x + (width - w) / 2, y + (2 * currentFontSize) + (int) (textY1 * tdp.getZoom())); } else { - g.drawString(equation, x + (width - w)/2, y + (2*currentFontSize) + (int)(textY1*tdp.getZoom())); + g.drawString(equation, x + (width - w) / 2, y + (2 * currentFontSize) + (int) (textY1 * tdp.getZoom())); } g.setFont(f0); } @@ -178,16 +177,14 @@ public class ATDConstraint extends TGCScalableWithInternalComponent implements }*/ - - public boolean editOndoubleClick(JFrame frame) { // String tmp; // boolean error = false; JDialogConstraintText dialog = new JDialogConstraintText(frame, "Setting constraint attributes", this, equation, "Equation"); - // dialog.setSize(450, 350); + // dialog.setSize(450, 350); GraphicLib.centerOnParent(dialog, 450, 350); - dialog.setVisible( true ); // blocked until dialog has been closed + dialog.setVisible(true); // blocked until dialog has been closed if (!dialog.isRegularClose()) { return false; @@ -233,27 +230,27 @@ public class ATDConstraint extends TGCScalableWithInternalComponent implements } public boolean isOR() { - return (value.compareTo(STEREOTYPES[0]) == 0); + return (value.compareTo(STEREOTYPES[0]) == 0); } public boolean isXOR() { - return (value.compareTo(STEREOTYPES[1]) == 0); + return (value.compareTo(STEREOTYPES[1]) == 0); } public boolean isAND() { - return (value.compareTo(STEREOTYPES[2]) == 0); + return (value.compareTo(STEREOTYPES[2]) == 0); } public boolean isSequence() { - return (value.compareTo(STEREOTYPES[3]) == 0); + return (value.compareTo(STEREOTYPES[3]) == 0); } public boolean isBefore() { - return (value.compareTo(STEREOTYPES[4]) == 0); + return (value.compareTo(STEREOTYPES[4]) == 0); } public boolean isAfter() { - return (value.compareTo(STEREOTYPES[5]) == 0); + return (value.compareTo(STEREOTYPES[5]) == 0); } protected String translateExtraParam() { @@ -265,7 +262,7 @@ public class ATDConstraint extends TGCScalableWithInternalComponent implements } @Override - public void loadExtraParam(NodeList nl, int decX, int decY, int decId) throws MalformedModelingException{ + public void loadExtraParam(NodeList nl, int decX, int decY, int decId) throws MalformedModelingException { //System.out.println("*** load extra synchro ***"); try { @@ -277,12 +274,12 @@ public class ATDConstraint extends TGCScalableWithInternalComponent implements // String prio; // String isRoot = null; - for(int i=0; i<nl.getLength(); i++) { + for (int i = 0; i < nl.getLength(); i++) { n1 = nl.item(i); //System.out.println(n1); if (n1.getNodeType() == Node.ELEMENT_NODE) { nli = n1.getChildNodes(); - for(int j=0; j<nli.getLength(); j++) { + for (int j = 0; j < nli.getLength(); j++) { n2 = nli.item(j); //System.out.println(n2); if (n2.getNodeType() == Node.ELEMENT_NODE) { diff --git a/src/main/java/ui/avatarcd/AvatarCDBlock.java b/src/main/java/ui/avatarcd/AvatarCDBlock.java index 18779427e4b99f222f4bb178a52fd5f6bddc601f..367fd6eba4245b5e01bb44beed05137d978d0e96 100644 --- a/src/main/java/ui/avatarcd/AvatarCDBlock.java +++ b/src/main/java/ui/avatarcd/AvatarCDBlock.java @@ -37,11 +37,12 @@ */ - - package ui.avatarcd; import myutil.GraphicLib; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; import ui.*; import ui.util.IconManager; @@ -51,44 +52,45 @@ import java.util.LinkedList; /** -* Class AvatarCDBlock -* Node. To be used in AVATAR Context Diagrams -* Creation: 31/08/2011 -* @version 1.1 31/08/2011 -* @author Ludovic APVRILLE + * Class AvatarCDBlock + * Node. To be used in AVATAR Context Diagrams + * Creation: 31/08/2011 + * + * @author Ludovic APVRILLE + * @version 1.1 31/08/2011 */ public class AvatarCDBlock extends TGCScalableWithInternalComponent implements SwallowTGComponent, SwallowedTGComponent { private int textY1 = 3; private String stereotype = "block"; - - private int maxFontSize = 12; - private int minFontSize = 4; - private int currentFontSize = -1; - private boolean displayText = true; - private int textX = 7; - - private int limitName = -1; - private int limitAttr = -1; - private int limitMethod = -1; - - // Icon - //private int iconSize = 15; - //private boolean iconIsDrawn = false; - - - public String oldValue; - - public AvatarCDBlock(int _x, int _y, int _minX, int _maxX, int _minY, int _maxY, boolean _pos, TGComponent _father, TDiagramPanel _tdp) { + + private int maxFontSize = 12; + private int minFontSize = 4; + private int currentFontSize = -1; + private boolean displayText = true; + private int textX = 7; + + private int limitName = -1; + private int limitAttr = -1; + private int limitMethod = -1; + + // Icon + //private int iconSize = 15; + //private boolean iconIsDrawn = false; + + + public String oldValue; + + public AvatarCDBlock(int _x, int _y, int _minX, int _maxX, int _minY, int _maxY, boolean _pos, TGComponent _father, TDiagramPanel _tdp) { super(_x, _y, _minX, _maxX, _minY, _maxY, _pos, _father, _tdp); - + width = 250; height = 200; minWidth = 5; minHeight = 2; - + nbConnectingPoint = 16; connectingPoint = new TGConnectingPoint[16]; - + connectingPoint[0] = new AvatarCDConnectingPoint(this, 0, 0, true, true, 0.0, 0.0); connectingPoint[1] = new AvatarCDConnectingPoint(this, 0, 0, true, true, 0.5, 0.0); connectingPoint[2] = new AvatarCDConnectingPoint(this, 0, 0, true, true, 1.0, 0.0); @@ -97,7 +99,7 @@ public class AvatarCDBlock extends TGCScalableWithInternalComponent implements S connectingPoint[5] = new AvatarCDConnectingPoint(this, 0, 0, true, true, 0.0, 1.0); connectingPoint[6] = new AvatarCDConnectingPoint(this, 0, 0, true, true, 0.5, 1.0); connectingPoint[7] = new AvatarCDConnectingPoint(this, 0, 0, true, true, 1.0, 1.0); - + connectingPoint[8] = new AvatarCDConnectingPoint(this, 0, 0, true, true, 0.25, 0.0); connectingPoint[9] = new AvatarCDConnectingPoint(this, 0, 0, true, true, 0.75, 0.0); connectingPoint[10] = new AvatarCDConnectingPoint(this, 0, 0, true, true, 0.0, 0.25); @@ -106,242 +108,278 @@ public class AvatarCDBlock extends TGCScalableWithInternalComponent implements S connectingPoint[13] = new AvatarCDConnectingPoint(this, 0, 0, true, true, 1.0, 0.75); connectingPoint[14] = new AvatarCDConnectingPoint(this, 0, 0, true, true, 0.25, 1.0); connectingPoint[15] = new AvatarCDConnectingPoint(this, 0, 0, true, true, 0.75, 1.0); - + addTGConnectingPointsComment(); - + nbInternalTGComponent = 0; - + moveable = true; editable = true; - //multieditable = true; + //multieditable = true; removable = true; userResizable = true; - + name = tdp.findAvatarCDBlockName("Block"); - setValue(name); - oldValue = value; - - currentFontSize = maxFontSize; - oldScaleFactor = tdp.getZoom(); - + setValue(name); + oldValue = value; + + currentFontSize = maxFontSize; + oldScaleFactor = tdp.getZoom(); + myImageIcon = IconManager.imgic700; - - actionOnAdd(); + + actionOnAdd(); } - + public void internalDrawing(Graphics g) { - String ster = "<<" + stereotype + ">>"; - Font f = g.getFont(); - Font fold = f; - - //System.out.println("width=" + width + " height=" + height); - - if ((rescaled) && (!tdp.isScaled())) { - - 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 - - int maxCurrentFontSize = Math.max(0, Math.min(height, maxFontSize)); - int w0, w1, w2; - 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); - w1 = g.getFontMetrics().stringWidth(ster); - w2 = Math.min(w0, w1); - if (w2 < (width - (2*textX))) { - break; - } - maxCurrentFontSize --; - f = f.deriveFont((float)maxCurrentFontSize); - g.setFont(f); - } - currentFontSize = maxCurrentFontSize; - - if(currentFontSize <minFontSize) { - displayText = false; - } else { - displayText = true; - f = f.deriveFont((float)currentFontSize); - g.setFont(f); - } - - } - - //System.out.println("Current font size:" + currentFontSize); - - Color c = g.getColor(); - - g.draw3DRect(x, y, width, height, true); - - //g.setColor(ColorManager.AVATAR_BLOCK); - Color avat = ColorManager.AVATAR_BLOCK; - int h; - h = 2* (currentFontSize + (int)(textY1 * tdp.getZoom())) + 2; - g.setColor(new Color(avat.getRed(), avat.getGreen(), Math.min(255, avat.getBlue() + (getMyDepth() * 10)))); - g.fill3DRect(x+1, y+1, width-1, Math.min(h, height)-1, true); - g.setColor(c); - + String ster = "<<" + stereotype + ">>"; + Font f = g.getFont(); + Font fold = f; + + //System.out.println("width=" + width + " height=" + height); + + if ((rescaled) && (!tdp.isScaled())) { + + 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 + + int maxCurrentFontSize = Math.max(0, Math.min(height, maxFontSize)); + int w0, w1, w2; + 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); + w1 = g.getFontMetrics().stringWidth(ster); + w2 = Math.min(w0, w1); + if (w2 < (width - (2 * textX))) { + break; + } + maxCurrentFontSize--; + f = f.deriveFont((float) maxCurrentFontSize); + g.setFont(f); + } + currentFontSize = maxCurrentFontSize; + + if (currentFontSize < minFontSize) { + displayText = false; + } else { + displayText = true; + f = f.deriveFont((float) currentFontSize); + g.setFont(f); + } + + } + + //System.out.println("Current font size:" + currentFontSize); + + Color c = g.getColor(); + + g.draw3DRect(x, y, width, height, true); + + //g.setColor(ColorManager.AVATAR_BLOCK); + Color avat = ColorManager.AVATAR_BLOCK; + int h; + h = 2 * (currentFontSize + (int) (textY1 * tdp.getZoom())) + 2; + g.setColor(new Color(avat.getRed(), avat.getGreen(), Math.min(255, avat.getBlue() + (getMyDepth() * 10)))); + g.fill3DRect(x + 1, y + 1, width - 1, Math.min(h, height) - 1, true); + g.setColor(c); + // Strings - int w; - h = 0; - if (displayText) { - f = f.deriveFont((float)currentFontSize); - Font f0 = g.getFont(); - g.setFont(f.deriveFont(Font.BOLD)); - - w = g.getFontMetrics().stringWidth(ster); - h = currentFontSize + (int)(textY1 * tdp.getZoom()); - if ((w < (2*textX + width)) && (h < height)) { - g.drawString(ster, x + (width - w)/2, y +h); - } - g.setFont(f0); - w = g.getFontMetrics().stringWidth(value); - h = 2* (currentFontSize + (int)(textY1 * tdp.getZoom())); - if ((w < (2*textX + width)) && (h < height)) { - g.drawString(value, x + (width - w)/2, y + h); - } - limitName = y + h; - } else { - limitName = -1; - } - - g.setFont(fold); - - h = h +2; - if (h < height) { - //g.drawLine(x, y+h, x+width, y+h); - g.setColor(new Color(avat.getRed(), avat.getGreen(), Math.min(255, avat.getBlue() + (getMyDepth() * 10)))); - g.fill3DRect(x+1, y+h, width-1, height-1-h, true); - g.setColor(c); - } - - // Icon - /*if ((width>30) && (height > (iconSize + 2*textX))) { + int w; + h = 0; + if (displayText) { + f = f.deriveFont((float) currentFontSize); + Font f0 = g.getFont(); + g.setFont(f.deriveFont(Font.BOLD)); + + w = g.getFontMetrics().stringWidth(ster); + h = currentFontSize + (int) (textY1 * tdp.getZoom()); + if ((w < (2 * textX + width)) && (h < height)) { + g.drawString(ster, x + (width - w) / 2, y + h); + } + g.setFont(f0); + w = g.getFontMetrics().stringWidth(value); + h = 2 * (currentFontSize + (int) (textY1 * tdp.getZoom())); + if ((w < (2 * textX + width)) && (h < height)) { + g.drawString(value, x + (width - w) / 2, y + h); + } + limitName = y + h; + } else { + limitName = -1; + } + + g.setFont(fold); + + h = h + 2; + if (h < height) { + //g.drawLine(x, y+h, x+width, y+h); + g.setColor(new Color(avat.getRed(), avat.getGreen(), Math.min(255, avat.getBlue() + (getMyDepth() * 10)))); + g.fill3DRect(x + 1, y + h, width - 1, height - 1 - h, true); + g.setColor(c); + } + + // Icon + /*if ((width>30) && (height > (iconSize + 2*textX))) { iconIsDrawn = true; g.drawImage(IconManager.img5100, x + width - iconSize - textX, y + textX, null); } else { iconIsDrawn = false; }*/ - - g.setFont(fold); - - - // Icon - //g.drawImage(IconManager.imgic1100.getImage(), x + 4, y + 4, null); - //g.drawImage(IconManager.img9, x + width - 20, y + 4, null); + + g.setFont(fold); + + + // Icon + //g.drawImage(IconManager.imgic1100.getImage(), x + 4, y + 4, null); + //g.drawImage(IconManager.img9, x + width - 20, y + 4, null); } - - + + public TGComponent isOnOnlyMe(int x1, int y1) { - + if (GraphicLib.isInRectangle(x1, y1, x, y, width, height)) { return this; } return null; } - + public String getStereotype() { return stereotype; - + } - + public String getNodeName() { return name; } - - public boolean editOndoubleClick(JFrame frame) { - - oldValue = value; - - //String text = getName() + ": "; - String s = (String)JOptionPane.showInputDialog(frame, "Block name", - "setting value", JOptionPane.PLAIN_MESSAGE, IconManager.imgic101, - null, - getValue()); - - if ((s != null) && (s.length() > 0) && (!s.equals(oldValue))) { - //boolean b; - if (!TAttribute.isAValidId(s, false, false)) { - JOptionPane.showMessageDialog(frame, - "Could not change the name of the Block: the new name is not a valid name", - "Error", - JOptionPane.INFORMATION_MESSAGE); - return false; - } - - if (!tdp.isBlockNameUnique(s)) { - JOptionPane.showMessageDialog(frame, - "Could not change the name of the Block: the new name is already in use", - "Error", - JOptionPane.INFORMATION_MESSAGE); - return false; - } - - setValue(s); - recalculateSize(); - - if (tdp.actionOnDoubleClick(this)) { - return true; - } else { - JOptionPane.showMessageDialog(frame, - "Could not change the name of the Block: this name is already in use", - "Error", - JOptionPane.INFORMATION_MESSAGE); - setValue(oldValue); - } - } - return false; - + + public boolean editOndoubleClick(JFrame frame) { + + oldValue = getStereotype() + "/" + getValue(); + + //String text = getName() + ": "; + String s = (String) JOptionPane.showInputDialog(frame, "Stereotype / identifier", + "Setting value", JOptionPane.PLAIN_MESSAGE, IconManager.imgic101, + null, + getStereotype() + "/" + getValue()); + + if ((s != null) && (s.length() > 0) && (!s.equals(oldValue))) { + //boolean b; + int index = s.indexOf("/"); + if (index == -1) { + JOptionPane.showMessageDialog(frame, + "Could not change the name of the stereotype / block: no \"/\" in the name", + "Error", + JOptionPane.INFORMATION_MESSAGE); + return false; + } + + String ster = s.substring(0, index); + String blo = s.substring(index+1, s.length()); + if (ster.length() == 0 ) { + JOptionPane.showMessageDialog(frame, + "Invalid stereotype", + "Error", + JOptionPane.INFORMATION_MESSAGE); + return false; + } + if (blo.length() == 0 ) { + JOptionPane.showMessageDialog(frame, + "Invalid stereotype", + "Error", + JOptionPane.INFORMATION_MESSAGE); + return false; + } + + if (!TAttribute.isAValidId(ster, false, false)) { + JOptionPane.showMessageDialog(frame, + "Could not change the name of the stereotype: the new name is not a valid name", + "Error", + JOptionPane.INFORMATION_MESSAGE); + return false; + } + + if (!TAttribute.isAValidId(blo, false, false)) { + JOptionPane.showMessageDialog(frame, + "Could not change the name of the Block: the new name is not a valid name", + "Error", + JOptionPane.INFORMATION_MESSAGE); + return false; + } + + if (!tdp.isBlockNameUnique(blo)) { + JOptionPane.showMessageDialog(frame, + "Could not change the name of the Block: the new name is already in use", + "Error", + JOptionPane.INFORMATION_MESSAGE); + return false; + } + + stereotype = ster; + setValue(blo); + + recalculateSize(); + + if (tdp.actionOnDoubleClick(this)) { + return true; + } else { + JOptionPane.showMessageDialog(frame, + "Could not change the name of the Block: this name is already in use", + "Error", + JOptionPane.INFORMATION_MESSAGE); + setValue(oldValue); + } + } + return false; + } - - public boolean acceptSwallowedTGComponent(TGComponent tgc) { + + public boolean acceptSwallowedTGComponent(TGComponent tgc) { return tgc instanceof AvatarCDBlock; } - - + + public int getType() { return TGComponentManager.ACD_BLOCK; } - + public boolean addSwallowedTGComponent(TGComponent tgc, int x, int y) { - boolean swallowed = false; - - for(int i=0; i<nbInternalTGComponent; i++) { - if (tgcomponent[i] instanceof SwallowTGComponent) { - if (tgcomponent[i].isOnMe(x, y) != null) { - swallowed = true; - ((SwallowTGComponent)tgcomponent[i]).addSwallowedTGComponent(tgc, x, y); - break; - } - } + boolean swallowed = false; + + for (int i = 0; i < nbInternalTGComponent; i++) { + if (tgcomponent[i] instanceof SwallowTGComponent) { + if (tgcomponent[i].isOnMe(x, y) != null) { + swallowed = true; + ((SwallowTGComponent) tgcomponent[i]).addSwallowedTGComponent(tgc, x, y); + break; + } + } } - - if (swallowed) { - return true; - } - - if (!acceptSwallowedTGComponent(tgc)) { - return false; - } - + + if (swallowed) { + return true; + } + + if (!acceptSwallowedTGComponent(tgc)) { + return false; + } + //System.out.println("Add swallow component"); // Choose its position - + // Make it an internal component // It's one of my son tgc.setFather(this); tgc.setDrawingZone(true); - + //Set its coordinates if (tgc instanceof AvatarCDBlock) { //tgc.setCdRectangle((width/2) - tgc.getWidth(), (width/2), spacePt, height-spacePt); @@ -350,121 +388,163 @@ public class AvatarCDBlock extends TGCScalableWithInternalComponent implements S //tgc.setCdRectangle(0, width - tgc.getWidth(), 0, height - tgc.getHeight()); //tgc.setCd(x, y); } - + // else unknown*/ - + //add it addInternalComponent(tgc, 0); - - return true; + + return true; } - + public void removeSwallowedTGComponent(TGComponent tgc) { - removeMyInternalComponent(tgc, false); - } - - public boolean removeMyInternalComponent(TGComponent tgc, boolean actionOnRemove) { + removeMyInternalComponent(tgc, false); + } + + public boolean removeMyInternalComponent(TGComponent tgc, boolean actionOnRemove) { //TGComponent tgc; - //TraceManager.addDev("Remove my internal component: " + tgc + ". I have " + nbInternalTGComponent + " internal components"); - - for(int i=0; i<nbInternalTGComponent; i++) { + //TraceManager.addDev("Remove my internal component: " + tgc + ". I have " + nbInternalTGComponent + " internal components"); + + for (int i = 0; i < nbInternalTGComponent; i++) { if (tgcomponent[i] == tgc) { nbInternalTGComponent = nbInternalTGComponent - 1; if (nbInternalTGComponent == 0) { tgcomponent = null; } else { - TGComponent [] tgcomponentbis = new TGComponent[nbInternalTGComponent]; - for(int j=0; j<nbInternalTGComponent; j++) { - if (j<i) { + TGComponent[] tgcomponentbis = new TGComponent[nbInternalTGComponent]; + for (int j = 0; j < nbInternalTGComponent; j++) { + if (j < i) { tgcomponentbis[j] = tgcomponent[j]; } - if (j>=i) { - tgcomponentbis[j] = tgcomponent[j+1]; + if (j >= i) { + tgcomponentbis[j] = tgcomponent[j + 1]; } } tgcomponent = tgcomponentbis; } - if (actionOnRemove) { - tgc.actionOnRemove(); - tdp.actionOnRemove(tgc); - } + if (actionOnRemove) { + tgc.actionOnRemove(); + tdp.actionOnRemove(tgc); + } return true; } else { - if (tgcomponent[i] instanceof AvatarCDBlock) { - if (((AvatarCDBlock)tgcomponent[i]).removeMyInternalComponent(tgc, false)) { - return true; - } - } + if (tgcomponent[i] instanceof AvatarCDBlock) { + if (((AvatarCDBlock) tgcomponent[i]).removeMyInternalComponent(tgc, false)) { + return true; + } + } } } return false; } - - public String getBlockName() { - return value; + + public String getBlockName() { + return value; } - - - + + public void hasBeenResized() { - for(int i=0; i<nbInternalTGComponent; i++) { + for (int i = 0; i < nbInternalTGComponent; i++) { if (tgcomponent[i] instanceof AvatarCDBlock) { tgcomponent[i].resizeWithFather(); } } - - if (getFather() != null) { - resizeWithFather(); - } - + + if (getFather() != null) { + resizeWithFather(); + } + } - - public void resizeWithFather() { + + public void resizeWithFather() { if ((father != null) && (father instanceof AvatarCDBlock)) { - // Too large to fit in the father? -> resize it! - resizeToFatherSize(); - + // Too large to fit in the father? -> resize it! + resizeToFatherSize(); + setCdRectangle(0, father.getWidth() - getWidth(), 0, father.getHeight() - getHeight()); setMoveCd(x, y); } } - - public LinkedList<AvatarCDBlock> getBlockList() { + + public LinkedList<AvatarCDBlock> getBlockList() { LinkedList<AvatarCDBlock> list = new LinkedList<AvatarCDBlock>(); - for(int i=0; i<nbInternalTGComponent; i++) { + for (int i = 0; i < nbInternalTGComponent; i++) { if (tgcomponent[i] instanceof AvatarCDBlock) { - list.add((AvatarCDBlock)(tgcomponent[i])); + list.add((AvatarCDBlock) (tgcomponent[i])); } } return list; } - - public LinkedList<AvatarCDBlock> getFullBlockList() { + + public LinkedList<AvatarCDBlock> getFullBlockList() { LinkedList<AvatarCDBlock> list = new LinkedList<AvatarCDBlock>(); - for(int i=0; i<nbInternalTGComponent; i++) { + for (int i = 0; i < nbInternalTGComponent; i++) { if (tgcomponent[i] instanceof AvatarCDBlock) { - list.add((AvatarCDBlock)(tgcomponent[i])); - list.addAll(((AvatarCDBlock)tgcomponent[i]).getFullBlockList()); + list.add((AvatarCDBlock) (tgcomponent[i])); + list.addAll(((AvatarCDBlock) tgcomponent[i]).getFullBlockList()); } } return list; } - - - public boolean hasInternalBlockWithName(String name) { - LinkedList<AvatarCDBlock> list = getFullBlockList(); - for(AvatarCDBlock b: list) { - if (b.getValue().compareTo(name) ==0) { - return true; - } - } - return false; - } - - - - public int getDefaultConnector() { + + + public boolean hasInternalBlockWithName(String name) { + LinkedList<AvatarCDBlock> list = getFullBlockList(); + for (AvatarCDBlock b : list) { + if (b.getValue().compareTo(name) == 0) { + return true; + } + } + return false; + } + + + public int getDefaultConnector() { return TGComponentManager.ACD_COMPOSITION_CONNECTOR; - } - + } + + protected String translateExtraParam() { + StringBuffer sb = new StringBuffer("<extraparam>\n"); + sb.append("<stereotype value=\"" + GTURTLEModeling.transformString(getStereotype())); + sb.append("\" />\n"); + sb.append("</extraparam>\n"); + return new String(sb); + } + + @Override + public void loadExtraParam(NodeList nl, int decX, int decY, int decId) throws MalformedModelingException { + //System.out.println("*** load extra synchro ***"); + try { + + NodeList nli; + Node n1, n2; + Element elt; +// int t1id; +// String sdescription = null; +// String prio; +// String isRoot = null; + + for (int i = 0; i < nl.getLength(); i++) { + n1 = nl.item(i); + //System.out.println(n1); + if (n1.getNodeType() == Node.ELEMENT_NODE) { + nli = n1.getChildNodes(); + for (int j = 0; j < nli.getLength(); j++) { + n2 = nli.item(j); + //System.out.println(n2); + if (n2.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) n2; + if (elt.getTagName().equals("stereotype")) { + stereotype = elt.getAttribute("value"); + } + } + } + } + } + + } catch (Exception e) { + throw new MalformedModelingException(); + } + } + }