Commit 3c210d83 authored by Nico Mack's avatar Nico Mack

Major changes to the SegmentedArcProperties API

parent eb8b4c6e
......@@ -50,7 +50,6 @@ public class SegmentedArcGraph extends SegmentedArc implements InformationReceiv
protected DisplayMode mode;
private VariableManager variableManager;
// private List<SegmentedArcGraphProperties> segmentProperties;
private int currentlySelected = -1;
// ---------------------------------------------------------------------------
......@@ -67,7 +66,6 @@ public class SegmentedArcGraph extends SegmentedArc implements InformationReceiv
super(builder);
this.variable = builder.variable;
this.mode = builder.mode;
// this.segmentProperties = builder.segmentProperties;
this.buildFromProperties();
}
......@@ -82,7 +80,6 @@ public class SegmentedArcGraph extends SegmentedArc implements InformationReceiv
super(original);
this.variable = original.variable;
this.mode = original.mode;
// this.segmentProperties = original.segmentProperties;
this.buildFromProperties();
}
......@@ -99,12 +96,7 @@ public class SegmentedArcGraph extends SegmentedArc implements InformationReceiv
// ---------------------------------------------------------------------------
private void setSelected(SegmentedArcGraphProperties property, boolean selectIt) {
if (property.fillColour != null)
property.fillColour.setSwitched(selectIt);
if (property.strokeColour != null)
property.strokeColour.setSwitched(selectIt);
if (property.textColour != null)
property.textColour.setSwitched(selectIt);
property.setSelected(selectIt);
}
// ---------------------------------------------------------------------------
......@@ -157,21 +149,21 @@ public class SegmentedArcGraph extends SegmentedArc implements InformationReceiv
Shape segment = segments.get(current);
SegmentedArcGraphProperties properties = (SegmentedArcGraphProperties) segmentProperties.get(current);
if (properties.fillColour != null) {
localCanvas.setPaint(properties.fillColour.getColor());
if (properties.hasFillColour()) {
localCanvas.setPaint(properties.getFillColour());
localCanvas.fill(segment);
}
if ((properties.strokeColour != null) && (properties.stroke != null)) {
localCanvas.setPaint(properties.strokeColour.getColor());
localCanvas.setStroke(properties.stroke);
if (properties.hasStrokeColour() && properties.hasStroke()) {
localCanvas.setPaint(properties.getStrokeColour());
localCanvas.setStroke(properties.getStroke());
localCanvas.draw(segment);
}
Shape label = labels.get(current);
if ((label != null) && (properties.textColour != null)) {
localCanvas.setPaint(properties.textColour.getColor());
if ((label != null) && properties.hasTextColour()) {
localCanvas.setPaint(properties.getTextColour());
localCanvas.fill(label);
}
}
......
......@@ -29,6 +29,7 @@ import lu.list.itis.dkd.tui.utility.ColorPair;
import lu.list.itis.dkd.tui.utility.CpsNamespace;
import lu.list.itis.dkd.tui.utility.Externalization;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.utility.SwitchablePair;
import lu.list.itis.dkd.tui.widget.corona.SegmentedArcGraph;
import lu.list.itis.dkd.tui.widget.corona.inner.DisplayMode;
import lu.list.itis.dkd.tui.widget.corona.inner.SegmentedArcGraphProperties;
......@@ -113,17 +114,6 @@ public abstract class BaseSegmentedArcGraphBuilder<B extends BaseSegmentedArcGra
if (displayModeElement != null) {
mode = DisplayModeBootstrapper.buildDisplayModeFromElement(rootElement, context, callback);
}
// this.segmentProperties = new ArrayList<>();
// Element segmentsNode = rootElement.getChild(Externalization.SEGMENTS_NODE);
// if (segmentsNode != null) {
// List<Element> segmentNodes = segmentsNode.getChildren(Externalization.SEGMENT_NODE);
// if (segmentNodes != null) {
// for (Element segmentNode : segmentNodes) {
// this.segmentProperties.add(this.buildSegmentProperty(segmentNode, context, callback));
// }
// }
// }
}
// ---------------------------------------------------------------------------
......@@ -131,12 +121,13 @@ public abstract class BaseSegmentedArcGraphBuilder<B extends BaseSegmentedArcGra
@Override
protected SegmentedArcGraphProperties buildSegmentProperty(@NonNull Element segmentElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
SegmentedArcGraphProperties property = new SegmentedArcGraphProperties();
property.label = BootstrappingUtils.getContentAsString(segmentElement, Externalization.LABEL_NODE, BootstrappingUtils.OPTIONAL, Externalization.EMPTY_STRING, context);
property.fillColour = buildColorPair(segmentElement.getChild(Externalization.FILL_COLOUR_ELEMENT), context);
property.textColour = buildColorPair(segmentElement.getChild(Externalization.TEXT_COLOUR_ELEMENT), context);
property.strokeColour = buildColorPair(segmentElement.getChild(Externalization.STROKE_COLOUR_ELEMENT), context);
property.setLabel(BootstrappingUtils.getContentAsString(segmentElement, Externalization.LABEL_NODE, BootstrappingUtils.OPTIONAL, Externalization.EMPTY_STRING, context));
property.setFillColourPair(buildColorPair(segmentElement.getChild(Externalization.FILL_COLOUR_ELEMENT), context));
property.setTextColourPair(buildColorPair(segmentElement.getChild(Externalization.TEXT_COLOUR_ELEMENT), context));
property.setStrokeColourPair(buildColorPair(segmentElement.getChild(Externalization.STROKE_COLOUR_ELEMENT), context));
property.setScalePair(buildScalePair(segmentElement.getChild(Externalization.SCALE_NODE), context));
int strokeWidth = BootstrappingUtils.getContentAsInteger(segmentElement, Externalization.STROKE_WIDTH_NODE, BootstrappingUtils.OPTIONAL, 0, context);
property.stroke = (strokeWidth > 0) ? new BasicStroke(strokeWidth) : null;
property.setStroke((strokeWidth > 0) ? new BasicStroke(strokeWidth) : null);
return property;
}
......@@ -154,6 +145,19 @@ public abstract class BaseSegmentedArcGraphBuilder<B extends BaseSegmentedArcGra
return new ColorPair(selectedColour, deselectedColour);
}
// ---------------------------------------------------------------------------
private SwitchablePair<Double> buildScalePair(Element rootElement, BootstrapContext context) throws BuildException {
if (rootElement == null) {
return null;
}
Double selectedScale = BootstrappingUtils.getContentAsDouble(rootElement, Externalization.SELECTED_ELEMENT, BootstrappingUtils.OPTIONAL, 1.0d, context);
Double deselectedScale = BootstrappingUtils.getContentAsDouble(rootElement, Externalization.DESELECTED_ELEMENT, BootstrappingUtils.OPTIONAL, 1.0d, context);
return new SwitchablePair<>(selectedScale, deselectedScale);
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
......
......@@ -16,7 +16,12 @@
*/
package lu.list.itis.dkd.tui.widget.corona.inner;
import lu.list.itis.dkd.tui.event.SelectionListener;
import lu.list.itis.dkd.tui.feature.selection.Selectable;
import lu.list.itis.dkd.tui.utility.ColorPair;
import lu.list.itis.dkd.tui.utility.SwitchablePair;
import java.awt.Color;
/**
* Class encapsulating all properties pertaining to an individual arc segment.
......@@ -30,8 +35,265 @@ import lu.list.itis.dkd.tui.utility.ColorPair;
// * Class Definition and Members *
// ***************************************************************************
public class SegmentedArcGraphProperties extends SegmentedArcProperties {
public ColorPair fillColour;
public ColorPair strokeColour;
public ColorPair textColour;
public class SegmentedArcGraphProperties extends SegmentedArcProperties implements Selectable {
private ColorPair fillColourPair;
private ColorPair strokeColourPair;
private ColorPair textColourPair;
private SwitchablePair<Double> scalePair;
private boolean selected;
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
public SegmentedArcGraphProperties() {
selected = false;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* Simple setter method for fillColour.
*
* @param fillColour
* The value to set fillColour to.
*/
// ---------------------------------------------------------------------------
public void setFillColourPair(ColorPair fillColourPair) {
this.fillColourPair = fillColourPair;
}
// ---------------------------------------------------------------------------
/**
* checks whether fillColour property is set or not.
*
* @return
*/
// ---------------------------------------------------------------------------
@Override
public boolean hasFillColour() {
return (fillColourPair != null);
}
// ---------------------------------------------------------------------------
/**
* Simple getter method for fillColour.
*
* @return The value of fillColour.
*/
// ---------------------------------------------------------------------------
@Override
public Color getFillColour() {
return fillColourPair.getColor();
}
// ---------------------------------------------------------------------------
/**
* Simple setter method for fillColour.
*
* @param fillColour
* The value to set fillColour to.
*/
// ---------------------------------------------------------------------------
@Override
public void setFillColour(Color fillColour) {
// Dummy method, since fillColour is provided by fillColorPair member
}
// ---------------------------------------------------------------------------
/**
* Simple setter method for strokeColour.
*
* @param strokeColour
* The value to set strokeColour to.
*/
// ---------------------------------------------------------------------------
public void setStrokeColourPair(ColorPair strokeColourPair) {
this.strokeColourPair = strokeColourPair;
}
// ---------------------------------------------------------------------------
/**
* checks whether fillColour property is set or not.
*
* @return
*/
// ---------------------------------------------------------------------------
@Override
public boolean hasStrokeColour() {
return (strokeColourPair != null);
}
// ---------------------------------------------------------------------------
/**
* Simple getter method for fillColour.
*
* @return The value of fillColour.
*/
// ---------------------------------------------------------------------------
@Override
public Color getStrokeColour() {
return strokeColourPair.getColor();
}
// ---------------------------------------------------------------------------
/**
* Simple setter method for fillColour.
*
* @param fillColour
* The value to set fillColour to.
*/
// ---------------------------------------------------------------------------
@Override
public void setStrokeColour(Color strokeColour) {
// Dummy method, since strokeColour is provided by strokeColourPair member
}
// ---------------------------------------------------------------------------
/**
* Simple setter method for textColour.
*
* @param textColour
* The value to set textColour to.
*/
// ---------------------------------------------------------------------------
public void setTextColourPair(ColorPair textColourPair) {
this.textColourPair = textColourPair;
}
// ---------------------------------------------------------------------------
/**
* checks whether fillColour property is set or not.
*
* @return
*/
// ---------------------------------------------------------------------------
@Override
public boolean hasTextColour() {
return (textColourPair != null);
}
// ---------------------------------------------------------------------------
/**
* Simple getter method for fillColour.
*
* @return The value of fillColour.
*/
// ---------------------------------------------------------------------------
@Override
public Color getTextColour() {
return textColourPair.getColor();
}
// ---------------------------------------------------------------------------
/**
* Simple setter method for fillColour.
*
* @param fillColour
* The value to set fillColour to.
*/
// ---------------------------------------------------------------------------
@Override
public void setTextColour(Color strokeColour) {
// Dummy method, since textColour is provided by textColourPair member
}
// ---------------------------------------------------------------------------
/**
* Simple setter method for fillColour.
*
* @param fillColour
* The value to set fillColour to.
*/
// ---------------------------------------------------------------------------
public void setScalePair(SwitchablePair<Double> scalePair) {
this.scalePair = scalePair;
}
// ---------------------------------------------------------------------------
/**
* checks whether fillColour property is set or not.
*
* @return
*/
// ---------------------------------------------------------------------------
public boolean hasScaleColour() {
return (scalePair != null);
}
// ---------------------------------------------------------------------------
/**
* Simple getter method for fillColour.
*
* @return The value of fillColour.
*/
// ---------------------------------------------------------------------------
public Double getScale() {
return scalePair.getCurrent();
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
@Override
public void addSelectionListener(SelectionListener listener) {
// Not required.
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
@Override
public void removeSelectionListener(SelectionListener listener) {
// Not required.
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
@Override
public void setSelected(boolean selectIt) {
selected = selectIt;
if (this.fillColourPair != null)
this.fillColourPair.setSwitched(selectIt);
if (this.strokeColourPair != null)
this.strokeColourPair.setSwitched(selectIt);
if (this.textColourPair != null)
this.textColourPair.setSwitched(selectIt);
if (this.scalePair != null)
this.scalePair.setSwitched(selectIt);
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
@Override
public boolean isSelected() {
return selected;
}
}
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