Search in sources :

Example 6 with MemoryData

use of com.dsoft.utils.DataLoader.MemoryData in project ramus by Vitaliy-Yakovchuk.

the class MovingArea method processMouse.

/**
 * Медод, який обробляє натискання на кнопці миші, якщо стан панелі
 * відображення змінює певні атрибути, то вони змінюються.
 *
 * @param e Пораметри натискання миші.
 */
protected void processMouse(final MouseEvent e) {
    if (e.getButton() == MouseEvent.BUTTON3)
        return;
    final int x = e.getX();
    final int y = e.getY();
    final double dX = getDoubleOrdinate(x);
    final double dY = getDoubleOrdinate(y);
    int type = Function.TYPE_OPERATION;
    if (getState() == FUNCTION_ADDING_STATE && getActiveObject() == null) {
        if (isOut(dX, LEFT_PART, CLIENT_WIDTH) || isOut(dY, TOP_PART, CLIENT_HEIGHT))
            return;
        if (!canAddOnContext()) {
            JOptionPane.showMessageDialog(this, ResourceLoader.getString("you_can_not_add_more_then_one_f"));
            return;
        }
        addInOutObject(dX, dY, type);
    } else if (getState() == EXTERNAL_REFERENCE_ADDING_STATE && getActiveObject() == null) {
        if (isOut(dX, LEFT_PART, CLIENT_WIDTH) || isOut(dY, TOP_PART, CLIENT_HEIGHT))
            return;
        addInOutObject(dX, dY, Function.TYPE_EXTERNAL_REFERENCE);
    } else if (getState() == DATA_STORE_ADDING_STATE && getActiveObject() == null) {
        if (isOut(dX, LEFT_PART, CLIENT_WIDTH) || isOut(dY, TOP_PART, CLIENT_HEIGHT))
            return;
        addInOutObject(dX, dY, Function.TYPE_DATA_STORE);
    } else if (getState() == DFDS_ROLE_ADDING_STATE && getActiveObject() == null) {
        if (isOut(dX, LEFT_PART, CLIENT_WIDTH) || isOut(dY, TOP_PART, CLIENT_HEIGHT))
            return;
        addInOutObject(dX, dY, Function.TYPE_DFDS_ROLE);
    } else if (getChangingState() == ARROW_CHANGING_STATE) {
        final PaintSector.Pin activePin = getPin(e.getX(), e.getY());
        if (activePin == null)
            addArrowToArea(dX, dY);
        else {
            PaintSector sector = activePin.getSector();
            if ((sector.isPart()) && (sector.isSelEnd() || sector.isSelStart())) {
                if (activeObject instanceof PaintSector.Pin) {
                    final PaintSector.Pin pin = (PaintSector.Pin) activeObject;
                    if (pin.getSector().isSelEnd() || pin.getSector().isSelStart()) {
                        setActiveObject(null);
                        refactor.setSector(pin.getSector());
                        if (pin.getSector().isSelEnd()) {
                            setState(END_POINT_CHANGING_ADD);
                        } else if (pin.getSector().isSelStart()) {
                            setState(START_POINT_CHANGING_ADD);
                        }
                        panel.getFramework().put(CURRENT_MOVING_AREA, this);
                    }
                }
            } else {
                if (getPointChangingType() == SectorRefactor.TYPE_START) {
                    if (sector.isPart() && activePin.getSector().getStart() == null)
                        return;
                } else {
                    if (activePin.getSector().isPart() && activePin.getSector().getEnd() == null)
                        return;
                }
                final SectorRefactor.PerspectivePoint pp = new SectorRefactor.PerspectivePoint();
                pp.type = getPointChangingType();
                pp.pin = activePin;
                pp.x = getDoubleOrdinate(e.getX());
                pp.y = getDoubleOrdinate(e.getY());
                refactor.setPoint(pp);
                doSector();
            }
        }
    } else if (getChangingState() == TILDA_ADDING_STATE) {
        final PaintSector.Pin activePin = getPin(e.getX(), e.getY());
        if (activePin != null) {
            startUserTransaction();
            List<PaintSector> ps = activePin.getSector().setTildaPos(getDoubleOrdinate(e.getX()), getDoubleOrdinate(e.getY()));
            for (PaintSector s : ps) PaintSector.save(s, new MemoryData(), dataPlugin.getEngine());
            refactor.setUndoPoint();
        }
    } else if (getChangingState() == TEXT_ADDING_STATE) {
        final MovingText text = createText();
        cancelAdding();
        refactor.addText(text);
        text.setBounds(dX, dY, text.getBounds().getWidth(), text.getBounds().getHeight());
        text.setFont(Options.getFont("DEFAULT_TEXT_FONT", new Font("Arial", 0, 10)));
        text.setColor(Options.getColor("DEFAULT_TEXT_COLOR", Color.black));
        startUserTransaction();
        refactor.setUndoPoint();
    } else {
        if (activeObject instanceof PaintSector.Pin) {
            final PaintSector.Pin pin = (PaintSector.Pin) activeObject;
            if (pin.getSector().isSelEnd() || pin.getSector().isSelStart()) {
                setActiveObject(null);
                refactor.setSector(pin.getSector());
                if (pin.getSector().isSelEnd()) {
                    setState(END_POINT_CHANGING);
                } else if (pin.getSector().isSelStart()) {
                    setState(START_POINT_CHANGING);
                }
                panel.getFramework().put(CURRENT_MOVING_AREA, this);
            }
        }
    }
}
Also used : Pin(com.ramussoft.pb.idef.elements.PaintSector.Pin) SectorRefactor(com.ramussoft.pb.idef.elements.SectorRefactor) Pin(com.ramussoft.pb.idef.elements.PaintSector.Pin) PaintSector(com.ramussoft.pb.idef.elements.PaintSector) PerspectivePoint(com.ramussoft.pb.idef.elements.SectorRefactor.PerspectivePoint) MemoryData(com.dsoft.utils.DataLoader.MemoryData) ArrayList(java.util.ArrayList) EventListenerList(javax.swing.event.EventListenerList) List(java.util.List) PerspectivePoint(com.ramussoft.pb.idef.elements.SectorRefactor.PerspectivePoint) PerspectivePoint(com.ramussoft.pb.idef.elements.SectorRefactor.PerspectivePoint) FloatPoint(com.dsoft.pb.types.FloatPoint) Crosspoint(com.ramussoft.pb.Crosspoint) Point(com.ramussoft.pb.idef.elements.Point) Font(java.awt.Font)

Example 7 with MemoryData

use of com.dsoft.utils.DataLoader.MemoryData in project ramus by Vitaliy-Yakovchuk.

the class MovingArea method setShowTilda.

/**
 * Робить так, що показується тільда на активному секторі.
 */
public void setShowTilda() {
    startUserTransaction();
    final PaintSector sector = ((PaintSector.Pin) activeObject).getSector();
    sector.setShowTilda(!sector.isShowTilda());
    PaintSector.save(sector, new MemoryData(), getDataPlugin().getEngine());
    refactor.setUndoPoint();
}
Also used : Pin(com.ramussoft.pb.idef.elements.PaintSector.Pin) PaintSector(com.ramussoft.pb.idef.elements.PaintSector) MemoryData(com.dsoft.utils.DataLoader.MemoryData)

Example 8 with MemoryData

use of com.dsoft.utils.DataLoader.MemoryData in project ramus by Vitaliy-Yakovchuk.

the class PaintSector method loadVisuals.

private void loadVisuals() {
    final byte[] bs = sector.getVisualAttributes();
    if (bs.length == 0) {
        stroke = Options.getStroke("DEFAULT_ARROW_STROKE", stroke);
        return;
    }
    final DataLoader.MemoryData memoryData = new DataLoader.MemoryData();
    final ByteArrayInputStream is = new ByteArrayInputStream(bs);
    try {
        stroke = DataLoader.readStroke(is, memoryData);
        font = DataLoader.readFont(is, memoryData);
        color = DataLoader.readColor(is, memoryData);
        is.close();
    } catch (final Exception e) {
        e.printStackTrace();
    }
}
Also used : DataLoader(com.dsoft.utils.DataLoader) ByteArrayInputStream(java.io.ByteArrayInputStream) MemoryData(com.dsoft.utils.DataLoader.MemoryData) IOException(java.io.IOException) MemoryData(com.dsoft.utils.DataLoader.MemoryData)

Example 9 with MemoryData

use of com.dsoft.utils.DataLoader.MemoryData in project ramus by Vitaliy-Yakovchuk.

the class PaintSector method saveVisual.

public void saveVisual() {
    try {
        final DataLoader.MemoryData memoryData = new DataLoader.MemoryData();
        final ByteArrayOutputStream os = new ByteArrayOutputStream();
        DataSaver.saveStroke(os, stroke, memoryData);
        DataSaver.saveFont(os, font, memoryData);
        DataSaver.saveColor(os, color, memoryData);
        sector.setVisualAttributes(os.toByteArray());
        os.close();
    } catch (final IOException e) {
        e.printStackTrace();
    }
}
Also used : DataLoader(com.dsoft.utils.DataLoader) MemoryData(com.dsoft.utils.DataLoader.MemoryData) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) MemoryData(com.dsoft.utils.DataLoader.MemoryData)

Example 10 with MemoryData

use of com.dsoft.utils.DataLoader.MemoryData in project ramus by Vitaliy-Yakovchuk.

the class UserTemplate method createChilds.

public void createChilds(final Function function, final DataPlugin dataPlugin) {
    Hashtable<Long, Long> trans = new Hashtable<Long, Long>();
    final MovingArea ma = new MovingArea(dataPlugin);
    ma.setDataPlugin(dataPlugin);
    ma.setActiveFunction(function);
    final SectorRefactor refactor = ma.getRefactor();
    try {
        final ByteArrayInputStream streamr = new ByteArrayInputStream(data);
        final ObjectInputStream stream = new ObjectInputStream(streamr);
        final MemoryData data = new MemoryData();
        int l = DataLoader.readInteger(stream);
        for (int i = 0; i < l; i++) {
            final Function c = (Function) dataPlugin.createRow(function, true);
            c.setName(functionNames.get(i));
            if (i < functionTypes.size())
                c.setType(functionTypes.get(i));
            if (i < functionLinks.size()) {
                Row r = dataPlugin.findRowByGlobalId(functionLinks.get(i));
                if (r != null) {
                    if (r instanceof Stream) {
                        Stream st = (Stream) r;
                        Stream s = (Stream) dataPlugin.createRow(dataPlugin.getBaseStream(), true);
                        s.setAttachedStatus(st.getAttachedStatus());
                        s.setEmptyName(st.isEmptyName());
                        s.setRows(st.getAdded());
                        c.setLink(s.getElement().getId());
                    }
                }
            }
            final long id = DataLoader.readLong(stream);
            trans.put(id, c.getElement().getId());
            c.setBounds(DataLoader.readFRectangle(stream));
            c.setFont(DataLoader.readFont(stream, data));
            c.setBackground(DataLoader.readColor(stream, data));
            c.setForeground(DataLoader.readColor(stream, data));
        }
        // Read version of
        final int ver = DataLoader.readInteger(stream);
        // Paint
        // Sector format
        l = DataLoader.readInteger(stream);
        HashMap<Sector, List<SectorPointPersistent>> pointsCache = new HashMap<Sector, List<SectorPointPersistent>>();
        HashMap<Long, Long> pointIds = new HashMap<Long, Long>();
        for (int i = 0; i < l; i++) {
            final Sector s = dataPlugin.createSector();
            s.setFunction(function);
            final long id = DataLoader.readLong(stream);
            trans.put(id, ((NSector) s).getElementId());
            final byte[] va = DataLoader.readBytes(stream);
            s.setVisualAttributes(va);
            List<SectorPointPersistent> points = (List) stream.readObject();
            pointsCache.put(s, points);
            normalize(points, dataPlugin.getEngine(), pointIds);
            s.setSectorPointPersistents(points);
            s.setSectorProperties((SectorPropertiesPersistent) stream.readObject());
            // final byte bs[] = DataLoader.readBytes(stream);
            // final ByteArrayInputStream ba = new ByteArrayInputStream(bs);
            final PaintSector ps = PaintSector.loadFromSector(ver, ma, data, dataPlugin, s);
            refactor.addSector(ps);
            Crosspoint c;
            if (DataLoader.readBoolean(stream)) {
                c = getCrosspoint(dataPlugin, trans, stream);
                s.getStart().setCrosspointA(c);
            }
            loadBorder(s.getStart(), stream, trans, dataPlugin, refactor, ps, true);
            s.getStart().commit();
            if (DataLoader.readBoolean(stream)) {
                c = getCrosspoint(dataPlugin, trans, stream);
                s.getEnd().setCrosspointA(c);
            }
            loadBorder(s.getEnd(), stream, trans, dataPlugin, refactor, ps, false);
            s.getEnd().commit();
            if (DataLoader.readBoolean(stream)) {
                int count = DataLoader.readInteger(stream);
                List<Row> rows = new ArrayList<Row>();
                for (int j = 0; j < count; j++) {
                    Row row = loadRow(stream, dataPlugin);
                    if (row != null)
                        rows.add(row);
                }
                if (rows.size() > 0) {
                    Stream stream2 = (Stream) dataPlugin.createRow(dataPlugin.getBaseStream(), true);
                    stream2.setRows(rows.toArray(new Row[rows.size()]));
                    ((NSector) s).setThisStream(stream2);
                }
            }
        }
        setPoints(pointsCache);
        refactor.saveToFunction();
    } catch (final Exception e) {
        e.printStackTrace();
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Function(com.ramussoft.pb.Function) NFunction(com.ramussoft.pb.data.negine.NFunction) NSector(com.ramussoft.pb.data.negine.NSector) PaintSector(com.ramussoft.pb.idef.elements.PaintSector) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectInputStream(java.io.ObjectInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectOutputStream(java.io.ObjectOutputStream) OutputStream(java.io.OutputStream) Stream(com.ramussoft.pb.Stream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) List(java.util.List) MovingArea(com.ramussoft.pb.idef.visual.MovingArea) SectorRefactor(com.ramussoft.pb.idef.elements.SectorRefactor) Hashtable(java.util.Hashtable) Sector(com.ramussoft.pb.Sector) NSector(com.ramussoft.pb.data.negine.NSector) PaintSector(com.ramussoft.pb.idef.elements.PaintSector) NCrosspoint(com.ramussoft.pb.data.negine.NCrosspoint) Crosspoint(com.ramussoft.pb.Crosspoint) NCrosspoint(com.ramussoft.pb.data.negine.NCrosspoint) Crosspoint(com.ramussoft.pb.Crosspoint) IOException(java.io.IOException) ByteArrayInputStream(java.io.ByteArrayInputStream) MemoryData(com.dsoft.utils.DataLoader.MemoryData) SectorPointPersistent(com.ramussoft.idef0.attribute.SectorPointPersistent) Row(com.ramussoft.pb.Row) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

MemoryData (com.dsoft.utils.DataLoader.MemoryData)11 PaintSector (com.ramussoft.pb.idef.elements.PaintSector)8 ArrayList (java.util.ArrayList)7 FloatPoint (com.dsoft.pb.types.FloatPoint)6 SectorRefactor (com.ramussoft.pb.idef.elements.SectorRefactor)5 NFunction (com.ramussoft.pb.data.negine.NFunction)4 Point (com.ramussoft.pb.idef.elements.Point)4 FRectangle (com.dsoft.pb.types.FRectangle)3 Crosspoint (com.ramussoft.pb.Crosspoint)3 Function (com.ramussoft.pb.Function)3 Pin (com.ramussoft.pb.idef.elements.PaintSector.Pin)3 IOException (java.io.IOException)3 DataLoader (com.dsoft.utils.DataLoader)2 Row (com.ramussoft.pb.Row)2 Stream (com.ramussoft.pb.Stream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 List (java.util.List)2 Engine (com.ramussoft.common.Engine)1 RectangleVisualOptions (com.ramussoft.idef0.attribute.RectangleVisualOptions)1