Package research.connection

Examples of research.connection.ElbowConnection2


    public void invokeStart(int x, int y, DrawingView view) {
        fLastX = x;
        fLastY = y;

        ElbowConnection2 line = ownerConnection();

        initStartOffset = (Point) line.getAttribute(ElbowConnection2.START_OFFSET);
        if (initStartOffset == null)
            initStartOffset = new Point(0, 0);
        else {
            initStartOffset = new Point(initStartOffset);
        }

        initEndOffset = (Point) line.getAttribute(ElbowConnection2.END_OFFSET);
        if (initEndOffset == null)
            initEndOffset = new Point(0, 0);
        else {
            initEndOffset = new Point(initEndOffset);
        }
View Full Code Here


        }

    }

    public void invokeStep(InputEvent inputEvent, int x, int y, int anchorX, int anchorY, DrawingView view) {
        ElbowConnection2 line = ownerConnection();

        if (fSegment == 0) {
            if ((inputEvent != null) && (inputEvent.isShiftDown())) {//������ʼ�˵����ӷ�ʽ(H <-> V)
                Point p1 = line.pointAt(fSegment);
                line.insertPointAt(new Point(p1), fSegment + 1);

                int displayMode = ((Integer) line.getAttribute(ElbowConnection2.DISPLAY_MODE)).intValue();

                if (displayMode == ElbowConnection2.V_V_MODE) {
                    line.setAttribute(ElbowConnection2.DISPLAY_MODE, new Integer(ElbowConnection2.H_V_MODE));
                } else if (displayMode == ElbowConnection2.H_H_MODE) {
                    line.setAttribute(ElbowConnection2.DISPLAY_MODE, new Integer(ElbowConnection2.V_H_MODE));
                } else if (displayMode == ElbowConnection2.H_V_MODE) {
                    line.setAttribute(ElbowConnection2.DISPLAY_MODE, new Integer(ElbowConnection2.V_V_MODE));
                } else if (displayMode == ElbowConnection2.V_H_MODE) {
                    line.setAttribute(ElbowConnection2.DISPLAY_MODE, new Integer(ElbowConnection2.H_H_MODE));
                } else {
                    //should not go here
                    System.out.println("ElbowHandle2: should not go here");
                }

                fSegment = 1;
            } else if ((inputEvent != null) && (inputEvent.isControlDown())) {//�ı俪ʼ������������ӵ�ƫ��
                int displayMode = ((Integer) line.getAttribute(ElbowConnection2.DISPLAY_MODE)).intValue();
                Point startOffset = (Point) line.getAttribute(ElbowConnection2.START_OFFSET);
                if (startOffset == null)
                    startOffset = new Point(0, 0);

                if (displayMode == ElbowConnection2.V_V_MODE || displayMode == ElbowConnection2.V_H_MODE) {
                    startOffset.x = x - anchorX + initStartOffset.x;
                    line.setAttribute(ElbowConnection2.START_OFFSET, startOffset);
                    line.layoutConnection();
                } else if (displayMode == ElbowConnection2.H_H_MODE || displayMode == ElbowConnection2.H_V_MODE) {
                    startOffset.y = y - anchorY + initStartOffset.y;
                    line.setAttribute(ElbowConnection2.START_OFFSET, startOffset);
                    line.layoutConnection();
                } else {
                    //should not go here
                    System.out.println("ElbowHandle2: should not go here");
                }
            } else {//���ѿ�ʼ��
                Point p1 = line.pointAt(fSegment);
                Point p2 = line.pointAt(fSegment + 1);
                int _x = (p1.x + p2.x) / 2;
                int _y = (p1.y + p2.y) / 2;
                line.insertPointAt(new Point(_x, _y), fSegment + 1);
                line.insertPointAt(new Point(_x, _y), fSegment + 1);

                fSegment = 2;
            }
        } else if (fSegment == line.pointCount() - 2) {//����ĩ�˵����ӷ�ʽ(H <-> V)
            if ((inputEvent != null) && (inputEvent.isShiftDown())) {
                Point p2 = line.pointAt(fSegment + 1);
                line.insertPointAt(new Point(p2), fSegment + 1);

                int displayMode = ((Integer) line.getAttribute(ElbowConnection2.DISPLAY_MODE)).intValue();

                if (displayMode == ElbowConnection2.V_V_MODE) {
                    line.setAttribute(ElbowConnection2.DISPLAY_MODE, new Integer(ElbowConnection2.V_H_MODE));
                } else if (displayMode == ElbowConnection2.H_H_MODE) {
                    line.setAttribute(ElbowConnection2.DISPLAY_MODE, new Integer(ElbowConnection2.H_V_MODE));
                } else if (displayMode == ElbowConnection2.H_V_MODE) {
                    line.setAttribute(ElbowConnection2.DISPLAY_MODE, new Integer(ElbowConnection2.H_H_MODE));
                } else if (displayMode == ElbowConnection2.V_H_MODE) {
                    line.setAttribute(ElbowConnection2.DISPLAY_MODE, new Integer(ElbowConnection2.V_V_MODE));
                } else {
                    //should not go here
                    System.out.println("ElbowHandle2: should not go here");
                }

            } else if ((inputEvent != null) && (inputEvent.isControlDown())) {//�ı�ĩ������������ӵ�ƫ��
                int displayMode = ((Integer) line.getAttribute(ElbowConnection2.DISPLAY_MODE)).intValue();
                Point endOffset = (Point) line.getAttribute(ElbowConnection2.END_OFFSET);
                if (endOffset == null)
                    endOffset = new Point(0, 0);

                if (displayMode == ElbowConnection2.V_V_MODE || displayMode == ElbowConnection2.H_V_MODE) {
                    endOffset.x = x - anchorX + initEndOffset.x;
                    line.setAttribute(ElbowConnection2.END_OFFSET, endOffset);
                    line.layoutConnection();
                } else if (displayMode == ElbowConnection2.V_H_MODE || displayMode == ElbowConnection2.H_H_MODE) {
                    endOffset.y = y - anchorY + initEndOffset.y;
                    line.setAttribute(ElbowConnection2.END_OFFSET, endOffset);
                    line.layoutConnection();
                } else {
                    //should not go here
                    System.out.println("ElbowHandle2: should not go here");
                }
            } else {//����ĩ��
                Point p1 = line.pointAt(fSegment);
                Point p2 = line.pointAt(fSegment + 1);
                int _x = (p1.x + p2.x) / 2;
                int _y = (p1.y + p2.y) / 2;
                line.insertPointAt(new Point(_x, _y), fSegment + 1);
                line.insertPointAt(new Point(_x, _y), fSegment + 1);
            }
        } else {
            Point p1 = line.pointAt(fSegment);
            Point p2 = line.pointAt(fSegment + 1);
            int ddx = x - fLastX;
            int ddy = y - fLastY;

            boolean _isCurrentVertical = isCurrentVertical();

            Point np1;
            Point np2;
            //if (isVertical(p1, p2)) {
            if (_isCurrentVertical) {
                int cx = constrainX(p1.x + ddx);
                np1 = new Point(cx, p1.y);
                np2 = new Point(cx, p2.y);
            } else {
                int cy = constrainY(p1.y + ddy);
                np1 = new Point(p1.x, cy);
                np2 = new Point(p2.x, cy);
            }
            line.setPointAt(np1, fSegment);
            line.setPointAt(np2, fSegment + 1);
            fLastX = x;
            fLastY = y;
        }
    }
View Full Code Here

            fLastY = y;
        }
    }

    public void invokeEnd(int x, int y, int anchorX, int anchorY, DrawingView view) {
        ElbowConnection2 line = ownerConnection();

        if (line.pointCount() <= 4) return;

        boolean _isCurrentVertical = isCurrentVertical();

        Point p1 = line.pointAt(fSegment);
        Point p2 = line.pointAt(fSegment + 1);

        boolean hasJointed = false;

        if (fSegment >= 2) {
            Point p0 = line.pointAt(fSegment - 1);
            Point ps = line.pointAt(fSegment - 2);

            if (_isCurrentVertical) {
                if (Math.abs(ps.x - p2.x) < 3) {
                    p2.x = ps.x;
                    line.setPointAt(p2, fSegment + 1);

                    line.removePointAt(fSegment - 1);
                    line.removePointAt(fSegment - 1);

                    hasJointed = true;
                }
            } else {
                if (Math.abs(ps.y - p2.y) < 3) {
                    p2.y = ps.y;
                    line.setPointAt(p2, fSegment + 1);

                    line.removePointAt(fSegment - 1);
                    line.removePointAt(fSegment - 1);

                    hasJointed = true;
                }
            }
        }

        if (!hasJointed && fSegment <= line.pointCount() - 4) {
            Point p3 = line.pointAt(fSegment + 2);
            Point pe = line.pointAt(fSegment + 3);

            if (_isCurrentVertical) {
                if (Math.abs(pe.x - p1.x) < 3) {
                    p1.x = pe.x;
                    line.setPointAt(p1, fSegment);

                    line.removePointAt(fSegment + 1);
                    line.removePointAt(fSegment + 1);

                    hasJointed = true;
                }
            } else {
                if (Math.abs(pe.y - p1.y) < 3) {
                    p1.y = pe.y;
                    line.setPointAt(p1, fSegment);

                    line.removePointAt(fSegment + 1);
                    line.removePointAt(fSegment + 1);

                    hasJointed = true;
                }
            }
        }
View Full Code Here

    }

    private boolean isCurrentVertical() {

        ElbowConnection2 line = ownerConnection();
        boolean _isStartVertical = true;

        int displayMode = ((Integer) line.getAttribute(ElbowConnection2.DISPLAY_MODE)).intValue();

        if (displayMode == ElbowConnection2.V_V_MODE) {
            _isStartVertical = true;
        } else if (displayMode == ElbowConnection2.H_H_MODE) {
            _isStartVertical = false;
        } else if (displayMode == ElbowConnection2.H_V_MODE) {
            _isStartVertical = false;
        } else if (displayMode == ElbowConnection2.V_H_MODE) {
            _isStartVertical = true;
        } else {
            int direction = line.getStartConnector().getDirection();

            if (direction == Connector.NORTH_DIRECTION || direction == Connector.SOUTH_DIRECTION) {
                _isStartVertical = true;
            } else if (direction == Connector.WEST_DIRECTION || direction == Connector.EAST_DIRECTION) {
                _isStartVertical = false;
View Full Code Here

        toolAction = new ConnectionToolAction();
        toolIcon = new ImageIcon(getClass().getResource("image/ns_elbow_connection.png"));
        toolAction.putValue(Action.SMALL_ICON, toolIcon);
        toolAction.putValue(Action.SHORT_DESCRIPTION, "Create a Elbow Connection Figure");
        toolAction.putValue(CreationToolAction.PROTOTYPE_FIGURE, new ElbowConnection2(ElbowConnection2.V_V_MODE));
        toolAction.putValue(ToolAction.TOOL, new ConnectionTool());
        controller.addToolAction(toolAction);
        toolAction.setSelected(false);
        tooButton = new ToolButton(toolAction);
        this.add(tooButton);

        toolAction = new ConnectionToolAction();
        toolIcon = new ImageIcon(getClass().getResource("image/we_elbow_connection.png"));
        toolAction.putValue(Action.SMALL_ICON, toolIcon);
        toolAction.putValue(Action.SHORT_DESCRIPTION, "Create a Elbow Connection Figure");
        toolAction.putValue(CreationToolAction.PROTOTYPE_FIGURE, new ElbowConnection2(ElbowConnection2.H_H_MODE));
        toolAction.putValue(ToolAction.TOOL, new ConnectionTool());
        controller.addToolAction(toolAction);
        toolAction.setSelected(false);
        tooButton = new ToolButton(toolAction);
        this.add(tooButton);
View Full Code Here

TOP

Related Classes of research.connection.ElbowConnection2

Copyright © 2018 www.massapicom. 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.