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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
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;
    }
 
    
        
}