Alejandro Acuña
2024-12-18 44b33e24b644459038edd956cfce7345ce3236c1
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
package svgdevicestest.maps.SVG;
 
import art.client.GUI.components.pictures.svg.PanelScaleVectorGraphics;
import art.client.controllers.ServerServiceName;
import art.client.invokes.Invokes;
import art.client.models.ModelGUI;
import art.client.models.Shared;
import art.library.gui.flat.FlatPanel;
import art.library.gui.flat.FlatTitle;
import art.library.interop.InteropParameter;
import art.library.interop.InteropParameters;
import art.library.interop.InteropResponse;
import art.library.model.devices.Device;
import art.library.model.devices.DeviceGraphics;
import art.library.model.devices.vms.general.VmsGeneral;
import com.kitfox.svg.SVGDiagram;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.lang.reflect.Method;
 
public class MyPanelDeviceStatusSvg extends FlatPanel
{
    private Device device;
    private PanelScaleVectorGraphics panelScaleVectorGraphics;
    private int dimensionHeight;
    private int dimensionWidth;
    private String titleString;
    private boolean loadedSVG = false;
    private FlatTitle title;
    private Object scriptClassInstance = null;
    private Class scriptClass = null;
 
            
    private boolean even = false;
    
    public MyPanelDeviceStatusSvg(Device device)
    {
        this.device = device;
        this.titleString = Shared.getMessage("Aspect");
        this.dimensionHeight = 0;
        this.dimensionWidth = 0;
        initialise();
        loadSVG();
    }
 
    public void reload(byte[] dataSVG)
    {
        if (panelScaleVectorGraphics != null)
        {
            panelScaleVectorGraphics.reload(dataSVG);
        }
    }
    
    public void reload(Class scriptClass)
    {
        this.scriptClass = scriptClass;
    }
    
 
    public void reload()
    {
        even = !even;
        
        SVGDiagram diagram = panelScaleVectorGraphics.getDiagram();
        
        if (diagram != null)
        {
            if (scriptClass == null)
            {
                scriptClassInstance = DeviceGraphics.revalidate(diagram, device);
            } else
            {
                try
                {
                    scriptClassInstance = scriptClass.getDeclaredConstructor(Device.class, SVGDiagram.class).newInstance(device, diagram);
                    
                    if(even)
                    {
                        try
                        {
                             scriptClassInstance.getClass().getDeclaredMethod("timer").invoke(scriptClassInstance);
                        } catch (Exception ex)
                        {
                        }
                    }
                    
                    scriptClassInstance.getClass().getDeclaredMethod("status").invoke(scriptClassInstance);
                } catch (Exception ex)
                {
                }
            }
        }
        repaint();
    }
 
    
 
    
    public void timer()
    {
        try
        {
            if (scriptClassInstance != null)
            {
                Method method = scriptClassInstance.getClass().getDeclaredMethod("timer");
                method.invoke(scriptClassInstance);
            }
        }
        catch (Exception e)
        {
        }
        
        if (panelScaleVectorGraphics != null) panelScaleVectorGraphics.repaint();
    }
 
    
    
    
    private void initialise()
    {
        try
        {
            if (panelScaleVectorGraphics == null)
            {
                panelScaleVectorGraphics = new PanelScaleVectorGraphics();
                panelScaleVectorGraphics.disableOptionLayers();
                panelScaleVectorGraphics.disableOptionDevices();
                panelScaleVectorGraphics.repaint();
            }
 
            this.setMinimumSize(new Dimension(dimensionWidth, dimensionHeight));
            this.setLayout(new BorderLayout());
            title  = new FlatTitle(titleString, ModelGUI.TABLE_TITLE_HEIGTH);
            this.add(title, BorderLayout.NORTH);
            this.add(panelScaleVectorGraphics, BorderLayout.CENTER);
        } 
        catch (Exception e)
        {
        }
 
    }
 
    public String getTitleString()
    {
        return titleString;
    }
   
    public void setTitleString(String text)
    {
        this.titleString = text;
        title.setText(titleString);
    }
    
    public int getDimensionHeight()
    {
        return dimensionHeight;
    }
 
    public void setDimensionHeight(int dimensionHeight)
    {
        this.dimensionHeight = dimensionHeight;
    }
 
    public int getDimensionWidth()
    {
        return dimensionWidth;
    }
 
    public void setDimensionWidth(int dimensionWidth)
    {
        this.dimensionWidth = dimensionWidth;
    }
    
    public void loadSVG()
    {
        if (loadedSVG == false)
        {
            try
            {
                int timeout = 5000;
                if (device instanceof VmsGeneral)
                {
                    VmsGeneral vms = (VmsGeneral)device;
                    if (vms.getDeviceInformation().dgtmat != null)
                        timeout = 120000;
                }
                InteropParameters parameters = Invokes.getParameters(ServerServiceName.UNKNOWN, "getScalableVectorGraphics", new InteropParameter("name", "status"));
                InteropResponse response = (InteropResponse) device.invoke("get", parameters, timeout, Shared.isConnectionExternal);
                byte[] dataSVG = (byte[])response.getValue()[0];
                
                if (dataSVG.length > 0) 
                {
                    reload(dataSVG);
                    loadedSVG = true;
                }
            } 
            catch (Exception e)
            {
            }
        }        
    }        
}