Commit 797f7dc9 authored by Valérie Maquil's avatar Valérie Maquil
Browse files

modification of the html box to improve speed

parent 471d6930
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<calibration> <calibration>
<screen> <screen>
<x1>0</x1> <x1>0</x1>
<y1>0</y1> <y1>0</y1>
<!-- <x2>800</x2> <!-- <x2>800</x2>
<y2>650</y2> --> <y2>650</y2> -->
<x2>1280</x2> <x2>1280</x2>
<y2>800</y2> <y2>800</y2>
</screen> </screen>
<camera> <camera>
<x1>0.06699997</x1> <x1>0.06699997</x1>
<y1>-0.013999984</y1> <y1>-0.013999984</y1>
<x2>0.92900026</x2> <x2>0.92900026</x2>
<y2>1.0049983</y2> <y2>1.0049983</y2>
</camera> </camera>
<table> <table>
<width>1000</width> <width>1000</width>
<height>750</height> <height>750</height>
<circleSize>60</circleSize> <circleSize>60</circleSize>
<triangleSize>80</triangleSize> <triangleSize>80</triangleSize>
<squareSize>50</squareSize> <squareSize>50</squareSize>
<cornerRadius>10</cornerRadius> <cornerRadius>10</cornerRadius>
<rectangleWidth>40</rectangleWidth> <rectangleWidth>40</rectangleWidth>
<rectangleHeight>20</rectangleHeight> <rectangleHeight>20</rectangleHeight>
<movementThreshold>0.01</movementThreshold> <movementThreshold>0.01</movementThreshold>
<rotationThreshold>0.2</rotationThreshold> <rotationThreshold>0.2</rotationThreshold>
</table> </table>
<window> <window>
<!-- <x>1550</x> <!-- <x>1550</x>
<y>10</y> --> <y>10</y> -->
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1280</width> <width>1280</width>
<height>800</height> <height>800</height>
</window> </window>
</calibration> </calibration>
...@@ -7,6 +7,7 @@ ASSET_ELEMENT=asset ...@@ -7,6 +7,7 @@ ASSET_ELEMENT=asset
ASSIGNABLE_NODE=assignable ASSIGNABLE_NODE=assignable
BACKGROUND_COLOUR_NODE=backgroundColour BACKGROUND_COLOUR_NODE=backgroundColour
BASE_VALUE_NODE=baseValue BASE_VALUE_NODE=baseValue
BASE_URL_NODE=baseUrl
BEGIN_NODE=begin BEGIN_NODE=begin
BEZEL_COLOUR_ELEMENT=bezelColour BEZEL_COLOUR_ELEMENT=bezelColour
BLOBS_NODE=blobs BLOBS_NODE=blobs
...@@ -70,6 +71,7 @@ INFORMATION=information ...@@ -70,6 +71,7 @@ INFORMATION=information
INITIAL_ROTATION_NODE=initialRotation INITIAL_ROTATION_NODE=initialRotation
INITIAL_TRANSLATION_NODE=initialTranslation INITIAL_TRANSLATION_NODE=initialTranslation
INNER_RADIUS_NODE=innerRadius INNER_RADIUS_NODE=innerRadius
INSET_BORDER_NODE=insetBorder
JAVA_AWT_COLOR_NAMESPACE=java.awt.Color JAVA_AWT_COLOR_NAMESPACE=java.awt.Color
LABEL_COLOUR_ELEMENT=labelColour LABEL_COLOUR_ELEMENT=labelColour
LABEL_FORMAT_NODE=labelFormat LABEL_FORMAT_NODE=labelFormat
......
...@@ -42,6 +42,7 @@ public class Externalization extends NLS { ...@@ -42,6 +42,7 @@ public class Externalization extends NLS {
public static String ASSIGNABLE_NODE; public static String ASSIGNABLE_NODE;
public static String BACKGROUND_COLOUR_NODE; public static String BACKGROUND_COLOUR_NODE;
public static String BASE_VALUE_NODE; public static String BASE_VALUE_NODE;
public static String BASE_URL_NODE;
public static String BEGIN_NODE; public static String BEGIN_NODE;
public static String BEZEL_COLOUR_ELEMENT; public static String BEZEL_COLOUR_ELEMENT;
public static String BLOBS_NODE; public static String BLOBS_NODE;
...@@ -105,6 +106,7 @@ public class Externalization extends NLS { ...@@ -105,6 +106,7 @@ public class Externalization extends NLS {
public static String INITIAL_ROTATION_NODE; public static String INITIAL_ROTATION_NODE;
public static String INITIAL_TRANSLATION_NODE; public static String INITIAL_TRANSLATION_NODE;
public static String INNER_RADIUS_NODE; public static String INNER_RADIUS_NODE;
public static String INSET_BORDER_NODE;
public static String JAVA_AWT_COLOR_NAMESPACE; public static String JAVA_AWT_COLOR_NAMESPACE;
public static String LABEL_COLOUR_ELEMENT; public static String LABEL_COLOUR_ELEMENT;
public static String LABEL_FORMAT_NODE; public static String LABEL_FORMAT_NODE;
......
...@@ -22,24 +22,30 @@ package lu.list.itis.dkd.tui.widget.corona; ...@@ -22,24 +22,30 @@ package lu.list.itis.dkd.tui.widget.corona;
import lu.list.itis.dkd.dbc.annotation.NonNullByDefault; import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.tui.content.InformationReceiver; import lu.list.itis.dkd.tui.content.InformationReceiver;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.utility.ScreenCoordinates;
import lu.list.itis.dkd.tui.utility.SyncHtmlEditorKit; import lu.list.itis.dkd.tui.utility.SyncHtmlEditorKit;
import lu.list.itis.dkd.tui.widget.corona.builder.BaseHtmlBoxBuilder; import lu.list.itis.dkd.tui.widget.corona.builder.BaseHtmlBoxBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.awt.AlphaComposite; import java.awt.AlphaComposite;
import java.awt.BasicStroke; import java.awt.BasicStroke;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.RenderingHints; import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.Stroke; import java.awt.Stroke;
import java.awt.geom.AffineTransform; import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.StringReader;
import java.net.URL;
import java.util.List; import java.util.List;
import javax.swing.JEditorPane; import javax.swing.JEditorPane;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.StyleSheet; import javax.swing.text.html.StyleSheet;
...@@ -55,16 +61,19 @@ import javax.swing.text.html.StyleSheet; ...@@ -55,16 +61,19 @@ import javax.swing.text.html.StyleSheet;
// *************************************************************************** // ***************************************************************************
@NonNullByDefault @NonNullByDefault
public class HtmlBox extends FadingCorona implements InformationReceiver<String> { public class HtmlBox extends SelectableCorona implements InformationReceiver<String> {
protected String htmlContent; protected String htmlContent;
protected URL baseUrl;
protected Color fillColour; protected Color fillColour;
protected Color strokeColour; protected Color strokeColour;
protected int strokeWidth; protected int strokeWidth;
protected int insetBorder;
protected List<String> styleRules; protected List<String> styleRules;
protected BufferedImage rendered;
private Stroke borderStroke; private Stroke borderStroke;
private Rectangle2D shapeBounds; private Rectangle2D shapeBounds;
private BufferedImage rendered; private Point renderedCentre;
private JEditorPane editor; private JEditorPane editor;
private SyncHtmlEditorKit htmlEditor; private SyncHtmlEditorKit htmlEditor;
...@@ -75,6 +84,8 @@ public class HtmlBox extends FadingCorona implements InformationReceiver<String> ...@@ -75,6 +84,8 @@ public class HtmlBox extends FadingCorona implements InformationReceiver<String>
private static final RenderingHints renderingHints = new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); private static final RenderingHints renderingHints = new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
private static final Logger LOGGER = LoggerFactory.getLogger(HtmlBox.class.getSimpleName());
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// *************************************************************************** // ***************************************************************************
// * Constructor(s) * // * Constructor(s) *
...@@ -93,11 +104,13 @@ public class HtmlBox extends FadingCorona implements InformationReceiver<String> ...@@ -93,11 +104,13 @@ public class HtmlBox extends FadingCorona implements InformationReceiver<String>
super(builder); super(builder);
htmlContent = builder.htmlContent; htmlContent = builder.htmlContent;
baseUrl = builder.baseUrl;
shape = builder.shape; shape = builder.shape;
fillColour = builder.fillColour; fillColour = builder.fillColour;
strokeColour = builder.strokeColour; strokeColour = builder.strokeColour;
strokeWidth = builder.strokeWidth; strokeWidth = builder.strokeWidth;
borderStroke = (builder.strokeWidth > 0) ? new BasicStroke(builder.strokeWidth) : null; borderStroke = (builder.strokeWidth > 0) ? new BasicStroke(builder.strokeWidth) : null;
insetBorder = builder.insetBorder;
styleRules = builder.styleRules; styleRules = builder.styleRules;
shapeBounds = shape.getBounds(); shapeBounds = shape.getBounds();
this.buildEditorFromProperties(); this.buildEditorFromProperties();
...@@ -116,11 +129,13 @@ public class HtmlBox extends FadingCorona implements InformationReceiver<String> ...@@ -116,11 +129,13 @@ public class HtmlBox extends FadingCorona implements InformationReceiver<String>
super(original); super(original);
htmlContent = original.htmlContent; htmlContent = original.htmlContent;
baseUrl = original.baseUrl;
shape = original.shape; shape = original.shape;
fillColour = original.fillColour; fillColour = original.fillColour;
strokeColour = original.strokeColour; strokeColour = original.strokeColour;
strokeWidth = original.strokeWidth; strokeWidth = original.strokeWidth;
borderStroke = (original.strokeWidth > 0) ? new BasicStroke(original.strokeWidth) : null; borderStroke = (original.strokeWidth > 0) ? new BasicStroke(original.strokeWidth) : null;
insetBorder = original.insetBorder;
styleRules = original.styleRules; styleRules = original.styleRules;
shapeBounds = shape.getBounds(); shapeBounds = shape.getBounds();
this.buildEditorFromProperties(); this.buildEditorFromProperties();
...@@ -150,6 +165,44 @@ public class HtmlBox extends FadingCorona implements InformationReceiver<String> ...@@ -150,6 +165,44 @@ public class HtmlBox extends FadingCorona implements InformationReceiver<String>
this.setInformation(htmlContent); this.setInformation(htmlContent);
} }
// ---------------------------------------------------------------------------
protected void renderHtml(String html) {
// BufferedImage renderedHtml;
// Rectangle2D bounds;
try {
editor.read(new StringReader(html), baseUrl);
} catch (IOException exception) {
LOGGER.error("failed to update HTML content!", exception); //$NON-NLS-1$
}
// bounds = canvas.getBounds2D();
// renderedHtml = new BufferedImage((int) bounds.getWidth() - (2 * insetBorder), (int)
// bounds.getHeight() - (2 * insetBorder), BufferedImage.TYPE_INT_ARGB);
// renderedCentre = new Point(((float) ((int) bounds.getWidth() - (2 * insetBorder)) / 2),
// ((float) ((int) bounds.getHeight() - (2 * insetBorder)) / 2), 0f,
// ScreenCoordinates.class);
/*
* Graphics2D offscreen = renderedHtml.createGraphics();
* offscreen.setRenderingHints(renderingHints); AffineTransform translate =
* AffineTransform.getTranslateInstance(-bounds.getX(), -bounds.getY());
* offscreen.setClip(translate.createTransformedShape(canvas)); // editor.paint(offscreen);
* offscreen.dispose();
*/
// return renderedHtml;
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// *************************************************************************** // ***************************************************************************
// * Class Body * // * Class Body *
...@@ -159,8 +212,6 @@ public class HtmlBox extends FadingCorona implements InformationReceiver<String> ...@@ -159,8 +212,6 @@ public class HtmlBox extends FadingCorona implements InformationReceiver<String>
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void paint(Graphics2D canvas) { public void paint(Graphics2D canvas) {
super.paint(canvas);
if (!active) if (!active)
return; return;
...@@ -171,23 +222,27 @@ public class HtmlBox extends FadingCorona implements InformationReceiver<String> ...@@ -171,23 +222,27 @@ public class HtmlBox extends FadingCorona implements InformationReceiver<String>
localCanvas.setComposite(AlphaComposite.SrcOver.derive(this.opacity)); localCanvas.setComposite(AlphaComposite.SrcOver.derive(this.opacity));
AffineTransform transform = this.getTransform(null); AffineTransform transform = this.getTransform(null);
Shape transformedShape = transform.createTransformedShape(shape); localCanvas.setTransform(transform);
localCanvas.setPaint(fillColour); localCanvas.setPaint(fillColour);
localCanvas.fill(transformedShape); localCanvas.fill(shape);
if (strokeColour != null) { if (strokeColour != null) {
localCanvas.setPaint(strokeColour); localCanvas.setPaint(strokeColour);
if (borderStroke != null) if (borderStroke != null)
localCanvas.setStroke(borderStroke); localCanvas.setStroke(borderStroke);
localCanvas.draw(transformedShape); localCanvas.draw(shape);
} }
if (rendered != null) { transform.translate(insetBorder - renderedCentre.x, insetBorder - renderedCentre.y);
transform.translate(-((double) rendered.getWidth()) / 2, -((double) rendered.getHeight()) / 2); localCanvas.setTransform(transform);
localCanvas.drawImage(rendered, transform, null);
} // if (rendered != null) {
editor.paint(localCanvas);
// localCanvas.drawImage(rendered, null, null);
// }
localCanvas.dispose(); localCanvas.dispose();
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
...@@ -195,19 +250,13 @@ public class HtmlBox extends FadingCorona implements InformationReceiver<String> ...@@ -195,19 +250,13 @@ public class HtmlBox extends FadingCorona implements InformationReceiver<String>
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void setInformation(String information) { public void setInformation(String information) {
HTMLDocument html = (HTMLDocument) htmlEditor.createDefaultDocument();
editor.setDocument(html);
editor.setText(information);
rendered = new BufferedImage((int) shapeBounds.getWidth(), (int) shapeBounds.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D offscreen = rendered.createGraphics();
offscreen.setRenderingHints(renderingHints);
AffineTransform translate = AffineTransform.getTranslateInstance(-shapeBounds.getX(), -shapeBounds.getY()); this.renderHtml(information);
offscreen.setClip(translate.createTransformedShape(shape));
editor.paint(offscreen); Rectangle2D bounds = shape.getBounds2D();
offscreen.dispose(); renderedCentre = new Point(((float) bounds.getWidth() / 2), ((float) bounds.getHeight() / 2), 0f, ScreenCoordinates.class);
// renderedCentre = new Point(((float) rendered.getWidth() / 2), ((float)
// rendered.getHeight() / 2), 0f, ScreenCoordinates.class);
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
......
...@@ -40,6 +40,7 @@ import java.awt.Color; ...@@ -40,6 +40,7 @@ import java.awt.Color;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -57,12 +58,14 @@ import java.util.List; ...@@ -57,12 +58,14 @@ import java.util.List;
// * Class Definition and Members * // * Class Definition and Members *
// *************************************************************************** // ***************************************************************************
public abstract class BaseHtmlBoxBuilder<B extends BaseHtmlBoxBuilder<B>> extends BaseFadingCoronaBuilder<B> { public abstract class BaseHtmlBoxBuilder<B extends BaseHtmlBoxBuilder<B>> extends BaseSelectableCoronaBuilder<B> {
public String htmlContent; public String htmlContent;
public URL baseUrl;
public Color fillColour; public Color fillColour;
public Color strokeColour; public Color strokeColour;
public int strokeWidth; public int strokeWidth;
public int insetBorder;
public List<String> styleRules; public List<String> styleRules;
// *************************************************************************** // ***************************************************************************
...@@ -149,9 +152,20 @@ public abstract class BaseHtmlBoxBuilder<B extends BaseHtmlBoxBuilder<B>> extend ...@@ -149,9 +152,20 @@ public abstract class BaseHtmlBoxBuilder<B extends BaseHtmlBoxBuilder<B>> extend
} }
} }
String url = BootstrappingUtils.getContentAsString(rootElement, Externalization.BASE_URL_NODE, BootstrappingUtils.OPTIONAL, Externalization.EMPTY_STRING, context);
if (!Strings.isNullOrEmpty(url)) {
try {
File urlFile = new File(url);
this.baseUrl = urlFile.toURI().toURL();
} catch (IOException e) {
throw new BuildException(StringUtils.build("Failed to set base URL to {}", url)); //$NON-NLS-1$
}
}
fillColour = BootstrappingUtils.getContentAsColour(rootElement, Externalization.FILL_COLOUR_ELEMENT, BootstrappingUtils.OPTIONAL, Color.WHITE, context); fillColour = BootstrappingUtils.getContentAsColour(rootElement, Externalization.FILL_COLOUR_ELEMENT, BootstrappingUtils.OPTIONAL, Color.WHITE, context);
strokeColour = BootstrappingUtils.getContentAsColour(rootElement, Externalization.STROKE_COLOUR_ELEMENT, BootstrappingUtils.OPTIONAL, null, context); strokeColour = BootstrappingUtils.getContentAsColour(rootElement, Externalization.STROKE_COLOUR_ELEMENT, BootstrappingUtils.OPTIONAL, null, context);
strokeWidth = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.STROKE_WIDTH_NODE, BootstrappingUtils.OPTIONAL, 1, context); strokeWidth = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.STROKE_WIDTH_NODE, BootstrappingUtils.OPTIONAL, 1, context);
insetBorder = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.INSET_BORDER_NODE, BootstrappingUtils.OPTIONAL, 0, context);
Element styleSheetElement = rootElement.getChild(Externalization.STYLESHEET_NODE); Element styleSheetElement = rootElement.getChild(Externalization.STYLESHEET_NODE);
if (styleSheetElement != null) { if (styleSheetElement != null) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment