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);
}
}
}
}
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();
}
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();
}
}
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();
}
}
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();
}
}
Aggregations