Navigation Menu

Skip to content

Commit

Permalink
5.7.0.8.2 release
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjgraph committed Oct 3, 2016
1 parent 8ad8f27 commit 5ad7d27
Show file tree
Hide file tree
Showing 27 changed files with 48,402 additions and 1,261 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
@@ -1,3 +1,7 @@
03-SEP-2016: 5.7.0.8.2

- Adds tolerance, uses fewer cells in scissors tool

27-SEP-2016: 5.7.0.7

- Adds filename for editors in Atlassian cloud plugins
Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
5.7.0.7
5.7.0.8.2
124 changes: 73 additions & 51 deletions src/com/mxgraph/io/gliffy/importer/GliffyDiagramConverter.java
Expand Up @@ -79,15 +79,16 @@ private void start() {
this.gliffyDiagram = new GsonBuilder().create().fromJson(diagramString, Diagram.class);

collectVerticesAndConvert(vertices, gliffyDiagram.stage.getObjects(), null);

//sort objects by the order specified in the Gliffy diagram
sortObjectsByOrder(gliffyDiagram.stage.getObjects());

drawioDiagram.getModel().beginUpdate();

try {
// sort objects by the order specified in the Gliffy diagram
sortObjectsByOrder(gliffyDiagram.stage.getObjects());

for (Object obj : gliffyDiagram.stage.getObjects()) {
importObject(obj, null);
importObject(obj, obj.parent);
}

} finally {
Expand Down Expand Up @@ -118,24 +119,26 @@ private void correctLineEndings() {
}

/**
* Imports the objects into the draw.io diagram. Recursively adds the
* children of groups and swimlanes
*
* Imports the objects into the draw.io diagram. Recursively adds the children
*/
private void importObject(Object obj, mxCell parent) {
private void importObject(Object obj, Object gliffyParent) {

mxCell parent = gliffyParent != null ? gliffyParent.mxObject : null;

if (obj.isGroup() || obj.isMindmap() || obj.isShape() || obj.isText() || obj.isImage() || obj.isSwimlane() || obj.isSvg()) {
if (!obj.isLine()) {
drawioDiagram.addCell(obj.mxObject, parent);

if (obj.isGroup() || obj.isSwimlane()) {
if (obj.hasChildren()) {
if (!obj.isSwimlane())// sort the children except for swimlanes, // their order value is "auto"
sortObjectsByOrder(obj.children);

for (Object go : obj.children) {
importObject(go, go.parent.mxObject);
for (Object child : obj.children) {
//do not import text as a child object, use inline text
if(!child.isText())
importObject(child, obj);
}
}
} else if(obj.isLine()) {
} else {
// gets the terminal cells for the edge
mxCell startTerminal = getTerminalCell(obj, true);
mxCell endTerminal = getTerminalCell(obj, false);
Expand All @@ -144,10 +147,6 @@ private void importObject(Object obj, mxCell parent) {

applyControlPoints(obj, startTerminal, endTerminal);
}
else
{
logger.warning("Unrecognized object, uid : " + obj.uid);
}
}

private void sortObjectsByOrder(Collection<Object> values) {
Expand Down Expand Up @@ -225,17 +224,19 @@ private void applyControlPoints(Object object, mxCell startTerminal, mxCell endT
* up terminal cells for edges
*/
private void collectVerticesAndConvert(Map<Integer, Object> vertices, Collection<Object> objects, Object parent) {

for (Object object : objects) {
object.mxObject = convertGliffyObject(object, null);

object.parent = parent;

if (object.isGroup())// only do this recursively for groups, swimlanes have children w/o uid
{

convertGliffyObject(object, parent);

if(!object.isLine())
vertices.put(object.id, object);

// don't collect for swimlanes and mindmaps, their children are treated differently
if (object.hasChildren() && !object.isSwimlane() && !object.isMindmap())
collectVerticesAndConvert(vertices, object.children, object);
} else if (object.isShape() || object.isText() || object.isImage() || object.isSwimlane() || object.isSvg() || object.isMindmap()) {
vertices.put(object.id, object);
}
}
}

Expand All @@ -261,9 +262,9 @@ public String getGraphXml() {
*
*
*/
private mxCell convertGliffyObject(Object gliffyObject, mxCell parent) {
private mxCell convertGliffyObject(Object gliffyObject, Object parent) {
mxCell cell = new mxCell();
cell.setParent(parent);

StringBuilder style = new StringBuilder();

mxGeometry geometry = new mxGeometry((int) gliffyObject.x, (int) gliffyObject.y, (int) gliffyObject.width, (int) gliffyObject.height);
Expand All @@ -279,12 +280,11 @@ private mxCell convertGliffyObject(Object gliffyObject, mxCell parent) {
}

String text = null;
Object textObject = null;
Object textObject = gliffyObject.getTextObject();

String link = null;

if (graphic != null) {
textObject = gliffyObject.getTextObject();
link = gliffyObject.getLink();

if (gliffyObject.isShape()) {
Expand All @@ -305,11 +305,10 @@ private mxCell convertGliffyObject(Object gliffyObject, mxCell parent) {
style.append("opacity=" + shape.opacity * 100).append(";");

style.append(DashStyleMapping.get(shape.dashStyle));
style.append("whiteSpace=wrap;");
text = gliffyObject.getTextRecursively();

} else if (gliffyObject.isLine()) {
GliffyLine line = graphic.getLine();
GliffyLine line = graphic.Line;

cell.setEdge(true);
style.append("strokeWidth=" + line.strokeWidth).append(";");
style.append("strokeColor=" + line.strokeColor).append(";");
Expand All @@ -320,20 +319,27 @@ private mxCell convertGliffyObject(Object gliffyObject, mxCell parent) {

geometry.setX(0);
geometry.setY(0);

text = gliffyObject.getText();

} else if (gliffyObject.isText()) {

textObject = gliffyObject;
cell.setVertex(true);
style.append("text;whiteSpace=wrap;");
text = gliffyObject.getText();
style.append("text;whiteSpace=wrap;html=1;nl2Br=0;");
cell.setValue(gliffyObject.getText());

//if text is a child of a cell, use relative geometry and set X and Y to 0
if(gliffyObject.parent != null && !gliffyObject.parent.isGroup())
{
mxGeometry parentGeometry = gliffyObject.parent.mxObject.getGeometry();
cell.setGeometry(new mxGeometry(0, 0, parentGeometry.getWidth(), parentGeometry.getHeight()));
cell.getGeometry().setRelative(true);
}

} else if (gliffyObject.isImage()) {
GliffyImage image = graphic.getImage();
cell.setVertex(true);
style.append("shape=" + StencilTranslator.translate(gliffyObject.uid)).append(";");
style.append("image=" + image.getUrl()).append(";");

text = gliffyObject.getText();
}
else if (gliffyObject.isSvg()) {
GliffySvg svg = graphic.Svg;
Expand All @@ -350,7 +356,7 @@ else if (gliffyObject.isSwimlane()) {
style.append(StencilTranslator.translate(gliffyObject.uid)).append(";");

boolean vertical = true;
gliffyObject.rotation = 0;

if (gliffyObject.uid.startsWith(Object.H_SWIMLANE)) {
vertical = false;
cell.getGeometry().setWidth(gliffyObject.height);
Expand All @@ -359,6 +365,8 @@ else if (gliffyObject.isSwimlane()) {
}

Object header = gliffyObject.children.get(0);// first child is the header of the swimlane
Object headerText = header.children.get(0);

gliffyObject.children.remove(header);

GliffyShape shape = header.graphic.getShape();
Expand All @@ -368,7 +376,7 @@ else if (gliffyObject.isSwimlane()) {
style.append("strokeColor=" + shape.strokeColor).append(";");
style.append("whiteSpace=wrap;");

text = header.getText();
text = headerText.getText();

for (int i = 0; i < gliffyObject.children.size(); i++) // rest of the children are lanes
{
Expand All @@ -387,15 +395,27 @@ else if (gliffyObject.isSwimlane()) {
mxCell mxLane = new mxCell();
mxLane.setVertex(true);
cell.insert(mxLane);
mxLane.setValue(gLane.getText());
mxLane.setValue(gLane.children.get(0).getText());
mxLane.setStyle(laneStyle.toString());
mxGeometry childGeometry = new mxGeometry(gLane.x, gLane.y, vertical ? gLane.width : gLane.height, vertical ? gLane.height : gLane.width);
mxLane.setGeometry(childGeometry);
gLane.mxObject = mxLane;
}
} else if (gliffyObject.isMindmap()) {
Object child = gliffyObject.children.get(0);
GliffyMindmap mindmap = child.graphic.Mindmap;
}
/* Gliffy mindmap objects have a 3 level hierarchy
*
* mindmap
* rectangle
* text
*
* Since mindmap object already converts to rectangle, rectangle object is removed and text object is put in it's place
*
*/
else if (gliffyObject.isMindmap()) {
Object rectangle = gliffyObject.children.get(0);
Object textObj = rectangle.children.get(0);

GliffyMindmap mindmap = rectangle.graphic.Mindmap;

style.append("shape=" + StencilTranslator.translate(gliffyObject.uid)).append(";");
style.append("shadow=" + (mindmap.dropShadow ? 1 : 0)).append(";");
Expand All @@ -409,7 +429,12 @@ else if (gliffyObject.isSwimlane()) {

cell.setVertex(true);

text = child.getTextRecursively();
mxCell textObjMx = convertGliffyObject(textObj, gliffyObject);
textObjMx.setGeometry(new mxGeometry(0, 0, gliffyObject.width, gliffyObject.height));
textObjMx.getGeometry().setRelative(true);

//sets the grandchild as a child
gliffyObject.children.set(0, textObj);
}

if (gliffyObject.rotation != 0) {
Expand All @@ -419,9 +444,11 @@ else if (gliffyObject.isSwimlane()) {
if (!gliffyObject.isLine() && textObject != null) {
style.append(textObject.graphic.getText().getStyle());
}

if (text != null && !text.equals("")) {
style.append("html=1;nl2Br=0;");// nl2Br=0 stops newline from becoming <br>

if(textObject != null)
{
cell.setValue(textObject.getText());
style.append("html=1;nl2Br=0;whiteSpace=wrap");
}

if(link != null)
Expand All @@ -434,15 +461,10 @@ else if (gliffyObject.isSwimlane()) {
if(text != null && !text.equals(""))
uo.setAttribute("label", text);
}
else if(text != null && !text.equals(""))
{
cell.setValue(text);
}

cell.setStyle(style.toString());
gliffyObject.mxObject = cell;

return cell;
}

}
66 changes: 32 additions & 34 deletions src/com/mxgraph/io/gliffy/model/GliffyText.java
Expand Up @@ -9,6 +9,9 @@ public class GliffyText
private String html;

private String valign;

//extracted from html
private String halign;

private String vposition;

Expand All @@ -28,59 +31,48 @@ public class GliffyText

private static Pattern pattern = Pattern.compile("<p(.*?)<\\/p>");

private static Pattern textAlignPattern = Pattern.compile(
".*text-align: ?(left|center|right).*", Pattern.DOTALL);
private static Pattern textAlign = Pattern.compile(".*(text-align: ?(left|center|right);).*", Pattern.DOTALL);

public GliffyText()
{
}

public String getHtml()
{
halign = halign == null ? getHorizontalTextAlignment() : halign;
return replaceParagraphWithDiv(html);
}

//this is never invoked by Gson builder
public void setHtml(String html)
{
this.html = html;
}

public String getStyle()
{
StringBuilder sb = new StringBuilder();

//vertical label position
if (vposition.equals("above"))
{
sb.append("verticalLabelPosition=top;").append(
"verticalAlign=bottom;");
}
sb.append("verticalLabelPosition=top;");
else if (vposition.equals("below"))
{
sb.append("verticalLabelPosition=bottom;").append(
"verticalAlign=top;");
}
sb.append("verticalLabelPosition=bottom;");
else if (vposition.equals("none"))
{
sb.append("verticalAlign=").append(valign).append(";");
}

if (hposition.equals("left"))
{
sb.append("labelPosition=left;").append("align=right;");
}
else if (hposition.equals("right"))
{
sb.append("labelPosition=right;").append("align=left;");
}
else if (hposition.equals("none"))
{
String hAlign = getHorizontalTextAlignment();
if (hAlign != null)
{
sb.append("align=").append(hAlign).append(";");
}
}

sb.append("verticalLabelPosition=middle;");

//vertical label align
sb.append("verticalAlign=").append(valign).append(";");

//horizontal label position
if (hposition.equals("none"))
sb.append("labelPosition=center;");
else
sb.append("labelPosition=").append(hposition).append(";");

//horizontal label align
if (halign != null)
sb.append("align=").append(halign).append(";");

sb.append("spacingLeft=").append(paddingLeft).append(";");
sb.append("spacingRight=").append(paddingRight).append(";");
sb.append("spacingTop=").append(paddingTop).append(";");
Expand All @@ -101,13 +93,19 @@ private String replaceParagraphWithDiv(String html)
return sb.length() > 0 ? sb.toString() : html;
}

/**
* Extracts horizontal text alignment from html and removes it
* so it does not interfere with alignment set in mxCell style
* @return horizontal text alignment or null if there is none
*/
private String getHorizontalTextAlignment()
{
Matcher m = textAlignPattern.matcher(html);
Matcher m = textAlign.matcher(html);

if (m.matches())
{
return m.group(1);
html = html.replaceAll("text-align: ?\\w*;", "");
return m.group(2);
}

return null;
Expand Down

0 comments on commit 5ad7d27

Please sign in to comment.