package art.servers.colorsserver.M.gui.diagrams;
|
|
import art.library.gui.FlatGUI;
|
import art.library.gui.flat.FlatPopupMenu;
|
import art.library.gui.flat.FlatButton;
|
import art.library.model.devices.colors.controller.M.M_ControllerConfiguration;
|
import art.library.model.devices.colors.controller.M.M_SubcontrollerConfiguration;
|
import art.library.model.devices.colors.controller.M.configuration.ALUVISA_Link;
|
import art.library.model.devices.colors.controller.M.configuration.ALUVISA_Phase;
|
import art.library.model.devices.colors.controller.M.configuration.ALUVISA_Plan;
|
import art.library.gui.flat.FlatMenuItem;
|
import art.servers.Shared;
|
import java.awt.AlphaComposite;
|
import java.awt.BasicStroke;
|
import java.awt.Color;
|
import java.awt.Font;
|
import java.awt.FontMetrics;
|
import java.awt.Graphics;
|
import java.awt.Graphics2D;
|
import java.awt.Point;
|
import java.awt.RenderingHints;
|
import java.awt.Stroke;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import java.awt.event.KeyAdapter;
|
import java.awt.event.KeyEvent;
|
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseMotionAdapter;
|
import java.awt.geom.Ellipse2D;
|
import java.awt.geom.GeneralPath;
|
import java.awt.geom.Line2D;
|
import java.awt.geom.Point2D;
|
import java.awt.geom.Rectangle2D;
|
import java.util.ArrayList;
|
import javax.swing.SwingUtilities;
|
|
public class DiagramPlan extends FlatButton
|
{
|
private M_ControllerConfiguration m_controller = null;
|
private M_SubcontrollerConfiguration m_subcontroller = null;
|
private ALUVISA_Plan plan = null;
|
private boolean editable = false;
|
private FlatPopupMenu popupMenu = null;
|
private DiagramPlanListener listener = null;
|
private boolean isStructure = false;
|
private DiagramALUVISAPhases diagramPhases = null;
|
|
|
private ArrayList<ObjetoGrafico> objetosGraficos = new ArrayList<ObjetoGrafico>();
|
private double scale = 1.0;
|
private double translatex = 0.0;
|
private double translatey = 0.0;
|
private Point mousePressed;
|
private Point mouseDragged;
|
private ObjetoGrafico objetoGraficoSeleccionado = null;
|
|
|
|
public DiagramPlan(M_ControllerConfiguration m_controller, M_SubcontrollerConfiguration m_subcontroller, ALUVISA_Plan plan, boolean isStructure)
|
{
|
this.m_controller = m_controller;
|
this.m_subcontroller = m_subcontroller;
|
this.plan = plan;
|
this.isStructure = isStructure;
|
reload();
|
initialise();
|
}
|
|
|
public DiagramPlan(M_ControllerConfiguration m_controller, M_SubcontrollerConfiguration m_subcontroller, ALUVISA_Plan plan, DiagramALUVISAPhases diagramPhases, boolean isStructure)
|
{
|
this.m_controller = m_controller;
|
this.m_subcontroller = m_subcontroller;
|
this.plan = plan;
|
this.isStructure = isStructure;
|
this.diagramPhases = diagramPhases;
|
reload();
|
initialise();
|
}
|
|
|
public void timer(int phase, int time)
|
{
|
if (diagramPhases != null)
|
{
|
diagramPhases.timer(phase, time);
|
}
|
}
|
|
|
|
|
public void editable(boolean value)
|
{
|
this.editable = value;
|
}
|
|
|
|
public void setDiagramPlanListener(DiagramPlanListener listener)
|
{
|
this.listener = listener;
|
}
|
|
|
|
private void initialise()
|
{
|
this.popupMenu = new FlatPopupMenu();
|
FlatMenuItem item = new FlatMenuItem();
|
item.setText(Shared.getMessage("Delete"));
|
item.addActionListener(new ActionListener()
|
{
|
public void actionPerformed(ActionEvent e)
|
{
|
try
|
{
|
ObjectoGraficoConector selected = (ObjectoGraficoConector)objetoGraficoSeleccionado;
|
|
for (ALUVISA_Link link : plan.lLink)
|
{
|
if (link == selected.link)
|
{
|
m_subcontroller.removeStructureLink(plan, link);
|
reload();
|
return;
|
}
|
}
|
}
|
catch (Exception exception)
|
{
|
}
|
}
|
});
|
popupMenu.add(item);
|
|
|
this.addKeyListener(new KeyAdapter()
|
{
|
public void keyPressed(KeyEvent e)
|
{
|
if ((e.getKeyCode() == 8) || (e.getKeyCode() == 127))
|
{
|
if (editable == true)
|
{
|
try
|
{
|
ObjectoGraficoConector selected = (ObjectoGraficoConector)objetoGraficoSeleccionado;
|
|
for (ALUVISA_Link link : plan.lLink)
|
{
|
if (link == selected.link)
|
{
|
m_subcontroller.removeStructureLink(plan, link);
|
reload();
|
}
|
}
|
}
|
catch (Exception exception)
|
{
|
}
|
}
|
}
|
}
|
|
});
|
|
|
addMouseListener(new MouseAdapter()
|
{
|
public void mousePressed(MouseEvent e)
|
{
|
objetoGraficoSeleccionado = null;
|
|
|
for (ObjetoGrafico objetoGrafico : objetosGraficos)
|
{
|
mousePressed = e.getPoint();
|
objetoGrafico.mousePressed(mousePressed);
|
repaint();
|
}
|
|
// Popup Menu
|
|
if (SwingUtilities.isRightMouseButton(e))
|
{
|
if (editable == true)
|
{
|
if (objetoGraficoSeleccionado instanceof ObjectoGraficoConector)
|
{
|
popupMenu.show(DiagramPlan.this, e.getX(), e.getY());
|
}
|
}
|
}
|
|
|
if (diagramPhases != null)
|
{
|
if (objetoGraficoSeleccionado != null)
|
{
|
if (objetoGraficoSeleccionado instanceof ObjetoGraficoFase)
|
{
|
diagramPhases.selectPhase(((ObjetoGraficoFase)objetoGraficoSeleccionado).phase);
|
}
|
else if (objetoGraficoSeleccionado instanceof ObjectoGraficoConector)
|
{
|
if (diagramPhases != null) diagramPhases.selectPhase(((ObjectoGraficoConector)objetoGraficoSeleccionado).link.lTransition);
|
}
|
}
|
else
|
{
|
diagramPhases.selectPhase();
|
}
|
}
|
|
|
if (listener != null)
|
{
|
if (objetoGraficoSeleccionado != null)
|
{
|
if (objetoGraficoSeleccionado instanceof ObjetoGraficoFase)
|
{
|
listener.selected(((ObjetoGraficoFase)objetoGraficoSeleccionado).phase);
|
}
|
else if (objetoGraficoSeleccionado instanceof ObjectoGraficoConector)
|
{
|
listener.selected(((ObjectoGraficoConector)objetoGraficoSeleccionado).link);
|
}
|
}
|
else
|
{
|
listener.selected();
|
}
|
}
|
}
|
|
|
public void mouseReleased(MouseEvent e)
|
{
|
if (mouseDragged != null)
|
{
|
// Mirar nueva transicion
|
|
ALUVISA_Phase origen = null;
|
ALUVISA_Phase destino = null;
|
|
for (ObjetoGrafico objetoGrafico : objetosGraficos)
|
{
|
if ((objetoGrafico.mousePressed == true) && (objetoGrafico instanceof ObjetoGraficoFase)) origen = ((ObjetoGraficoFase)objetoGrafico).phase;
|
if (objetoGrafico.mouseDragged == true && (objetoGrafico instanceof ObjetoGraficoFase)) destino = ((ObjetoGraficoFase)objetoGrafico).phase;
|
objetoGrafico.deseleccionar();
|
}
|
|
if ((origen != null) && (destino != null))
|
{
|
ALUVISA_Link link = plan.getLink(origen, destino);
|
|
if (link == null)
|
{
|
if (origen != destino)
|
{
|
link = new ALUVISA_Link();
|
link.source = origen.number;
|
link.destination = destino.number;
|
m_subcontroller.addStructureLink(plan, link);
|
}
|
}
|
else
|
{
|
plan.lLink.remove(link);
|
}
|
}
|
|
objetoGraficoSeleccionado = null;
|
listener.selected();
|
reload();
|
}
|
mouseDragged = null;
|
repaint();
|
}
|
});
|
|
addMouseMotionListener(new MouseMotionAdapter()
|
{
|
public void mouseDragged(MouseEvent e)
|
{
|
if (editable == false) return;
|
|
for (ObjetoGrafico objetoGrafico : objetosGraficos)
|
{
|
mouseDragged = e.getPoint();
|
objetoGrafico.mouseDragged(mouseDragged);
|
repaint();
|
}
|
}
|
});
|
|
}
|
|
|
|
|
private ObjetoGraficoFase obtenerFaseGrafica(int number)
|
{
|
for (Object objeto : objetosGraficos)
|
{
|
if (objeto instanceof ObjetoGraficoFase)
|
{
|
ObjetoGraficoFase objetoGraficoFase = (ObjetoGraficoFase)objeto;
|
if (objetoGraficoFase.phase.number == number) return objetoGraficoFase;
|
}
|
}
|
|
return null;
|
}
|
|
|
public void reload(ALUVISA_Plan plan)
|
{
|
this.plan = plan;
|
reload();
|
}
|
|
|
public void reload()
|
{
|
objetosGraficos.clear();
|
objetoGraficoSeleccionado = null;
|
|
for (int i=0; i<plan.lPhase.size(); i++)
|
{
|
objetosGraficos.add(new ObjetoGraficoFase(plan.lPhase.get(i), i));
|
}
|
|
for (ALUVISA_Link link : plan.lLink)
|
{
|
ObjectoGraficoConector conectorGrafico = new ObjectoGraficoConector(link);
|
objetosGraficos.add(conectorGrafico);
|
}
|
|
if (listener != null) listener.selected();
|
repaint();
|
|
}
|
|
|
|
public void paint (Graphics g)
|
{
|
|
try
|
{
|
Graphics2D g2 = (Graphics2D)g;
|
int widht = getWidth();
|
int height = getHeight();
|
|
g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
|
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
|
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
g2.setBackground(FlatGUI.lookDesign.getColor("window.color.background.content"));
|
g2.clearRect(0, 0, widht, height);
|
|
double x1 = 999999;
|
double y1 = 999999;
|
double x2 = -999999;
|
double y2 = -999999;
|
double w = 0;
|
double h = 0;
|
|
|
for (ObjetoGrafico objetoGrafico : objetosGraficos)
|
{
|
if (objetoGrafico instanceof ObjetoGraficoFase)
|
{
|
ObjetoGraficoFase objetoGraficoFase = (ObjetoGraficoFase)objetoGrafico;
|
objetoGrafico.recalcular(objetoGraficoFase.order * 150, 0);
|
}
|
x1 = Math.min(x1, objetoGrafico.min().x);
|
y1 = Math.min(y1, objetoGrafico.min().y);
|
x2 = Math.max(x2, objetoGrafico.max().x);
|
y2 = Math.max(y2, objetoGrafico.max().y);
|
}
|
|
g2.setStroke(new BasicStroke(2.0f));
|
for (ObjetoGrafico objetoGrafico : objetosGraficos) objetoGrafico.paint(g2);
|
|
if ((mousePressed != null) && (mouseDragged != null))
|
{
|
ObjetoGrafico origen = null;
|
ObjetoGrafico destino = null;
|
|
for (ObjetoGrafico objetoGrafico : objetosGraficos)
|
{
|
g2.setColor(Color.blue);
|
|
if ((objetoGrafico.mousePressed == true) && (objetoGrafico instanceof ObjetoGraficoFase)) origen = objetoGrafico;
|
if (objetoGrafico.mouseDragged == true && (objetoGrafico instanceof ObjetoGraficoFase)) destino = objetoGrafico;
|
|
if (origen != null)
|
{
|
Point2D P1 = origen.centro();
|
g2.fill(new Ellipse2D.Double(P1.getX() - 5, P1.getY() - 5, 10, 10));
|
}
|
|
if (destino != null)
|
{
|
Point2D P1 = destino.centro();
|
g2.fill(new Ellipse2D.Double(P1.getX() - 5, P1.getY() - 5, 10, 10));
|
}
|
|
if ((origen != null) && (destino != null))
|
{
|
Point2D P1 = origen.centro();
|
Point2D P2 = destino.centro();
|
g2.setStroke(new BasicStroke(2.5f));
|
Line2D.Double linea = new Line2D.Double(P1.getX(), P1.getY(), P2.getX(), P2.getY());
|
g2.draw(linea);
|
}
|
}
|
}
|
|
g2.setColor(Color.black);
|
g2.setFont(new Font("Arial",0,13));
|
g2.drawString(Shared.getMessage("Structure") + " " + plan.structure, 15, 25);
|
|
if (plan.number == 0)
|
{
|
g2.drawString(Shared.getMessage("Custom plan"), 15, 50);
|
}
|
else
|
{
|
g2.drawString(Shared.getMessage("Plan") + " " + plan.number, 15, 50);
|
}
|
|
g2.drawString(Shared.getMessage("Cycle") + " " + plan.getCycleTime() + " (" + plan.getTransisionsTime() + "," + plan.getMinimumCycleTime() + ")", 15, 75);
|
g2.drawString(Shared.getMessage("Offset") + " " + plan.offset, 15, 100);
|
|
}
|
catch (Exception e)
|
{
|
}
|
|
}
|
|
|
|
|
|
|
|
private Stroke stroke1 = new BasicStroke(1.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL);
|
|
|
private class ObjetoGrafico
|
{
|
protected double tx = 0.0;
|
protected double ty = 0.0;
|
protected boolean mousePressed = false;
|
protected boolean mouseDragged = false;
|
protected Rectangle2D rectangle = new Rectangle2D.Double(0,0,0,0);
|
|
public void paint (Graphics2D g2)
|
{
|
}
|
|
|
|
public void recalcular (double tx, double ty)
|
{
|
this.tx = tx;
|
this.ty = ty;
|
}
|
|
|
|
public boolean mousePressed(Point P)
|
{
|
mousePressed = selected(P);
|
if (mousePressed == true) objetoGraficoSeleccionado = this;
|
return mousePressed;
|
}
|
|
public boolean mouseDragged(Point P)
|
{
|
mouseDragged = selected(P);
|
return mouseDragged;
|
}
|
|
public void deseleccionar()
|
{
|
mousePressed = false;
|
mouseDragged = false;
|
}
|
|
|
public boolean selected(Point P)
|
{
|
return getRectangle().contains(P);
|
}
|
|
|
public Point2D centro()
|
{
|
Rectangle2D rectangle = getRectangle();
|
return new Point2D.Double(rectangle.getCenterX(), rectangle.getCenterY());
|
}
|
|
public Point2D.Double min()
|
{
|
Rectangle2D rectangle = getRectangle();
|
return new Point2D.Double(rectangle.getMinX(), rectangle.getMinY());
|
}
|
|
public Point2D.Double max()
|
{
|
Rectangle2D rectangle = getRectangle();
|
return new Point2D.Double(rectangle.getMaxX(), rectangle.getMaxY());
|
}
|
|
|
public Point2D.Double dimension()
|
{
|
Rectangle2D rectangle = getRectangle();
|
return new Point2D.Double(rectangle.getWidth(), rectangle.getHeight());
|
}
|
|
|
|
protected Rectangle2D getRectangle()
|
{
|
return rectangle;
|
}
|
|
|
|
}
|
|
|
|
|
|
private class ObjetoGraficoFase extends ObjetoGrafico
|
{
|
public ALUVISA_Phase phase = null;
|
public int order = 0;
|
|
public ObjetoGraficoFase(ALUVISA_Phase phase, int order)
|
{
|
this.phase = phase;
|
this.order = order;
|
}
|
|
|
public void paint (Graphics2D g2)
|
{
|
rectangle = createRectangle();
|
|
double x1 = rectangle.getX();
|
double y1 = rectangle.getY();
|
double w = rectangle.getWidth();
|
double h = rectangle.getHeight();
|
double x2 = x1 + w;
|
double y2 = x1 + h;
|
|
g2.setColor(Color.lightGray);
|
g2.fill(rectangle);
|
|
if ((mousePressed == true) || (mouseDragged == true))
|
{
|
g2.setColor(Color.blue);
|
}
|
else
|
{
|
g2.setColor(Color.black);
|
}
|
|
g2.draw(rectangle);
|
g2.draw(new Line2D.Double(x1, y1 + 32, x2, y1 + 32));
|
|
|
g2.setFont(new Font("Arial",1,16));
|
FontMetrics metrics = g2.getFontMetrics();
|
String texto = Shared.getMessage("mnemonic-Fixed") + " " + phase.number;
|
if (phase.type == ALUVISA_Phase.TYPE_ACTUATED) texto = Shared.getMessage("mnemonic-Actuated") + phase.number;
|
|
int textWidth = metrics.stringWidth(texto);
|
int textHeight = metrics.getHeight() - metrics.getDescent();
|
g2.drawString(texto, (float)(x1 + (w - textWidth)/2), (float)(y1 + (textHeight + 32) / 2));
|
|
textWidth = metrics.stringWidth(texto);
|
textHeight = metrics.getHeight() - metrics.getDescent();
|
g2.setFont(new Font("Arial",0,12));
|
|
if (isStructure == false)
|
{
|
g2.drawString(Shared.getMessage("Phase time"), (float)x1 + 10, (float)(y1 + 36 + textHeight));
|
g2.drawString(Shared.getMessage("Minimum"), (float)x1 + 10, (float)(y1 + 41 + (textHeight * 2)));
|
g2.drawString(Shared.getMessage("Extension"), (float)x1 + 10, (float)(y1 + 46 + (textHeight * 3)));
|
g2.drawString("" + phase.maximumTime, (float)x1 + 75, (float)(y1 + 36 + textHeight));
|
g2.drawString("" + phase.minimumTime, (float)x1 + 75, (float)(y1 + 41 + (textHeight * 2)));
|
g2.drawString("" + phase.extensionTime, (float)x1 + 75, (float)(y1 + 46 + (textHeight * 3)));
|
}
|
|
|
|
if ((mousePressed == true) || (mouseDragged == true))
|
{
|
g2.setColor(Color.blue);
|
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));
|
g2.fill(rectangle);
|
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
|
}
|
}
|
|
|
|
protected Rectangle2D createRectangle()
|
{
|
double wmaximo = (getWidth() / plan.lPhase.size());
|
double hfase = 125;
|
double wfase = Math.min(wmaximo / 2, hfase);
|
//double wfase = 110;
|
double x = (order * wmaximo) + ((wmaximo - wfase)/2);
|
double y = ((getHeight() - hfase) / 2);
|
//y = y + (fase.numero - 1) * hfase;
|
return new Rectangle2D.Double(x, y,wfase, hfase);
|
}
|
}
|
|
|
|
|
|
private class ObjectoGraficoConector extends ObjetoGrafico
|
{
|
private ALUVISA_Link link;
|
private ObjetoGraficoFase faseGraficaOrigen;
|
private ObjetoGraficoFase faseGraficaDestino;
|
private int TX = 25;
|
private Color color = Color.black;
|
private float thickness = 1.5f;
|
private Stroke stroke2 = new BasicStroke(thickness, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);
|
private Stroke stroke3 = new BasicStroke(thickness, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL);
|
int distanciaVerticalEntreLineas = 35;
|
|
|
|
public ObjectoGraficoConector(ALUVISA_Link link)
|
{
|
this.link = link;
|
this.faseGraficaOrigen = obtenerFaseGrafica(link.source);
|
this.faseGraficaDestino = obtenerFaseGrafica(link.destination);
|
}
|
|
|
|
|
public void paint (Graphics2D g2)
|
{
|
Point2D centroSalida = faseGraficaOrigen.centro();
|
Point2D centroLlegada = faseGraficaDestino.centro();
|
Point2D dimensionSalida = faseGraficaOrigen.dimension();
|
Point2D dimensionLlegada = faseGraficaDestino.dimension();
|
|
g2.setColor(color);
|
|
if (mousePressed == true)
|
{
|
g2.setColor(Color.BLUE);
|
}
|
|
if (link.lTransition.size() == 0)
|
{
|
g2.setColor(Color.RED);
|
}
|
|
g2.setStroke(stroke1);
|
|
int distanciaEntreFases = Math.abs(faseGraficaOrigen.order - faseGraficaDestino.order);
|
|
if (distanciaEntreFases == 1)
|
{
|
if (centroLlegada.getX() > centroSalida.getX())
|
{
|
double x1 = centroSalida.getX() + dimensionSalida.getX()/2;
|
double y1 = centroSalida.getY();
|
double x2 = centroLlegada.getX() - dimensionLlegada.getX()/2;
|
double y2 = centroLlegada.getY();
|
|
y1 = y1 - (distanciaVerticalEntreLineas/2);
|
y2 = y2 - (distanciaVerticalEntreLineas/2);
|
rectangle = new Rectangle2D.Double(x1, y1 - 8, Math.abs(x2 - x1), y2 - y1 + 16);
|
|
|
Line2D.Double linea = new Line2D.Double(x1,y1,x2-2.5,y2);
|
GeneralPath triangulo = new GeneralPath();
|
triangulo.moveTo(x2-10, y2-5);
|
triangulo.lineTo(x2, y2);
|
triangulo.lineTo(x2-10, y2+5);
|
triangulo.closePath();
|
|
g2.setStroke(stroke2);
|
g2.draw(linea);
|
g2.setStroke(stroke1);
|
g2.fill(triangulo);
|
|
g2.setFont(new Font("Arial",Font.BOLD|Font.ITALIC,12));
|
g2.setColor(Color.GRAY);
|
textoIzquierdaDerecha(g2, getLinkText1(), rectangle.getMinX(), rectangle.getCenterY());
|
g2.setFont(new Font("Arial",Font.BOLD,12));
|
g2.setColor(color);
|
textoIzquierdaDerecha(g2, getLinkText2(), rectangle.getMinX() + 25, rectangle.getCenterY());
|
}
|
else
|
{
|
double x1 = centroSalida.getX() - dimensionSalida.getX()/2;
|
double y1 = centroSalida.getY();
|
double x2 = centroLlegada.getX() + dimensionLlegada.getX()/2;
|
double y2 = centroLlegada.getY();
|
|
y1 = y1 + (distanciaVerticalEntreLineas/2);
|
y2 = y2 + (distanciaVerticalEntreLineas/2);
|
rectangle = new Rectangle2D.Double(x2, y1 - 8, Math.abs(x2 - x1), y2 - y1 + 16);
|
|
Line2D.Double linea = new Line2D.Double(x1,y1,x2+2.5,y2);
|
GeneralPath triangulo = new GeneralPath();
|
triangulo.moveTo(x2+10, y2+5);
|
triangulo.lineTo(x2, y2);
|
triangulo.lineTo(x2+10, y2-5);
|
triangulo.closePath();
|
|
g2.setStroke(stroke2);
|
g2.draw(linea);
|
g2.setStroke(stroke1);
|
g2.fill(triangulo);
|
|
g2.setFont(new Font("Arial",Font.BOLD|Font.ITALIC,12));
|
g2.setColor(Color.GRAY);
|
textoDerechaIzquierda(g2, getLinkText1(), rectangle.getMaxX(), rectangle.getCenterY());
|
g2.setFont(new Font("Arial",Font.BOLD,12));
|
g2.setColor(color);
|
textoDerechaIzquierda(g2, getLinkText2(), rectangle.getMaxX() - 25, rectangle.getCenterY());
|
|
}
|
}
|
else
|
{
|
double altura = distanciaVerticalEntreLineas;
|
|
if (centroLlegada.getX() > centroSalida.getX())
|
{
|
double x1 = centroSalida.getX();
|
double y1 = centroSalida.getY() - dimensionSalida.getY()/2 - altura;
|
double x2 = centroLlegada.getX();
|
double y2 = centroLlegada.getY() - dimensionLlegada.getY()/2 - altura;
|
rectangle = new Rectangle2D.Double(x1, y1 - 8, Math.abs(x2 - x1), y2 - y1 + 16);
|
corregirAltura(-distanciaVerticalEntreLineas);
|
y1 = rectangle.getCenterY();
|
y2 = rectangle.getCenterY();
|
|
double minySalida = faseGraficaOrigen.min().getY();
|
double minyLlegada = faseGraficaDestino.min().getY();
|
|
Line2D.Double linea1 = new Line2D.Double(x1,y1,x2,y2);
|
Line2D.Double linea2 = new Line2D.Double(x1,y1,x1,minySalida);
|
Line2D.Double linea3 = new Line2D.Double(x2,minyLlegada-2.5,x2,y2);
|
GeneralPath triangulo = new GeneralPath();
|
triangulo.moveTo(x2,minyLlegada);
|
triangulo.lineTo(x2+5,minyLlegada-10);
|
triangulo.lineTo(x2-5,minyLlegada-10);
|
triangulo.closePath();
|
|
g2.setStroke(stroke3);
|
g2.draw(linea1);
|
g2.setStroke(stroke2);
|
g2.draw(linea2);
|
g2.draw(linea3);
|
g2.setStroke(stroke1);
|
g2.fill(triangulo);
|
|
g2.setFont(new Font("Arial",Font.BOLD|Font.ITALIC,12));
|
g2.setColor(Color.GRAY);
|
textoIzquierdaDerecha(g2, getLinkText1(), rectangle.getMinX(), rectangle.getCenterY());
|
g2.setFont(new Font("Arial",Font.BOLD,12));
|
g2.setColor(color);
|
textoIzquierdaDerecha(g2, getLinkText2(), rectangle.getMinX() + 25, rectangle.getCenterY());
|
}
|
else
|
{
|
// X X
|
// ^ |
|
// |______|
|
|
double x1 = centroSalida.getX();
|
double y1 = centroSalida.getY() + dimensionSalida.getY()/2 + altura;
|
double x2 = centroLlegada.getX();
|
double y2 = centroLlegada.getY() + dimensionLlegada.getY()/2 + altura;
|
rectangle = new Rectangle2D.Double(x2, y1 - 8, x1 - x2, y2 - y1 + 16);
|
corregirAltura(distanciaVerticalEntreLineas);
|
y1 = rectangle.getCenterY();
|
y2 = rectangle.getCenterY();
|
|
double maxySalida = faseGraficaOrigen.max().getY();
|
double maxyLlegada = faseGraficaDestino.max().getY();
|
|
Line2D.Double linea1 = new Line2D.Double(x1,y1,x2,y2);
|
Line2D.Double linea2 = new Line2D.Double(x1,y1,x1,maxySalida);
|
Line2D.Double linea3 = new Line2D.Double(x2,maxyLlegada+2.5,x2,y2);
|
GeneralPath triangulo = new GeneralPath();
|
triangulo.moveTo(x2,maxyLlegada);
|
triangulo.lineTo(x2+5,maxyLlegada+10);
|
triangulo.lineTo(x2-5,maxyLlegada+10);
|
triangulo.closePath();
|
|
g2.setStroke(stroke3);
|
g2.draw(linea1);
|
g2.setStroke(stroke2);
|
g2.draw(linea2);
|
g2.draw(linea3);
|
g2.fill(triangulo);
|
|
g2.setFont(new Font("Arial",Font.BOLD|Font.ITALIC,12));
|
g2.setColor(Color.GRAY);
|
textoDerechaIzquierda(g2, getLinkText1(), rectangle.getMaxX(), rectangle.getCenterY());
|
g2.setFont(new Font("Arial",Font.BOLD,12));
|
g2.setColor(color);
|
textoDerechaIzquierda(g2, getLinkText2(), rectangle.getMaxX() - 25, rectangle.getCenterY());
|
}
|
|
}
|
|
}
|
|
|
|
private void corregirAltura(double dy)
|
{
|
for (ObjetoGrafico objeto : objetosGraficos)
|
{
|
if (objeto instanceof ObjectoGraficoConector)
|
{
|
ObjectoGraficoConector conector = (ObjectoGraficoConector)objeto;
|
|
if (conector == this)
|
{
|
return;
|
}
|
else
|
{
|
Rectangle2D r2 = objeto.getRectangle();
|
|
if (rectangle.intersects(r2) == true)
|
{
|
rectangle.setFrame(rectangle.getX(), rectangle.getY() + dy, rectangle.getWidth(), rectangle.getHeight());
|
}
|
}
|
|
}
|
}
|
}
|
|
|
|
private void textoDerechaIzquierda(Graphics2D g2, String texto, double x, double y)
|
{
|
FontMetrics metrics = g2.getFontMetrics();
|
int textWidth = metrics.stringWidth(texto);
|
int textHeight = metrics.getHeight() - metrics.getDescent();
|
g2.drawString(texto, (float)x - textWidth - 10, (float)y - textHeight);
|
}
|
|
|
|
private void textoIzquierdaDerecha(Graphics2D g2, String texto, double x, double y)
|
{
|
FontMetrics metrics = g2.getFontMetrics();
|
int textHeight = metrics.getHeight() - metrics.getDescent();
|
g2.drawString(texto, (float)x + 10, (float)y - textHeight);
|
}
|
|
|
private String getLinkText1()
|
{
|
return "" + plan.getLinkPosition(link);
|
}
|
|
|
private String getLinkText2()
|
{
|
String result = "";
|
|
for (int i=0; i<link.lTransition.size(); i++)
|
{
|
if (i == 0)
|
{
|
result = result + link.lTransition.get(i).number;
|
}
|
else
|
{
|
result = result + ", " + link.lTransition.get(i).number;
|
}
|
}
|
|
return result;
|
}
|
|
}
|
|
|
|
|
}
|