Skip to content
Snippets Groups Projects
AvatarBDInterface.java 57.7 KiB
Newer Older
/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille
 *
 * ludovic.apvrille AT enst.fr
 *
 * This software is a computer program whose purpose is to allow the
 * edition of TURTLE analysis, design and deployment diagrams, to
 * allow the generation of RT-LOTOS or Java code from this diagram,
 * and at last to allow the analysis of formal validation traces
 * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP
 * from INRIA Rhone-Alpes.
 *
 * This software is governed by the CeCILL  license under French law and
 * abiding by the rules of distribution of free software.  You can  use,
 * modify and/ or redistribute the software under the terms of the CeCILL
 * license as circulated by CEA, CNRS and INRIA at the following URL
 * "http://www.cecill.info".
 *
 * As a counterpart to the access to the source code and  rights to copy,
 * modify and redistribute granted by the license, users are provided only
 * with a limited warranty  and the software's author,  the holder of the
 * economic rights,  and the successive licensors  have only  limited
 * liability.
 *
 * In this respect, the user's attention is drawn to the risks associated
 * with loading,  using,  modifying and/or developing or reproducing the
 * software by the user in light of its specific status of free software,
 * that may mean  that it is complicated to manipulate,  and  that  also
 * therefore means  that it is reserved for developers  and  experienced
 * professionals having in-depth computer knowledge. Users are therefore
 * encouraged to load and test the software's suitability as regards their
 * requirements in conditions enabling the security of their systems and/or
 * data to be ensured and,  more generally, to use and operate it in the
 * same conditions as regards security.
 *
 * The fact that you are presently reading this means that you have had
 * knowledge of the CeCILL license and that you accept its terms.
 */

package ui.avatarbd;

import myutil.Conversion;
import myutil.GenericTree;
import myutil.GraphicLib;
import myutil.TraceManager;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import proverifspec.ProVerifResultTrace;
import proverifspec.ProVerifResultTraceStep;
import ui.*;
import ui.avatarsmd.AvatarSMDPanel;
import ui.interactivesimulation.JFrameSimulationSDPanel;
import ui.util.IconManager;
//import ui.window.JDialogAvatarBlock;
import ui.window.JDialogAvatarInterface;
import ui.window.JDialogIDAndStereotype;

import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.util.*;
import java.util.List;

/**
 * Class AvatarBDInterface
 * Node. To be used in AVATAR Block Diagrams
 * Creation: 06/04/2010
 *
 * @author Ludovic APVRILLE
 * @version 1.1 06/04/2010
 */
public class AvatarBDInterface extends TGCScalableWithInternalComponent implements SwallowTGComponent, SwallowedTGComponent, GenericTree, AvatarBDStateMachineOwner, WithAttributes {

    private static String GLOBAL_CODE_INFO = "(block code)";

//    private int textY1 = 3;
//    private int textX = 7;

    private static String stereotype = "amsinterface";
    private static Color stereotypeColor = ColorManager.AVATAR_INTERFACE;


    private int maxFontSize = 12;
    //    private int minFontSize = 4;
    private int currentFontSize = -1;

    private int limitName = -1;
    private int limitAttr = -1;
    private int limitMethod = -1;
    private int limitSignal = -1;

    // Icon
    private int iconSize = 15;


    // TAttribute, AvatarMethod, AvatarSignal
    protected List<TAttribute> myAttributes;
    protected List<AvatarMethod> myMethods;
    protected List<AvatarSignal> mySignals;
    protected String[] globalCode;

    protected Map<TAttribute, ProVerifResultTrace> attrTraceMap = new HashMap<TAttribute, ProVerifResultTrace>();
    protected Map<TAttribute, Integer> attrLocMap = new HashMap<TAttribute, Integer>();

    public String oldValue;

    public AvatarBDInterface(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;
        textY = 3;
        textX = 7;
        initScaling(250, 200);


        nbConnectingPoint = 16;
        connectingPoint = new TGConnectingPoint[16];

        connectingPoint[0] = new AvatarBDConnectingPoint(this, 0, 0, true, true, 0.0, 0.0);
        connectingPoint[1] = new AvatarBDConnectingPoint(this, 0, 0, true, true, 0.5, 0.0);
        connectingPoint[2] = new AvatarBDConnectingPoint(this, 0, 0, true, true, 1.0, 0.0);
        connectingPoint[3] = new AvatarBDConnectingPoint(this, 0, 0, true, true, 0.0, 0.5);
        connectingPoint[4] = new AvatarBDConnectingPoint(this, 0, 0, true, true, 1.0, 0.5);
        connectingPoint[5] = new AvatarBDConnectingPoint(this, 0, 0, true, true, 0.0, 1.0);
        connectingPoint[6] = new AvatarBDConnectingPoint(this, 0, 0, true, true, 0.5, 1.0);
        connectingPoint[7] = new AvatarBDConnectingPoint(this, 0, 0, true, true, 1.0, 1.0);

        connectingPoint[8] = new AvatarBDConnectingPoint(this, 0, 0, true, true, 0.25, 0.0);
        connectingPoint[9] = new AvatarBDConnectingPoint(this, 0, 0, true, true, 0.75, 0.0);
        connectingPoint[10] = new AvatarBDConnectingPoint(this, 0, 0, true, true, 0.0, 0.25);
        connectingPoint[11] = new AvatarBDConnectingPoint(this, 0, 0, true, true, 1.0, 0.25);
        connectingPoint[12] = new AvatarBDConnectingPoint(this, 0, 0, true, true, 0.0, 0.75);
        connectingPoint[13] = new AvatarBDConnectingPoint(this, 0, 0, true, true, 1.0, 0.75);
        connectingPoint[14] = new AvatarBDConnectingPoint(this, 0, 0, true, true, 0.25, 1.0);
        connectingPoint[15] = new AvatarBDConnectingPoint(this, 0, 0, true, true, 0.75, 1.0);

        addTGConnectingPointsComment();

        nbInternalTGComponent = 0;

        moveable = true;
        editable = true;
        multieditable = true;
        removable = true;
        userResizable = true;

        name = tdp.findAvatarBDInterfaceName("Interface");
        setValue(name);
        oldValue = value;

        oldScaleFactor = tdp.getZoom();
        currentFontSize = (int) (maxFontSize * oldScaleFactor);

        //myImageIcon = IconManager.imgic700;
	myImageIcon = IconManager.imgic700;

        this.myAttributes = new LinkedList<TAttribute>();
        this.myMethods = new LinkedList<AvatarMethod>();
        this.mySignals = new LinkedList<AvatarSignal>();

        actionOnAdd();
    }

    @Override
    public void internalDrawing(Graphics graph) {
        Font font = graph.getFont();
        this.internalDrawingAux(graph);
        graph.setFont(font);
    }

    public void addProVerifTrace(TAttribute attr, ProVerifResultTrace trace) {
        attrTraceMap.put(attr, trace);
    }

    public void setSignalsAsNonAttached() {
        for (AvatarSignal mySig : mySignals) mySig.attachedToARelation = false;
    }

    public void addSignal(AvatarSignal sig) {
        this.mySignals.add(sig);
    }

    /**
     * Issue #31: text disappearance
     *
     * @param graph
     */
    private void internalDrawingAux(Graphics graph) {
        //Rectangle
        Color c = graph.getColor();
        graph.drawRect(this.x, this.y, this.width, this.height);
        graph.setColor(stereotypeColor);
        graph.fillRect(this.x + 1, this.y + 1, this.width - 1, this.height - 1);
        graph.setColor(c);

        //string
        int h = graph.getFontMetrics().getAscent() + graph.getFontMetrics().getLeading() + textY;

        if (h + graph.getFontMetrics().getDescent() + textY >= this.height)
            return;
        Font f = graph.getFont();

        // limits
//        this.limitName = -1;
//        this.limitAttr = -1;
//        this.limitMethod = -1;
//        this.limitSignal = y + height;
//
//        // h retains the coordinate along X where an element was last drawn
//        int h = 0;
//
//        int textY1 = (int) (this.textY1 * this.tdp.getZoom());
//        int textX = (int) (this.textX * this.tdp.getZoom());
//
//        // Draw icon
//        this.iconIsDrawn = this.width > IconManager.iconSize + 2 * textX && height > IconManager.iconSize + 2 * textX;
//        if (this.iconIsDrawn) {
//            graph.drawImage(IconManager.img5100, this.x + this.width - IconManager.iconSize - textX, this.y + textX, null);
//        }
//
//
//        Font font = graph.getFont();


        String ster = stereotype;
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835
        int w = graph.getFontMetrics().stringWidth(ster);
        h = graph.getFontMetrics().getAscent() + graph.getFontMetrics().getLeading() + textY;
        graph.setFont(f.deriveFont(Font.BOLD));
        if (w + 2 * textX < this.width)
            drawSingleString(graph, ster, getCenter(graph, ster), this.y + h);
        h += graph.getFontMetrics().getHeight() + textY;
        w = graph.getFontMetrics().stringWidth(value);
        graph.setFont(f.deriveFont(Font.PLAIN));
        if (w + 2 * textX < this.width)
            drawSingleString(graph, this.value, getCenter(graph, value), this.y + h);

        //draw separator
        this.limitName = this.y + h;
        //TraceManager.addDev("limitName=" + limitName);

        if (h + textY >= this.height)
            return;
        h += graph.getFontMetrics().getDescent() + textY;
        //if (canTextGoInTheBox(graph, h, "line", 0));
        graph.drawLine(this.x, this.y + h, this.x + this.width, this.y + h);
        h += textY;

        //Attributes
        if (!this.tdp.areAttributesVisible())
            return;
        int attributeFontSize = f.getSize() * 5 / 6;
        graph.setFont(f.deriveFont((float) attributeFontSize));
        int step = graph.getFontMetrics().getHeight();
        h += textY;
        limitAttr = limitName;
        for (TAttribute attr : this.myAttributes) {
            h += step;
            if (h >= this.height - textX) {
                this.limitAttr = this.y + this.height;
                return;
            }

            // Get the string for this parameter
            String attrString = attr.toAvatarString();
            w = graph.getFontMetrics().stringWidth(attrString);
            attrLocMap.put(attr, this.y + h);
            if (w + 2 * textX < this.width) {
                //graph.drawString(attrString, this.x + textX, this.y + h);
                drawSingleString(graph, attrString, this.x + textX, this.y + h);
                this.drawConfidentialityVerification(attr.getConfidentialityVerification(), graph, this.x, this.y + h);
            }
        }

        //ICON
        drawImageWithCheck(graph, IconManager.img5100, this.x + this.width - scale(IconManager.iconSize) - textX, this.y + textX);


        // Remember the end of attributes
        this.limitAttr = this.y + h;
        if (h + textY >= this.height)
            return;

        h += graph.getFontMetrics().getDescent();

        graph.drawLine(this.x, this.y + h, this.x + this.width, this.y + h);
        h += textY;

        // Methods
        limitMethod = limitAttr;
        limitSignal = limitAttr;

        for (AvatarMethod method : this.myMethods) {
            h += step;
            if (h >= this.height - textX) {
                this.limitMethod = this.y + this.height;
                this.limitSignal = limitMethod;
                return;
            }

            // Get the string for this method
            String methodString = "- " + method.toString();

            w = graph.getFontMetrics().stringWidth(methodString);
            if (w + 2 * textX < this.width)
                drawSingleString(graph, methodString, this.x + textX, this.y + h);
            else {
                // If we can't, try to draw with "..." instead
                int stringLength;
                for (stringLength = methodString.length() - 1; stringLength >= 0; stringLength--) {
                    String abbrev = methodString.substring(0, stringLength) + "...";
                    w = graph.getFontMetrics().stringWidth(abbrev);
                    if (w + 2 * textX < this.width) {
                        drawSingleString(graph, abbrev, this.x + textX, this.y + h);
                        break;
                    }
                }

                if (stringLength < 0)
                    // skip method
                    h -= step;
            }
        }

        h += graph.getFontMetrics().getDescent() + textY;

        if (h + textY >= this.height) {
            limitMethod = this.y + this.height;
            limitSignal = this.y + this.height;
            return;
        }

        // Remember limit of methods
        this.limitMethod = this.y + h;
        this.limitSignal = this.y + h;

        graph.drawLine(this.x, this.y + h, this.x + this.width, this.y + h);
        h += textY;

        // Signals
        for (AvatarSignal signal : this.mySignals) {
            h += step;
            if (h >= this.height - textX) {
                limitSignal = this.height + this.y;
                return;
            }

            String signalString = "~ " + signal.toString();
            w = graph.getFontMetrics().stringWidth(signalString);
            if (w + 2 * textX < this.width) {
//                graph.drawString(signalString, this.x + textX, this.y + h);
                drawSingleString(graph, signalString, this.x + textX, this.y + h);
                drawInfoAttachement(signal, graph, x, y + h);

            } else {
                // If we can't, try to draw with "..." instead
                int stringLength;
                for (stringLength = signalString.length() - 1; stringLength >= 0; stringLength--) {
                    String abbrev = signalString.substring(0, stringLength) + "...";
                    w = graph.getFontMetrics().stringWidth(abbrev);
                    if (w + 2 * textX < this.width) {
                        //graph.drawString(abbrev, this.x + textX, this.y + h);
                        drawSingleString(graph, abbrev, this.x + textX, this.y + h);
                        drawInfoAttachement(signal, graph, x, y + h);
                        break;
                    }
                }

                if (stringLength < 0)
                    // skip signal
                    h -= step;
            }
        }

        h += graph.getFontMetrics().getDescent() + textY;

        if (h + textY >= this.height) {
            limitSignal = this.height + this.y;
            return;
        }

        // Global code
        limitSignal = this.y + h;
        if (hasGlobalCode()) {
            if (h + textY + step >= this.height - textX)
                return;
            graph.drawLine(this.x, this.y + h, this.x + this.width, this.y + h);
            h += textY + step;

            w = graph.getFontMetrics().stringWidth(GLOBAL_CODE_INFO);
            if (w + 2 * textX < this.width)
                drawSingleString(graph, GLOBAL_CODE_INFO, this.x + (this.width - w) / 2, this.y + h);
//                graph.drawString(GLOBAL_CODE_INFO, this.x + (this.width - w) / 2, this.y + h);
        } else {
            limitSignal = height;
        }

    }

//    private void internalDrawingAu(Graphics graph) {
//
//        //TraceManager.addDev("Interface drawing aux = " + this);
//
//        // Draw outer rectangle (for border)
//        Color c = graph.getColor();
//        graph.drawRect(this.x, this.y, this.width, this.height);
//
//        // Draw inner rectangle
//        //graph.setColor(ColorManager.AVATAR_BLOCK);
//
//        //TraceManager.addDev("type stereotype=" + typeStereotype);
//
//        graph.setColor(BLOCK_TYPE_COLOR.get(typeStereotype));
//        graph.fillRect(this.x + 1, this.y + 1, this.width - 1, this.height - 1);
//        graph.setColor(c);
//
//        // limits
//        this.limitName = -1;
//        this.limitAttr = -1;
//        this.limitMethod = -1;
//        this.limitSignal = y + height;
//
//        // h retains the coordinate along X where an element was last drawn
//        int h = 0;
//
////        int textY1 = (int) (this.textY1 * this.tdp.getZoom());
////        int textX = (int) (this.textX * this.tdp.getZoom());
//
//        // Draw icon
//        this.iconIsDrawn = this.width > IconManager.iconSize + 2 * textX && height > IconManager.iconSize + 2 * textX;
//        if (this.iconIsDrawn)
//            graph.drawImage(scale(IconManager.img5100), this.x + this.width - scale(IconManager.iconSize) - textX, this.y + textX, null);
//
//
//        Font font = graph.getFont();
//
//
//        String ster = BLOCK_TYPE_STR.get(typeStereotype);
//
//        //TraceManager.addDev("My ster=" + ster);
//
//        if (this.rescaled && !this.tdp.isScaled()) {
//            this.rescaled = false;
//            // Must set the font size...
//            // Incrementally find the biggest font not greater than max_font size
//            // If font is less than min_font, no text is displayed
//
//            // This is the maximum font size possible
//            int maxCurrentFontSize = Math.max(0, Math.min(this.height, (int) (this.maxFontSize * this.tdp.getZoom())));
//            font = font.deriveFont((float) maxCurrentFontSize);
//
//            // Try to decrease font size until we get below the minimum
//            while (maxCurrentFontSize > (this.minFontSize * this.tdp.getZoom() - 1)) {
//                // Compute width of name of the function
//                int w0 = graph.getFontMetrics(font).stringWidth(this.value);
//                // Compute width of string stereotype
//                int w1 = graph.getFontMetrics(font).stringWidth(ster);
//
//                // if one of the two width is small enough use this font size
//                if (Math.min(w0, w1) < this.width - (2 * this.textX))
//                    break;
//
//                // Decrease font size
//                maxCurrentFontSize--;
//                // Scale the font
//                font = font.deriveFont((float) maxCurrentFontSize);
//            }
//
//            // Box is too damn small
//            if (this.currentFontSize < this.minFontSize * this.tdp.getZoom()) {
//                maxCurrentFontSize++;
//                // Scale the font
//                font = font.deriveFont((float) maxCurrentFontSize);
//            }
//
//            // Use this font
//            graph.setFont(font);
//            this.currentFontSize = maxCurrentFontSize;
//        } else
//            font = font.deriveFont(this.currentFontSize);
//
//        graph.setFont(font.deriveFont(Font.BOLD));
//        h = graph.getFontMetrics().getAscent() + graph.getFontMetrics().getLeading() + textY;
//
//        if (h + graph.getFontMetrics().getDescent() + textY >= this.height)
//            return;
//
//        // Write stereotype if small enough
//        int w = graph.getFontMetrics().stringWidth(ster);
//        if (w + 2 * textX < this.width)
////            graph.drawString(ster, this.x + (this.width - w) / 2, this.y + h);
//        	drawSingleString(graph, ster, this.x + (this.width - w) / 2, this.y + h);
//        else {
//            // try to draw with "..." instead
//            if (!this.isCryptoBlock())
//                ster = stereotype;
//            else
//                ster = stereotypeCrypto;
//
//            for (int stringLength = ster.length() - 1; stringLength >= 0; stringLength--) {
//                String abbrev = "<<" + ster.substring(0, stringLength) + "...>>";
//                w = graph.getFontMetrics().stringWidth(abbrev);
//                if (w + 2 * textX < this.width) {
////                    graph.drawString(abbrev, this.x + (this.width - w) / 2, this.y + h);
//                	drawSingleString(graph, abbrev, this.x + (this.width - w) / 2, this.y + h);
//                    break;
//                }
//            }
//        }
//
//        // Write value if small enough
//        graph.setFont(font);
//        h += graph.getFontMetrics().getHeight() + textY;
//        if (h + graph.getFontMetrics().getDescent() + textY >= this.height)
//            return;
//
//        w = graph.getFontMetrics().stringWidth(this.value);
//        if (w + 2 * textX < this.width)
//            graph.drawString(this.value, this.x + (this.width - w) / 2, this.y + h);
//        else {
//            // try to draw with "..." instead
//            for (int stringLength = this.value.length() - 1; stringLength >= 0; stringLength--) {
//                String abbrev = this.value.substring(0, stringLength) + "...";
//                w = graph.getFontMetrics().stringWidth(abbrev);
//                if (w + 2 * textX < this.width) {
//                    graph.drawString(abbrev, this.x + (this.width - w) / 2, this.y + h);
//                    break;
//                }
//            }
//        }
//
//        h += graph.getFontMetrics().getDescent() + textY;
//
//        // Update lower bound of text
//        this.limitName = this.y + h;
//
//        if (h + textY >= this.height)
//            return;
//
//        // Draw separator
//        graph.drawLine(this.x, this.y + h, this.x + this.width, this.y + h);
//
//        if (!this.tdp.areAttributesVisible())
//            return;
//
//        // Set font size
//        // int attributeFontSize = Math.min (12, this.currentFontSize - 2);
//        int attributeFontSize = this.currentFontSize * 5 / 6;
//        graph.setFont(font.deriveFont((float) attributeFontSize));
//        int step = graph.getFontMetrics().getHeight();
//
//        h += textY;
//
//        // Attributes
//        limitAttr = limitName;
//        for (TAttribute attr : this.myAttributes) {
//            h += step;
//            if (h >= this.height - textX) {
//                this.limitAttr = this.y + this.height;
//                return;
//            }
//
//            // Get the string for this parameter
//            String attrString = attr.toAvatarString();
//
//            // Try to draw it
//            w = graph.getFontMetrics().stringWidth(attrString);
//            
//            attrLocMap.put(attr,this.y+h);
//            if (w + 2 * textX < this.width) {
//                graph.drawString(attrString, this.x + textX, this.y + h);
//                this.drawConfidentialityVerification(attr.getConfidentialityVerification(), graph, this.x, this.y + h);
//            } else {
//                // If we can't, try to draw with "..." instead
//                int stringLength;
//                for (stringLength = attrString.length() - 1; stringLength >= 0; stringLength--) {
//                    String abbrev = attrString.substring(0, stringLength) + "...";
//                    w = graph.getFontMetrics().stringWidth(abbrev);
//                    if (w + 2 * textX < this.width) {
//                        graph.drawString(abbrev, this.x + textX, this.y + h);
//                        this.drawConfidentialityVerification(attr.getConfidentialityVerification(), graph, this.x, this.y + h);
//                        break;
//                    }
//                }
//
//                if (stringLength < 0)
//                    // skip attribute
//                    h -= step;
//            }
//        }
//
//        h += graph.getFontMetrics().getDescent() + textY;
//
//        // Remember the end of attributes
//        this.limitAttr = this.y + h;
//
//        if (h + textY >= this.height)
//            return;
//
//        graph.drawLine(this.x, this.y + h, this.x + this.width, this.y + h);
//        h += textY;
//
//        // Methods
//        limitMethod = limitAttr;
//        limitSignal = limitAttr;
//        for (AvatarMethod method : this.myMethods) {
//            h += step;
//            if (h >= this.height - textX) {
//                this.limitMethod = this.y + this.height;
//                this.limitSignal = limitMethod;
//                return;
//            }
//
//            // Get the string for this method
//            String methodString = "- " + method.toString();
//
//            w = graph.getFontMetrics().stringWidth(methodString);
//            if (w + 2 * textX < this.width)
//                graph.drawString(methodString, this.x + textX, this.y + h);
//            else {
//                // If we can't, try to draw with "..." instead
//                int stringLength;
//                for (stringLength = methodString.length() - 1; stringLength >= 0; stringLength--) {
//                    String abbrev = methodString.substring(0, stringLength) + "...";
//                    w = graph.getFontMetrics().stringWidth(abbrev);
//                    if (w + 2 * textX < this.width) {
//                        graph.drawString(abbrev, this.x + textX, this.y + h);
//                        break;
//                    }
//                }
//
//                if (stringLength < 0)
//                    // skip method
//                    h -= step;
//            }
//        }
//
//        h += graph.getFontMetrics().getDescent() + textY;
//
//        if (h + textY >= this.height) {
//            limitMethod = this.y + this.height;
//            limitSignal = this.y + this.height;
//            return;
//        }
//
//        // Remember limit of methods
//        this.limitMethod = this.y + h;
//        this.limitSignal = this.y + h;
//
//        graph.drawLine(this.x, this.y + h, this.x + this.width, this.y + h);
//        h += textY;
//
//        // Signals
//        for (AvatarSignal signal : this.mySignals) {
//            h += step;
//            if (h >= this.height - textX) {
//                limitSignal = this.height + this.y;
//                return;
//            }
//
//            String signalString = "~ " + signal.toString();
//            w = graph.getFontMetrics().stringWidth(signalString);
//            if (w + 2 * textX < this.width) {
//                graph.drawString(signalString, this.x + textX, this.y + h);
//                drawInfoAttachement(signal, graph, x, y + h);
//
//            } else {
//                // If we can't, try to draw with "..." instead
//                int stringLength;
//                for (stringLength = signalString.length() - 1; stringLength >= 0; stringLength--) {
//                    String abbrev = signalString.substring(0, stringLength) + "...";
//                    w = graph.getFontMetrics().stringWidth(abbrev);
//                    if (w + 2 * textX < this.width) {
//                        graph.drawString(abbrev, this.x + textX, this.y + h);
//                        drawInfoAttachement(signal, graph, x, y + h);
//
//
//                        break;
//                    }
//                }
//
//                if (stringLength < 0)
//                    // skip signal
//                    h -= step;
//            }
//        }
//
//        h += graph.getFontMetrics().getDescent() + textY;
//
//        if (h + textY >= this.height) {
//            limitSignal = this.height + this.y;
//            return;
//        }
//
//        // Global code
//        limitSignal = this.y + h;
//        if (hasGlobalCode()) {
//            if (h + textY + step >= this.height - textX)
//                return;
//            graph.drawLine(this.x, this.y + h, this.x + this.width, this.y + h);
//            h += textY + step;
//
//            w = graph.getFontMetrics().stringWidth(GLOBAL_CODE_INFO);
//            if (w + 2 * textX < this.width)
//                graph.drawString(GLOBAL_CODE_INFO, this.x + (this.width - w) / 2, this.y + h);
//        } else {
//            limitSignal = height;
//        }
//    }

    private void drawInfoAttachement(AvatarSignal _as, Graphics g, int _x, int _y) {
        if (_as.attachedToARelation) {
            return;
        }
        Color c = g.getColor();
        g.setColor(Color.RED);
        int[] xA = new int[3];
        int[] yA = new int[3];
        //top of triangle
        xA[0] = _x + 5;
        yA[0] = _y - 7;

        // Right bottom point
        xA[1] = _x + 2;
        yA[1] = _y;

        // Left bottom point
        xA[2] = _x + 8;
        yA[2] = _y;

        g.fillPolygon(xA, yA, 3);

        g.setColor(c);
    }

    public void showTrace(int y) {

        if (y < limitAttr) {
            for (TAttribute attr : attrLocMap.keySet()) {
                if (attrLocMap.get(attr) < y && y < attrLocMap.get(attr) + currentFontSize && attrTraceMap.get(attr) != null) {
                    PipedOutputStream pos = new PipedOutputStream();
                    try {
                        PipedInputStream pis = new PipedInputStream(pos, 4096);
                        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(pos));

                        JFrameSimulationSDPanel jfssdp = new JFrameSimulationSDPanel(null, tdp.getMGUI(), "Confidentiality " + attr.toString());
                        jfssdp.setIconImage(IconManager.img8);
                        GraphicLib.centerOnParent(jfssdp, 600, 600);
                        jfssdp.setFileReference(new BufferedReader(new InputStreamReader(pis)));
                        jfssdp.setVisible(true);
                        //jfssdp.setModalExclusionType(ModalExclusionType
                        //      .APPLICATION_EXCLUDE);
                        jfssdp.toFront();

                        // TraceManager.addDev("\n--- Trace ---");
                        int i = 0;
                        for (ProVerifResultTraceStep step : attrTraceMap.get(attr).getTrace()) {
                            step.describeAsTMLSDTransaction(bw, i);
                            i++;
                        }
                        bw.close();
                    } catch (IOException e) {
                        TraceManager.addDev("Error when writing trace step SD transaction");
                    } finally {
                        try {
                            pos.close();
                        } catch (IOException ignored) {
                        }
                    }

                }
            }
        }
    }

    private void drawConfidentialityVerification(int confidentialityVerification, Graphics g, int _x, int _y) {
        Color c = g.getColor();
        Color c1;
        int xc = (int) (6 * tdp.getZoom());
        int yc = (int) (10 * tdp.getZoom());
        int lockwidth = (int) (9 * tdp.getZoom());
        int lockheight = (int) (7 * tdp.getZoom());
        int ovalwidth = (int) (6 * tdp.getZoom());
        int ovalheight = (int) (9 * tdp.getZoom());
        switch (confidentialityVerification) {
            case TAttribute.CONFIDENTIALITY_OK:
                c1 = Color.green;
                break;
            case TAttribute.CONFIDENTIALITY_KO:
                c1 = Color.red;
                break;
            case TAttribute.COULD_NOT_VERIFY_CONFIDENTIALITY:
                c1 = Color.orange;
                break;
            default:
                return;
        }

        g.drawOval(_x + xc, _y - yc, ovalwidth, ovalheight);
        g.setColor(c1);
        g.fillRect(_x + xc * 2 / 3, _y - yc * 2 / 3, lockwidth, lockheight);
        g.setColor(c);
        g.drawRect(_x + xc * 2 / 3, _y - yc * 2 / 3, lockwidth, lockheight);

    }

    @Override
    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 String getFullyQualifiedName() {
        String result = "";
        if (this.father != null && (this.father instanceof AvatarBDInterface)) {
            result = ((AvatarBDInterface) this.father).getFullyQualifiedName() + ".";
        }
        result += this.value;

        return result;
    }

    @Override
    public boolean editOnDoubleClick(JFrame frame, int _x, int _y) {
        int textX = (int) (this.textX * this.tdp.getZoom());

        if (GraphicLib.isInRectangle(_x, _y, x + width - iconSize - textX, y + textX, iconSize, iconSize)) {
            tdp.getMouseManager().setSelection(-1, -1);
            tdp.selectTab(getValue());
            return true;
        }

        // On the name ?
        //TraceManager.addDev("_y=" + _y + " limitName=" + limitName);
        if ((limitName == -1) || _y < limitName) {
            String s = (String) JOptionPane.showInputDialog(frame, "Library Function Name",
                    "setting value", JOptionPane.PLAIN_MESSAGE, IconManager.imgic101,
                    null,
                    this.getValue());

            if ((s != null) && (s.length() > 0)) {
                //boolean b;
                if (!s.equals(oldValue)) {
                    if (!TAttribute.isAValidId(s, false, false, false)) {
                        JOptionPane.showMessageDialog(frame,
                                "Could not change the name of the Interface: the new name is not a valid name",
                                "Error",
                                JOptionPane.INFORMATION_MESSAGE);
                        return false;
                    }

		    /*    if (!tdp.isAvatarInterfaceNameUnique(s)) {
                        JOptionPane.showMessageDialog(frame,
                                "Could not change the name of the Interface: the new name is already in use",
                                "Error",
                                JOptionPane.INFORMATION_MESSAGE);
                        return false;
			}*/

                    setValue(s);
                    recalculateSize();

                    if (!(tdp.actionOnDoubleClick(this))) {
                        JOptionPane.showMessageDialog(frame,
                                "Could not change the name of the Interface: this name is already in use",
                                "Error",
                                JOptionPane.INFORMATION_MESSAGE);
                        setValue(oldValue);
                        return false;
                    }


                }




                return true;

            }


            return false;
        }

        // And so -> attributes!

        int tab = 0;

        //TraceManager.addDev("limitAttr=" + limitAttr + " method=" + limitMethod + " limitSignal=" + limitSignal + " y=" + _y + " height=" + height);

        if (limitMethod == -1) {
            limitMethod = limitAttr;
        }

        if (limitSignal == -1) {
            limitSignal = limitMethod;
        }

        if (limitAttr == -1) {
            tab = 0;
        } else {
            if (_y < limitAttr) {
                tab = 0;
            } else if (_y < limitMethod) {
                tab = 1;
            } else if (_y < limitSignal) {
                tab = 2;
            } else if (_y > limitSignal && hasGlobalCode()) {
                tab = 3;
            } else if (_y > limitSignal && !hasGlobalCode()) {
                tab = 2;
            }
        }

        /*if (limitAttr != -1) {
            if (_y > limitAttr) {
                if (limitMethod == -1) {
                    tab = 2;
                } else {
                    tab = 1;
                }
            }
        }
        if (limitMethod != -1) {
            if (_y > limitMethod) {
                tab = 2;
            }
        }

        if ((limitMethod == -1) && (limitAttr == -1)) {
            if (this.mySignals.size() > 1) {
                tab = 2;
            }
	    }*/

        String mainCode = null;
        TDiagramPanel ttdp = getTDiagramPanel();
        if (ttdp instanceof AvatarBDPanel) {
            mainCode = ((AvatarBDPanel) (ttdp)).getMainCode();
        }
        JDialogAvatarInterface jdab = new JDialogAvatarInterface(this.myAttributes, this.myMethods, this.mySignals, null, frame, "Setting attributes of " + value, "Attribute", tab, globalCode, true, mainCode);
        setJDialogOptions(jdab);
//        jdab.setSize(650, 575);
        GraphicLib.centerOnParent(jdab, 780, 700);
        jdab.setVisible(true); // blocked until dialog has been closed
        //makeValue();
        //if (oldValue.equals(value)) {
        //return false;
        //}

        if (!jdab.hasBeenCancelled()) {
            globalCode = jdab.getGlobalCode();
            String tmp = jdab.getMainCode();
            if (tmp != null) {
                ((AvatarBDPanel) (ttdp)).setMainCode(tmp);
            }
        }

        ((AvatarBDPanel) tdp).updateAllSignalsOnConnectors();
        rescaled = true;
        return true;
    }

    protected void setJDialogOptions(JDialogAvatarInterface _jdab) {
        //jda.addAccess(TAttribute.getStringAccess(TAttribute.PUBLIC));
        _jdab.addAccess(TAttribute.getStringAccess(TAttribute.PRIVATE));
        //_jdab.addType(TAttribute.getStringType(TAttribute.NATURAL), true);
        _jdab.addType(TAttribute.getStringAvatarType(TAttribute.BOOLEAN), true);
        _jdab.addType(TAttribute.getStringAvatarType(TAttribute.INTEGER), true);
        _jdab.addType(TAttribute.getStringType(TAttribute.TIMER), false);

        for (String s : tdp.getAllDataTypes()) {
            _jdab.addType(s, false);
        }

        _jdab.enableInitialValue(true);
        _jdab.enableRTLOTOSKeyword(false);
        _jdab.enableJavaKeyword(false);
        _jdab.enableUPPAALKeyword(false);
    }

    @Override
    public int getType() {
        return TGComponentManager.AVATARBD_AMS_INTERFACE;