public code v1

This commit is contained in:
Francisco Jesús Martínez Mimbrera
2026-05-23 00:32:57 +02:00
commit 759a8968a2
4357 changed files with 163763 additions and 0 deletions
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>flintstones.group</groupId>
<artifactId>flintstones.bundles</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>flintstones.domain.fuzzyset.ui.chart</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<name>[bundle] Chart</name>
</project>
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>flintstones.domain.fuzzyset.ui.chart</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1779484362538</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
@@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
@@ -0,0 +1,17 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Chart
Bundle-SymbolicName: flintstones.domain.fuzzyset.ui.chart;singleton:=true
Bundle-Version: 1.0.0.qualifier
Automatic-Module-Name: flintstones.domain.fuzzyset.ui.chart
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: flintstones.entity.domain.ui.chart;visibility:=reexport,
flintstones.domain.fuzzyset,
org.eclipse.swt,
flintstones.entity.domain,
flintstones.domain.numeric.real,
javax.inject,
flintstones.entity.domain.ui,
javax.annotation,
org.jfree.chart.jfreechart
Export-Package: flintstones.domain.fuzzyset.ui.chart
@@ -0,0 +1,5 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="flintstones.domain.ui.chart.extensionpoint">
<chart_ui
chart="flintstones.domain.fuzzyset.ui.chart.LinguisticDomainChart"
domain="flintstones.domain.linguistic"
uid="flintstones.domain.linguistic.chart">
</chart_ui>
<chart_ui
chart="flintstones.domain.fuzzyset.ui.chart.LinguisticDomainChart"
domain="flintstones.domain.hesitant"
uid="flintstones.domain.linguistic.ui.chart.hesitant">
</chart_ui>
</extension>
</plugin>
@@ -0,0 +1,198 @@
package flintstones.domain.fuzzyset.ui.chart;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.swt.widgets.Composite;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.ValueMarker;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.chart.swt.ChartComposite;
import org.jfree.chart.ui.Layer;
import org.jfree.chart.ui.RectangleInsets;
import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction;
import flintstones.domain.fuzzyset.label.LabelLinguisticDomain;
import flintstones.domain.fuzzyset.semantic.IMembershipFunction;
import flintstones.entity.domain.Domain;
import flintstones.entity.domain.ui.chart.DomainChart;
@SuppressWarnings("javadoc")
public class CreateManualDomainDialogChart extends DomainChart {
private LabelLinguisticDomain _label;
public static final Color[] colors = { Color.RED, Color.CYAN, Color.GREEN, Color.MAGENTA, Color.LIGHT_GRAY, Color.ORANGE, Color.ORANGE, Color.MAGENTA, Color.PINK, Color.WHITE, Color.YELLOW };
private ValueMarker[] _alternativesMarkers;
public CreateManualDomainDialogChart() {
this._label = null;
this._chart = null;
this._chartComposite = null;
}
@Override
public void initialize(Domain domain, Composite container, int width, int height, int style) {
this.setDomain(domain);
this._chartComposite = new ChartComposite(container, style, this._chart, true);
this._chartComposite.setSize(width, height);
}
@Override
public void setDomain(Domain domain) {
this._domain = domain;
this.refreshChart();
}
@Override
public void refreshChart() {
if (this._chart == null)
this._chart = this.createChart(this.createDataset());
else
this._chart.getXYPlot()
.setDataset(this.createDataset());
this.setBasicRenderer(this._chart.getXYPlot());
}
@Override
public void setSelection(Object selection) {
}
public void setLabel(LabelLinguisticDomain label) {
this._label = label;
this.refreshChart();
}
private JFreeChart createChart(XYSeriesCollection dataset) {
JFreeChart result = ChartFactory.createXYLineChart("", "", "", dataset, PlotOrientation.VERTICAL, false, true, false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
result.setBackgroundPaint(Color.WHITE);
XYPlot xyplot = (XYPlot) result.getPlot();
xyplot.setBackgroundPaint(Color.WHITE);
xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY);
xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY);
xyplot.getDomainAxis()
.setRange(0d, 1d);
xyplot.getRangeAxis()
.setRange(0d, 1.1d);
return result;
}
private XYSeriesCollection createDataset() {
XYSeriesCollection dataset = new XYSeriesCollection();
if (this._label != null) {
XYSeries series = new XYSeries(this._label.getName());
IMembershipFunction membershipFunction = this._label.getSemantic();
if (membershipFunction instanceof TrapezoidalFunction) {
TrapezoidalFunction trapezoidalFunction = (TrapezoidalFunction) membershipFunction;
series.add(trapezoidalFunction.getCoverage()
.getMin(), 0.0);
series.add(trapezoidalFunction.getCenter()
.getMin(), 1.0);
series.add(trapezoidalFunction.getCenter()
.getMax(), 1.0);
series.add(trapezoidalFunction.getCoverage()
.getMax(), 0.0);
}
dataset.addSeries(series);
}
return dataset;
}
private void setBasicRenderer(XYPlot xyplot) {
xyplot = this._chart.getXYPlot();
XYItemRenderer renderer = xyplot.getRenderer(0);
for (int i = 0; i < xyplot.getSeriesCount(); ++i)
renderer.setSeriesStroke(i, new BasicStroke(1));
}
@Override
public void displayRanking(Object ranking) {
if (ranking != null) {
String[] alternatives = (String[]) ((Object[]) ranking)[0];
int[] pos = (int[]) ((Object[]) ranking)[1];
this.displayAlternatives(alternatives, pos, CreateManualDomainDialogChart.colors);
}
}
public void displayAlternatives(String[] alternatives, int[] pos, Color[] colors) {
if (this._alternativesMarkers != null)
for (ValueMarker marker : this._alternativesMarkers)
this._chart.getXYPlot()
.removeRangeMarker(marker);
this._alternativesMarkers = null;
class MyItem implements Comparable<MyItem> {
public String alternative;
public Double pos;
public Color color;
public MyItem(String alternative, double pos, Color color) {
this.alternative = alternative;
this.pos = pos;
this.color = color;
}
@Override
public int compareTo(MyItem other) {
return Double.compare(this.pos, other.pos);
}
}
List<MyItem> items = null;
if ((alternatives != null) && (pos != null) && (colors != null)) {
items = new LinkedList<>();
for (int i = 0; i < pos.length; i++)
if (alternatives[i] != null)
items.add(new MyItem(alternatives[i], pos[i], colors[i]));
Collections.sort(items);
}
if (items != null) {
int size = items.size();
if (size > 0) {
int height = (int) (this._chartComposite.getSize().y * 0.75f);
int offset = height / size;
this._alternativesMarkers = new ValueMarker[size];
MyItem item;
for (int i = 0; i < size; i++) {
item = items.get(i);
this._alternativesMarkers[i] = new ValueMarker(item.pos);
this._alternativesMarkers[i].setPaint(item.color);
this._alternativesMarkers[i].setStroke(new BasicStroke(3));
this._alternativesMarkers[i].setLabel(item.alternative);
this._alternativesMarkers[i].setLabelFont(new Font("TimesRoman", Font.BOLD, 20)); //$NON-NLS-1$
this._alternativesMarkers[i].setLabelPaint(item.color);
this._alternativesMarkers[i].setLabelOffset(new RectangleInsets(offset + (offset * i), 15, 0, 0));
this._chart.getXYPlot()
.addRangeMarker(0, this._alternativesMarkers[i], Layer.FOREGROUND);
}
}
}
}
}
@@ -0,0 +1,368 @@
package flintstones.domain.fuzzyset.ui.chart;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.swt.widgets.Composite;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.annotations.XYTextAnnotation;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.ValueMarker;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.swt.ChartComposite;
import org.jfree.chart.ui.Layer;
import org.jfree.chart.ui.RectangleInsets;
import org.jfree.data.xy.XYDataItem;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import flintstones.domain.fuzzyset.FuzzySet;
import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction;
import flintstones.domain.fuzzyset.label.LabelLinguisticDomain;
import flintstones.domain.fuzzyset.semantic.IMembershipFunction;
import flintstones.entity.domain.Domain;
import flintstones.entity.domain.ui.chart.DomainChart;
@SuppressWarnings("javadoc")
public class LinguisticDomainChart extends DomainChart {
private XYSeriesCollection _dataset;
public static final Color[] colors = { Color.RED, Color.CYAN, Color.GREEN, Color.MAGENTA, Color.LIGHT_GRAY, Color.ORANGE, Color.ORANGE, Color.MAGENTA,
Color.PINK, Color.WHITE, Color.YELLOW };
private ValueMarker[] _alternativesMarkers;
public LinguisticDomainChart() {
this._domain = null;
this._chart = null;
this._chartComposite = null;
}
@Override
public void initialize(Domain domain, Composite container, int width, int height, int style) {
this.setDomain(domain);
this._chartComposite = new ChartComposite(container, style, this._chart, true);
this._chartComposite.setSize(width, height);
}
public void initialize(Domain domain, Composite container, int width, int height, double initialPos, double finalPos, int style) {
this.setDomain(domain, initialPos, finalPos);
this._chartComposite = new ChartComposite(container, style, this._chart, true);
this._chartComposite.setSize(width, height);
}
@Override
public void setDomain(Domain domain) {
this._domain = domain;
this.refreshChart();
}
public void setDomain(Domain domain, double initialPos, double finalPos) {
this._domain = domain;
this.refreshChart(initialPos, finalPos);
}
@Override
public void refreshChart() {
if (this._chart == null)
this._chart = this.createChart(this.createDataset());
else
this._chart.getXYPlot().setDataset(this.createDataset());
this.setBasicRenderer(this._chart.getXYPlot());
}
public void refreshChart(double initialPos, double finalPos) {
if (this._chart == null)
this._chart = this.createChart(this.createDataset(), initialPos, finalPos);
else
this._chart.getXYPlot().setDataset(this.createDataset());
this.setBasicRenderer(this._chart.getXYPlot());
}
@SuppressWarnings("unchecked")
@Override
public void setSelection(Object selection) {
XYPlot xyplot = (XYPlot) this._chart.getPlot();
XYItemRenderer renderer = xyplot.getRenderer(0);
if (!(selection instanceof LinkedList<?>)) {
for (int i = 0; i < xyplot.getSeriesCount(); ++i)
if (i != (Integer) selection)
renderer.setSeriesStroke(i, new BasicStroke(1));
else
renderer.setSeriesStroke(i, new BasicStroke(3));
} else if (((LinkedList<Integer>) selection).size() > 1) {
int lower = ((LinkedList<Integer>) selection).get(0);
int upper = ((LinkedList<Integer>) selection).get(1);
for (int i = 0; i < xyplot.getSeriesCount(); ++i)
if ((lower <= i) && (i <= upper))
renderer.setSeriesStroke(i, new BasicStroke(3));
else
renderer.setSeriesStroke(i, new BasicStroke(1));
} else if (((LinkedList<Integer>) selection).size() == 1) {
int value = ((LinkedList<Integer>) selection).get(0);
for (int i = 0; i < xyplot.getSeriesCount(); ++i)
if (i != value)
renderer.setSeriesStroke(i, new BasicStroke(1));
else
renderer.setSeriesStroke(i, new BasicStroke(3));
}
}
private JFreeChart createChart(XYSeriesCollection dataset) {
JFreeChart result = ChartFactory.createXYLineChart("", "", "", dataset, PlotOrientation.VERTICAL, true, true, false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
result.setBackgroundPaint(Color.WHITE);
XYPlot xyplot = (XYPlot) result.getPlot();
xyplot.setBackgroundPaint(Color.WHITE);
xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY);
xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY);
xyplot.getDomainAxis().setRange(0d, 1d);
xyplot.getRangeAxis().setRange(0d, 1.1d);
this.setBasicRenderer(xyplot);
return result;
}
private JFreeChart createChart(XYSeriesCollection dataset, double initialPos, double finalPos) {
JFreeChart result = ChartFactory.createXYLineChart("", "", "", dataset, PlotOrientation.VERTICAL, true, true, false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
result.setBackgroundPaint(Color.WHITE);
XYPlot xyplot = (XYPlot) result.getPlot();
xyplot.setBackgroundPaint(Color.WHITE);
xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY);
xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY);
xyplot.getDomainAxis().setRange(initialPos, finalPos);
xyplot.getRangeAxis().setRange(0d, 1.1d);
this.setBasicRenderer(xyplot);
return result;
}
private XYSeriesCollection createDataset() {
this._dataset = new XYSeriesCollection();
if (this._domain != null)
if (((FuzzySet) this._domain).getLabelSet().getCardinality() > 0) {
XYSeries series;
for (LabelLinguisticDomain label : ((FuzzySet) this._domain).getLabelSet().getLabels()) {
series = new XYSeries(label.getName());
IMembershipFunction membershipFunction = label.getSemantic();
if (membershipFunction instanceof TrapezoidalFunction) {
TrapezoidalFunction trapezoidalFunction = (TrapezoidalFunction) membershipFunction;
series.add(trapezoidalFunction.getCoverage().getMin(), 0.0);
series.add(trapezoidalFunction.getCenter().getMin(), 1.0);
series.add(trapezoidalFunction.getCenter().getMax(), 1.0);
series.add(trapezoidalFunction.getCoverage().getMax(), 0.0);
}
this._dataset.addSeries(series);
}
}
return this._dataset;
}
private Color colorForEachLabel(int pos) {
int r, g, b;
r = (63 * (pos + 1)) % 255;
g = (107 * (pos + 2)) % 255;
b = (217 * (pos + 3)) % 255;
return new Color(r, g, b);
}
private void setBasicRenderer(XYPlot xyplot) {
XYItemRenderer renderer = xyplot.getRenderer(0);
for (int i = 0; i < xyplot.getSeriesCount(); ++i) {
renderer.setSeriesStroke(i, new BasicStroke());
renderer.setSeriesPaint(i, this.colorForEachLabel(i));
}
}
@Override
public void displayRanking(Object ranking) {
Double[] values = null;
if (ranking != null) {
String[] alternatives = (String[]) ((Object[]) ranking)[0];
if (((Object[]) ranking)[1] instanceof int[]) {
values = new Double[((int[]) ((Object[]) ranking)[1]).length];
for (int i = 0; i < ((int[]) ((Object[]) ranking)[1]).length; ++i)
values[i] = (double) ((int[]) ((Object[]) ranking)[1])[i];
} else if (((Object[]) ranking)[1] instanceof double[]) {
values = new Double[((double[]) ((Object[]) ranking)[1]).length];
for (int i = 0; i < ((double[]) ((Object[]) ranking)[1]).length; ++i)
values[i] = (double) ((double[]) ((Object[]) ranking)[1])[i];
}
if (((Object[]) ranking).length == 2)
this.displayAlternatives(alternatives, values, LinguisticDomainChart.colors);
else {
int[] pos = ((int[]) ((Object[]) ranking)[2]);
double[] alpha = ((double[]) ((Object[]) ranking)[3]);
this.displayAlternatives(alternatives, values, pos, alpha, LinguisticDomainChart.colors);
}
}
}
public void displayAlternatives(String[] alternatives, Double[] pos, Color[] colors) {
if (this._alternativesMarkers != null)
for (ValueMarker marker : this._alternativesMarkers)
this._chart.getXYPlot().removeRangeMarker(marker);
this._alternativesMarkers = null;
class MyItem implements Comparable<MyItem> {
public String alternative;
public Double pos;
public Color color;
public MyItem(String alternative, double pos, Color color) {
this.alternative = alternative;
this.pos = pos;
this.color = color;
}
@Override
public int compareTo(MyItem other) {
return Double.compare(this.pos, other.pos);
}
}
List<MyItem> items = null;
if ((alternatives != null) && (pos != null) && (colors != null)) {
items = new LinkedList<>();
for (int i = 0; i < pos.length; i++)
if (alternatives[i] != null)
items.add(new MyItem(alternatives[i], pos[i], colors[i]));
Collections.sort(items);
}
if (items != null) {
int size = items.size();
if (size > 0) {
int height = (int) (this._chartComposite.getSize().y * 0.75f);
int offset = height / size;
this._alternativesMarkers = new ValueMarker[size];
MyItem item;
for (int i = 0; i < size; i++) {
item = items.get(i);
this._alternativesMarkers[i] = new ValueMarker(item.pos);
this._alternativesMarkers[i].setPaint(item.color);
this._alternativesMarkers[i].setStroke(new BasicStroke(3));
this._alternativesMarkers[i].setLabel(item.alternative);
this._alternativesMarkers[i].setLabelFont(new Font("TimesRoman", Font.BOLD, 20)); //$NON-NLS-1$
this._alternativesMarkers[i].setLabelPaint(item.color);
this._alternativesMarkers[i].setLabelOffset(new RectangleInsets(offset * (i / offset), 25, 0, 0));
this._chart.getXYPlot().addRangeMarker(0, this._alternativesMarkers[i], Layer.FOREGROUND);
}
}
}
}
public void displayAlternatives(String[] alternatives, Double[] values, int[] pos, double[] alpha, Color[] colors) {
this.displayAlternatives(alternatives, values, colors);
this.displayAlternatives(alternatives, pos, alpha);
}
@SuppressWarnings("unchecked")
public void displayAlternatives(String[] alternatives, int[] pos, double[] alpha) {
int size = alternatives.length;
int cardinality = ((FuzzySet) this._domain).getLabelSet().getCardinality();
XYSeries series, alternativeSeries;
double[] centers = new double[size];
double x, y, factor;
List<XYDataItem> dataItems;
for (int i = 0; i < size; i++)
if (alternatives[i] != null) {
series = this._dataset.getSeries(pos[i]);
alternativeSeries = new XYSeries(alternatives[i]);
dataItems = series.getItems();
if (alpha[i] >= 0)
factor = (dataItems.get(3).getX().doubleValue() - dataItems.get(2).getX().doubleValue()) * alpha[i];
else
factor = (dataItems.get(1).getX().doubleValue() - dataItems.get(0).getX().doubleValue()) * alpha[i];
XYDataItem item;
for (int itemPos = 0; itemPos < dataItems.size(); itemPos++) {
item = dataItems.get(itemPos);
x = item.getXValue();
y = item.getYValue();
if (itemPos == 0) {
if (x == dataItems.get(1).getX().doubleValue())
x -= dataItems.get(3).getX().doubleValue() - dataItems.get(2).getX().doubleValue();
} else if (itemPos == 1)
centers[i] = x + factor;
else if (itemPos == 3)
if (x == dataItems.get(2).getX().doubleValue())
x += dataItems.get(1).getX().doubleValue() - dataItems.get(0).getX().doubleValue();
alternativeSeries.add(x + factor, y);
}
this._dataset.addSeries(alternativeSeries);
}
this._chart.getXYPlot().setDataset(this._dataset);
XYPlot xyplot = (XYPlot) this._chart.getPlot();
XYItemRenderer renderer = xyplot.getRenderer(0);
XYTextAnnotation annotation;
for (int i = 0; i < xyplot.getSeriesCount(); i++)
if (i >= cardinality) {
renderer.setSeriesStroke(i, new BasicStroke(3));
renderer.setSeriesPaint(i, this.colorForEachLabel(pos[i - cardinality]));
annotation = new XYTextAnnotation(alternatives[i - cardinality], centers[i - cardinality], 1.05);
annotation.setFont(new Font("SansSerif", Font.PLAIN, 10)); //$NON-NLS-1$
xyplot.addAnnotation(annotation);
} else {
renderer.setSeriesStroke(i, new BasicStroke(1));
renderer.setSeriesPaint(i, this.colorForEachLabel(i));
}
}
public void displayAlternatives(String[] alternatives, TrapezoidalFunction[] fuzzyNumbers) {
int size = fuzzyNumbers.length;
XYSeries alternativeSeries = null;
for (int i = 0; i < size; i++) {
alternativeSeries = new XYSeries(alternatives[i]);
alternativeSeries.add(fuzzyNumbers[i].getLimits()[0], 0);
alternativeSeries.add(fuzzyNumbers[i].getLimits()[1], 1);
alternativeSeries.add(fuzzyNumbers[i].getLimits()[2], 1);
alternativeSeries.add(fuzzyNumbers[i].getLimits()[3], 0);
this._dataset.addSeries(alternativeSeries);
}
this._chart.getXYPlot().setDataset(this._dataset);
XYPlot xyplot = (XYPlot) this._chart.getPlot();
XYItemRenderer renderer = xyplot.getRenderer(0);
for (int i = 0; i < xyplot.getSeriesCount(); i++)
if (i >= ((FuzzySet) this._domain).getLabelSet().getCardinality())
renderer.setSeriesStroke(i, new BasicStroke(3));
else {
renderer.setSeriesStroke(i, new BasicStroke());
renderer.setSeriesPaint(i, this.colorForEachLabel(i));
}
}
}
@@ -0,0 +1,287 @@
package flintstones.domain.fuzzyset.ui.chart;
import java.awt.BasicStroke;
import java.awt.Color;
import java.text.MessageFormat;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.eclipse.e4.core.services.nls.Translation;
import org.eclipse.swt.widgets.Composite;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.chart.swt.ChartComposite;
import org.jfree.chart.ui.RectangleInsets;
import flintstones.domain.fuzzyset.FuzzySet;
import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction;
import flintstones.domain.fuzzyset.label.LabelLinguisticDomain;
import flintstones.domain.fuzzyset.semantic.IMembershipFunction;
import flintstones.domain.fuzzyset.ui.chart.messages.Messages;
import flintstones.entity.domain.Domain;
import flintstones.entity.domain.ui.chart.DomainChart;
@SuppressWarnings("javadoc")
public class PlainFuzzySetChart extends DomainChart {
@Inject
@Translation
private Messages messages;
private XYSeriesCollection _datasetSeries;
private boolean _fixColor;
private int _r;
private int _g;
private int _b;
private boolean _dashed;
public PlainFuzzySetChart() {
// No debería llamarse nunca directamente
this._domain = null;
this._chart = null;
this._chartComposite = null;
this._fixColor = false;
}
@PostConstruct
private void init() {
this._domain = null;
this._chart = null;
this._chartComposite = null;
this._fixColor = false;
}
@Override
public void initialize(Domain domain, Composite container, int width, int height, int style) {
this.setDomain(domain);
this._chartComposite = new ChartComposite(container, style, this._chart, true);
this._chartComposite.setSize(width, height);
}
public void initialize(Domain domain, Composite container, int width, int height, int style, boolean dashed) {
this.setDomain(domain);
this._dashed = dashed;
this._chartComposite = new ChartComposite(container, style, this._chart, true);
this._chartComposite.setSize(width, height);
}
public void initialize(FuzzySet domain, Composite composite, int width, int height, int style, int r, int g, int b, boolean dashed) {
this._dashed = dashed;
this._fixColor = true;
this._r = r;
this._g = g;
this._b = b;
this._domain = domain;
this._chart = this.createChart(this.createDataset());
this._chartComposite = new ChartComposite(composite, style, this._chart, true);
this._chartComposite.setSize(width, height);
this._chartComposite.setBounds(-1, -1, width, height);
}
private JFreeChart createChart(XYSeriesCollection xySeriesCollection) {
JFreeChart result = ChartFactory.createXYLineChart("", "", "", xySeriesCollection, PlotOrientation.VERTICAL, false, false, false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
result.setBackgroundPaint(Color.white);
XYPlot xyplot = (XYPlot) result.getPlot();
xyplot.setBackgroundPaint(Color.white);
xyplot.setDomainGridlinePaint(Color.lightGray);
xyplot.setRangeGridlinePaint(Color.lightGray);
xyplot.getDomainAxis()
.setRange(0d, 1d);
xyplot.getRangeAxis()
.setRange(0d, 1.01d);
xyplot.getDomainAxis()
.setVisible(false);
xyplot.getRangeAxis()
.setVisible(false);
xyplot.setAxisOffset(RectangleInsets.ZERO_INSETS);
xyplot.setInsets(RectangleInsets.ZERO_INSETS);
result.setPadding(RectangleInsets.ZERO_INSETS);
this.setBasicRenderer(xyplot);
return result;
}
private XYSeriesCollection createDataset() {
this._datasetSeries = new XYSeriesCollection();
if (this._domain != null)
if (((FuzzySet) this._domain).getLabelSet()
.getCardinality() > 0) {
XYSeries series;
for (LabelLinguisticDomain label : ((FuzzySet) this._domain).getLabelSet()
.getLabels()) {
IMembershipFunction membershipFunction = label.getSemantic();
if (membershipFunction instanceof TrapezoidalFunction) {
TrapezoidalFunction tmf = (TrapezoidalFunction) membershipFunction;
String templateLeft = this.messages.PlainFuzzySetChart_template_left;
String text = MessageFormat.format(templateLeft, label.getName());
series = new XYSeries(text);
series.add(tmf.getCoverage()
.getMin(), 0.0);
series.add(tmf.getCenter()
.getMin(), 1.0);
this._datasetSeries.addSeries(series);
String templateRight = this.messages.PlainFuzzySetChart_template_right;
text = MessageFormat.format(templateRight, label.getName());
series = new XYSeries(text);
series.add(tmf.getCenter()
.getMax(), 1.0);
series.add(tmf.getCoverage()
.getMax(), 0.0);
this._datasetSeries.addSeries(series);
}
}
}
return this._datasetSeries;
}
private Color getRGB(int pos) {
if (!this._fixColor) {
this._r = (63 * ((pos / 2) + 1)) % 255;
this._g = (107 * ((pos / 2) + 2)) % 255;
this._b = (217 * ((pos / 2) + 3)) % 255;
}
return new Color(this._r, this._g, this._b);
}
public static Color getColor(int pos) {
int r, g, b;
r = (63 * (pos + 1)) % 255;
g = (107 * (pos + 2)) % 255;
b = (217 * (pos + 3)) % 255;
return new Color(r, g, b);
}
private void setBasicRenderer(XYPlot xyplot) {
XYItemRenderer renderer = xyplot.getRenderer(0);
BasicStroke stroke;
for (int i = 0; i < xyplot.getSeriesCount(); i++) {
if (this._dashed)
stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 20.0f }, 0.0f);
else
stroke = new BasicStroke(1);
renderer.setSeriesStroke(i, stroke);
renderer.setSeriesPaint(i, this.getRGB(i));
}
}
@Override
public void setDomain(Domain domain) {
this._domain = domain;
this.refreshChart();
}
@Override
public void refreshChart() {
if (this._chart == null)
this._chart = this.createChart(this.createDataset());
else
this._chart.getXYPlot()
.setDataset(this.createDataset());
this.setBasicRenderer(this._chart.getXYPlot());
}
public void setPosLeftColor(int pos, Color color) {
XYPlot xyplot = (XYPlot) this._chart.getPlot();
XYItemRenderer renderer = xyplot.getRenderer(0);
renderer.setSeriesPaint(pos * 2, color);
renderer.setSeriesStroke(pos * 2, new BasicStroke(1));
}
public void setPosRightColor(int pos, Color color) {
XYPlot xyplot = (XYPlot) this._chart.getPlot();
XYItemRenderer renderer = xyplot.getRenderer(0);
renderer.setSeriesPaint((pos * 2) + 1, color);
renderer.setSeriesStroke((pos * 2) + 1, new BasicStroke(1));
}
public void setPosColor(int pos, Color color) {
XYPlot xyplot = (XYPlot) this._chart.getPlot();
XYItemRenderer renderer = xyplot.getRenderer(0);
renderer.setSeriesPaint(pos * 2, color);
renderer.setSeriesPaint((pos * 2) + 1, color);
renderer.setSeriesStroke(pos * 2, new BasicStroke(1));
renderer.setSeriesStroke((pos * 2) + 1, new BasicStroke(1));
}
public void selectLeft(int pos) {
XYPlot xyplot = (XYPlot) this._chart.getPlot();
XYItemRenderer renderer = xyplot.getRenderer(0);
renderer.setSeriesStroke(pos * 2, new BasicStroke(3));
}
public void selectRight(int pos) {
XYPlot xyplot = (XYPlot) this._chart.getPlot();
XYItemRenderer renderer = xyplot.getRenderer(0);
renderer.setSeriesStroke((pos * 2) + 1, new BasicStroke(3));
}
public void select(int pos) {
XYPlot xyplot = (XYPlot) this._chart.getPlot();
XYItemRenderer renderer = xyplot.getRenderer(0);
renderer.setSeriesStroke(pos * 2, new BasicStroke(3));
renderer.setSeriesStroke((pos * 2) + 1, new BasicStroke(3));
}
public void setSelection(int lower, int upper) {
XYPlot xyplot = (XYPlot) this._chart.getPlot();
XYItemRenderer renderer = xyplot.getRenderer(0);
for (int i = 0; i < xyplot.getSeriesCount(); i++)
if (((lower * 2) <= i) && (i <= (upper * 2)))
renderer.setSeriesStroke(i, new BasicStroke(3));
else
renderer.setSeriesStroke(i, new BasicStroke(1));
}
@SuppressWarnings("unchecked")
@Override
public void setSelection(Object selection) {
if (selection instanceof Integer) {
XYPlot xyplot = (XYPlot) this._chart.getPlot();
XYItemRenderer renderer = xyplot.getRenderer(0);
for (int i = 0; i < xyplot.getSeriesCount(); i++)
if ((i == ((Integer) selection * 2)) || (i == (((Integer) selection * 2) + 1)))
renderer.setSeriesStroke(i, new BasicStroke(3));
else
renderer.setSeriesStroke(i, new BasicStroke(1));
} else {
List<Integer> lowerUpper = (List<Integer>) selection;
XYPlot xyplot = (XYPlot) this._chart.getPlot();
XYItemRenderer renderer = xyplot.getRenderer(0);
for (int i = 0; i < xyplot.getSeriesCount(); i++)
if (((lowerUpper.get(0) * 2) <= i) && (i <= (lowerUpper.get(1) * 2)))
renderer.setSeriesStroke(i, new BasicStroke(3));
else
renderer.setSeriesStroke(i, new BasicStroke(1));
}
}
@Override
public void displayRanking(Object ranking) {
}
}
@@ -0,0 +1,36 @@
// This file has been auto-generated
package flintstones.domain.fuzzyset.ui.chart.messages;
import org.eclipse.e4.core.services.nls.Message;
@Message
@SuppressWarnings("javadoc")
public class Messages {
public String PlainFuzzySetChart_template_left;
public String PlainFuzzySetChart_template_right;
public String Domain_id;
public String Insert_label_names_with_separator_colon;
public String Preview;
public String Auto_generated_domain;
public String Empty_domain;
public String Duplicated_id;
public String Empty_value;
public String Labels;
public String Name;
public String Semantic;
public String Manually_create_domain;
public String Add;
public String Add_label;
public String Modify;
public String Modify_label;
public String Remove;
public String Remove_label;
public String Label_name;
public String Trapezoidal;
public String Values;
public String Duplicated_name;
public String Invalid_value;
public String Value_lower_than_the_previous;
}
@@ -0,0 +1,25 @@
Auto_generated_domain=Auto-generated domain
Empty_domain=Empty domain
Insert_label_names_with_separator_colon=Insert label names with separator ':'
PlainFuzzySetChart_template_left={0}_left
PlainFuzzySetChart_template_right={0}_right
Duplicated_name=Duplicated name
Invalid_value=Invalid value
Label_name=Label name
Trapezoidal=Trapezoidal
Value_lower_than_the_previous=Value lower than the previous
Values=Values
Add=Add
Add_label=Add label
Domain_id=Domain id
Duplicated_id=Duplicated id
Empty_value=Empty value
Labels=Labels
Manually_create_domain=Manually create domain
Modify=Modify
Modify_label=Modify label
Name=Name
Preview=Preview
Remove=Remove
Remove_label=Remove label
Semantic=Semantic
@@ -0,0 +1,25 @@
Auto_generated_domain=Dominio auto generador
Domain_id=Identificador de dominio
Duplicated_id=Id dupliacada
Empty_domain=Dominio vacio
Empty_value=Valor vaico
Insert_label_names_with_separator_colon=Inserta las etiquetas separadas por ':'
PlainFuzzySetChart_template_left={0}_left
PlainFuzzySetCharttemplate_right={0}_right
Duplicated_name=Nombre duplicado
Invalid_value=Valor no valido
Label_name=Nombre de la etiqueta
Preview=Previsualización
Semantic=Semantica
Trapezoidal=Trapezoidal
Value_lower_than_the_previous=Valor inferior que el previo
Values=Valores
Add=Añadir
Add_label=Añadir etiqueta
Labels=Etiquetas
Manually_create_domain=Crear dominio manualmente
Modify=Modificar
Modify_label=Modificar etiqueta
Name=Nombre
Remove=Eliminar
Remove_label=Eliminar etiqueta