1

例のconnection_labeledit_inplaceのような編集可能なラベルを作成しようとしました。

私が抱えている問題は、接続の代わりにカスタムVectorFigureにラベルを添付したいということです。その場合、ラベルは図の一部にすぎず、エディターを起動しないでください。

ivr.shape.menu.MenuItem = graphiti.VectorFigure.extend({

NAME:"ivr.shape.menu.MenuItem",

MyOutputPortLocator : graphiti.layout.locator.Locator.extend({
    init: function(parent)
    {
        this._super(parent);
    },
    relocate:function(index, figure){
        var w = figure.getParent().getWidth();
        var h = figure.getParent().getHeight();

        figure.setPosition(w, h/2);
    }
}),

/**
 * @constructor
 * Creates a new figure element which are not assigned to any canvas.
 *
 */
init: function( width, height) {
    this._super();
    this.setBackgroundColor( new graphiti.util.Color(200,200,200));
    this.setColor(new graphiti.util.Color(50,50,50));

    // set some good defaults
    //
    if(typeof width === "undefined"){
        this.setDimension(100, 15);
    }
    else{
        this.setDimension(width, height);
    }

    // add port
    var outputLocator = new this.MyOutputPortLocator(this);
    this.createPort("output",outputLocator);

    this.label = new graphiti.shape.basic.Label("I'm a Label");
    this.label.setColor("#0d0d0d");
    this.label.setFontColor("#0d0d0d");
    this.addFigure(this.label, new graphiti.layout.locator.LeftLocator(this));

    this.label.installEditor(new graphiti.ui.LabelInplaceEditor());
},


repaint : function(attributes)
{
    if(this.repaintBlocked===true || this.shape===null){
        return;
    }

    if (typeof attributes === "undefined") {
        attributes = {};
    }

    var box = this.getBoundingBox();
    var center = box.getCenter();
    var path = ["M",box.x,",",box.y];
    path.push("l", box.w-10, ",0");
    path.push("l10,", box.h/2);
    path.push("l-10,", box.h/2);
    path.push("L",box.x,",", box.getBottomLeft().y);
    path.push("Z");
    var strPath = path.join("");
    attributes.path = strPath;

    this._super(attributes);
},


/**
 * @method
 * Called by the framework. Don't call them manually.
 *
 * @private
 **/
createShapeElement:function()
{
    // create dummy line
    return this.canvas.paper.path("M0 0L1 1");
}

});

この例では、図の左側にラベルを配置しますが、明らかに、図にラベルを配置するロケーターを作成します(何かが変更された場合に備えて)

私の場合、問題は「graphiti.Canvas.getBestFigure()」の動作方法に起因しています。この関数は、「graphity.Canvas」に直接接続されている要素のみをチェックします。また、この関数には、子にイベントを伝播するための再帰がありません。

4

1 に答える 1

0

GraphitiはCenterLocatorを提供します。dblClickのようなすべてのイベントは、図でキャッチできます。

....最新バージョンを使用しましたか?

于 2012-07-20T21:41:42.553 に答える