Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamille Letavernier2015-02-12 04:14:57 -0500
committerGerrit Code Review @ Eclipse.org2015-02-12 04:14:58 -0500
commite662f35d3a6ec941a247a33834933713cd0bd873 (patch)
treea5f61c820b279f73db52d4922e923d85631f583b
parentf1b2c032ad58389f35e2d86f077e8e23d1b9ad65 (diff)
parentf398b5df800541fd95e628ee5eaf62129b9c8e9f (diff)
downloadorg.eclipse.papyrus-e662f35d3a6ec941a247a33834933713cd0bd873.tar.gz
org.eclipse.papyrus-e662f35d3a6ec941a247a33834933713cd0bd873.tar.xz
org.eclipse.papyrus-e662f35d3a6ec941a247a33834933713cd0bd873.zip
Merge "Bug 458957 - [Classs Diagram - Tests] Tests are failing due the change of behavior in Comments" into streams/1.0-maintenance
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/HTMLCornerBentFigure.java156
1 files changed, 80 insertions, 76 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/HTMLCornerBentFigure.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/HTMLCornerBentFigure.java
index a406e5cc326..56475252d70 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/HTMLCornerBentFigure.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/HTMLCornerBentFigure.java
@@ -13,6 +13,7 @@
package org.eclipse.papyrus.uml.diagram.common.figure.node;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -68,8 +69,8 @@ public class HTMLCornerBentFigure extends CornerBentFigure implements ILabelFigu
/** main flow page */
protected FlowPage page;
- /** properties stack to store which format to apply */
- protected Stack<Styles> textProperties = new Stack<Styles>();
+ /** text styles stack */
+ private final List<List<Styles>> myStyles = new ArrayList<List<Styles>>();
/** font used for the figure */
private FontData currentFontData;
@@ -89,7 +90,6 @@ public class HTMLCornerBentFigure extends CornerBentFigure implements ILabelFigu
super();
this.setBackgroundColor(THIS_BACK);
createContents();
-
}
/**
@@ -212,17 +212,16 @@ public class HTMLCornerBentFigure extends CornerBentFigure implements ILabelFigu
// parse the HMTL text and transforms it into a tree. "Body" tags
// enforce the character chain to be a valid xml chain
NodeList nodeList = generateNodeList("<body>" + text + "</body>");
-
+ myStyles.clear();
// generate blocks from this list and adds it to the flow page children
if (nodeList.getLength() > 0) {
- generateBlocksFromNodeList(nodeList, page);
+ generateBlocksFromNodeList(nodeList, page, new Stack<Styles>());
} else {
// problem during parsing
// return only one text flow with the content of the text
TextFlowEx textFlow = new TextFlowEx(text);
page.add(textFlow);
}
-
}
/**
@@ -231,41 +230,46 @@ public class HTMLCornerBentFigure extends CornerBentFigure implements ILabelFigu
* @param nodeList
* the list of nodes from which to generates the blockflows
*/
- protected void generateBlocksFromNodeList(NodeList nodeList, BlockFlow parentFlow) {
+ protected void generateBlocksFromNodeList(NodeList nodeList, BlockFlow parentFlow, Stack<Styles> parentStyles) {
// for each element in the list, generates the corresponding blocks
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
-
String nodeName = node.getNodeName();
short nodeType = node.getNodeType();
if (nodeType == Node.TEXT_NODE) {
- generateTextFromTextNode(node, parentFlow);
+ String text = HTMLCleaner.cleanHTMLTags(node.getNodeValue());
+ if (text == null || text.trim().isEmpty()) {
+ continue;
+ }
+ List<Styles> styles = Collections.list(parentStyles.elements());
+ myStyles.add(styles);
+ generateTextFromTextNode(text, parentFlow, styles);
} else {
try {
switch (HTMLTags.valueOf(nodeName)) {
case body: // main tag for the comment body
// create a block for the body
- generateBlocksFromBodyNode(node, parentFlow);
+ generateBlocksFromBodyNode(node, parentFlow, parentStyles);
break;
case h3:
- generateBlocksFromH3Node(node, parentFlow);
+ generateBlocksFromH3Node(node, parentFlow, parentStyles);
break;
case h4: // sub section heading
- generateBlocksFromH4Node(node, parentFlow);
+ generateBlocksFromH4Node(node, parentFlow, parentStyles);
break;
case h5: // sub sub section heading
- generateBlocksFromH5Node(node, parentFlow);
+ generateBlocksFromH5Node(node, parentFlow, parentStyles);
break;
case strong: // bold character
case b:
- generateBlocksFromStrongNode(node, parentFlow);
+ generateBlocksFromStrongNode(node, parentFlow, parentStyles);
break;
case em: // italic
- generateBlocksFromItalicNode(node, parentFlow);
+ generateBlocksFromItalicNode(node, parentFlow, parentStyles);
break;
case u: // underline
- generateBlocksFromUnderlineNode(node, parentFlow);
+ generateBlocksFromUnderlineNode(node, parentFlow, parentStyles);
break;
case sub: // subscript
break;
@@ -276,13 +280,13 @@ public class HTMLCornerBentFigure extends CornerBentFigure implements ILabelFigu
case table: // table
break;
case p: // paragraph
- generateBlocksFromParagraphNode(node, parentFlow);
+ generateBlocksFromParagraphNode(node, parentFlow, parentStyles);
break;
case br:
generateBlocksFromBRNode(node, parentFlow);
break;
case font:
- generateBlocksForFontNode(node, parentFlow);
+ generateBlocksForFontNode(node, parentFlow, parentStyles);
break;
default:
break;
@@ -303,12 +307,12 @@ public class HTMLCornerBentFigure extends CornerBentFigure implements ILabelFigu
* @param parentFlow
* the parent block flow which will contain the block created
*/
- protected void generateBlocksFromUnderlineNode(Node node, BlockFlow parentFlow) {
+ protected void generateBlocksFromUnderlineNode(Node node, BlockFlow parentFlow, Stack<Styles> styles) {
NodeList childrenNodes = node.getChildNodes();
- textProperties.push(Styles.underline);
- generateBlocksFromNodeList(childrenNodes, parentFlow);
- textProperties.pop();
+ styles.push(Styles.underline);
+ generateBlocksFromNodeList(childrenNodes, parentFlow, styles);
+ styles.pop();
}
/**
@@ -320,9 +324,10 @@ public class HTMLCornerBentFigure extends CornerBentFigure implements ILabelFigu
public void setFont(Font f) {
super.setFont(f);
List<TextFlow> textFlowList = findTextFlowChildList(page);
- Font currentParentFont = calculateCurrentFont();
+ int i = 0;
for (TextFlow nextTextFlow : textFlowList) {
- nextTextFlow.setFont(currentParentFont);
+ nextTextFlow.setFont(calculateCurrentFont(myStyles.get(i)));
+ i++;
}
}
@@ -353,12 +358,10 @@ public class HTMLCornerBentFigure extends CornerBentFigure implements ILabelFigu
* @param parentFlow
* the parent block flow which will contain the block created
*/
- protected void generateTextFromTextNode(Node node, BlockFlow parentFlow) {
- // node has type: TEXT_NODE
- String text = HTMLCleaner.cleanHTMLTags(node.getNodeValue());
+ protected void generateTextFromTextNode(String text, BlockFlow parentFlow, List<Styles> styles) {
TextFlowEx textFlow = new TextFlowEx(text);
- textFlow.setTextUnderline(getUnderLineFromStyles());
- textFlow.setFont(calculateCurrentFont());
+ textFlow.setTextUnderline(getUnderLineFromStyles(styles));
+ textFlow.setFont(calculateCurrentFont(styles));
parentFlow.add(textFlow);
}
@@ -369,8 +372,8 @@ public class HTMLCornerBentFigure extends CornerBentFigure implements ILabelFigu
*
* @return
*/
- private Font calculateCurrentFont() {
- return composeFontWithStyles(getDefaultFontData());
+ private Font calculateCurrentFont(List<Styles> styles) {
+ return composeFontWithStyles(getDefaultFontData(), styles);
}
/**
@@ -379,9 +382,9 @@ public class HTMLCornerBentFigure extends CornerBentFigure implements ILabelFigu
* @see generateTextFromTextNode() for using
* @return
*/
- private boolean getUnderLineFromStyles() {
+ private boolean getUnderLineFromStyles(List<Styles> styles) {
boolean result = false;
- for (Styles style : textProperties) {
+ for (Styles style : styles) {
switch (style) {
case underline:
result = true;
@@ -435,15 +438,16 @@ public class HTMLCornerBentFigure extends CornerBentFigure implements ILabelFigu
* @param defaultFontData
* @return
*/
- private Font composeFontWithStyles(FontData defaultFontData) {
- if (textProperties == null || textProperties.isEmpty()) {
+ private Font composeFontWithStyles(FontData defaultFontData, List<Styles> styles) {
+ if (styles == null || styles.isEmpty()) {
return (Font) JFaceResources.getResources().get(FontDescriptor.createFrom(defaultFontData));
}
- int defaultStyle = defaultFontData.getStyle();
+ FontData defaultFontDataCopy = FontDescriptor.copy(defaultFontData);
+ int defaultStyle = defaultFontDataCopy.getStyle();
boolean quote = false;
boolean codeSample = false;
// calculate the font to apply
- for (Styles style : textProperties) {
+ for (Styles style : styles) {
switch (style) {
case italic:
defaultStyle = defaultStyle | SWT.ITALIC;
@@ -459,26 +463,26 @@ public class HTMLCornerBentFigure extends CornerBentFigure implements ILabelFigu
break;
case font:
if (Styles.font.getData().get(FONT_NAME) != null) {
- defaultFontData.setName((String) Styles.font.getData().get(FONT_NAME));
+ defaultFontDataCopy.setName((String) Styles.font.getData().get(FONT_NAME));
}
if (Styles.font.getData().get(FONT_SIZE) != null) {
// font size = [1..7] in html, but does not correspond to system
// size... 2 by default => 8 in real size.
// so: real size = (html font size)+6
- defaultFontData.setHeight(((Integer) Styles.font.getData().get(FONT_SIZE)) * 2 + 4);
+ defaultFontDataCopy.setHeight(((Integer) Styles.font.getData().get(FONT_SIZE)) * 2 + 4);
}
break;
default:
break;
}
}
- defaultFontData.setStyle(defaultStyle);
+ defaultFontDataCopy.setStyle(defaultStyle);
if (codeSample) {
- defaultFontData = CODE_SAMPLE_FONT;
+ defaultFontDataCopy = CODE_SAMPLE_FONT;
} else if (quote) {
- defaultFontData = QUOTE_FONT;
+ defaultFontDataCopy = QUOTE_FONT;
}
- return (Font) JFaceResources.getResources().get(FontDescriptor.createFrom(defaultFontData));
+ return (Font) JFaceResources.getResources().get(FontDescriptor.createFrom(defaultFontDataCopy));
}
/**
@@ -489,12 +493,12 @@ public class HTMLCornerBentFigure extends CornerBentFigure implements ILabelFigu
* @param parentFlow
* the parent block flow which will contain the block created
*/
- protected void generateBlocksFromStrongNode(Node node, BlockFlow parentFlow) {
+ protected void generateBlocksFromStrongNode(Node node, BlockFlow parentFlow, Stack<Styles> styles) {
NodeList childrenNodes = node.getChildNodes();
- textProperties.push(Styles.strong);
- generateBlocksFromNodeList(childrenNodes, parentFlow);
- textProperties.pop();
+ styles.push(Styles.strong);
+ generateBlocksFromNodeList(childrenNodes, parentFlow, styles);
+ styles.pop();
}
/**
@@ -505,12 +509,12 @@ public class HTMLCornerBentFigure extends CornerBentFigure implements ILabelFigu
* @param parentFlow
* the parent block flow which will contain the block created
*/
- protected void generateBlocksFromItalicNode(Node node, BlockFlow parentFlow) {
+ protected void generateBlocksFromItalicNode(Node node, BlockFlow parentFlow, Stack<Styles> styles) {
NodeList childrenNodes = node.getChildNodes();
- textProperties.push(Styles.italic);
- generateBlocksFromNodeList(childrenNodes, parentFlow);
- textProperties.pop();
+ styles.push(Styles.italic);
+ generateBlocksFromNodeList(childrenNodes, parentFlow, styles);
+ styles.pop();
}
/**
@@ -521,7 +525,7 @@ public class HTMLCornerBentFigure extends CornerBentFigure implements ILabelFigu
* @param parentFlow
* the parent block flow which will contain the block created
*/
- protected void generateBlocksForFontNode(Node node, BlockFlow parentFlow) {
+ protected void generateBlocksForFontNode(Node node, BlockFlow parentFlow, Stack<Styles> styles) {
// retrieves the font to apply
Node fontNameNode = node.getAttributes().getNamedItem("face");
Node fontSizeNode = node.getAttributes().getNamedItem("size");
@@ -532,26 +536,26 @@ public class HTMLCornerBentFigure extends CornerBentFigure implements ILabelFigu
String fontName = fontNameNode.getNodeValue();
oldFont = (Styles.font.getData().get(FONT_NAME) != null) ? (String) Styles.font.getData().get(FONT_NAME) : "Arial";
Styles.font.getData().put(FONT_NAME, fontName);
- textProperties.push(Styles.font);
+ styles.push(Styles.font);
}
if (fontSizeNode != null) {
int fontSize = Integer.parseInt(fontSizeNode.getNodeValue());
oldSize = (Styles.font.getData().get(FONT_SIZE) != null) ? ((Integer) Styles.font.getData().get(FONT_SIZE)) : 2;
Styles.font.getData().put(FONT_SIZE, fontSize);
- textProperties.push(Styles.font);
+ styles.push(Styles.font);
}
NodeList childrenNodes = node.getChildNodes();
- generateBlocksFromNodeList(childrenNodes, parentFlow);
+ generateBlocksFromNodeList(childrenNodes, parentFlow, styles);
if (fontNameNode != null) {
Styles.font.getData().put(FONT_NAME, oldFont);
- textProperties.pop();
+ styles.pop();
}
if (fontSizeNode != null) {
Styles.font.getData().put(FONT_SIZE, oldSize);
- textProperties.pop();
+ styles.pop();
}
}
@@ -563,13 +567,13 @@ public class HTMLCornerBentFigure extends CornerBentFigure implements ILabelFigu
* @param parentFlow
* the parent block flow which will contain the block created
*/
- protected void generateBlocksFromH3Node(Node node, BlockFlow parentFlow) {
+ protected void generateBlocksFromH3Node(Node node, BlockFlow parentFlow, Stack<Styles> styles) {
BlockFlow blockFlow = new BlockFlow();
NodeList childrenNodes = node.getChildNodes();
- textProperties.push(Styles.header3);
- generateBlocksFromNodeList(childrenNodes, blockFlow);
- textProperties.pop();
+ styles.push(Styles.header3);
+ generateBlocksFromNodeList(childrenNodes, blockFlow, styles);
+ styles.pop();
parentFlow.add(blockFlow);
}
@@ -581,13 +585,13 @@ public class HTMLCornerBentFigure extends CornerBentFigure implements ILabelFigu
* @param parentFlow
* the parent block flow which will contain the block created
*/
- protected void generateBlocksFromH4Node(Node node, BlockFlow parentFlow) {
+ protected void generateBlocksFromH4Node(Node node, BlockFlow parentFlow, Stack<Styles> styles) {
BlockFlow blockFlow = new BlockFlow();
NodeList childrenNodes = node.getChildNodes();
- textProperties.push(Styles.header4);
- generateBlocksFromNodeList(childrenNodes, blockFlow);
- textProperties.pop();
+ styles.push(Styles.header4);
+ generateBlocksFromNodeList(childrenNodes, blockFlow, styles);
+ styles.pop();
parentFlow.add(blockFlow);
}
@@ -599,13 +603,13 @@ public class HTMLCornerBentFigure extends CornerBentFigure implements ILabelFigu
* @param parentFlow
* the parent block flow which will contain the block created
*/
- protected void generateBlocksFromH5Node(Node node, BlockFlow parentFlow) {
+ protected void generateBlocksFromH5Node(Node node, BlockFlow parentFlow, Stack<Styles> styles) {
BlockFlow blockFlow = new BlockFlow();
NodeList childrenNodes = node.getChildNodes();
- textProperties.push(Styles.header5);
- generateBlocksFromNodeList(childrenNodes, blockFlow);
- textProperties.pop();
+ styles.push(Styles.header5);
+ generateBlocksFromNodeList(childrenNodes, blockFlow, styles);
+ styles.pop();
parentFlow.add(blockFlow);
}
@@ -629,11 +633,11 @@ public class HTMLCornerBentFigure extends CornerBentFigure implements ILabelFigu
* @param parentFlow
* the parent block flow which will contain the block created
*/
- protected void generateBlocksFromBodyNode(Node node, BlockFlow parentFlow) {
+ protected void generateBlocksFromBodyNode(Node node, BlockFlow parentFlow, Stack<Styles> styles) {
BlockFlow blockFlow = new BlockFlow();
NodeList childrenNodes = node.getChildNodes();
- generateBlocksFromNodeList(childrenNodes, blockFlow);
+ generateBlocksFromNodeList(childrenNodes, blockFlow, styles);
parentFlow.add(blockFlow);
}
@@ -646,7 +650,7 @@ public class HTMLCornerBentFigure extends CornerBentFigure implements ILabelFigu
* @param parentFlow
* the parent block flow which will contain the block created
*/
- protected void generateBlocksFromParagraphNode(Node node, BlockFlow parentFlow) {
+ protected void generateBlocksFromParagraphNode(Node node, BlockFlow parentFlow, Stack<Styles> styles) {
BlockFlow blockFlow = new BlockFlow();
// perhaps a style is associated to the paragraph (class="code sample"
@@ -659,19 +663,19 @@ public class HTMLCornerBentFigure extends CornerBentFigure implements ILabelFigu
if ("codeSample".equals(classNodeValue)) {
hasToPop = true;
- textProperties.push(Styles.code);
+ styles.push(Styles.code);
} else if ("quote".equals(classNodeValue)) {
- textProperties.push(Styles.quote);
+ styles.push(Styles.quote);
hasToPop = true;
}
}
NodeList childrenNodes = node.getChildNodes();
- generateBlocksFromNodeList(childrenNodes, blockFlow);
+ generateBlocksFromNodeList(childrenNodes, blockFlow, styles);
if (hasToPop) {
- textProperties.pop();
+ styles.pop();
}
parentFlow.add(blockFlow);
}

Back to the top