Search in sources :

Example 31 with Stream

use of com.ramussoft.pb.Stream in project ramus by Vitaliy-Yakovchuk.

the class SectorRowsEditor method selectRows.

protected boolean selectRows() {
    final Stream tmp = getArrowRowsDialog().showModal();
    if (tmp == getStream() || tmp == null)
        return false;
    Stream ls = lowstream;
    setStream(tmp);
    lowstream = ls;
    if (getStream() != null) {
        rows = getStream().getAdded();
        fillStatuses();
    }
    rowsModel.refresh();
    return true;
}
Also used : Stream(com.ramussoft.pb.Stream)

Example 32 with Stream

use of com.ramussoft.pb.Stream in project ramus by Vitaliy-Yakovchuk.

the class SectorRefactor method createNewSector.

/**
 * Створює новий сектор по переданим точкам, новостворений сектор можна
 * отримати методом getSector().
 */
public void createNewSector() {
    Stream stream = null;
    boolean start = true;
    PaintSector fromSector = null;
    if (pointA.pin != null) {
        fromSector = pointA.pin.getSector();
        if (fromSector.getEnd() == null) {
            return;
        }
        if (pointB.pin != null) {
            final Sector s = pointB.pin.getSector().getSector();
            if (s.isConnectedOnFunction(fromSector.getSector()))
                return;
        }
        stream = fromSector.getStream();
    }
    if (pointB.pin != null) {
        fromSector = pointB.pin.getSector();
        if (fromSector.getStart() == null) {
            return;
        }
        if (stream == null) {
            stream = fromSector.getStream();
            start = false;
        }
    }
    Sector s1 = createMiss(pointA);
    Sector s2 = createMiss(pointB);
    final Sector s = getDataPlugin().createSector();
    s.setFunction(function);
    copyToSectorBorder(s.getStart(), pointA);
    s.getStart().setCrosspointA(pointA.crosspoint);
    s.getStart().commit();
    copyToSectorBorder(s.getEnd(), pointB);
    s.getEnd().setCrosspointA(pointB.crosspoint);
    s.getEnd().commit();
    final PaintSector sector = new PaintSector(s, pointA.point, pointB.point, movingArea);
    addSector(sector);
    if (stream != null && fromSector != null) {
        s.setStream(cloneStream(stream, movingArea.dataPlugin, s), ReplaceStreamType.CHILDREN);
        s.loadRowAttributes(fromSector.getSector(), start);
        s.setVisualAttributes(fromSector.getSector().getVisualAttributes());
    }
    if (fromSector != null) {
        if (s1 != null)
            s1.setVisualAttributes(fromSector.getSector().getVisualAttributes());
        if (s2 != null)
            s2.setVisualAttributes(fromSector.getSector().getVisualAttributes());
    }
    if (fromSector == null && stream == null && (pointA.sector != null || pointB.sector != null)) {
        PaintSector ps = pointA.sector;
        if (ps == null)
            ps = pointB.sector;
        if (s1 != null)
            s1.setVisualAttributes(ps.getSector().getVisualAttributes());
        if (s2 != null)
            s2.setVisualAttributes(ps.getSector().getVisualAttributes());
        if (ps.getStream() != null)
            s.setStream(ps.getStream(), ReplaceStreamType.CHILDREN);
    }
    sector.tryRemovePin(movingArea);
    sector.savePointOrdinates();
    // sector.saveVisual();
    lightSaveToFunction();
    this.sector = sector;
}
Also used : Sector(com.ramussoft.pb.Sector) NSector(com.ramussoft.pb.data.negine.NSector) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) Stream(com.ramussoft.pb.Stream)

Example 33 with Stream

use of com.ramussoft.pb.Stream in project ramus by Vitaliy-Yakovchuk.

the class SectorRefactor method copyOwnersFrom.

public static void copyOwnersFrom(Function function, DataPlugin dataPlugin) {
    Function par = (Function) function.getParent();
    HashSet<Function> roles = new HashSet<Function>();
    for (Sector sector : par.getSectors()) {
        if (function.equals(sector.getStart().getFunction())) {
            getEndRoles(sector, roles, dataPlugin);
            getStartRoles(sector, roles, dataPlugin);
        }
        if (function.equals(sector.getEnd().getFunction())) {
            getStartRoles(sector, roles, dataPlugin);
            getEndRoles(sector, roles, dataPlugin);
        }
    }
    Stream stream = (Stream) dataPlugin.findRowByGlobalId(function.getLink());
    Row[] owners;
    if (stream == null)
        owners = new Row[] {};
    else
        owners = stream.getAdded();
    for (Function function2 : roles) {
        stream = (Stream) dataPlugin.findRowByGlobalId(function2.getLink());
        if (stream == null) {
            if (owners.length > 0) {
                stream = (Stream) dataPlugin.createRow(dataPlugin.getBaseStream(), true);
                function2.setLink(stream.getElement().getId());
                stream.setRows(owners);
            }
        } else {
            stream.setRows(owners);
        }
    }
}
Also used : Function(com.ramussoft.pb.Function) NFunction(com.ramussoft.pb.data.negine.NFunction) Sector(com.ramussoft.pb.Sector) NSector(com.ramussoft.pb.data.negine.NSector) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) Stream(com.ramussoft.pb.Stream) Row(com.ramussoft.pb.Row) HashSet(java.util.HashSet)

Example 34 with Stream

use of com.ramussoft.pb.Stream in project ramus by Vitaliy-Yakovchuk.

the class ModelParaleler method getRow.

private Row getRow(long rowId) {
    if (rowId < 0l)
        return null;
    Row res = rowHash.get(rowId);
    if (res == null) {
        Row row = fromDataPlugin.findRowByGlobalId(rowId);
        if (row == null)
            return null;
        Element element = row.getElement();
        if (!((row instanceof Stream) && (element.getName().equals("")))) {
            Qualifier qualifier = null;
            if (row instanceof Stream)
                qualifier = IDEF0Plugin.getBaseStreamQualifier(toEngine);
            else
                qualifier = getQualifier(element.getQualifierId());
            if (qualifier == null)
                return null;
            Element e = toEngine.getElement(element.getName(), qualifier.getId());
            if (e != null) {
                Row row2 = toDataPlugin.findRowByGlobalId(e.getId());
                rowHash.put(e.getId(), row2);
                return row2;
            }
        }
        Row r = fromDataPlugin.findRowByGlobalId(rowId);
        res = toDataPlugin.createRow(getRow(getParentRow(r)), r.isElement());
        rowHash.put(r.getElement().getId(), res);
        copyRow(r, res);
    }
    return res;
}
Also used : Element(com.ramussoft.common.Element) Stream(com.ramussoft.pb.Stream) Qualifier(com.ramussoft.common.Qualifier) Row(com.ramussoft.pb.Row)

Example 35 with Stream

use of com.ramussoft.pb.Stream in project ramus by Vitaliy-Yakovchuk.

the class StreamAttributePlugin method getAttributeEditor.

@Override
public AttributeEditor getAttributeEditor(final Engine engine, final AccessRules rules, final Element element, final Attribute attribute, AttributeEditor old) {
    if (old != null)
        old.close();
    return new AbstractAttributeEditor() {

        private SectorRowsEditor sectorRowsEditor;

        private SectorNameEditor sectorNameEditor;

        private PaintSector.Pin pin;

        private DataPlugin dataPlugin;

        private PaintSector sector;

        private JTabbedPane component;

        {
            dataPlugin = NDataPluginFactory.getDataPlugin(null, engine, rules);
            Sector sector = dataPlugin.findSectorByGlobalId(GlobalId.create(element.getId()));
            if (sector != null) {
                dataPlugin = NDataPluginFactory.getDataPlugin(engine.getQualifier(sector.getFunction().getElement().getQualifierId()), engine, rules);
                component = new JTabbedPane();
                sectorRowsEditor = new SectorRowsEditor(dataPlugin, framework, rules);
                sectorNameEditor = new SectorNameEditor(dataPlugin, framework, rules) {

                    @Override
                    public Stream getStream() {
                        return sectorRowsEditor.getStream();
                    }
                };
                sectorRowsEditor.setSectorNameEditor(sectorNameEditor);
                component.addTab(ResourceLoader.getString("stream"), null, sectorRowsEditor, null);
                component.addTab(ResourceLoader.getString("name"), null, sectorNameEditor, null);
                ResourceLoader.setJComponentsText(sectorRowsEditor);
                ResourceLoader.setJComponentsText(sectorNameEditor);
            }
        }

        @Override
        public Object setValue(Object value) {
            this.pin = (PaintSector.Pin) value;
            sector = pin.getSector();
            sectorNameEditor.setSector(sector.getSector());
            sectorRowsEditor.setSector(sector.getSector());
            return value;
        }

        @Override
        public Object getValue() {
            return pin;
        }

        @Override
        public JComponent getComponent() {
            if (component == null)
                return new JPanel();
            return component;
        }

        @Override
        public JComponent getLastComponent() {
            return component;
        }

        @Override
        public void apply(Engine engine, Element element, Attribute attribute, Object value) {
            sector.setShowText(sectorNameEditor.getBox().isSelected());
            sector.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);
            final Row[] added = stream.getAdded();
            stream.setRows(sectorRowsEditor.getRows());
            sector.setStream(stream, sectorNameEditor.getReplaceStreamType());
            stream = sector.getStream();
            stream.setRows(added);
            // sector.setStreamAddedByRefactor(false);
            final Row[] rs = sectorRowsEditor.getRows();
            sector.setRows(rs);
            sector.createTexts();
            PaintSector.save(sector, new DataLoader.MemoryData(), engine);
            sector.getMovingArea().getRefactor().setUndoPoint();
            sectorNameEditor.setChanged(false);
        }

        @Override
        public boolean canApply() {
            final boolean b = isSave();
            if (b) {
                if (!isOkStreamName()) {
                    if (JOptionPane.showConfirmDialog(component, ResourceLoader.getString("you_entered_exists_stream_continue"), ResourceLoader.getString("warning"), JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION)
                        return false;
                }
            } else {
                JOptionPane.showMessageDialog(component, ResourceLoader.getString("you_should_enter_name_or_at_least_on_added_elemen"));
                return false;
            }
            return b;
        }

        private boolean isSave() {
            final Row[] rs = sectorRowsEditor.getRows();
            final boolean b = rs.length > 0 || !sectorNameEditor.getArrowName().equals("");
            return b;
        }

        private boolean isOkStreamName() {
            final Stream stream = sectorNameEditor.findStreamByName();
            if (stream != null)
                return stream.equals(sectorNameEditor.getNullStream());
            return true;
        }

        @Override
        public boolean isSaveAnyway() {
            return sectorRowsEditor.isChanged() || sectorNameEditor.isChanged();
        }

        @Override
        public void close() {
            super.close();
            sectorRowsEditor.dispose();
        }
    };
}
Also used : JPanel(javax.swing.JPanel) Attribute(com.ramussoft.common.Attribute) Sector(com.ramussoft.pb.Sector) PaintSector(com.ramussoft.pb.idef.elements.PaintSector) JTabbedPane(javax.swing.JTabbedPane) Element(com.ramussoft.common.Element) SectorNameEditor(com.ramussoft.pb.idef.frames.SectorNameEditor) DataLoader(com.dsoft.utils.DataLoader) AbstractAttributeEditor(com.ramussoft.gui.common.AbstractAttributeEditor) SectorRowsEditor(com.ramussoft.pb.idef.frames.SectorRowsEditor) PaintSector(com.ramussoft.pb.idef.elements.PaintSector) Stream(com.ramussoft.pb.Stream) Row(com.ramussoft.pb.Row) DataPlugin(com.ramussoft.pb.DataPlugin) Engine(com.ramussoft.common.Engine)

Aggregations

Stream (com.ramussoft.pb.Stream)51 Row (com.ramussoft.pb.Row)30 Function (com.ramussoft.pb.Function)21 Sector (com.ramussoft.pb.Sector)18 ByteArrayOutputStream (java.io.ByteArrayOutputStream)15 NSector (com.ramussoft.pb.data.negine.NSector)14 Vector (java.util.Vector)13 InputStream (java.io.InputStream)11 PaintSector (com.ramussoft.pb.idef.elements.PaintSector)10 ByteArrayInputStream (java.io.ByteArrayInputStream)10 Crosspoint (com.ramussoft.pb.Crosspoint)9 NFunction (com.ramussoft.pb.data.negine.NFunction)9 OutputStream (java.io.OutputStream)7 NStream (com.ramussoft.pb.data.negine.NStream)6 ArrayList (java.util.ArrayList)6 FloatPoint (com.dsoft.pb.types.FloatPoint)4 SectorRefactor (com.ramussoft.pb.idef.elements.SectorRefactor)4 MovingFunction (com.ramussoft.pb.idef.visual.MovingFunction)4 IOException (java.io.IOException)4 FRectangle (com.dsoft.pb.types.FRectangle)3