Search in sources :

Example 1 with RectangleVisualOptions

use of com.ramussoft.idef0.attribute.RectangleVisualOptions in project ramus by Vitaliy-Yakovchuk.

the class DFDSRole method onProcessEndBoundsChange.

@Override
public void onProcessEndBoundsChange() {
    final FRectangle oldRec = function.getBounds();
    myBounds.setTransformNetBounds(MovingArea.NET_LENGTH);
    List<PaintSector> list = new ArrayList<PaintSector>();
    final SectorRefactor refactor = movingArea.getRefactor();
    boolean sectorReplaced = false;
    DFDSFunction function = movingArea.findDFDSFunction(this.getBounds());
    if (function != null) {
        getFunction().setOwner(function.getFunction());
        for (int i = 0; i < refactor.getSectorsCount(); i++) {
            PaintSector ps = refactor.getSector(i);
            Function function2 = ps.getSector().getStart().getFunction();
            if (function2 != null && function2.equals(this.function)) {
                replaceFunction(ps.getSector().getStart(), ps, list, ps.getStartPoint(), ps.getSector().getStart().getFunctionType(), function, refactor, true);
            }
            Function function3 = ps.getSector().getEnd().getFunction();
            if (function3 != null && function3.equals(this.function)) {
                replaceFunction(ps.getSector().getEnd(), ps, list, ps.getEndPoint(), ps.getSector().getEnd().getFunctionType(), function, refactor, false);
            }
        }
        function.justifyRoles();
        sectorReplaced = true;
    } else {
        if (this.getFunction().getOwner() != null) {
            DFDSFunction function2 = movingArea.findDFDSFunction(this.getFunction().getOwner());
            if (function2 != null && function2.getBounds().intersects(this.getBounds())) {
                function2.justifyRoles();
            } else
                this.function.setBounds(new FRectangle(myBounds));
        } else
            this.function.setBounds(new FRectangle(myBounds));
    }
    MemoryData memoryData = new MemoryData();
    if (!sectorReplaced) {
        for (int i = 0; i < refactor.getSectorsCount(); i++) {
            PaintSector sector = refactor.getSector(i);
            setAddedSectorPos(oldRec, sector, list);
        }
    }
    for (PaintSector ps : list) PaintSector.save(ps, memoryData, ((NFunction) this.function).getEngine());
    long l = this.function.getLink();
    if (l >= 0l) {
        Stream stream = (Stream) movingArea.getDataPlugin().findRowByGlobalId(l);
        if (stream != null) {
            Row[] rows = stream.getAdded();
            RectangleVisualOptions ops = new RectangleVisualOptions();
            ops.bounds = this.function.getBounds();
            ops.background = this.function.getBackground();
            ops.font = this.function.getFont();
            ops.foreground = this.function.getForeground();
            for (Row row : rows) if (row != null) {
                IDEF0Plugin.setDefaultRectangleVisualOptions(movingArea.getDataPlugin().getEngine(), row.getElement(), ops);
            }
        }
    }
}
Also used : SectorRefactor(com.ramussoft.pb.idef.elements.SectorRefactor) NFunction(com.ramussoft.pb.data.negine.NFunction) ArrayList(java.util.ArrayList) Point(com.ramussoft.pb.idef.elements.Point) FloatPoint(com.dsoft.pb.types.FloatPoint) Function(com.ramussoft.pb.Function) NFunction(com.ramussoft.pb.data.negine.NFunction) FRectangle(com.dsoft.pb.types.FRectangle) PaintSector(com.ramussoft.pb.idef.elements.PaintSector) MemoryData(com.dsoft.utils.DataLoader.MemoryData) RectangleVisualOptions(com.ramussoft.idef0.attribute.RectangleVisualOptions) Stream(com.ramussoft.pb.Stream) Row(com.ramussoft.pb.Row)

Example 2 with RectangleVisualOptions

use of com.ramussoft.idef0.attribute.RectangleVisualOptions in project ramus by Vitaliy-Yakovchuk.

the class IDEF0Plugin method getDefaultRectangleVisualOptions.

/**
 * Can return null if there is no visual options
 */
public static RectangleVisualOptions getDefaultRectangleVisualOptions(Engine engine, Element element) {
    if (hasVisualAttributes(engine, element)) {
        RectangleVisualOptions ops = new RectangleVisualOptions();
        ops.bounds = (FRectangle) engine.getAttribute(element, getAttribute(engine, F_BOUNDS));
        if (ops.bounds == null)
            return null;
        ops.background = (Color) engine.getAttribute(element, getAttribute(engine, F_BACKGROUND));
        ops.foreground = (Color) engine.getAttribute(element, getAttribute(engine, F_FOREGROUND));
        ops.font = (Font) engine.getAttribute(element, getAttribute(engine, F_FONT));
        return ops;
    }
    return null;
}
Also used : RectangleVisualOptions(com.ramussoft.idef0.attribute.RectangleVisualOptions)

Example 3 with RectangleVisualOptions

use of com.ramussoft.idef0.attribute.RectangleVisualOptions 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 4 with RectangleVisualOptions

use of com.ramussoft.idef0.attribute.RectangleVisualOptions in project ramus by Vitaliy-Yakovchuk.

the class DFDSRoleOptionsDialog method onOk.

@Override
protected void onOk() {
    if (!isCanOk()) {
        JOptionPane.showMessageDialog(this, ResourceLoader.getString("you_should_enter_name_or_at_least_on_added_elemen"));
        return;
    }
    if (!isOkStreamName()) {
        if (JOptionPane.showConfirmDialog(this, ResourceLoader.getString("you_entered_exists_stream_continue"), ResourceLoader.getString("warning"), JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {
            return;
        }
    }
    DFDSRole role = (DFDSRole) object;
    Journaled journaled = (Journaled) dataPlugin.getEngine();
    journaled.startUserTransaction();
    Function function = object.getFunction();
    function.setFont(fontChooser.getSelFont());
    function.setBackground(backgroundColorChooser.getColor());
    function.setForeground(foregroundColorChooser.getColor());
    role.setAlternativeText(sectorNameEditor.getAlternativeTextField().getText());
    Stream stream = sectorRowsEditor.getStream();
    if (stream == null) {
        stream = sectorNameEditor.findStreamByName();
        if (stream == null) {
            stream = (Stream) dataPlugin.createRow(dataPlugin.getBaseStream(), true);
        }
    }
    final String t = sectorNameEditor.getArrowName();
    if (!t.equals("")) {
        if (!t.equals(stream.getName()) && sectorNameEditor.findStreamByName(stream.getName()) != null) {
            stream = (Stream) dataPlugin.createRow(dataPlugin.getBaseStream(), true);
        }
    }
    if (t.equals("")) {
        if (!stream.isEmptyName()) {
            stream = (Stream) dataPlugin.createRow(dataPlugin.getBaseStream(), true);
            stream.setEmptyName(true);
        }
    } else {
        stream.setName(t);
    }
    stream.setRows(sectorRowsEditor.getRows());
    role.setStream(stream, ReplaceStreamType.SIMPLE);
    // sector.setStreamAddedByRefactor(false);
    final Row[] rs = sectorRowsEditor.getRows();
    role.setRows(rs);
    if (rs != null) {
        RectangleVisualOptions ops = new RectangleVisualOptions();
        ops.bounds = function.getBounds();
        ops.background = function.getBackground();
        ops.font = function.getFont();
        ops.foreground = function.getForeground();
        for (Row row : rs) if (row != null) {
            IDEF0Plugin.setDefaultRectangleVisualOptions(dataPlugin.getEngine(), row.getElement(), ops);
        }
    }
    journaled.commitUserTransaction();
    setVisible(false);
}
Also used : DFDSRole(com.ramussoft.pb.dfds.visual.DFDSRole) Journaled(com.ramussoft.common.journal.Journaled) Function(com.ramussoft.pb.Function) RectangleVisualOptions(com.ramussoft.idef0.attribute.RectangleVisualOptions) Stream(com.ramussoft.pb.Stream) Row(com.ramussoft.pb.Row)

Aggregations

RectangleVisualOptions (com.ramussoft.idef0.attribute.RectangleVisualOptions)4 Function (com.ramussoft.pb.Function)3 Stream (com.ramussoft.pb.Stream)3 FRectangle (com.dsoft.pb.types.FRectangle)2 FloatPoint (com.dsoft.pb.types.FloatPoint)2 Row (com.ramussoft.pb.Row)2 NFunction (com.ramussoft.pb.data.negine.NFunction)2 ArrayList (java.util.ArrayList)2 MemoryData (com.dsoft.utils.DataLoader.MemoryData)1 Journaled (com.ramussoft.common.journal.Journaled)1 Rows (com.ramussoft.gui.qualifier.table.Rows)1 DFDFunction (com.ramussoft.pb.dfd.visual.DFDFunction)1 DFDSFunction (com.ramussoft.pb.dfds.visual.DFDSFunction)1 DFDSRole (com.ramussoft.pb.dfds.visual.DFDSRole)1 PaintSector (com.ramussoft.pb.idef.elements.PaintSector)1 Point (com.ramussoft.pb.idef.elements.Point)1 SectorRefactor (com.ramussoft.pb.idef.elements.SectorRefactor)1 ActiveFunctionEvent (com.ramussoft.pb.idef.visual.event.ActiveFunctionEvent)1 ActiveFunctionListener (com.ramussoft.pb.idef.visual.event.ActiveFunctionListener)1 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1