package art.servers.colorsserver.M.gui.diagrams;
|
|
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_Phase;
|
import art.library.model.devices.colors.controller.M.configuration.ALUVISA_Plan;
|
import art.library.gui.FlatGUI;
|
import art.library.gui.flat.FlatButton;
|
import art.library.gui.flat.FlatLabel;
|
import art.library.gui.flat.FlatPanel;
|
import art.library.gui.flat.FlatTextField;
|
import art.library.gui.flat.combobox.FlatComboBox;
|
import art.servers.Shared;
|
import java.awt.AlphaComposite;
|
import java.awt.BasicStroke;
|
import java.awt.BorderLayout;
|
import java.awt.Color;
|
import java.awt.Component;
|
import java.awt.Dimension;
|
import java.awt.Font;
|
import java.awt.FontMetrics;
|
import java.awt.Graphics;
|
import java.awt.Graphics2D;
|
import java.awt.GridLayout;
|
import java.awt.RenderingHints;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import java.awt.event.ComponentAdapter;
|
import java.awt.event.ComponentEvent;
|
import java.awt.event.TextEvent;
|
import java.awt.event.TextListener;
|
import java.awt.geom.Line2D;
|
import java.awt.geom.Rectangle2D;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
|
|
public class DiagramALUVISAPhases extends FlatPanel
|
{
|
private boolean colorEditable = false;
|
private M_ControllerConfiguration m_controllerConfiguration = null;
|
private M_SubcontrollerConfiguration m_subcontrollerConfiguration = null;
|
private ALUVISA_Plan plan = null;
|
private List<ALUVISA_Phase> lphase = null;
|
private List<ALUVISA_Phase> lselected = new ArrayList<ALUVISA_Phase>();
|
private DiagramColumns diagramColumns = null;
|
private DiagramRows diagramRows = null;
|
private Diagram diagram = null;
|
private Color color = new FlatPanel().getLook().background;
|
private int selectedColor = 0;
|
private double totalTime = 0;
|
private double ty = 0;
|
private ActionListener listener = null;
|
private FlatPanel firstDiagramColumn = null;
|
private List<FlatPanel> ldiagramColumns = new ArrayList<FlatPanel>();
|
private int realtimeCurrentPhase = -1;
|
private int realtimeCurrentTime = -1;
|
|
|
public DiagramALUVISAPhases(M_ControllerConfiguration m_controllerConfiguration, M_SubcontrollerConfiguration m_subcontrollerConfiguration, ALUVISA_Plan plan, ALUVISA_Phase phase)
|
{
|
List<ALUVISA_Phase> lphase = new ArrayList<ALUVISA_Phase>();
|
lphase.add(phase);
|
initialise(m_controllerConfiguration, m_subcontrollerConfiguration, plan, lphase);
|
}
|
|
public DiagramALUVISAPhases(M_ControllerConfiguration m_controllerConfiguration, M_SubcontrollerConfiguration m_subcontrollerConfiguration, ALUVISA_Phase phase)
|
{
|
List<ALUVISA_Phase> lphase = new ArrayList<ALUVISA_Phase>();
|
lphase.add(phase);
|
initialise(m_controllerConfiguration, m_subcontrollerConfiguration, null, lphase);
|
}
|
|
|
public DiagramALUVISAPhases(M_ControllerConfiguration m_controllerConfiguration, M_SubcontrollerConfiguration m_subcontrollerConfiguration, ALUVISA_Plan plan, List<ALUVISA_Phase> lphase)
|
{
|
initialise(m_controllerConfiguration, m_subcontrollerConfiguration, plan, lphase);
|
}
|
|
public DiagramALUVISAPhases(M_ControllerConfiguration m_controllerConfiguration, M_SubcontrollerConfiguration m_subcontrollerConfiguration, List<ALUVISA_Phase> lphase)
|
{
|
initialise(m_controllerConfiguration, m_subcontrollerConfiguration, null, lphase);
|
}
|
|
|
|
private void initialise(M_ControllerConfiguration m_controllerConfiguration, M_SubcontrollerConfiguration m_subcontrollerConfiguration, ALUVISA_Plan plan, List<ALUVISA_Phase> lphase)
|
{
|
this.plan = plan;
|
this.m_controllerConfiguration = m_controllerConfiguration;
|
this.m_subcontrollerConfiguration = m_subcontrollerConfiguration;
|
this.lphase = lphase;
|
this.setLayout(new BorderLayout());
|
this.add(diagramColumns = new DiagramColumns(), BorderLayout.NORTH);
|
this.add(diagramRows = new DiagramRows(), BorderLayout.WEST);
|
this.add(diagram = new Diagram(), BorderLayout.CENTER);
|
setConfiguration(m_controllerConfiguration, m_subcontrollerConfiguration, lphase);
|
|
this.addComponentListener(new ComponentAdapter()
|
{
|
public void componentResized(ComponentEvent e)
|
{
|
redimensionar();
|
}
|
});
|
}
|
|
|
public void timer(int phase, int time)
|
{
|
this.realtimeCurrentPhase = phase;
|
this.realtimeCurrentTime = time;
|
}
|
|
|
|
|
|
private void redimensionar()
|
{
|
totalTime = 0;
|
for (ALUVISA_Phase phase : lphase) totalTime = totalTime + phase.maximumTime;
|
if (totalTime <= 0) totalTime = 1;
|
((DiagramColumns1)DiagramALUVISAPhases.this.ldiagramColumns.get(0)).redimensionar();
|
((DiagramColumns2)DiagramALUVISAPhases.this.ldiagramColumns.get(1)).redimensionar();
|
DiagramALUVISAPhases.this.revalidate();
|
DiagramALUVISAPhases.this.repaint();
|
}
|
|
|
|
public void setConfiguration(M_ControllerConfiguration m_controllerConfiguration, M_SubcontrollerConfiguration m_subcontrollerConfiguration, ALUVISA_Phase phase)
|
{
|
List<ALUVISA_Phase> lphase = new ArrayList<ALUVISA_Phase>();
|
lphase.add(phase);
|
setConfiguration(m_controllerConfiguration, m_subcontrollerConfiguration, lphase);
|
}
|
|
|
public void setConfiguration(M_ControllerConfiguration m_controllerConfiguration, M_SubcontrollerConfiguration m_subcontrollerConfiguration, List<ALUVISA_Phase> lphase)
|
{
|
this.m_controllerConfiguration = m_controllerConfiguration;
|
this.m_subcontrollerConfiguration = m_subcontrollerConfiguration;
|
this.lphase = lphase;
|
diagramColumns.reload();
|
}
|
|
|
public void selectPhase()
|
{
|
lselected.clear();
|
repaint();
|
}
|
|
|
public void selectPhase(List<ALUVISA_Phase> lphase)
|
{
|
lselected.clear();
|
lselected.addAll(lphase);
|
repaint();
|
}
|
|
|
public void selectPhase(ALUVISA_Phase phase)
|
{
|
lselected.clear();
|
lselected.add(phase);
|
repaint();
|
}
|
|
|
|
public void reload()
|
{
|
diagramColumns.reload();
|
revalidate();
|
repaint();
|
}
|
|
|
|
public void setActionListener (ActionListener listener)
|
{
|
this.listener = listener;
|
}
|
|
|
public void setSelectedColor(int color)
|
{
|
this.selectedColor = color;
|
}
|
|
|
public void showFields(boolean lvalue[])
|
{
|
diagramColumns.showFields(lvalue);
|
}
|
|
|
public void editable(boolean[] lvalue)
|
{
|
diagramColumns.editable(lvalue);
|
repaint();
|
}
|
|
public void editable(boolean value)
|
{
|
diagramColumns.editable(value);
|
repaint();
|
}
|
|
|
public void colorEditable(boolean value)
|
{
|
this.colorEditable = value;
|
repaint();
|
}
|
|
|
|
|
private class DiagramColumns extends FlatPanel
|
{
|
|
public DiagramColumns()
|
{
|
ldiagramColumns.add(new DiagramColumns1());
|
ldiagramColumns.add(new DiagramColumns2());
|
ldiagramColumns.add(new DiagramColumns3());
|
ldiagramColumns.add(new DiagramColumns4());
|
ldiagramColumns.add(new DiagramColumns5());
|
initialise();
|
}
|
|
|
private void initialise()
|
{
|
this.removeAll();
|
int total = getVisibles();
|
this.setLayout(new GridLayout(total,1));
|
this.setPreferredSize(new Dimension(0, 22 * total));
|
for (FlatPanel panel : ldiagramColumns)
|
{
|
if (panel.isVisible() == true)
|
{
|
this.add(panel);
|
}
|
}
|
}
|
|
public void editable(boolean value)
|
{
|
((DiagramColumns1)ldiagramColumns.get(0)).editable(value);
|
((DiagramColumns2)ldiagramColumns.get(1)).editable(value);
|
}
|
|
public void editable(boolean[] lvalue)
|
{
|
((DiagramColumns1)ldiagramColumns.get(0)).editable(lvalue[0]);
|
((DiagramColumns2)ldiagramColumns.get(1)).editable(lvalue[1]);
|
}
|
|
|
private int getVisibles()
|
{
|
int result = 0;
|
|
for (FlatPanel panel : ldiagramColumns)
|
{
|
if (panel.isVisible() == true) result = result + 1;
|
}
|
|
return result;
|
}
|
|
|
|
public void showFields (boolean[] lvalue)
|
{
|
firstDiagramColumn = null;
|
for (int i=0; i<lvalue.length; i++)
|
{
|
if ((firstDiagramColumn == null) && (lvalue[i] == true)) firstDiagramColumn = ldiagramColumns.get(i);
|
ldiagramColumns.get(i).setVisible(lvalue[i]);
|
}
|
initialise();
|
reload();
|
}
|
|
|
|
public void set (boolean[] lvalue)
|
{
|
initialise();
|
reload();
|
}
|
|
|
public void reload()
|
{
|
totalTime = 0;
|
for (ALUVISA_Phase phase : lphase) totalTime = totalTime + phase.maximumTime;
|
if (totalTime <= 0) totalTime = 1;
|
((DiagramColumns1)ldiagramColumns.get(0)).reload();
|
((DiagramColumns2)ldiagramColumns.get(1)).reload();
|
revalidate();
|
repaint();
|
}
|
|
}
|
|
|
private class DiagramColumns1 extends FlatPanel
|
{
|
public boolean editable = false;
|
private List<Component> lcombobox = new ArrayList<Component>();
|
|
public DiagramColumns1()
|
{
|
setLayout(null);
|
}
|
|
public void reload()
|
{
|
editable(editable);
|
}
|
|
|
public void editable(boolean value)
|
{
|
this.editable = value;
|
|
for (Component component : lcombobox)
|
{
|
this.remove(component);
|
}
|
|
lcombobox.clear();
|
|
String[] intergreens = m_subcontrollerConfiguration.getIntergreensNumbers();
|
String[] phases = m_subcontrollerConfiguration.getPhasesStablesNumbers();
|
|
if (value == true)
|
{
|
for (ALUVISA_Phase phase : lphase)
|
{
|
FlatComboBox combobox = new FlatComboBox();
|
combobox.getLook().border = false;
|
combobox.getLook().borderColor = FlatGUI.lookDesign.getColor("label.color.background").darker();
|
combobox.revalidate();
|
if(phase.type == ALUVISA_Phase.TYPE_TRANSITION) combobox.addItems(intergreens);
|
if(phase.type == ALUVISA_Phase.TYPE_FIXED) combobox.addItems(phases);
|
if(phase.type == ALUVISA_Phase.TYPE_ACTUATED) combobox.addItems(phases);
|
combobox.setSelectedItem("" + phase.number);
|
combobox.addActionListener(new ActionListener()
|
{
|
public void actionPerformed(ActionEvent e)
|
{
|
for (int i=0; i<lphase.size(); i++)
|
{
|
if (lphase.get(i).type == ALUVISA_Phase.TYPE_TRANSITION)
|
{
|
// No puede ser un plan
|
|
lphase.get(i).updateIntergreenNumber(m_subcontrollerConfiguration, getInteger((String)((FlatComboBox)lcombobox.get(i)).getSelectedItem()));
|
}
|
|
if (lphase.get(i).type == ALUVISA_Phase.TYPE_FIXED)
|
{
|
// No puede ser una estructura
|
|
lphase.get(i).updatePhaseStableNumber(m_subcontrollerConfiguration, getInteger((String)((FlatComboBox)lcombobox.get(i)).getSelectedItem()));
|
}
|
}
|
|
if (plan != null) m_subcontrollerConfiguration.updateStructureLink(plan, lphase);
|
|
DiagramALUVISAPhases.this.redimensionar();
|
if (listener != null) listener.actionPerformed(null);
|
}
|
});
|
lcombobox.add(combobox);
|
this.add(combobox);
|
}
|
|
DiagramALUVISAPhases.this.redimensionar();
|
}
|
}
|
|
|
|
public void redimensionar()
|
{
|
try
|
{
|
if (totalTime <= 0) totalTime = 1;
|
int w = getWidth();
|
int h = getHeight();
|
double dx = (w-150) / totalTime;
|
int time = 0;
|
|
for (int i=0; i<lphase.size(); i++)
|
{
|
int maximumtime = lphase.get(i).maximumTime;
|
lcombobox.get(i).setBounds((int)((dx * time) + 150)+1, 1, (int)((dx * maximumtime))-1, (int)h-1);
|
time = time + maximumtime;
|
}
|
}
|
catch (Exception exception)
|
{
|
}
|
}
|
|
|
|
public void paint (Graphics g)
|
{
|
try
|
{
|
if (totalTime <= 0) totalTime = 1;
|
Graphics2D g2 = (Graphics2D)g;
|
format(g2);
|
int w = getWidth();
|
int h = getHeight();
|
double dx = (w-150) / totalTime;
|
|
|
if (editable == true)
|
{
|
super.paint(g);
|
Font font = FlatGUI.lookDesign.getFont("label.font");
|
g2.setColor(FlatGUI.lookDesign.getColor("label.color.foreground"));
|
drawCenteredString(g2, getPhaseName(), 5, new Rectangle2D.Double(0,0,150,22), font);
|
paintLines(g2, w, h, firstDiagramColumn != this);
|
return;
|
}
|
|
|
Font font = FlatGUI.lookDesign.getFont("label.font");
|
g2.setColor(FlatGUI.lookDesign.getColor("label.color.foreground"));
|
drawCenteredString(g2, getPhaseName(), 5, new Rectangle2D.Double(0,0,150,22), font);
|
|
int time = 0;
|
|
for (int i=0; i<lphase.size(); i++)
|
{
|
g2.setColor(FlatGUI.lookDesign.getColor("label.color.foreground"));
|
int maximumtime = lphase.get(i).maximumTime;
|
|
if (lphase.get(i).type == ALUVISA_Phase.TYPE_FIXED)
|
{
|
drawCenteredString(g2, Shared.getMessage("mnemonic-Fixed") + lphase.get(i).number, new Rectangle2D.Double((dx * time) + 150, 0, (dx * maximumtime), h), font.deriveFont(Font.BOLD));
|
}
|
else if (lphase.get(i).type == ALUVISA_Phase.TYPE_ACTUATED)
|
{
|
drawCenteredString(g2, Shared.getMessage("mnemonic-Actuated") + lphase.get(i).number, new Rectangle2D.Double((dx * time) + 150, 0, (dx * maximumtime), h), font.deriveFont(Font.BOLD));
|
}
|
else if (lphase.get(i).type == ALUVISA_Phase.TYPE_TRANSITION)
|
{
|
drawCenteredString(g2, Shared.getMessage("mnemonic-Intergreen") + lphase.get(i).number, new Rectangle2D.Double((dx * time) + 150, 0, (dx * maximumtime), h), font.deriveFont(Font.BOLD).deriveFont(font.getSize()-2.0f));
|
}
|
else if (lphase.get(i).type == ALUVISA_Phase.TYPE_START)
|
{
|
drawCenteredString(g2, Shared.getMessage("mnemonic-Semiactuated") + lphase.get(i).number, new Rectangle2D.Double((dx * time) + 150, 0, (dx * maximumtime), h), font);
|
}
|
|
drawCenteredString(g2, "" + lphase.get(i).maximumTime, new Rectangle2D.Double((dx * time) + 150, 22, (dx * maximumtime), h), font);
|
|
time = time + maximumtime;
|
}
|
|
|
paintLines(g2, w, h, firstDiagramColumn != this);
|
|
}
|
catch (Exception e)
|
{
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
private class DiagramColumns2 extends FlatPanel
|
{
|
public boolean editable = false;
|
private List<Component> ltextfield = new ArrayList<Component>();
|
|
public DiagramColumns2()
|
{
|
setLayout(null);
|
}
|
|
public void reload()
|
{
|
editable(editable);
|
}
|
|
public void editable(boolean value)
|
{
|
this.editable = value;
|
|
for (Component component : ltextfield)
|
{
|
this.remove(component);
|
}
|
|
ltextfield.clear();
|
|
String[] intergreens = m_subcontrollerConfiguration.getIntergreensNumbers();
|
String[] phases = m_subcontrollerConfiguration.getPhasesStablesNumbers();
|
|
if (value == true)
|
{
|
for (ALUVISA_Phase phase : lphase)
|
{
|
FlatTextField textfield = new FlatTextField();
|
textfield.setNumeric(true, 1, 120);
|
textfield.getLook().border = false;
|
textfield.getLook().colorBorder = FlatGUI.lookDesign.getColor("label.color.background").darker();
|
textfield.revalidate();
|
textfield.setText("" + phase.maximumTime);
|
textfield.setField(phase, "maximumTime");
|
textfield.setTextListener(new TextListener()
|
{
|
public void textValueChanged(TextEvent e)
|
{
|
try
|
{
|
totalTime = 0;
|
|
for (ALUVISA_Phase phase : lphase)
|
{
|
totalTime = totalTime + phase.maximumTime;
|
}
|
|
if (totalTime <= 0) totalTime = 1;
|
}
|
catch (Exception exception)
|
{
|
}
|
|
DiagramALUVISAPhases.this.redimensionar();
|
}
|
});
|
ltextfield.add(textfield);
|
this.add(textfield);
|
}
|
|
DiagramALUVISAPhases.this.redimensionar();
|
}
|
}
|
|
|
|
public void redimensionar()
|
{
|
try
|
{
|
if (totalTime <= 0) totalTime = 1;
|
int w = getWidth();
|
int h = getHeight();
|
double dx = (w-150) / totalTime;
|
int time = 0;
|
|
for (int i=0; i<lphase.size(); i++)
|
{
|
int maximumtime = lphase.get(i).maximumTime;
|
ltextfield.get(i).setBounds((int)((dx * time) + 150)+1, 1, (int)((dx * maximumtime))-1, (int)h-1);
|
time = time + maximumtime;
|
}
|
}
|
catch (Exception exception)
|
{
|
}
|
}
|
|
|
|
public void paint (Graphics g)
|
{
|
try
|
{
|
if (totalTime <= 0) totalTime = 1;
|
Graphics2D g2 = (Graphics2D)g;
|
format(g2);
|
int w = getWidth();
|
int h = getHeight();
|
g2.setBackground(color);
|
g2.clearRect(0, 0, w, h);
|
double dx = (w-150) / totalTime;
|
|
|
if (editable == true)
|
{
|
super.paint(g);
|
Font font = FlatGUI.lookDesign.getFont("label.font");
|
g2.setColor(FlatGUI.lookDesign.getColor("label.color.foreground"));
|
drawCenteredString(g2, Shared.getMessage("Duration"), 5, new Rectangle2D.Double(0,0,150,h), font);
|
paintLines(g2, w, h, firstDiagramColumn != this);
|
return;
|
}
|
|
|
|
Font font = FlatGUI.lookDesign.getFont("label.font");
|
g2.setColor(FlatGUI.lookDesign.getColor("label.color.foreground"));
|
drawCenteredString(g2, Shared.getMessage("Duration"), 5, new Rectangle2D.Double(0,0,150,h), font);
|
|
int time = 0;
|
|
for (int i=0; i<lphase.size(); i++)
|
{
|
g2.setColor(FlatGUI.lookDesign.getColor("label.color.foreground"));
|
int maximumtime = lphase.get(i).maximumTime;
|
drawCenteredString(g2, "" + lphase.get(i).maximumTime, new Rectangle2D.Double((dx * time) + 150, 0, (dx * maximumtime), h), font);
|
time = time + maximumtime;
|
}
|
|
paintLines(g2, w, h, firstDiagramColumn != this);
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
|
}
|
|
|
|
|
private class DiagramColumns3 extends FlatPanel
|
{
|
public void paint (Graphics g)
|
{
|
try
|
{
|
if (totalTime <= 0) totalTime = 1;
|
Graphics2D g2 = (Graphics2D)g;
|
format(g2);
|
int w = getWidth();
|
int h = getHeight();
|
g2.setBackground(color);
|
g2.clearRect(0, 0, w, h);
|
double dx = (w-150) / totalTime;
|
|
Font font = FlatGUI.lookDesign.getFont("label.font");
|
g2.setColor(FlatGUI.lookDesign.getColor("label.color.foreground"));
|
drawCenteredString(g2, Shared.getMessage("Minimum"), 5, new Rectangle2D.Double(0,0,150,h), font);
|
|
int time = 0;
|
|
for (int i=0; i<lphase.size(); i++)
|
{
|
g2.setColor(FlatGUI.lookDesign.getColor("label.color.foreground"));
|
int maximumtime = lphase.get(i).maximumTime;
|
if ((lphase.get(i).type == ALUVISA_Phase.TYPE_FIXED) || (lphase.get(i).type == ALUVISA_Phase.TYPE_ACTUATED))
|
{
|
drawCenteredString(g2, "" + lphase.get(i).minimumTime, new Rectangle2D.Double((dx * time) + 150, 0, (dx * maximumtime), h), font);
|
}
|
time = time + maximumtime;
|
}
|
|
paintLines(g2, w, h, firstDiagramColumn != this);
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
|
}
|
|
|
|
|
private class DiagramColumns4 extends FlatPanel
|
{
|
public void paint (Graphics g)
|
{
|
try
|
{
|
if (totalTime <= 0) totalTime = 1;
|
Graphics2D g2 = (Graphics2D)g;
|
format(g2);
|
int w = getWidth();
|
int h = getHeight();
|
g2.setBackground(color);
|
g2.clearRect(0, 0, w, h);
|
double dx = (w-150) / totalTime;
|
|
Font font = FlatGUI.lookDesign.getFont("label.font");
|
g2.setColor(FlatGUI.lookDesign.getColor("label.color.foreground"));
|
drawCenteredString(g2, Shared.getMessage("Extension"), 5, new Rectangle2D.Double(0,0,150,h), font);
|
|
int time = 0;
|
|
for (int i=0; i<lphase.size(); i++)
|
{
|
g2.setColor(FlatGUI.lookDesign.getColor("label.color.foreground"));
|
int maximumtime = lphase.get(i).maximumTime;
|
if ((lphase.get(i).type == ALUVISA_Phase.TYPE_FIXED) || (lphase.get(i).type == ALUVISA_Phase.TYPE_ACTUATED))
|
{
|
drawCenteredString(g2, "" + lphase.get(i).extensionTime, new Rectangle2D.Double((dx * time) + 150, 0, (dx * maximumtime), h), font);
|
}
|
time = time + maximumtime;
|
}
|
|
paintLines(g2, w, h, firstDiagramColumn != this);
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
|
}
|
|
|
|
|
|
private class DiagramColumns5 extends FlatPanel
|
{
|
public void paint (Graphics g)
|
{
|
try
|
{
|
if (totalTime <= 0) totalTime = 1;
|
Graphics2D g2 = (Graphics2D)g;
|
format(g2);
|
int w = getWidth();
|
int h = getHeight();
|
g2.setBackground(color);
|
g2.clearRect(0, 0, w, h);
|
double dx = (w-150) / totalTime;
|
|
g2.setFont(FlatGUI.lookDesign.getFont("label.font"));
|
g2.setColor(FlatGUI.lookDesign.getColor("label.color.foreground"));
|
drawCenteredString(g2, Shared.getMessage("Timeline"), 5, new Rectangle2D.Double(0,0,150,h), FlatGUI.lookDesign.getFont("label.font"));
|
|
|
|
int escala = 0;
|
|
for (int i=0; i<10; i++)
|
{
|
int width = g2.getFontMetrics().stringWidth("999");
|
if (width < (dx + (dx * i * 5)))
|
{
|
escala = i * 5;
|
break;
|
}
|
}
|
|
escala = Math.max(escala,1);
|
|
|
for (int i=0; i<totalTime; i=i+1)
|
{
|
g2.setColor(FlatGUI.lookDesign.getColor("label.color.background").darker());
|
g2.draw(new Line2D.Double((dx * i) + 150, 0, (dx * i) + 150, h));
|
}
|
|
|
paintLines(g2, w, h, firstDiagramColumn != this);
|
|
|
Font font = FlatGUI.lookDesign.getFont("label.font").deriveFont((float)(FlatGUI.lookDesign.getFont("label.font").getSize()-2.5f));
|
|
for (int i=0; i<totalTime; i=i+1)
|
{
|
g2.setColor(FlatGUI.lookDesign.getColor("label.color.foreground"));
|
|
if (((i+1) % escala) == 0)
|
{
|
drawCenteredString(g2, "" + (i+1), new Rectangle2D.Double((dx * i) + 150, 0, dx, h), font);
|
}
|
}
|
|
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
|
}
|
|
|
|
|
|
|
|
private class DiagramRows extends FlatPanel
|
{
|
private DiagramRows()
|
{
|
setPreferredSize(new Dimension(150,0));
|
}
|
|
|
public void paint (Graphics g)
|
{
|
try
|
{
|
Graphics2D g2 = (Graphics2D)g;
|
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
|
g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
|
|
int w = getWidth();
|
int h = getHeight();
|
g2.setBackground(color);
|
g2.clearRect(0, 0, w, h);
|
Font font = new FlatLabel().getLook().font;
|
g2.setColor(new FlatButton().getLook().colorForeground);
|
|
|
double dy = (double)h / (double)m_subcontrollerConfiguration.ltrafficGroup.size();
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
// Quitar si se quiere que ocupe toda la altura de pantalla
|
//
|
//dy = Math.min(dy, 36);
|
//h = (int)(dy * m_subcontrollerConfiguration.lTrafficGroup.size());
|
//
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
g2.rotate(-Math.PI/2, 25, h/2);
|
drawCenteredString(g2, Shared.getMessage("Group"), new Rectangle2D.Double(0, 0, 50, h), font);
|
g2.rotate((Math.PI/2), 25, h/2);
|
for (int i=0; i<m_subcontrollerConfiguration.ltrafficGroup.size(); i++)
|
{
|
drawCenteredString(g2, "" + m_subcontrollerConfiguration.ltrafficGroup.get(i), new Rectangle2D.Double(50, dy * i, w-50, dy), font);
|
}
|
|
g2.setColor(new FlatButton().getLook().colorBackground.darker());
|
g2.draw(new Line2D.Double(0, 0, w, 0));
|
g2.draw(new Line2D.Double(50, 0, 50, h));
|
g2.draw(new Line2D.Double(0, h, w, h));
|
for (int i=0; i<=m_subcontrollerConfiguration.ltrafficGroup.size(); i++)
|
{
|
g2.draw(new Line2D.Double(50, dy * i, w, dy * i));
|
}
|
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
}
|
|
|
|
|
|
private class Diagram extends FlatPanel
|
{
|
private int currentPhase = -1;
|
private int currentGroup = -1;
|
private Rectangle2D rectangle = null;
|
|
public Diagram ()
|
{
|
this.addMouseListener(new java.awt.event.MouseAdapter()
|
{
|
public void mousePressed(java.awt.event.MouseEvent evt)
|
{
|
if (colorEditable == true) selection(evt.getX(), evt.getY(), false);
|
}
|
public void mouseExited(java.awt.event.MouseEvent evt)
|
{
|
rectangle = null;
|
repaint();
|
}
|
});
|
|
this.addMouseMotionListener(new java.awt.event.MouseAdapter()
|
{
|
public void mouseDragged(java.awt.event.MouseEvent evt)
|
{
|
if (colorEditable == true) selection(evt.getX(), evt.getY(), true);
|
}
|
public void mouseMoved(java.awt.event.MouseEvent evt)
|
{
|
movement(evt.getX(), evt.getY());
|
}
|
});
|
}
|
|
|
public void paint (Graphics g)
|
{
|
Rectangle2D currentTimePositionRectangle = null;
|
|
try
|
{
|
Graphics2D g2 = (Graphics2D)g;
|
int w = getWidth();
|
int h = getHeight();
|
g2.setBackground(FlatGUI.lookDesign.getColor("window.color.background.content"));
|
g2.clearRect(0, 0, w, h);
|
|
if (totalTime <= 0) totalTime = 1;
|
double dx = (double)w / totalTime;
|
double dy = (double)h / (double)m_subcontrollerConfiguration.ltrafficGroup.size();
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
// Quitar si se quiere que ocupe toda la altura de pantalla
|
//
|
// dy = Math.min(dy, 36);
|
// h = (int)(dy * m_subcontrollerConfiguration.lTrafficGroup.size());
|
//
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
|
g2.setStroke(new BasicStroke(0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0.0f, new float[]{1.0f, 2.0f}, 0.0f));
|
int time = 0;
|
List<Integer> ltime = new ArrayList<Integer>();
|
|
for (int i=0; i<lphase.size(); i++)
|
{
|
ltime.add(time);
|
int maximumtime = lphase.get(i).maximumTime;
|
time = time + maximumtime;
|
}
|
|
if (ldiagramColumns.get(4).isVisible() == true)
|
{
|
for (int i=0; i<totalTime; i=i+1)
|
{
|
if (ltime.contains(new Integer(i)) == false)
|
{
|
g2.setColor(FlatGUI.lookDesign.getColor("label.color.background").darker());
|
g2.draw(new Line2D.Double((dx * i), 0, (dx * i), h));
|
}
|
}
|
}
|
|
time = 0;
|
|
g2.setStroke(new BasicStroke(1.0f));
|
|
for (int i=0; i<lphase.size(); i++)
|
{
|
ALUVISA_Phase phase = lphase.get(i);
|
|
for (int j=0; j<phase.lColor.size(); j++)
|
{
|
g2.setStroke(new BasicStroke(1.0f));
|
int color = phase.lColor.get(j).color;
|
double x = dx * time;
|
double y = dy * j;
|
|
if (dy > 36) y = y + (dy-36)/2;
|
DiagramColors.paint(g2, x, y, phase.maximumTime * dx, Math.min(36, dy), color);
|
}
|
|
time = time + phase.maximumTime;
|
|
// Current position phase and time
|
|
if ((phase.number == realtimeCurrentPhase) && (realtimeCurrentTime >= 0))
|
{
|
double x = dx * realtimeCurrentTime;
|
currentTimePositionRectangle = new Rectangle2D.Double(x,0,dx,getHeight());
|
}
|
}
|
|
|
|
g2.setColor(FlatGUI.lookDesign.getColor("label.color.background").darker());
|
|
time = 0;
|
|
for (int i=0; i<lphase.size(); i++)
|
{
|
int maximumtime = lphase.get(i).maximumTime;
|
g2.setColor(FlatGUI.lookDesign.getColor("label.color.background").darker());
|
g2.draw(new Line2D.Double((dx * time), 0, (dx * time), h));
|
time = time + maximumtime;
|
}
|
|
g2.setColor(FlatGUI.lookDesign.getColor("label.color.background").darker());
|
g2.setStroke(new BasicStroke(1.0f));
|
g2.draw(new Line2D.Double(0, 0, w, 0));
|
g2.draw(new Line2D.Double(0, h, w, h));
|
g2.draw(new Line2D.Double(0, 0, 0, h));
|
|
|
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.25f));
|
|
time = 0;
|
|
for (int i=0; i<lphase.size(); i++)
|
{
|
ALUVISA_Phase phase = lphase.get(i);
|
|
if (lselected.contains(phase))
|
{
|
g2.setColor(Color.BLUE);
|
double x = dx * time;
|
g2.fill(new Rectangle2D.Double(x, 0, phase.maximumTime * dx, h));
|
}
|
|
time = time + phase.maximumTime;
|
}
|
|
|
if ((colorEditable == true) && (rectangle != null))
|
{
|
g2.setColor(Color.BLUE);
|
g2.fill(rectangle);
|
}
|
|
|
if (currentTimePositionRectangle != null)
|
{
|
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));
|
g2.setStroke(new BasicStroke(1.0f));
|
g2.setColor(Color.BLUE);
|
g2.fill(currentTimePositionRectangle);
|
}
|
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
|
|
private void selection (int x, int y, boolean dragging)
|
{
|
try
|
{
|
updateCurrentPhase(x, y);
|
lphase.get(currentPhase).lColor.get(currentGroup).color = selectedColor;
|
repaint();
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
|
|
private void movement (int x, int y)
|
{
|
try
|
{
|
updateCurrentPhase(x, y);
|
repaint();
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
|
|
|
private void updateCurrentPhase(int x, int y)
|
{
|
int time = 0;
|
|
if (totalTime <= 0) totalTime = 1;
|
double dx = (double)getWidth() / (double)totalTime;
|
double dy = (double)getHeight() / (double)m_subcontrollerConfiguration.ltrafficGroup.size();
|
|
currentGroup = (int)((double)y / dy);
|
|
for (int i=0; i<lphase.size(); i++)
|
{
|
int maximumtime = lphase.get(i).maximumTime;
|
double x1 = dx * time;
|
double x2 = x1 + (dx * maximumtime);
|
if ((x >= x1) && (x < x2))
|
{
|
rectangle = new Rectangle2D.Double(x1, (currentGroup * dy), x2-x1, dy);
|
currentPhase = i;
|
return;
|
}
|
time = time + maximumtime;
|
}
|
}
|
|
}
|
|
|
private void drawCenteredString(Graphics2D g2, String text, Rectangle2D rect, Font font)
|
{
|
FontMetrics metrics = g2.getFontMetrics(font);
|
double x = rect.getX() + (rect.getWidth() - metrics.stringWidth(text)) / 2;
|
double y = rect.getY() + ((rect.getHeight() - metrics.getHeight()) / 2) + metrics.getAscent();
|
g2.setFont(font);
|
g2.drawString(text, (float)x, (float)y);
|
}
|
|
|
|
private void drawCenteredString(Graphics2D g2, String text, double x, Rectangle2D rect, Font font)
|
{
|
FontMetrics metrics = g2.getFontMetrics(font);
|
double y = rect.getY() + ((rect.getHeight() - metrics.getHeight()) / 2) + metrics.getAscent();
|
g2.setFont(font);
|
g2.drawString(text, (float)x, (float)y);
|
}
|
|
|
|
private void format(Graphics2D g2)
|
{
|
try
|
{
|
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
|
g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
|
g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
g2.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DEFAULT);
|
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
|
g2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
|
g2.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
|
g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
|
int w = getWidth();
|
int h = getHeight();
|
g2.setBackground(color);
|
g2.clearRect(0, 0, w, h);
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
|
|
|
|
private void paintLines(Graphics2D g2, int w, int h, boolean paintUpperLine)
|
{
|
try
|
{
|
if (totalTime <= 0) totalTime = 1;
|
double dx = (w-150) / totalTime;
|
int time = 0;
|
|
g2.setColor(FlatGUI.lookDesign.getColor("label.color.background").darker());
|
|
for (int i=0; i<lphase.size(); i++)
|
{
|
int maximumtime = lphase.get(i).maximumTime;
|
g2.draw(new Line2D.Double((dx * time) + 150, 0, (dx * time) + 150, h));
|
time = time + maximumtime;
|
}
|
|
if (paintUpperLine == true) g2.draw(new Line2D.Double(0, 0, w, 0));
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
|
|
|
private int getInteger(String value)
|
{
|
try
|
{
|
return Integer.parseInt(value);
|
}
|
catch (Exception e)
|
{
|
return 0;
|
}
|
}
|
|
|
|
private String getPhaseName()
|
{
|
if (lphase.size() == 0) return "";
|
|
int type = lphase.get(0).type;
|
|
for (ALUVISA_Phase phase : lphase)
|
{
|
if (phase.type != type)
|
{
|
return Shared.getMessage("Phase");
|
}
|
}
|
|
if (lphase.get(0).type == ALUVISA_Phase.TYPE_TRANSITION)
|
{
|
return Shared.getMessage("Intergreen");
|
}
|
else if (lphase.get(0).type == ALUVISA_Phase.TYPE_START)
|
{
|
return Shared.getMessage("Start phase");
|
}
|
return Shared.getMessage("Phase");
|
}
|
}
|