Package de.FeatureModellingTool.GraphicalEditor

Source Code of de.FeatureModellingTool.GraphicalEditor.PLHandle$InerElbowConnection

package de.FeatureModellingTool.GraphicalEditor;

import research.*;
import research.connection.ElbowConnection;
import research.connector.Connector;

import java.awt.*;
import java.awt.event.InputEvent;

import research.util.Geom;

/**
* Created by IntelliJ IDEA.
* User: saturn
* Date: 2003-9-24
* Time: 23:41:07
* To change this template use Options | File Templates.
*/
public class PLHandle extends LocatorHandle {

    private transient ElbowConnection connection = null;
    private transient Figure targetFigure = null;
    private transient Connector startConnector = null;
    private transient Connector endConnector = null;

    public PLHandle(PLFigure owner, Locator locator) {
        super(owner, locator);
    }

    public void draw(Graphics g) {
        Rectangle r = displayBox();

        g.setColor(Color.yellow);
        g.fillOval(r.x, r.y, r.width, r.height);

        g.setColor(Color.black);
        g.drawOval(r.x, r.y, r.width, r.height);
    }


    public void invokeStart(int x, int y, DrawingView view) {

        PLFigure pl = (PLFigure) owner();

        startConnector = pl.connectorAt(x, y);

        connection = new InerElbowConnection(ElbowConnection.W_E_MODE);
        connection.setAttribute("type", "LinkPL2F");
        connection.startPoint(x, y);
        connection.endPoint(x, y);

        view.add(connection);
    }

    public void invokeStep(InputEvent inputEvent, int x, int y, int anchorX, int anchorY, DrawingView view) {

        trackConnectors(x, y, view);

        if(endConnector != null){
            Rectangle rect =endConnector.getDisplayBox();
            Point p = Geom.center(rect);
            connection.endPoint(p.x, p.y);
        }
        else{
            connection.endPoint(x, y);
        }


    }

    public void invokeEnd(int x, int y, int anchorX, int anchorY, DrawingView view) {

        if (targetFigure != null) { //���ص�ǰ����ͼԪ�����ӵ�Ŀɼ���
            FigureHelper.setConnectorVisible(targetFigure, false);
        }

        if (endConnector != null){
            connection.connectStart(startConnector);
            connection.connectEnd(endConnector);
            connection.updateConnection();
        }else{
            targetFigure = null;
            startConnector = null;
            endConnector = null;

            view.remove(connection);
            connection = null;

        }

    }

    protected void trackConnectors(int x, int y, DrawingView view) {
        Figure c = null;

        c = findTarget(x, y, view.getDrawing());

        if (c != targetFigure) {
            if (targetFigure != null) {
                FigureHelper.setConnectorVisible(targetFigure, false);
            }

            targetFigure = c;

            if (targetFigure != null) {
                FigureHelper.setConnectorVisible(targetFigure, true);
            }

        }

        Connector cc = null;

        if (targetFigure != null) {
            cc = targetFigure.connectorAt(x, y);
        }

        if (cc != endConnector) {
            endConnector = cc;
        }

        view.checkDamage();
    }


    protected Figure findTarget(int x, int y, Drawing drawing) {
        Figure target = findConnectableFigure(x, y, drawing);

        PLFigure pl = (PLFigure) owner();

        if (target != null
                && FigureHelper.isConnectable(target)
                && !target.includes(pl)
                && connection.canConnect(pl, target)) {
            return target;
        }

        return null;
    }

    protected Figure findConnectableFigure(int x, int y, Drawing drawing) {
        FigureEnumeration k = drawing.getFiguresReverse();

        while (k.hasMoreElements()) {
            Figure figure = k.nextFigure();
            if (!figure.includes(connection) && FigureHelper.isConnectable(figure)
                    && figure.containsPoint(x, y)) {
                return figure;
            }
        }

        return null;
    }

    protected class InerElbowConnection extends ElbowConnection{
        public InerElbowConnection(){
            super();
        }

        public InerElbowConnection(int mode){
            super(mode);
        }

        public boolean canConnect(Figure start, Figure end){
            if(!PLFigure.class.isInstance(start))
                return false;

            if(!FeatureFigure.class.isInstance(end))
                return false;

            FeatureFigure ff = (FeatureFigure)end;

            Boolean value = (Boolean)ff.getAttribute(FeatureFigure.IS_A_LINK);

            if((value == null)||(!value.booleanValue())){
                return false;
            }

            return true;
        }
    }

}
TOP

Related Classes of de.FeatureModellingTool.GraphicalEditor.PLHandle$InerElbowConnection

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.