df
Alejandro Acuña
2024-09-16 f56295b7f2c7282783589fb4903529b09e161daa
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
package art.servers.colorsserver.M.gui;
 
import art.library.model.devices.colors.controller.M.M_ControllerConfiguration;
import art.library.model.devices.colors.controller.M.M_SubcontrollerConfiguration;
import art.library.model.devices.colors.controller.M.configuration.ALUVISA_Plan;
import art.servers.colorsserver.M.gui.diagrams.DiagramALUVISAPhases;
import art.servers.colorsserver.M.gui.diagrams.DiagramConflicts;
import art.servers.colorsserver.M.gui.diagrams.DiagramPlan;
import art.servers.colorsserver.M.gui.diagrams.DiagramTimetable;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.util.List;
import javax.swing.JComponent;
import javax.swing.JWindow;
 
public class Diagrams
{
    
    public static BufferedImage getDiagramPlan(int width, int height, M_ControllerConfiguration m_controller, M_SubcontrollerConfiguration m_subcontroller, ALUVISA_Plan plan, boolean isStructure)
    {
        DiagramPlan diagram = new DiagramPlan(m_controller, m_subcontroller, plan, isStructure);
        diagram.setSize(new Dimension(width, height));
        BufferedImage image = new BufferedImage(diagram.getWidth(),diagram.getHeight(), BufferedImage.TYPE_INT_ARGB);
        diagram.paint(image.getGraphics());
        return image;
    }
 
 
    public static BufferedImage getDiagramALUVISAPhases(int width, int height, M_ControllerConfiguration m_controller, M_SubcontrollerConfiguration m_subcontroller, ALUVISA_Plan plan, int pathnumber)
    {
        List<ALUVISA_Plan> lpath = plan.getPaths();
        DiagramALUVISAPhases diagram = new DiagramALUVISAPhases(m_controller, m_subcontroller, plan, lpath.get(pathnumber).getPathSequence());
        return getImage(diagram, width, height, 0);
    }
 
                    
    
    public static BufferedImage getDiagramConflicts(int width, int height, M_ControllerConfiguration m_controller)
    {
        DiagramConflicts diagram = new DiagramConflicts(m_controller);
        return getImage(diagram, width, height, 0);
    }
 
         
    
    public static BufferedImage getDiagramTimetable(int width, int height, M_ControllerConfiguration m_controller, M_SubcontrollerConfiguration m_subcontroller)
    {
        DiagramTimetable diagram = new DiagramTimetable(m_controller, m_subcontroller);
        return getImage(diagram, width, height, 1000);
    }
 
            
            
            
    private static BufferedImage getImage(JComponent component, int width, int height, int sleep)
    {
        JWindow window = new JWindow();
        
        try
        {
            window.setContentPane(component);
            window.setSize(new Dimension(width,height));
            window.setLocation(-99999,-99999);
            BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
            window.setVisible(true);
            if (sleep > 0) 
            {
                try
                {
                    Thread.sleep(sleep);
                }
                catch (Exception e)
                {
                }
            }
            component.paint(image.getGraphics());
            return image;
        }
        finally
        {
            window.setVisible(false);
            window.dispose();
        }
    }    
}