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

modification of the html box to improve speed

parent 471d6930
<?xml version="1.0" encoding="UTF-8"?>
<calibration>
<screen>
<x1>0</x1>
<y1>0</y1>
<!-- <x2>800</x2>
<y2>650</y2> -->
<x2>1280</x2>
<y2>800</y2>
</screen>
<camera>
<x1>0.06699997</x1>
<y1>-0.013999984</y1>
<x2>0.92900026</x2>
<y2>1.0049983</y2>
</camera>
<table>
<width>1000</width>
<height>750</height>
<circleSize>60</circleSize>
<triangleSize>80</triangleSize>
<squareSize>50</squareSize>
<cornerRadius>10</cornerRadius>
<rectangleWidth>40</rectangleWidth>
<rectangleHeight>20</rectangleHeight>
<movementThreshold>0.01</movementThreshold>
<rotationThreshold>0.2</rotationThreshold>
</table>
<window>
<!-- <x>1550</x>
<y>10</y> -->
<x>0</x>
<y>0</y>
<width>1280</width>
<height>800</height>
</window>
</calibration>
<?xml version="1.0" encoding="UTF-8"?>
<calibration>
<screen>
<x1>0</x1>
<y1>0</y1>
<!-- <x2>800</x2>
<y2>650</y2> -->
<x2>1280</x2>
<y2>800</y2>
</screen>
<camera>
<x1>0.06699997</x1>
<y1>-0.013999984</y1>
<x2>0.92900026</x2>
<y2>1.0049983</y2>
</camera>
<table>
<width>1000</width>
<height>750</height>
<circleSize>60</circleSize>
<triangleSize>80</triangleSize>
<squareSize>50</squareSize>
<cornerRadius>10</cornerRadius>
<rectangleWidth>40</rectangleWidth>
<rectangleHeight>20</rectangleHeight>
<movementThreshold>0.01</movementThreshold>
<rotationThreshold>0.2</rotationThreshold>
</table>
<window>
<!-- <x>1550</x>
<y>10</y> -->
<x>0</x>
<y>0</y>
<width>1280</width>
<height>800</height>
</window>
</calibration>
......@@ -7,6 +7,7 @@ ASSET_ELEMENT=asset
ASSIGNABLE_NODE=assignable
BACKGROUND_COLOUR_NODE=backgroundColour
BASE_VALUE_NODE=baseValue
BASE_URL_NODE=baseUrl
BEGIN_NODE=begin
BEZEL_COLOUR_ELEMENT=bezelColour
BLOBS_NODE=blobs
......@@ -70,6 +71,7 @@ INFORMATION=information
INITIAL_ROTATION_NODE=initialRotation
INITIAL_TRANSLATION_NODE=initialTranslation
INNER_RADIUS_NODE=innerRadius
INSET_BORDER_NODE=insetBorder
JAVA_AWT_COLOR_NAMESPACE=java.awt.Color
LABEL_COLOUR_ELEMENT=labelColour
LABEL_FORMAT_NODE=labelFormat
......
......@@ -42,6 +42,7 @@ public class Externalization extends NLS {
public static String ASSIGNABLE_NODE;
public static String BACKGROUND_COLOUR_NODE;
public static String BASE_VALUE_NODE;
public static String BASE_URL_NODE;
public static String BEGIN_NODE;
public static String BEZEL_COLOUR_ELEMENT;
public static String BLOBS_NODE;
......@@ -105,6 +106,7 @@ public class Externalization extends NLS {
public static String INITIAL_ROTATION_NODE;
public static String INITIAL_TRANSLATION_NODE;
public static String INNER_RADIUS_NODE;
public static String INSET_BORDER_NODE;
public static String JAVA_AWT_COLOR_NAMESPACE;
public static String LABEL_COLOUR_ELEMENT;
public static String LABEL_FORMAT_NODE;
......
......@@ -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.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.widget.corona.builder.BaseHtmlBoxBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.awt.AlphaComposite;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.StringReader;
import java.net.URL;
import java.util.List;
import javax.swing.JEditorPane;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.StyleSheet;
......@@ -55,16 +61,19 @@ import javax.swing.text.html.StyleSheet;
// ***************************************************************************
@NonNullByDefault
public class HtmlBox extends FadingCorona implements InformationReceiver<String> {
public class HtmlBox extends SelectableCorona implements InformationReceiver<String> {
protected String htmlContent;
protected URL baseUrl;
protected Color fillColour;
protected Color strokeColour;
protected int strokeWidth;
protected int insetBorder;
protected List<String> styleRules;
protected BufferedImage rendered;
private Stroke borderStroke;
private Rectangle2D shapeBounds;
private BufferedImage rendered;
private Point renderedCentre;
private JEditorPane editor;
private SyncHtmlEditorKit htmlEditor;
......@@ -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 Logger LOGGER = LoggerFactory.getLogger(HtmlBox.class.getSimpleName());
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
......@@ -93,11 +104,13 @@ public class HtmlBox extends FadingCorona implements InformationReceiver<String>
super(builder);
htmlContent = builder.htmlContent;
baseUrl = builder.baseUrl;
shape = builder.shape;
fillColour = builder.fillColour;
strokeColour = builder.strokeColour;
strokeWidth = builder.strokeWidth;
borderStroke = (builder.strokeWidth > 0) ? new BasicStroke(builder.strokeWidth) : null;
insetBorder = builder.insetBorder;
styleRules = builder.styleRules;
shapeBounds = shape.getBounds();
this.buildEditorFromProperties();
......@@ -116,11 +129,13 @@ public class HtmlBox extends FadingCorona implements InformationReceiver<String>
super(original);
htmlContent = original.htmlContent;
baseUrl = original.baseUrl;
shape = original.shape;
fillColour = original.fillColour;
strokeColour = original.strokeColour;
strokeWidth = original.strokeWidth;
borderStroke = (original.strokeWidth > 0) ? new BasicStroke(original.strokeWidth) : null;
insetBorder = original.insetBorder;
styleRules = original.styleRules;
shapeBounds = shape.getBounds();
this.buildEditorFromProperties();
......@@ -150,6 +165,44 @@ public class HtmlBox extends FadingCorona implements InformationReceiver<String>
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 *
......@@ -159,8 +212,6 @@ public class HtmlBox extends FadingCorona implements InformationReceiver<String>
/** {@inheritDoc} */
@Override
public void paint(Graphics2D canvas) {
super.paint(canvas);
if (!active)
return;
......@@ -171,23 +222,27 @@ public class HtmlBox extends FadingCorona implements InformationReceiver<String>
localCanvas.setComposite(AlphaComposite.SrcOver.derive(this.opacity));
AffineTransform transform = this.getTransform(null);
Shape transformedShape = transform.createTransformedShape(shape);
localCanvas.setTransform(transform);
localCanvas.setPaint(fillColour);
localCanvas.fill(transformedShape);
localCanvas.fill(shape);
if (strokeColour != null) {
localCanvas.setPaint(strokeColour);
if (borderStroke != null)
localCanvas.setStroke(borderStroke);
localCanvas.draw(transformedShape);
localCanvas.draw(shape);
}
if (rendered != null) {
transform.translate(-((double) rendered.getWidth()) / 2, -((double) rendered.getHeight()) / 2);
localCanvas.drawImage(rendered, transform, null);
}
transform.translate(insetBorder - renderedCentre.x, insetBorder - renderedCentre.y);
localCanvas.setTransform(transform);
// if (rendered != null) {
editor.paint(localCanvas);
// localCanvas.drawImage(rendered, null, null);
// }
localCanvas.dispose();
}
// ---------------------------------------------------------------------------
......@@ -195,19 +250,13 @@ public class HtmlBox extends FadingCorona implements InformationReceiver<String>
/** {@inheritDoc} */
@Override
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());
offscreen.setClip(translate.createTransformedShape(shape));
this.renderHtml(information);
editor.paint(offscreen);
offscreen.dispose();
Rectangle2D bounds = shape.getBounds2D();
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;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
......@@ -57,12 +58,14 @@ import java.util.List;
// * 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 URL baseUrl;
public Color fillColour;
public Color strokeColour;
public int strokeWidth;
public int insetBorder;
public List<String> styleRules;
// ***************************************************************************
......@@ -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);
strokeColour = BootstrappingUtils.getContentAsColour(rootElement, Externalization.STROKE_COLOUR_ELEMENT, BootstrappingUtils.OPTIONAL, null, 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);
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