Alejandro Acuña
2024-07-30 65a64a81d30f00f1fffd5da6866850e1308e1135
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
244
245
246
247
248
249
250
251
package art.client.GUI.components.devices.window.colors.rtz32.configuration;
 
import art.library.gui.flat.FlatTabbedPane;
import art.library.model.devices.colors.controller.RTZ32.RTZ32_Controller;
import art.library.model.devices.colors.controller.RTZ32.RTZ32_ControllerConfiguration;
import art.client.GUI.components.ArticPanel;
import art.client.GUI.components.devices.window.DeviceWindow;
import art.client.GUI.components.devices.window.colors.junction.configuration.PanelConfigurationGeneric;
import art.client.models.ModelGUI;
import art.library.gui.flat.FlatButton;
import art.library.gui.flat.FlatDialog;
import art.library.gui.flat.FlatPanel;
import art.library.gui.flat.FlatProgressBar;
import art.library.gui.flat.FlatWindow;
import art.library.interop.InteropParameters;
import art.library.interop.InteropResponse;
import art.library.interop.serialization.Serialization;
import art.library.model.devices.colors.controller.RTZ32.RTZ32_ControllerCommands;
import art.library.utils.resources.Resources;
import art.servers.Shared;
import art.servers.rtzserver.controller.ListenerImplementation;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.SwingUtilities;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
 
 
public class RTZ32_PanelConfiguration extends ArticPanel
{
    private RTZ32_Controller controller = null;
    private RTZ32_ControllerConfiguration configuration = null;
    private FlatTabbedPane flatTabbedPane = null;
    private PanelConfigurationGeneric selectedPanel = null;    
    private FlatButton buttonDownload = null;
    private FlatPanel panelContent = null;
    private FlatProgressBar progressbar = null;
    
    private RTZ32_PanelConfiguration_Programs panelConfiguration_Programs = null;
    private RTZ32_PanelConfiguration_Tables panelConfiguration_Tables = null;
    
        
    public RTZ32_PanelConfiguration(RTZ32_Controller controller)
    {
        this.controller = controller;
        reload();
    }
    
    public RTZ32_ControllerConfiguration getConfiguration()
    {
        return configuration;
    }
 
    public void setConfiguration(RTZ32_ControllerConfiguration configuration)
    {
        this.configuration = configuration;
    }
    
    
    public void reload()
    {
        try
        {
            deselection();
            this.configuration = (RTZ32_ControllerConfiguration)Serialization.clone(controller.getDeviceConfiguration());
            initialise();
        }
        catch (Exception e)
        {
        }
    }
 
 
    public void grants()
    {
    }
 
    public void help()
    {
    }
 
    public void timer()
    {
        try
        {
            // TODO 
            // rtz32.reading.progress
            // progressbar.setVisible(true);
            // progressbar.setValue(rtz32.reading.progress);
            // progressbar.setString(Shared.getMessage("Table") + " " + rtz32.reading.table);
        }
        catch (Exception exception)
        {
            progressbar.setValue(0);
            progressbar.setVisible(false);
        }
    }
 
    public void print()
    {
    }
 
    public void edit(boolean value)
    {
    }
 
   
 
    public void selection()
    {
        
        try
        {
            FlatWindow window = (FlatWindow) SwingUtilities.getRoot(this);
            window.addButtonSeparator();
            
            // TODO : grants
            window.addButtonMenu(buttonDownload);
            window.addComponent(progressbar);
            window.addTransparentSeparator(8);
            
            selectedPanel = (PanelConfigurationGeneric)flatTabbedPane.getSelectedComponent();
            selectedPanel.selection();
        }
        catch (Exception e)
        {
        }
    }
 
 
 
    public void deselection()
    {
        try
        {
            FlatWindow window = (FlatWindow) SwingUtilities.getRoot(this);
            window.addButtonSeparator();
            
            // TODO : grants
            window.removeComponentMenu(buttonDownload);
            window.removeComponentMenu(progressbar);
            selectedPanel.deselection();
        }
        catch (Exception e)
        {
        }
    }
    
    
    
 
    private void initialise()
    {
        if (configuration == null) return;
        
        
        removeAll();
        
        progressbar = new FlatProgressBar();
        {
            progressbar.setSize(new Dimension(128, 24));
            progressbar.setStringPainted(true);
            progressbar.setPreferredSize(new Dimension(128, 24));
            progressbar.setMaximumSize(new Dimension(128, 24));
            progressbar.setMinimum(0);
            progressbar.setMaximum(100);
            progressbar.setValue(0);        
            progressbar.setVisible(false);
        }
                
                
        buttonDownload = new FlatButton(Shared.getMessage("&Read tables"));
        buttonDownload.setPreferredSize(new Dimension(buttonDownload.getStringWidth(), 0));
        buttonDownload.setIcon(Resources.getResourceURL(ModelGUI.Icons.DOWNLOAD_24x24));
        buttonDownload.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                readTables();
            }
        });        
        
        
        panelConfiguration_Programs = new RTZ32_PanelConfiguration_Programs(configuration);
        panelConfiguration_Tables = new RTZ32_PanelConfiguration_Tables(configuration);
        
        flatTabbedPane = new FlatTabbedPane();
        {
            flatTabbedPane.addTab(Shared.getMessage("Programs"), panelConfiguration_Programs);
            flatTabbedPane.addTab(Shared.getMessage("Tables"), panelConfiguration_Tables);
            flatTabbedPane.allowTitleChange(false);
            flatTabbedPane.addChangeListener(new ChangeListener()
            {
                public void stateChanged(ChangeEvent e)
                {
                    deselection();
                    selection();
                }
            });
        }
        
        panelContent = new FlatPanel();
        {
            panelContent.setLayout(new BorderLayout());
            panelContent.add(flatTabbedPane, BorderLayout.CENTER);
        }
 
        this.setLayout(new BorderLayout());
        this.add(flatTabbedPane, BorderLayout.CENTER);
        this.selectedPanel = panelConfiguration_Programs;
        this.selectedPanel.selection();
    }
    
    
    
    private void readTables()
    {
        
        // TODO : Cambiar por invokes (listenerImplementation.xxxxxx)
        
        DeviceWindow window = (DeviceWindow)SwingUtilities.getRoot(RTZ32_PanelConfiguration.this);
        RTZ32_Controller rtz32 = (RTZ32_Controller)window.getDevice();
        
        try
        {
 
            // Comprobar si existe
            
            ListenerImplementation listenerImplementation = (art.servers.rtzserver.controller.ListenerImplementation)art.servers.rtzserver.Shared.controllerListenerHttps.getListenerImplementation();
            RTZ32_ControllerCommands commands = new RTZ32_ControllerCommands();
            commands.configurationRead = new Boolean(true);
            
            InteropParameters parameters = new InteropParameters();
            parameters.addParameter("language", "en-GB");
            parameters.addParameter("device", rtz32.getIdentifier());
            parameters.addBodycontent(commands);
            InteropResponse response = listenerImplementation.sendCommands(parameters);  
 
            // Barra de progreso
            
            timer();
        }
        catch (Exception exception)
        {
            FlatDialog.showDialog(window, Shared.getMessage("Error"), exception.getMessage(), true, FlatDialog.DIALOG_ERROR);
        }
    }
    
    
    
}