package art.client.GUI.components.devices.window.colors.rtz32.configuration.components; import art.library.gui.FlatGUI; import art.library.model.devices.colors.controller.RTZ32.configuration.RTZ32_Configuration; import art.library.model.devices.colors.controller.RTZ32.configuration.RTZ32_Configuration_Program; import art.library.model.devices.colors.controller.RTZ32.configuration.RTZ32_Configuration_Program_Trolley_Cancellation; import art.library.model.devices.colors.controller.RTZ32.configuration.RTZ32_Configuration_Program_VariablePhase; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics2D; import java.awt.geom.GeneralPath; import java.awt.geom.Line2D; import javax.swing.JPanel; public class Diagram_Distribution_Bars_Content_Variables_Cancellations extends JPanel { private RTZ32_Configuration configuration = null; private int programNumber = 0; protected RTZ32_Configuration_Program_VariablePhase currentVariable = null; protected RTZ32_Configuration_Program_Trolley_Cancellation currentCancellation = null; protected int order = 0; public Diagram_Distribution_Bars_Content_Variables_Cancellations(RTZ32_Configuration configuration, int programNumber) { this.configuration = configuration; this.programNumber = programNumber; } public void setCurrentTime(int time) { RTZ32_Configuration_Program program = configuration.getProgram(programNumber); if (currentVariable != null) { if (order == 0) { currentVariable.startTime = time; if (currentVariable.startTime < 0) currentVariable.startTime = 0; if (currentVariable.startTime > (program.cycle - 1)) currentVariable.startTime = program.cycle - 1; if (currentVariable.startTime >= currentVariable.endTime) currentVariable.endTime = currentVariable.startTime + 1; } else if (order == 1) { currentVariable.endTime = time; if (currentVariable.endTime < 1) currentVariable.endTime = 1; if (currentVariable.endTime > program.cycle) currentVariable.endTime = program.cycle; if (currentVariable.endTime <= currentVariable.startTime) currentVariable.startTime = currentVariable.endTime - 1; } } else if (currentCancellation != null) { currentCancellation.time = time; if (currentCancellation.time < 0) currentCancellation.time = 0; if (currentCancellation.time > program.cycle) currentCancellation.time = program.cycle; } } public boolean updateCurrentVariableCancellation(int x, int y) { RTZ32_Configuration_Program program = configuration.getProgram(programNumber); double dx = (double)getWidth() / (double)program.cycle; for (RTZ32_Configuration_Program_VariablePhase variable : program.variablePhases) { GeneralPath[] paths = getPath(variable, dx); if (paths[0].contains(x, y)) { currentVariable = variable; order = 0; return true; } if (paths[1].contains(x, y)) { currentVariable = variable; order = 1; return true; } } currentVariable = null; for (RTZ32_Configuration_Program_Trolley_Cancellation cancellation : program.trolley.cancellations) { GeneralPath path = getPath(cancellation, dx); if (path.contains(x, y)) { currentCancellation = cancellation; return true; } } currentCancellation = null; return false; } public void paint (Graphics2D g2) { try { int w = getWidth(); int h = getHeight(); RTZ32_Configuration_Program program = configuration.getProgram(programNumber); double dy = (double)h / (double)configuration.groups.length; double dx = (double)w / (double)program.cycle; g2.setFont(FlatGUI.lookDesign.getFont("label.font").deriveFont((float)(FlatGUI.lookDesign.getFont("label.font").getSize()-2.5f))); for (RTZ32_Configuration_Program_VariablePhase phase : program.variablePhases) { if (phase.isEmpty() == false) { paint(g2, w, h, dx, phase); } } for (RTZ32_Configuration_Program_Trolley_Cancellation cancellation : program.trolley.cancellations) { if (cancellation.isEmpty() == false) { paint(g2, w, h, dx, cancellation); } } } catch (Exception e) { } } private void paint (Graphics2D g2, int w, int h, double dx, RTZ32_Configuration_Program_VariablePhase phase) { g2.setColor(new Color(145, 186, 20)); g2.setStroke(new BasicStroke(1.0f)); GeneralPath[] paths = getPath(phase, dx); g2.fill(paths[0]); g2.fill(paths[1]); g2.setStroke(new BasicStroke(1.0f)); g2.draw(new Line2D.Double((phase.startTime * dx), 8, (phase.endTime * dx), 8)); g2.draw(new Line2D.Double((phase.startTime * dx), 24, (phase.startTime * dx), h)); g2.draw(new Line2D.Double((phase.endTime * dx), 24, (phase.endTime * dx), h)); g2.setColor(FlatGUI.lookDesign.getColor("label.color.foreground")); Diagram_Distribution.drawRightString(g2, "" + phase.startTime, (phase.startTime * dx) - 10, 10); Diagram_Distribution.drawLeftString(g2, "" + phase.endTime, (phase.endTime * dx) + 10, 10); Diagram_Distribution.drawCenteredString(g2, "I", (phase.startTime * dx), 5); Diagram_Distribution.drawCenteredString(g2, "F", (phase.endTime * dx), 5); if (currentVariable == phase) { g2.setColor(Color.blue); g2.draw(paths[order]); } } private void paint (Graphics2D g2, int w, int h, double dx, RTZ32_Configuration_Program_Trolley_Cancellation cancellation) { g2.setColor(Color.red); g2.setStroke(new BasicStroke(1.0f)); GeneralPath path = getPath(cancellation, dx); g2.fill(path); g2.setStroke(new BasicStroke(1.0f)); g2.draw(new Line2D.Double((cancellation.time * dx), 5, (cancellation.time * dx), h)); g2.setStroke(new BasicStroke(1.0f)); g2.setColor(FlatGUI.lookDesign.getColor("label.color.foreground")); Diagram_Distribution.drawRightString(g2, "" + cancellation.time, (cancellation.time * dx) - 10, 10); Diagram_Distribution.drawCenteredString(g2, "C", (cancellation.time * dx), 0); if (currentCancellation == cancellation) { g2.setColor(Color.blue); g2.draw(path); } } private GeneralPath[] getPath(RTZ32_Configuration_Program_VariablePhase phase, double dx) { GeneralPath path1 = new GeneralPath(GeneralPath.WIND_NON_ZERO); path1.moveTo((phase.startTime * dx) - 10, 7.5); path1.lineTo((phase.startTime * dx) + 10, 7.5); path1.lineTo((phase.startTime * dx), 25); path1.closePath(); GeneralPath path2 = new GeneralPath(GeneralPath.WIND_NON_ZERO); path2.moveTo((phase.endTime * dx) - 10, 7.5); path2.lineTo((phase.endTime * dx) + 10, 7.5); path2.lineTo((phase.endTime * dx), 25); path2.closePath(); return new GeneralPath[]{path1, path2}; } private GeneralPath getPath(RTZ32_Configuration_Program_Trolley_Cancellation cancellation, double dx) { GeneralPath path = new GeneralPath(GeneralPath.WIND_NON_ZERO); path.moveTo((cancellation.time * dx) - 10, 2.5); path.lineTo((cancellation.time * dx) + 10, 2.5); path.lineTo((cancellation.time * dx), 17.5); path.closePath(); return path; } }