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_Retractable; 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_Retractables extends JPanel { private RTZ32_Configuration configuration = null; private int programNumber = 0; protected RTZ32_Configuration_Program_Trolley_Retractable currentRetractable = null; protected int order = 0; public Diagram_Distribution_Bars_Content_Retractables(RTZ32_Configuration configuration, int programNumber) { this.configuration = configuration; this.programNumber = programNumber; } public void setCurrentTime(int time) { if (currentRetractable != null) { if (order == 0) { currentRetractable.startTime = time; } else if (order == 1) { currentRetractable.endTime = time; } RTZ32_Configuration_Program program = configuration.getProgram(programNumber); if (currentRetractable.startTime < 0) currentRetractable.startTime = 0; if (currentRetractable.endTime < 1) currentRetractable.endTime = 1; if (currentRetractable.startTime > (program.cycle - 1)) currentRetractable.startTime = program.cycle - 1; if (currentRetractable.endTime > program.cycle) currentRetractable.endTime = program.cycle; if (currentRetractable.startTime >= currentRetractable.endTime) currentRetractable.endTime = currentRetractable.startTime + 1; if (currentRetractable.endTime <= currentRetractable.startTime) currentRetractable.startTime = currentRetractable.endTime - 1; } } public boolean updateCurrentRetractable(int x, int y) { RTZ32_Configuration_Program program = configuration.getProgram(programNumber); double dx = (double)getWidth() / (double)program.cycle; for (RTZ32_Configuration_Program_Trolley_Retractable retractable : program.trolley.retractables) { GeneralPath[] paths = getPath(retractable, dx); if (paths[0].contains(x, y)) { currentRetractable = retractable; order = 0; return true; } if (paths[1].contains(x, y)) { currentRetractable = retractable; order = 1; return true; } } currentRetractable = null; return false; } public void paint (Graphics2D g2) { try { int w = getWidth(); int h = getHeight(); RTZ32_Configuration_Program program = configuration.getProgram(programNumber); 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_Trolley_Retractable retractable : program.trolley.retractables) { if (retractable.isEmpty() == false) { paint(g2, retractable, h, dx); } } } catch (Exception e) { } } private void paint (Graphics2D g2, RTZ32_Configuration_Program_Trolley_Retractable phase, int h, double dx) { g2.setColor(new Color(153, 217, 234)); 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 (currentRetractable == phase) { g2.setColor(Color.blue); g2.draw(paths[order]); } } private GeneralPath[] getPath(RTZ32_Configuration_Program_Trolley_Retractable 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}; } }