Search in sources :

Example 21 with FloatPoint

use of com.dsoft.pb.types.FloatPoint in project ramus by Vitaliy-Yakovchuk.

the class MovingArea method setActiveFunction.

/**
 * Задає значення активного на блоку (того який являється базовим для
 * решти).
 *
 * @param activeFunction Значення активної функції.
 */
public void setActiveFunction(final Function activeFunction) {
    synchronized (backgroundPaintlock) {
        bImage = null;
    }
    String size = activeFunction.getPageSize();
    initSize(size);
    if (panel != null) {
        cancelAdding();
        panel.setMovingAreaSize(zoom);
    }
    if (activeFunction.getType() >= Function.TYPE_EXTERNAL_REFERENCE)
        return;
    textPaintCache.clear();
    if (activeFunction.getDecompositionType() == DIAGRAM_TYPE_DFDS) {
        DropTarget dropTarget = new DropTarget();
        this.setDropTarget(dropTarget);
        try {
            dropTarget.addDropTargetListener(new DropTargetAdapter() {

                @Override
                public void drop(DropTargetDropEvent event) {
                    if (event.getTransferable().isDataFlavorSupported(RowTreeTable.rowsListFlavor)) {
                        try {
                            event.acceptDrop(event.getSourceActions());
                            Rows rows = (Rows) event.getTransferable().getTransferData(RowTreeTable.rowsListFlavor);
                            FloatPoint point = toPoint(event.getLocation().x, event.getLocation().y);
                            Function owner = null;
                            for (MovingPanel panel : panels) if (panel instanceof DFDSFunction && panel.contain(point)) {
                                owner = ((DFDSFunction) panel).getFunction();
                            }
                            startUserTransaction();
                            Function function = createFunctionalObject(getDoubleOrdinate(event.getLocation().getX()), getDoubleOrdinate(event.getLocation().getY()), Function.TYPE_DFDS_ROLE, activeFunction);
                            RectangleVisualOptions ops = IDEF0Plugin.getDefaultRectangleVisualOptions(dataPlugin.getEngine(), rows.get(0).getElement());
                            if (ops != null) {
                                FRectangle rect = function.getBounds();
                                rect.setHeight(ops.bounds.getHeight());
                                rect.setWidth(ops.bounds.getWidth());
                                function.setBounds(rect);
                                function.setFont(ops.font);
                                function.setBackground(ops.background);
                                function.setForeground(ops.foreground);
                            }
                            Stream stream = (Stream) dataPlugin.createRow(dataPlugin.getBaseStream(), true);
                            Row[] rows2 = new Row[rows.size()];
                            for (int i = 0; i < rows2.length; i++) rows2[i] = dataPlugin.findRowByGlobalId(rows.get(i).getElementId());
                            stream.setRows(rows2);
                            function.setLink(stream.getElement().getId());
                            if (owner != null) {
                                function.setOwner(owner);
                                DFDSFunction function2 = findDFDSFunction(owner);
                                List<Function> roles = getRoles(function2);
                                if (!roles.contains(function))
                                    roles.add(function);
                                if (function2 != null)
                                    function2.justifyRoles(roles);
                            }
                            commitUserTransaction();
                            panel.getFrame().propertyChange(MChangeListener.RELOAD_FUNCTION_IN_TREE, activeFunction);
                        } catch (UnsupportedFlavorException e) {
                            e.printStackTrace();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    } else
                        event.rejectDrop();
                }
            });
        } catch (TooManyListenersException e) {
            e.printStackTrace();
        }
    } else
        this.setDropTarget(null);
    if (rec)
        return;
    rec = true;
    if (panel != null) {
        boolean locked;
        if (activeFunction.equals(lockedFunction))
            locked = true;
        else
            locked = activeFunction.lock();
        refactor.loadFromFunction(activeFunction, false);
        if (!activeFunction.equals(lockedFunction)) {
            if (lockedFunction != null)
                lockedFunction.unlock();
            if (locked)
                lockedFunction = activeFunction;
            else
                lockedFunction = null;
        }
        panel.setMovingActiveFunction(activeFunction);
        if (getState() == END_POINT_ADDING)
            setState(START_POINT_ADDING);
        if ((getState() == END_POINT_CHANGING) || (getState() == START_POINT_CHANGING) || (getState() == FUNCTION_ADDING_STATE) || (getState() == TEXT_ADDING_STATE))
            cancelAdding();
    } else
        refactor.loadFromFunction(activeFunction, false);
    boolean updateListeneres = this.activeFunction != activeFunction;
    this.activeFunction = activeFunction;
    if (panel != null) {
        panel.getFrame().propertyChange(MChangeListener.REFRESH_FUNCTION_IN_TREE, activeFunction);
    }
    setPanels();
    if (panel != null) {
        setActiveObject(null);
        final java.awt.Point mp = getMousePosition();
        if (mp != null)
            moveMoveListener.mouseMoved(new MouseEvent(this, 0, 0, 0, mp.x, mp.y, 0, false));
    }
    functionIndex = dataPlugin.indexOfFunction(activeFunction);
    if (functionIndex < 0)
        functionIndex = 0;
    rec = false;
    if (updateListeneres) {
        ActiveFunctionEvent event = new ActiveFunctionEvent(activeFunction);
        for (ActiveFunctionListener l : getActiveFunctionListeners()) l.activeFunctionChanged(event);
    }
    if (panel != null) {
        panel.getFrame().refreshActions(panel);
    }
}
Also used : MouseEvent(java.awt.event.MouseEvent) ActiveFunctionListener(com.ramussoft.pb.idef.visual.event.ActiveFunctionListener) IOException(java.io.IOException) ActiveFunctionEvent(com.ramussoft.pb.idef.visual.event.ActiveFunctionEvent) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) DropTargetAdapter(java.awt.dnd.DropTargetAdapter) DFDSFunction(com.ramussoft.pb.dfds.visual.DFDSFunction) Function(com.ramussoft.pb.Function) DFDFunction(com.ramussoft.pb.dfd.visual.DFDFunction) NFunction(com.ramussoft.pb.data.negine.NFunction) TooManyListenersException(java.util.TooManyListenersException) FloatPoint(com.dsoft.pb.types.FloatPoint) FRectangle(com.dsoft.pb.types.FRectangle) RectangleVisualOptions(com.ramussoft.idef0.attribute.RectangleVisualOptions) Stream(com.ramussoft.pb.Stream) ArrayList(java.util.ArrayList) EventListenerList(javax.swing.event.EventListenerList) List(java.util.List) DropTarget(java.awt.dnd.DropTarget) DropTargetDropEvent(java.awt.dnd.DropTargetDropEvent) DFDSFunction(com.ramussoft.pb.dfds.visual.DFDSFunction) Rows(com.ramussoft.gui.qualifier.table.Rows)

Example 22 with FloatPoint

use of com.dsoft.pb.types.FloatPoint in project ramus by Vitaliy-Yakovchuk.

the class MovingPanel method mouseDragged.

public void mouseDragged(final FloatPoint point) {
    if (!canMove)
        return;
    final FloatPoint add = point.minus(pressedPoint);
    if (xt == 2)
        pressedPoint.setX(point.getX());
    if (yt == 2)
        pressedPoint.setY(point.getY());
    switch(state) {
        case STATE_MOVE:
            move(add);
            break;
        case STATE_RESIZE_BOTTOM:
            {
                moveBottomWall(add.getY());
                moveRightWall(0);
            }
            break;
        case STATE_RESIZE_TOP:
            {
                moveTopWall(add.getY());
                moveRightWall(0);
            }
            break;
        case STATE_RESIZE_LEFT:
            {
                moveLeftWall(add.getX());
                moveBottomWall(0);
            }
            break;
        case STATE_RESIZE_RIGHT:
            {
                moveRightWall(add.getX());
                moveBottomWall(0);
            }
            break;
        case STATE_RESIZE_BOTTOM_LEFT:
            {
                moveBottomWall(add.getY());
                moveLeftWall(add.getX());
            }
            break;
        case STATE_RESIZE_LEFT_TOP:
            {
                moveTopWall(add.getY());
                moveLeftWall(add.getX());
            }
            break;
        case STATE_RESIZE_TOP_RIGHT:
            {
                moveTopWall(add.getY());
                moveRightWall(add.getX());
            }
            break;
        case STATE_RESIZE_RIGHT_BOTTOM:
            {
                moveBottomWall(add.getY());
                moveRightWall(add.getX());
            }
            break;
    }
    onBoundsChange();
}
Also used : FloatPoint(com.dsoft.pb.types.FloatPoint)

Example 23 with FloatPoint

use of com.dsoft.pb.types.FloatPoint in project ramus by Vitaliy-Yakovchuk.

the class IDEF0Object method mouseClicked.

/**
 * @see com.ramussoft.pb.idef.visual.MovingPanel#mouseClicked(com.dsoft.pb.types.FloatPoint)
 */
@Override
public void mouseClicked(final FloatPoint point) {
    super.mouseClicked(point);
    if (movingArea.getChangingState() == MovingArea.ARROW_CHANGING_STATE) {
        if (movingArea.getPointChangingType() == SectorRefactor.TYPE_START) {
            if (getTriangle(point) == RIGHT) {
                final Ordinate x = new Ordinate(Ordinate.TYPE_X);
                final Ordinate y = new Ordinate(Ordinate.TYPE_Y);
                final Point p = new Point(x, y);
                x.setPosition(getBounds().getRight());
                y.setPosition(getBounds().getY() + point.getY());
                final SectorRefactor.PerspectivePoint pp = new SectorRefactor.PerspectivePoint();
                pp.point = p;
                pp.x = p.getX();
                pp.y = p.getY();
                pp.setFunction(getFunction(), RIGHT);
                pp.type = SectorRefactor.TYPE_START;
                movingArea.getRefactor().setPoint(pp);
                movingArea.doSector();
            }
        } else {
            final int type = getTriangle(point);
            if (type == -1 || type == RIGHT)
                return;
            final Ordinate x = new Ordinate(Ordinate.TYPE_X);
            final Ordinate y = new Ordinate(Ordinate.TYPE_Y);
            final Point p = new Point(x, y);
            final SectorRefactor.PerspectivePoint pp = new SectorRefactor.PerspectivePoint();
            pp.point = p;
            switch(type) {
                case LEFT:
                    {
                        pp.setFunction(getFunction(), LEFT);
                        x.setPosition(getBounds().getLeft());
                        y.setPosition(getBounds().getY() + point.getY());
                    }
                    break;
                case TOP:
                    {
                        pp.setFunction(getFunction(), TOP);
                        x.setPosition(getBounds().getX() + point.getX());
                        y.setPosition(getBounds().getTop());
                    }
                    break;
                case BOTTOM:
                    {
                        pp.setFunction(getFunction(), BOTTOM);
                        x.setPosition(getBounds().getX() + point.getX());
                        y.setPosition(getBounds().getBottom());
                    }
                    break;
            }
            pp.x = x.getPosition();
            pp.y = y.getPosition();
            pp.type = SectorRefactor.TYPE_END;
            movingArea.getRefactor().setPoint(pp);
            movingArea.doSector();
        }
    }
}
Also used : SectorRefactor(com.ramussoft.pb.idef.elements.SectorRefactor) Point(com.ramussoft.pb.idef.elements.Point) FloatPoint(com.dsoft.pb.types.FloatPoint) Ordinate(com.ramussoft.pb.idef.elements.Ordinate) Point(com.ramussoft.pb.idef.elements.Point) FloatPoint(com.dsoft.pb.types.FloatPoint)

Example 24 with FloatPoint

use of com.dsoft.pb.types.FloatPoint in project ramus by Vitaliy-Yakovchuk.

the class IDEF0Object method getTriangle.

protected int getTriangle(final FloatPoint point) {
    int res = -1;
    FloatPoint l = getLocation();
    for (int type = MovingPanel.RIGHT; type <= MovingPanel.TOP; type++) {
        GeneralPath gp = getTrianglePath(type);
        double y = point.getY() + l.getY();
        double x = point.getX() + l.getX();
        if (gp.contains(new Point2D.Double(x, y))) {
            res = type;
            break;
        }
    }
    if (isShowRight() ^ res == Point.RIGHT)
        res = -1;
    return res;
}
Also used : FloatPoint(com.dsoft.pb.types.FloatPoint) GeneralPath(java.awt.geom.GeneralPath) Point2D(java.awt.geom.Point2D) Point(com.ramussoft.pb.idef.elements.Point) FloatPoint(com.dsoft.pb.types.FloatPoint)

Example 25 with FloatPoint

use of com.dsoft.pb.types.FloatPoint in project ramus by Vitaliy-Yakovchuk.

the class MouseSelection method onProcessEndBoundsChange.

public void onProcessEndBoundsChange(MovingArea movingArea, MovingText[] panels, FloatPoint diff) {
    for (MovingText text : panels) if (text instanceof DFDSRole) {
        IDEF0Object idef = (IDEF0Object) text;
        if (contains(text))
            idef.onProcessEndBoundsChange(sectors);
    }
    for (MovingText text : panels) {
        if (!(text instanceof DFDSRole))
            if (contains(text)) {
                if (text instanceof IDEF0Object) {
                    IDEF0Object idef = (IDEF0Object) text;
                    idef.onProcessEndBoundsChange(sectors);
                }
            }
    }
    List<Ordinate> xOrdinates = new ArrayList<Ordinate>();
    List<Ordinate> yOrdinates = new ArrayList<Ordinate>();
    for (PaintSector ps : sectors) {
        for (Point point : ps.getPoints()) {
            boolean has;
            has = false;
            for (Ordinate o : xOrdinates) if (o.getOrdinateId() == point.getXOrdinate().getOrdinateId()) {
                has = true;
                break;
            }
            if (!has)
                xOrdinates.add(point.getXOrdinate());
            has = false;
            for (Ordinate o : yOrdinates) if (o.getOrdinateId() == point.getYOrdinate().getOrdinateId()) {
                has = true;
                break;
            }
            if (!has)
                yOrdinates.add(point.getYOrdinate());
        }
    }
    List<PaintSector> psrs = new ArrayList<PaintSector>();
    psrs.addAll(sectors);
    for (Ordinate xOrdinate : xOrdinates) {
        xOrdinate.setPosition(xOrdinate.getPosition() + diff.getX());
        for (Point point : xOrdinate.getPoints()) if (!psrs.contains(point.getSector()))
            psrs.add(point.getSector());
    }
    for (Ordinate yOrdinate : yOrdinates) {
        yOrdinate.setPosition(yOrdinate.getPosition() + diff.getY());
        for (Point point : yOrdinate.getPoints()) if (!psrs.contains(point.getSector()))
            psrs.add(point.getSector());
    }
    MemoryData data = new MemoryData();
    for (PaintSector paintSector : sectors) {
        Function sFunction = paintSector.getSector().getStart().getFunction();
        if (sFunction != null) {
            switch(paintSector.getSector().getStart().getFunctionType()) {
                case MovingFunction.LEFT:
                    paintSector.getStartPoint().setX(sFunction.getBounds().getLeft());
                    break;
                case MovingFunction.RIGHT:
                    paintSector.getStartPoint().setX(sFunction.getBounds().getRight());
                    break;
                case MovingFunction.TOP:
                    paintSector.getStartPoint().setY(sFunction.getBounds().getTop());
                    break;
                case MovingFunction.BOTTOM:
                    paintSector.getStartPoint().setY(sFunction.getBounds().getBottom());
                    break;
            }
        }
        sFunction = paintSector.getSector().getEnd().getFunction();
        if (sFunction != null) {
            switch(paintSector.getSector().getEnd().getFunctionType()) {
                case MovingFunction.LEFT:
                    paintSector.getEndPoint().setX(sFunction.getBounds().getLeft());
                    break;
                case MovingFunction.RIGHT:
                    paintSector.getEndPoint().setX(sFunction.getBounds().getRight());
                    break;
                case MovingFunction.TOP:
                    paintSector.getEndPoint().setY(sFunction.getBounds().getTop());
                    break;
                case MovingFunction.BOTTOM:
                    paintSector.getEndPoint().setY(sFunction.getBounds().getBottom());
                    break;
            }
        }
    }
    for (MovingText text : panels) {
        if (!(text instanceof DFDSRole))
            if (contains(text)) {
                if (!(text instanceof IDEF0Object)) {
                    text.onProcessEndBoundsChange();
                    if (text instanceof MovingLabel)
                        ((MovingLabel) text).boundsCopy = text.getBounds();
                }
            }
    }
    for (PaintSector ps : psrs) PaintSector.save(ps, data, movingArea.getDataPlugin().getEngine());
}
Also used : DFDSRole(com.ramussoft.pb.dfds.visual.DFDSRole) ArrayList(java.util.ArrayList) FloatPoint(com.dsoft.pb.types.FloatPoint) Point(com.ramussoft.pb.idef.elements.Point) Ordinate(com.ramussoft.pb.idef.elements.Ordinate) Function(com.ramussoft.pb.Function) PaintSector(com.ramussoft.pb.idef.elements.PaintSector) MemoryData(com.dsoft.utils.DataLoader.MemoryData)

Aggregations

FloatPoint (com.dsoft.pb.types.FloatPoint)25 Point (com.ramussoft.pb.idef.elements.Point)14 Crosspoint (com.ramussoft.pb.Crosspoint)8 Ordinate (com.ramussoft.pb.idef.elements.Ordinate)7 SectorRefactor (com.ramussoft.pb.idef.elements.SectorRefactor)6 Function (com.ramussoft.pb.Function)5 PaintSector (com.ramussoft.pb.idef.elements.PaintSector)4 GeneralPath (java.awt.geom.GeneralPath)4 Point2D (java.awt.geom.Point2D)4 FRectangle (com.dsoft.pb.types.FRectangle)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 NFunction (com.ramussoft.pb.data.negine.NFunction)2 DFDFunction (com.ramussoft.pb.dfd.visual.DFDFunction)2 MovingFunction (com.ramussoft.pb.idef.visual.MovingFunction)2 MovingText (com.ramussoft.pb.idef.visual.MovingText)2 StringTokenizer (java.util.StringTokenizer)2 Status (com.dsoft.pb.idef.elements.Status)1 MemoryData (com.dsoft.utils.DataLoader.MemoryData)1 Rows (com.ramussoft.gui.qualifier.table.Rows)1