Alejandro Acuña
2024-10-25 bf65497ed7abf9c669eb3cc0ba219dfa4494b759
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
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};
 
    }
    
    
        
}