package art.client.GUI.components.devices.window.colors.rtz32.configuration.components;
|
|
import art.library.gui.FlatGUI;
|
import art.library.gui.flat.FlatButton;
|
import art.library.model.devices.colors.controller.RTZ32.configuration.RTZ32_Configuration;
|
import art.library.model.devices.colors.controller.RTZ32.configuration.RTZ32_Configuration_Group;
|
import art.library.model.devices.colors.controller.RTZ32.configuration.RTZ32_Configuration_Program;
|
import art.library.model.devices.colors.controller.RTZ32.configuration.constants.RTZ32_Constants_Colors;
|
import art.library.model.devices.colors.controller.RTZ32.types.RTZ32_Distribution_Group_Hidden;
|
import art.library.model.devices.colors.controller.RTZ32.types.RTZ32_Distribution_Group_Segment;
|
import java.awt.BasicStroke;
|
import java.awt.Color;
|
import java.awt.Font;
|
import java.awt.Graphics2D;
|
import java.awt.Stroke;
|
import java.awt.geom.GeneralPath;
|
import java.awt.geom.Line2D;
|
import java.awt.geom.Rectangle2D;
|
import java.util.ArrayList;
|
import javax.swing.JPanel;
|
|
|
|
public class Diagram_Distribution_Bars_Content_Groups extends JPanel
|
{
|
private RTZ32_Configuration configuration = null;
|
private int programNumber = 0;
|
private Diagram_Distribution diagram_Distribution = null;
|
|
public Diagram_Distribution_Bars_Content_Groups(RTZ32_Configuration configuration, int programNumber, Diagram_Distribution diagram_Distribution)
|
{
|
this.configuration = configuration;
|
this.programNumber = programNumber;
|
this.diagram_Distribution = diagram_Distribution;
|
}
|
|
|
public int getCurrentTime(int x)
|
{
|
RTZ32_Configuration_Program program = configuration.getProgram(programNumber);
|
double dx = (double)getWidth()/(double)program.cycle;
|
return (int)Math.round(x/dx);
|
}
|
|
|
public int getCurrentBar(int y, int numberBars)
|
{
|
double dy = (int)((double)getHeight()/(double)numberBars);
|
return (1 + (int)(y/dy));
|
}
|
|
|
public RTZ32_Configuration_Group getCurrentGroup(int x, int y, int numberBars)
|
{
|
double dy = (int)((double)getHeight()/(double)numberBars);
|
|
double currenty = 0;
|
|
int numberValidsGroups = configuration.getNumberValidGroups();
|
|
for (int i=0; i<numberValidsGroups; i++)
|
{
|
RTZ32_Configuration_Group group = configuration.groups[i];
|
|
// Paint white under de bar to hide gray lines
|
|
if (group.type != 20)
|
{
|
double y1 = currenty;
|
double y2 = currenty + dy;
|
if ((y >= y1) && (y < y2)) return group;
|
currenty = currenty + dy;
|
}
|
else
|
{
|
for (ArrayList<RTZ32_Distribution_Group_Segment> listSegments : diagram_Distribution.distribution.groups.get(i).listBars)
|
{
|
for (RTZ32_Distribution_Group_Segment segment : listSegments)
|
{
|
double y1 = currenty;
|
double y2 = currenty + dy;
|
if ((y >= y1) && (y < y2)) return group;
|
currenty = currenty + dy;
|
}
|
}
|
}
|
}
|
|
return null;
|
}
|
|
|
|
public RTZ32_Distribution_Group_Hidden getCurrentHidden(int x, int y, int numberBars)
|
{
|
RTZ32_Configuration_Program program = configuration.getProgram(programNumber);
|
double dy = (int)((double)getHeight() / numberBars);
|
double dx = (double)getWidth() / (double)program.cycle;
|
double width = Math.min(dx/1.25, dy/1.25);
|
|
double currenty = 0;
|
|
int numberValidsGroups = configuration.getNumberValidGroups();
|
|
for (int i=0; i<numberValidsGroups; i++)
|
{
|
for (RTZ32_Distribution_Group_Hidden hidden : diagram_Distribution.distribution.groups.get(i).hiddens)
|
{
|
double x1 = (hidden.time * dx)-1 - width;
|
double y1 = (currenty + width/4)-1 - width;
|
double x2 = (hidden.time * dx)-1 + width;
|
double y2 = (currenty + width/4)-1 + width;
|
|
if ((x >= x1) && (x < x2) && (y >= y1) && (y < y2)) return hidden;
|
}
|
|
currenty = currenty + dy;
|
}
|
|
return null;
|
}
|
|
|
|
public RTZ32_Distribution_Group_Segment getCurrentSegment(int x, int y, int numberBars)
|
{
|
RTZ32_Configuration_Program program = configuration.getProgram(programNumber);
|
double dx = (double)getWidth()/(double)program.cycle;
|
double dy = (int)((double)getHeight()/(double)numberBars);
|
|
double currenty = 0;
|
|
int numberValidsGroups = configuration.getNumberValidGroups();
|
|
|
for (int i=0; i<numberValidsGroups; i++)
|
{
|
RTZ32_Configuration_Group group = configuration.groups[i];
|
|
// Paint white under de bar to hide gray lines
|
|
if (group.type != 20)
|
{
|
for (RTZ32_Distribution_Group_Segment segment : diagram_Distribution.distribution.groups.get(i).segments)
|
{
|
double x1 = segment.startTime * dx;
|
double y1 = currenty;
|
double x2 = segment.endTime * dx;
|
double y2 = currenty + dy;
|
if ((x >= x1) && (x < x2) && (y >= y1) && (y < y2)) return segment;
|
}
|
|
currenty = currenty + dy;
|
}
|
else
|
{
|
for (ArrayList<RTZ32_Distribution_Group_Segment> listSegments :diagram_Distribution.distribution.groups.get(i).listBars)
|
{
|
for (RTZ32_Distribution_Group_Segment segment : listSegments)
|
{
|
double x1 = segment.startTime * dx;
|
double y1 = currenty;
|
double x2 = segment.endTime * dx;
|
double y2 = currenty + dy;
|
if ((x >= x1) && (x < x2) && (y >= y1) && (y < y2)) return segment;
|
}
|
|
currenty = currenty + dy;
|
}
|
}
|
}
|
|
return null;
|
}
|
|
|
|
|
|
|
public void paintBars (Graphics2D g2, int numberBars, RTZ32_Distribution_Group_Segment currentSegment)
|
{
|
try
|
{
|
int w = getWidth();
|
int h = getHeight();
|
|
RTZ32_Configuration_Program program = configuration.getProgram(programNumber);
|
numberBars = Diagram_Distribution.getNumberBars(configuration);
|
g2.setColor(new FlatButton().getLook().colorForeground);
|
double dy = (int)((double)h / (double)numberBars);
|
double dx = (double)w / (double)program.cycle;
|
|
// Draw color bars
|
|
double currenty = 0;
|
|
int numberValidsGroups = configuration.getNumberValidGroups();
|
|
for (int i=0; i<numberValidsGroups; i++)
|
{
|
RTZ32_Configuration_Group group = configuration.groups[i];
|
|
// Paint white under de bar to hide gray lines
|
|
if (group.type != 20)
|
{
|
for (RTZ32_Distribution_Group_Segment segment : diagram_Distribution.distribution.groups.get(i).segments)
|
{
|
drawBar(segment.startTime * dx, currenty, segment.endTime * dx, currenty + dy, segment.color, g2, (segment == currentSegment));
|
}
|
|
g2.setFont(FlatGUI.lookDesign.getFont("label.font").deriveFont(Font.BOLD + Font.ITALIC).deriveFont(12.0f));
|
currenty = currenty + dy;
|
}
|
else
|
{
|
for (ArrayList<RTZ32_Distribution_Group_Segment> listSegments : diagram_Distribution.distribution.groups.get(i).listBars)
|
{
|
for (RTZ32_Distribution_Group_Segment segment : listSegments)
|
{
|
drawBar(segment.startTime * dx, currenty, segment.endTime * dx, currenty + dy, segment.color, g2, (segment == currentSegment));
|
}
|
|
currenty = currenty + dy;
|
}
|
|
g2.setFont(FlatGUI.lookDesign.getFont("label.font").deriveFont(Font.BOLD + Font.ITALIC).deriveFont(12.0f));
|
}
|
|
}
|
}
|
catch (Exception e)
|
{
|
}
|
|
}
|
|
|
|
|
public void paintHidden (Graphics2D g2, int numberBars, RTZ32_Distribution_Group_Hidden currentHidden)
|
{
|
try
|
{
|
int w = getWidth();
|
int h = getHeight();
|
g2.setColor(new FlatButton().getLook().colorForeground);
|
RTZ32_Configuration_Program program = configuration.getProgram(programNumber);
|
double dy = (int)((double)h / numberBars);
|
double dx = (double)w / (double)program.cycle;
|
|
// Arrow
|
|
double d = Math.min(dx/1.25, dy/1.25);
|
|
GeneralPath arrow1 = null;
|
{
|
double[] xPoints = {0, 0, -d, 0};
|
double[] yPoints = {0, -d, 0, 0};
|
arrow1 = new GeneralPath(GeneralPath.WIND_EVEN_ODD, xPoints.length);
|
arrow1.moveTo(xPoints[0], yPoints[0]);
|
for (int i=1; i<xPoints.length; i++) arrow1.lineTo(xPoints[i], yPoints[i]);
|
arrow1.closePath();
|
}
|
|
GeneralPath arrow2 = null;
|
{
|
double[] xPoints = {0, 0, -d*1.5, 0};
|
double[] yPoints = {0, -d*1.5, 0, 0};
|
arrow2 = new GeneralPath(GeneralPath.WIND_EVEN_ODD, xPoints.length);
|
arrow2.moveTo(xPoints[0], yPoints[0]);
|
for (int i=1; i<xPoints.length; i++) arrow2.lineTo(xPoints[i], yPoints[i]);
|
arrow2.closePath();
|
}
|
|
|
// Paint arrows
|
|
g2.setFont(FlatGUI.lookDesign.getFont("label.font").deriveFont(Font.BOLD).deriveFont(12.5f));
|
g2.setStroke(new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
|
|
|
double currenty = 0;
|
|
int numberValidsGroups = configuration.getNumberValidGroups();
|
|
for (int i=0; i<numberValidsGroups; i++)
|
{
|
for (RTZ32_Distribution_Group_Hidden hidden : diagram_Distribution.distribution.groups.get(i).hiddens)
|
{
|
double tx = (hidden.time * dx)-1;
|
double ty = (currenty + dy/4)-1;
|
g2.setColor(Color.blue);
|
g2.translate(tx, ty);
|
|
if (hidden != currentHidden)
|
{
|
g2.fill(arrow1);
|
g2.draw(new Line2D.Double(-1,-1,-d,-d));
|
}
|
else
|
{
|
g2.fill(arrow2);
|
g2.draw(new Line2D.Double(-1,-1,-d*1.5, -d*1.5));
|
}
|
|
|
g2.translate(-tx, -ty);
|
drawHidden(hidden.time * dx, currenty, (hidden.time + 1) * dx, currenty + dy, hidden.colorOrder, g2);
|
}
|
|
currenty = currenty + dy;
|
}
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
|
|
|
public void paintFocus (Graphics2D g2, int numberBars, int currentSecond)
|
{
|
try
|
{
|
int w = getWidth();
|
int h = getHeight();
|
RTZ32_Configuration_Program program = configuration.getProgram(programNumber);;
|
double dy = (int)((double)h / (double)numberBars);
|
double dx = (double)w / (double)program.cycle;
|
|
if (currentSecond > 0)
|
{
|
Font font = FlatGUI.lookDesign.getFont("label.font").deriveFont((float)(FlatGUI.lookDesign.getFont("label.font").getSize()-2f));
|
|
g2.setFont(font);
|
g2.setStroke(new BasicStroke(1.0f));
|
|
// Second
|
{
|
g2.setColor(Color.blue);
|
g2.draw(new Line2D.Double(currentSecond * dx, 0, currentSecond * dx, getHeight() * 2));
|
Rectangle2D rectangle2D = new Rectangle2D.Double(currentSecond * dx - 10, -20, 20, 17);
|
g2.setColor(Color.white);
|
g2.fill(rectangle2D);
|
g2.setColor(FlatGUI.lookDesign.getColor("label.color.background").darker());
|
g2.draw(rectangle2D);
|
g2.setColor(Color.blue);
|
Diagram_Distribution.drawCenteredString(g2, "" + currentSecond, currentSecond * dx, -20);
|
}
|
|
}
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
|
|
|
|
|
private static final float[] dashFast = {1.5f, 1.5f};
|
private static final float[] dashSlow = {2.25f, 2.25f};
|
private static final float[] dashDouble = {4.0f, 2.0f, 8.0f, 2.0f};
|
|
|
private void drawBar(double x1, double y1, double x2, double y2, int color, Graphics2D g2, boolean current)
|
{
|
try
|
{
|
double centery = y1 + ((y2 - y1) /2);
|
float height1 = (float)Math.min(18, (y2-y1)/2);
|
float height2 = (float)Math.min(9, (y2-y1)/4);
|
|
Color colorA = null;
|
Color colorB = null;
|
Stroke strokeA = null;
|
Stroke strokeB = null;
|
|
Stroke strokeNone1 = new BasicStroke(height1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);
|
Stroke strokeFast1 = new BasicStroke(height1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0.0f, dashFast, 0.0f);
|
Stroke strokeSlow1 = new BasicStroke(height1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0.0f, dashSlow, 0.0f);
|
|
Stroke strokeNone2 = new BasicStroke(height2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);
|
Stroke strokeFast2 = new BasicStroke(height2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0.0f, dashFast, 0.0f);
|
Stroke strokeSlow2 = new BasicStroke(height2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0.0f, dashSlow, 0.0f);
|
|
switch (color)
|
{
|
case RTZ32_Constants_Colors.COLOR_OFF : colorA = Color.lightGray; strokeA = strokeNone1; break;
|
case RTZ32_Constants_Colors.COLOR_V : colorA = Color.green; strokeA = strokeNone1; break;
|
case RTZ32_Constants_Colors.COLOR_A : colorA = Color.orange; strokeA = strokeNone1; break;
|
case RTZ32_Constants_Colors.COLOR_R : colorA = Color.red; strokeA = strokeNone1; break;
|
case RTZ32_Constants_Colors.COLOR_VI : colorA = Color.green; strokeA = strokeFast1; break;
|
//case RTZ32_Constants_Colors.COLOR_AI : colorA = Color.orange; strokeA = strokeSlow1; break;
|
case RTZ32_Constants_Colors.COLOR_AI : colorA = Color.orange; strokeA = strokeNone2; colorB = Color.white; strokeB = strokeNone2; break;
|
case RTZ32_Constants_Colors.COLOR_RI : colorA = Color.red; strokeA = strokeSlow1; break;
|
|
case RTZ32_Constants_Colors.COLOR_ViAI : colorA = Color.green; strokeA = strokeFast2; colorB = Color.orange; strokeB = strokeSlow2; break;
|
case RTZ32_Constants_Colors.COLOR_RiAI : colorA = Color.red; strokeA = strokeFast2; colorB = Color.orange; strokeB = strokeSlow2; break;
|
case RTZ32_Constants_Colors.COLOR_VAI : colorA = Color.green; strokeA = strokeNone2; colorB = Color.orange; strokeB = strokeSlow2; break;
|
case RTZ32_Constants_Colors.COLOR_RAI : colorA = Color.red; strokeA = strokeNone2; colorB = Color.blue; strokeB = strokeSlow2; break;
|
case RTZ32_Constants_Colors.COLOR_AIVI : colorA = Color.orange; strokeA = strokeSlow2; colorB = Color.green; strokeB = strokeSlow2; break;
|
case RTZ32_Constants_Colors.COLOR_AIRI : colorA = Color.orange; strokeA = strokeSlow2; colorB = Color.red; strokeB = strokeSlow2; break;
|
case RTZ32_Constants_Colors.COLOR_RiVi : colorA = Color.red; strokeA = strokeFast2; colorB = Color.green; strokeB = strokeFast2; break;
|
case RTZ32_Constants_Colors.COLOR_AR : colorA = Color.red; strokeA = strokeNone2; colorB = Color.blue; strokeB = strokeNone2; break;
|
case RTZ32_Constants_Colors.COLOR_Vi : colorA = Color.green; strokeA = strokeFast1; break;
|
case RTZ32_Constants_Colors.COLOR_VA : colorA = Color.green; strokeA = strokeNone2; colorB = Color.orange; strokeB = strokeNone2; break;
|
case RTZ32_Constants_Colors.COLOR_VR : colorA = Color.green; strokeA = strokeNone2; colorB = Color.red; strokeB = strokeNone2; break;
|
case RTZ32_Constants_Colors.COLOR_VAR : break;
|
|
case RTZ32_Constants_Colors.COLOR_Vd : colorA = Color.green.darker(); strokeA = strokeNone1; break;
|
case RTZ32_Constants_Colors.COLOR_VId : colorA = Color.green.darker(); strokeA = strokeSlow1; break;
|
case RTZ32_Constants_Colors.COLOR_Vid : colorA = Color.green.darker(); strokeA = strokeFast1; break;
|
case RTZ32_Constants_Colors.Rd : break;
|
|
case RTZ32_Constants_Colors.COLOR_AIe : colorA = Color.orange.darker(); strokeA = strokeSlow1; break;
|
case RTZ32_Constants_Colors.COLOR_Ae : colorA = Color.orange.darker(); strokeA = strokeNone1; break;
|
case RTZ32_Constants_Colors.COLOR_Re : colorA = Color.red.darker(); strokeA = strokeNone1; break;
|
case RTZ32_Constants_Colors.COLOR_OFFe : colorA = Color.darkGray; strokeA = strokeNone1; break;
|
|
default: colorA = Color.magenta; strokeA = strokeNone1; break;
|
}
|
|
|
if ((strokeA == strokeSlow1) || (strokeA == strokeFast1) || (strokeB == strokeSlow1) || (strokeB == strokeFast1) ||
|
(strokeA == strokeSlow2) || (strokeA == strokeFast2) || (strokeB == strokeSlow2) || (strokeB == strokeFast2))
|
{
|
g2.setStroke(strokeNone1);
|
g2.setColor(Color.white);
|
g2.fill(new Rectangle2D.Double(x1, centery-(height1/2), x2-x1, height1));
|
}
|
|
if ((colorA != null) && (colorB == null))
|
{
|
g2.setColor(colorA);
|
g2.setStroke(strokeA);
|
g2.draw(new Line2D.Double(x1, centery, x2, centery));
|
}
|
else if ((colorA != null) && (colorB != null))
|
{
|
g2.setColor(colorA);
|
g2.setStroke(strokeA);
|
g2.draw(new Line2D.Double(x1, centery - height2/2, x2, centery - height2/2));
|
|
g2.setColor(colorB);
|
g2.setStroke(strokeB);
|
g2.draw(new Line2D.Double(x1, centery + height2/2, x2, centery + height2/2));
|
}
|
|
if (current == true)
|
{
|
g2.setStroke(new BasicStroke(1.25f));
|
g2.setColor(Color.blue);
|
}
|
else
|
{
|
g2.setStroke(new BasicStroke(1.0f));
|
g2.setColor(FlatGUI.lookDesign.getColor("label.color.background").darker());
|
}
|
|
g2.draw(new Rectangle2D.Double(x1, centery - height2, x2-x1, height2 * 2));
|
}
|
catch (Exception exception)
|
{
|
}
|
|
g2.setStroke(new BasicStroke(1.0f));
|
|
}
|
|
|
private void drawHidden(double x1, double y1, double x2, double y2, String text, Graphics2D g2)
|
{
|
try
|
{
|
g2.setColor(Color.blue);
|
Diagram_Distribution.drawLeftString(g2, "" + text, new Rectangle2D.Double(x1, y1, x2-x1, y2-y1), g2.getFont());
|
}
|
catch (Exception exception)
|
{
|
}
|
|
g2.setStroke(new BasicStroke(1.0f));
|
|
}
|
|
|
|
|
|
|
|
|
}
|