Commit 14c6101f authored by Nico Mack's avatar Nico Mack

minor bug fixes

parent 39be0e66
......@@ -77,22 +77,22 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.23</version>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.8.1</version>
<version>2.10.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.8.1</version>
<version>2.10.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.8</version>
<version>2.10.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
......
......@@ -41,6 +41,7 @@ import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingUtilities;
import javax.swing.text.DefaultCaret;
/**
......@@ -144,15 +145,17 @@ public class SplashScreen extends JPanel implements LogListener {
/** {@inheritDoc} */
@Override
public void messageLogged(String message) {
log.append(message);
if (this.isVisible()) {
log.setRows(appender.getMessageCount());
}
}
// ---------------------------------------------------------------------------
Runnable runnable = new Runnable() {
public void run() {
log.append(message);
if (log.isVisible()) {
log.setRows(appender.getMessageCount());
}
}
};
SwingUtilities.invokeLater(runnable);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
......
......@@ -95,6 +95,15 @@ public class Graph {
// ***************************************************************************
// * Class Body
// ***************************************************************************
// ---------------------------------------------------------------------------
public synchronized void clear() {
this.neighbours.clear();
this.nodesLookup.clear();
this.edges.clear();
this.nodes.clear();
}
// ---------------------------------------------------------------------------
/**
* @param listener
......
......@@ -312,11 +312,21 @@ public class ForceDirectedGraph implements GraphListener, Runnable {
this.updatePositions(graphBodies, timestep);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body
// ***************************************************************************
// ---------------------------------------------------------------------------
public void clear() {
if (running) {
Thread.currentThread().interrupt();
}
this.springs.clear();
this.bodies.clear();
this.graph.clear();
}
// ---------------------------------------------------------------------------
/**
* @return the underlying graph holding the nodes and edges represented by this force directed
......
......@@ -43,6 +43,9 @@ public class GraphCoordinates extends CoordinateState {
private static Bounds2D bounds;
// ***************************************************************************
// * Constants *
// ***************************************************************************
/**
* Constructing an instance with the provided points.
*
......
......@@ -27,22 +27,25 @@ 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;
......@@ -73,7 +76,6 @@ public class HtmlBox extends SelectableCorona implements InformationReceiver<Str
private Point renderedCentre;
private JEditorPane editor;
private SyncHtmlEditorKit htmlEditor;
// ***************************************************************************
// * Constant(s) *
......@@ -81,6 +83,8 @@ public class HtmlBox extends SelectableCorona implements InformationReceiver<Str
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) *
......@@ -143,7 +147,7 @@ public class HtmlBox extends SelectableCorona implements InformationReceiver<Str
// ---------------------------------------------------------------------------
private void buildEditorFromProperties() {
htmlEditor = new SyncHtmlEditorKit();
SyncHtmlEditorKit htmlEditor = new SyncHtmlEditorKit();
if (styleRules != null) {
StyleSheet stylesheet = htmlEditor.getStyleSheet();
styleRules.forEach(rule -> stylesheet.addRule(rule));
......@@ -155,6 +159,9 @@ public class HtmlBox extends SelectableCorona implements InformationReceiver<Str
editor.setEditable(false);
editor.setSize(new Dimension((int) shapeBounds.getWidth(), (int) shapeBounds.getHeight()));
editor.setOpaque(false);
editor.setDoubleBuffered(false);
renderedCentre = new Point(((float) (shapeBounds.getWidth() - insetBorder) / 2), ((float) (shapeBounds.getHeight() - insetBorder) / 2), 0f, ScreenCoordinates.class);
if ((htmlContent != null) && !htmlContent.isEmpty())
this.setInformation(htmlContent);
......@@ -162,31 +169,43 @@ public class HtmlBox extends SelectableCorona implements InformationReceiver<Str
// ---------------------------------------------------------------------------
protected BufferedImage renderHtml(String html, Shape canvas) {
BufferedImage renderedHtml;
Rectangle2D bounds;
private void renderHtml(String html) {
HTMLDocument document = (HTMLDocument) htmlEditor.createDefaultDocument();
if (baseUrl != null) {
document.setBase(baseUrl);
try {
editor.read(new StringReader(html), baseUrl);
} catch (IOException exception) {
LOGGER.error("failed to update HTML content!", exception); //$NON-NLS-1$
}
bounds = canvas.getBounds2D();
editor.setDocument(document);
editor.setText(html);
renderedHtml = new BufferedImage((int) bounds.getWidth() - (2 * insetBorder), (int) bounds.getHeight() - (2 * insetBorder), BufferedImage.TYPE_INT_ARGB);
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;
this.rendered = null;
// bounds = canvas.getBounds2D();
// renderedHtml = new BufferedImage((int) bounds.getWidth() - (2 * insetBorder), (int)
// bounds.getHeight() - (2 * insetBorder), BufferedImage.TYPE_INT_ARGB);
// Graphics2D offscreen = renderedHtml.createGraphics();
// offscreen.setRenderingHints(renderingHints);
//
// AffineTransform translate = AffineTransform.getTranslateInstance(-bounds.getX(), -bounds.getY());
// offscreen.setClip(translate.createTransformedShape(canvas));
//
// editor.invalidate();
// editor.paint(offscreen);
// offscreen.dispose();
// int reference = renderedHtml.getRGB(0, 0);
// boolean different = false;
// for (int x = 0; x < renderedHtml.getWidth(); x++) {
// for (int y = 0; y < renderedHtml.getHeight(); y++) {
// int current = renderedHtml.getRGB(x, y);
// different |= (current != reference);
// }
// }
//
// if (!different) {
// LOGGER.warn("Rendered an empty Picture!");
// }
// return renderedHtml;
}
......@@ -224,9 +243,19 @@ public class HtmlBox extends SelectableCorona implements InformationReceiver<Str
transform.translate(insetBorder - renderedCentre.x, insetBorder - renderedCentre.y);
localCanvas.setTransform(transform);
if (rendered != null) {
localCanvas.drawImage(rendered, null, null);
if (rendered == null) {
Rectangle2D bounds = shape.getBounds2D();
rendered = new BufferedImage((int) bounds.getWidth() - (2 * insetBorder), (int) bounds.getHeight() - (2 * insetBorder), BufferedImage.TYPE_INT_ARGB);
Graphics2D offscreen = rendered.createGraphics();
offscreen.setRenderingHints(renderingHints);
AffineTransform translate = AffineTransform.getTranslateInstance(-bounds.getX(), -bounds.getY());
offscreen.setClip(translate.createTransformedShape(shape));
editor.paint(offscreen);
offscreen.dispose();
}
localCanvas.drawImage(rendered, null, null);
localCanvas.dispose();
}
......@@ -236,8 +265,9 @@ public class HtmlBox extends SelectableCorona implements InformationReceiver<Str
@Override
public void setInformation(String information) {
rendered = this.renderHtml(information, shape);
renderedCentre = new Point(((float) rendered.getWidth() / 2), ((float) rendered.getHeight() / 2), 0f, ScreenCoordinates.class);
this.renderHtml(information);
// renderedCentre = new Point(((float) rendered.getWidth() / 2), ((float) rendered.getHeight() / 2),
// 0f, ScreenCoordinates.class);
}
// ---------------------------------------------------------------------------
......
......@@ -193,6 +193,15 @@ public class Sector extends SelectableCorona {
this.textColour.setSwitched(this.isSelected());
}
// ---------------------------------------------------------------------------
/**
* @return
*/
// ---------------------------------------------------------------------------
public String getLabel() {
return this.label;
}
// ---------------------------------------------------------------------------
@Override
......
......@@ -174,6 +174,16 @@ public class ForceManager implements Runnable {
}
}
// ---------------------------------------------------------------------------
public synchronized void clear() {
if (this.running) {
Thread.currentThread().interrupt();
}
this.potentialSubjects.clear();
this.motionables.clear();
}
// ---------------------------------------------------------------------------
/**
*
......
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