Commit ba136533 authored by Nico Mack's avatar Nico Mack

Made fill and stroke colour selectable

parent 51678222
......@@ -22,6 +22,7 @@ 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.ColorPair;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.utility.ScreenCoordinates;
import lu.list.itis.dkd.tui.utility.SyncHtmlEditorKit;
......@@ -32,7 +33,6 @@ 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;
......@@ -64,8 +64,8 @@ import javax.swing.text.html.StyleSheet;
public class HtmlBox extends SelectableCorona implements InformationReceiver<String> {
protected String htmlContent;
protected URL baseUrl;
protected Color fillColour;
protected Color strokeColour;
protected ColorPair fillColour;
protected ColorPair strokeColour;
protected int strokeWidth;
protected int insetBorder;
protected List<String> styleRules;
......@@ -192,6 +192,21 @@ public class HtmlBox extends SelectableCorona implements InformationReceiver<Str
// ***************************************************************************
// ---------------------------------------------------------------------------
@Override
public void setSelected(boolean selectIt) {
super.setSelected(selectIt);
if (this.fillColour != null) {
this.fillColour.setSwitched(selectIt);
}
if (this.strokeColour != null) {
this.strokeColour.setSwitched(selectIt);
}
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
@Override
public void paint(Graphics2D canvas) {
......@@ -207,11 +222,13 @@ public class HtmlBox extends SelectableCorona implements InformationReceiver<Str
AffineTransform transform = this.getTransform(null);
localCanvas.setTransform(transform);
localCanvas.setPaint(fillColour);
localCanvas.fill(shape);
if (fillColour != null) {
localCanvas.setPaint(fillColour.getColor());
localCanvas.fill(shape);
}
if (strokeColour != null) {
localCanvas.setPaint(strokeColour);
localCanvas.setPaint(strokeColour.getColor());
if (borderStroke != null)
localCanvas.setStroke(borderStroke);
localCanvas.draw(shape);
......@@ -228,7 +245,6 @@ public class HtmlBox extends SelectableCorona implements InformationReceiver<Str
AffineTransform translate = AffineTransform.getTranslateInstance(-bounds.getX(), -bounds.getY());
offscreen.setClip(translate.createTransformedShape(shape));
editor.paint(offscreen);
offscreen.dispose();
}
......
......@@ -26,6 +26,7 @@ import lu.list.itis.dkd.tui.bootstrapping.BootstrapCallback;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapContext;
import lu.list.itis.dkd.tui.bootstrapping.BootstrappingUtils;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.ColorPair;
import lu.list.itis.dkd.tui.utility.Externalization;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.utility.StringUtils;
......@@ -62,8 +63,8 @@ public abstract class BaseHtmlBoxBuilder<B extends BaseHtmlBoxBuilder<B>> extend
public String htmlContent;
public URL baseUrl;
public Color fillColour;
public Color strokeColour;
public ColorPair fillColour;
public ColorPair strokeColour;
public int strokeWidth;
public int insetBorder;
public List<String> styleRules;
......@@ -162,8 +163,8 @@ public abstract class BaseHtmlBoxBuilder<B extends BaseHtmlBoxBuilder<B>> extend
}
}
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);
fillColour = buildColorPair(rootElement.getChild(Externalization.FILL_COLOUR_ELEMENT), BootstrappingUtils.OPTIONAL, context);
strokeColour = buildColorPair(rootElement.getChild(Externalization.STROKE_COLOUR_ELEMENT), BootstrappingUtils.OPTIONAL, 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);
......@@ -175,6 +176,21 @@ public abstract class BaseHtmlBoxBuilder<B extends BaseHtmlBoxBuilder<B>> extend
// ---------------------------------------------------------------------------
private ColorPair buildColorPair(Element rootElement, boolean optional, BootstrapContext context) throws BuildException {
ColorPair color = null;
if (rootElement == null)
return null;
Color selectedColour = BootstrappingUtils.getContentAsColour(rootElement, Externalization.SELECTED_ELEMENT, optional, null, context);
Color deselectedColour = BootstrappingUtils.getContentAsColour(rootElement, Externalization.DESELECTED_ELEMENT, optional, null, context);
color = new ColorPair(selectedColour, deselectedColour);
return color;
}
// ---------------------------------------------------------------------------
private List<String> buildStyleRules(@Nullable Element cssElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
List<String> rules = new ArrayList<>();
List<Element> ruleElements = cssElement.getChildren(Externalization.STYLERULE_NODE);
......@@ -191,61 +207,6 @@ public abstract class BaseHtmlBoxBuilder<B extends BaseHtmlBoxBuilder<B>> extend
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* Method for setting the initial information to display.
*
* @param info
* The initial text to display.
* @return An instance of this builder for chain calling.
*/
// ---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public B withStyleRules(List<String> rules) {
styleRules = rules;
return (B) this;
}
// ---------------------------------------------------------------------------
/**
* @param colour
* @return
*/
// ---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public B withFillColour(Color colour) {
fillColour = colour;
return (B) this;
}
// ---------------------------------------------------------------------------
/**
* @param colour
* @return
*/
// ---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public B withStrokeColour(Color colour) {
strokeColour = colour;
return (B) this;
}
// ---------------------------------------------------------------------------
/**
* @param width
* @return
*/
// ---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public B withStrokeWidth(int width) {
this.strokeWidth = width;
return (B) this;
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
......
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