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,275 @@
package flintstones.domain.numeric.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 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.IntervalMarker;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.ValueMarker;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.StandardXYBarPainter;
import org.jfree.chart.renderer.xy.XYBarRenderer;
import org.jfree.data.xy.DefaultIntervalXYDataset;
import org.jfree.data.xy.IntervalXYDataset;
import org.jfree.chart.swt.ChartComposite;
import org.jfree.chart.ui.Layer;
import org.jfree.chart.ui.RectangleInsets;
import flintstones.domain.numeric.NumericDomain;
import flintstones.domain.numeric.ui.chart.messages.Messages;
import flintstones.entity.domain.Domain;
import flintstones.entity.domain.ui.chart.DomainChart;
import flintstones.helper.validator.Validator;
@SuppressWarnings("javadoc")
public class NumericDomainChart extends DomainChart {
@Inject
@Translation
private Messages messages;
@Inject
@Translation
private flintstones.entity.domain.messages.Messages domainMessages;
private NumericDomain _domain;
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 _numMarker;
private IntervalMarker _intervalMarker;
private ValueMarker[] _alternativesMarkers;
public NumericDomainChart() {
super();
this._domain = null;
this._chart = null;
this._chartComposite = null;
this._numMarker = null;
this._intervalMarker = null;
}
@Override
public void refreshChart() {
if (this._chart == null)
this._chart = this.createChart(this.createIntervalDataset());
else
this._chart.getXYPlot()
.setDataset(this.createIntervalDataset());
double upperLimit = this._domain.getMax(), lowerLimit = this._domain.getMin();
boolean inRange = this._domain.getInRange();
double rangeSize = upperLimit - lowerLimit;
double margin = (rangeSize > 0) ? rangeSize / 4d : 1;
this._chart.getXYPlot()
.getRangeAxis()
.setRange(lowerLimit - margin, upperLimit + margin);
this._chart.getXYPlot()
.getRangeAxis()
.setTickLabelsVisible(inRange);
if (inRange) {
if (this._domain.getName()
.equals("")) //$NON-NLS-1$
this._chart.getXYPlot()
.getRangeAxis()
.setLabel(this.domainMessages.Domain_entity);
else
this._chart.getXYPlot()
.getRangeAxis()
.setLabel(this._domain.getName()); // $NON-NLS-1$
} else
this._chart.getXYPlot()
.getRangeAxis()
.setLabel(this.messages.lessInfinity + this.messages.noInfinity + this.messages.plusInfinity);
}
@Override
public void setDomain(Domain domain) {
Validator.notNull(domain);
// Validator.notIllegalElementType(domain, new String[] {
// NumericDomain.class.toString() });
this._domain = (NumericDomain) domain;
this.refreshChart();
}
@Override
public void setSelection(Object selection) {
if (this._numMarker != null)
this._chart.getXYPlot()
.removeRangeMarker(this._numMarker);
if (this._intervalMarker != null)
this._chart.getXYPlot()
.removeRangeMarker(this._intervalMarker);
if (selection instanceof LinkedList<?>) {
LinkedList<?> selectionL = (LinkedList<?>) selection;
if (selectionL.getFirst() instanceof Integer) {
Integer mark1 = (int) (selectionL).getFirst();
Integer mark2 = (int) (selectionL).getLast();
this._intervalMarker = new IntervalMarker(mark1, mark2);
} else if (selectionL.getFirst() instanceof Double) {
Double mark1 = (double) (selectionL).getFirst();
Double mark2 = (double) (selectionL).getLast();
this._intervalMarker = new IntervalMarker(mark1, mark2);
} else
throw new Error("Tipo no esperado " + selectionL.getFirst() //$NON-NLS-1$
.getClass());
this._intervalMarker.setAlpha(0.5f);
this._intervalMarker.setPaint(Color.RED);
this._chart.getXYPlot()
.addRangeMarker(this._intervalMarker);
} else {
if (selection instanceof Integer)
this._numMarker = new ValueMarker((Integer) selection);
else if (selection instanceof Double)
this._numMarker = new ValueMarker((Double) selection);
else
throw new Error("Tipo no esperado " + selection.getClass()); //$NON-NLS-1$
this._numMarker.setPaint(Color.RED);
this._numMarker.setStroke(new BasicStroke(4));
this._chart.getXYPlot()
.addRangeMarker(this._numMarker);
}
}
@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);
}
private JFreeChart createChart(IntervalXYDataset intervalXYDataset) {
JFreeChart result = ChartFactory.createXYBarChart("", "X", false, "", intervalXYDataset, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
PlotOrientation.HORIZONTAL, false, false, false);
result.setBackgroundPaint(Color.WHITE);
XYPlot xyplot = (XYPlot) result.getPlot();
XYBarRenderer xyBarRenderer = (XYBarRenderer) xyplot.getRenderer();
xyBarRenderer.setSeriesPaint(0, Color.BLUE);
xyBarRenderer.setUseYInterval(true);
xyBarRenderer.setBarPainter(new StandardXYBarPainter());
xyplot.setBackgroundPaint(Color.WHITE);
xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY);
xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY);
xyplot.getDomainAxis()
.setVisible(false);
return result;
}
private IntervalXYDataset createIntervalDataset() {
DefaultIntervalXYDataset result = new DefaultIntervalXYDataset();
double upperLimit = this._domain.getMax(), lowerLimit = this._domain.getMin();
double[] x = new double[] { 1 };
double[] xStart = new double[] { 0.1 };
double[] xEnd = new double[] { 0.9 };
double[] y = new double[] { upperLimit - lowerLimit };
double[] yStart = new double[] { lowerLimit };
double[] yEnd = new double[] { upperLimit };
double[][] data = new double[][] { x, xStart, xEnd, y, yStart, yEnd };
result.addSeries(this.messages.NumericDomainChart_range, data);
return result;
}
@Override
public void displayRanking(Object ranking) {
if (ranking != null) {
String[] alternatives = (String[]) ((Object[]) ranking)[0];
double[] pos = (double[]) ((Object[]) ranking)[1];
this.displayAlternatives(alternatives, pos, NumericDomainChart.colors);
}
}
public void displayAlternatives(String[] alternatives, double[] pos, Color[] colors) {
if (this._numMarker != null)
this._chart.getXYPlot()
.removeRangeMarker(this._numMarker);
if (this._alternativesMarkers != null)
for (ValueMarker marker : this._alternativesMarkers)
this._chart.getXYPlot()
.removeRangeMarker(marker);
this._alternativesMarkers = null;
class MyItem implements Comparable<MyItem> {
private final String alternative;
private final Double pos;
private final 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 / 2 + (offset * i), 15, 0, 0));
this._chart.getXYPlot()
.addRangeMarker(0, this._alternativesMarkers[i], Layer.FOREGROUND);
}
}
}
}
}
@@ -0,0 +1,38 @@
// This file has been auto-generated
package flintstones.domain.numeric.ui.chart.messages;
import org.eclipse.e4.core.services.nls.Message;
@Message
@SuppressWarnings("javadoc")
public class Messages {
public String NumericDomain_formatTemplate;
public String NumericDomain_toStringTemplate;
public String NumericDomainChart_range;
public String plusInfinity;
public String noInfinity;
public String Without_range;
public String lessInfinity;
public String label_domain_name;
public String error_domain_name;
public String limits;
public String rangeless;
public String limitless;
public String error_limits;
public String error_limits1;
public String to;
public String error_limits2;
public String preview;
public String dialogTitleTemplate;
public String crating;
public String integer;
public String intervalar;
public String error_empty_domain;
public String error_alredy_used_name;
public String error_out_of_limits;
public String modifying;
public String real;
public String blank;
}
@@ -0,0 +1,28 @@
Without_range=Without range
error_limits1=limits1
error_limits2=limits2
error_domain_name=name
error_limits=limits
chart=chart
crating=Creating
dialogTitleTemplate=%s domain of type %s %s
label_domain_name=Domain name
error_alredy_used_name=The chosen name is alredy used by another domain
error_empty_domain=Domain name can not be empty
error_out_of_limits=The first limit must be smaller than the second one
integer=Integer
intervalar=intervalar
lessInfinity=-Infinity
limitless=(-\u221E to \u221E)
limits=Limits
modifying=Editing
noInfinity=\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
NumericDomainChart_range=Range
plusInfinity=+Infinity
preview=Preview
rangeless=No range
real=Real
to=to
NumericDomain_formatTemplate={0} {1}
NumericDomain_toStringTemplate=[ {0} - {1} ]
blank=\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
@@ -0,0 +1,28 @@
Without_range=Sin rango
error_limits1=limits1
error_limits2=limits2
error_domain_name=name
error_limits=limits
chart=chart
crating=Creando
dialogTitleTemplate=%s dominio de tipo %s %s
label_domain_name=Nombre del dominio
error_alredy_used_name=El nombre ya esta siendo usado por otro dominio
error_empty_domain=El nombre de dominio no puede estar vacio
error_out_of_limits=El limite inferior debe ser menor que el limite superior
integer=Entero
intervalar=intervalar
limitless=(-\u221E to \u221E)
limits=Limites
modifying=Modificando
preview=Previsualización
rangeless=Sin rango
real=Real
to=a
NumericDomainChart_range=Rango
plusInfinity=+Infinito
lessInfinity=-Infinito
noInfinity=\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
NumericDomain_formatTemplate={0} {1}
NumericDomain_toStringTemplate=[ {0} - {1} ]
blank=\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \