Alejandro Acuña
2025-04-29 d1d736e487d9eb104dcae9def948066037afd2f0
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
package art.client.GUI.components.devices.window.colors.rtz32.tables;
 
import art.library.gui.FlatGUI;
import art.library.gui.flat.FlatLabel;
import art.library.gui.flat.FlatPanel;
import art.library.gui.flat.FlatScrollPane;
import art.library.gui.flat.FlatTableInput;
import art.library.gui.flat.table.FlatCellRender;
import art.library.gui.flat.table.FlatTable;
import art.library.gui.flat.table.Model.TableDataColumn;
import art.library.model.devices.colors.controller.RTZ32.RTZ32_ControllerConfiguration;
import art.library.utils.resources.Resources;
import java.awt.Color;
import java.awt.Component;
import java.awt.Insets;
import java.io.File;
import java.nio.file.Files;
import javax.swing.JEditorPane;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.border.Border;
import javax.swing.border.MatteBorder;
 
public class Table extends FlatPanel
{
    protected RTZ32_ControllerConfiguration configuration = null;
    protected boolean editable = false;
    protected FlatTable table = null;
    protected FlatTableInput tableinput = null;
    protected JEditorPane tooltip = null;
    protected FlatScrollPane scrollpane = null;
    
    public Table(RTZ32_ControllerConfiguration configuration, String filename)
    {
        this.tooltip = new JEditorPane();
        this.tooltip.setContentType("text/html");
        this.tooltip.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
        this.tooltip.setFont(FlatGUI.lookDesign.getFont("label.font"));
        this.tooltip.setBackground(FlatGUI.lookDesign.getColor("tooltip.color.background"));
        this.tooltip.setForeground(FlatGUI.lookDesign.getColor("tooltip.color.foreground"));
        this.tooltip.setEditable(false);
                
        
        try
        {
            // TODO:es-ES coger el idioma del cliente
            
            File file = new File("data/art.client/rtz32/tooltips/es-ES/" + filename);
 
            if (file.exists() == true)
            {
                tooltip.setText(new String(Files.readAllBytes(file.toPath())));
            }
            else
            {
                tooltip.setText(new String(Resources.getResourceBytes("data/art.client/rtz32/tooltips/es-ES/" + filename)));
            }
        }
        catch (Exception exception)
        {
        }
 
        scrollpane = new FlatScrollPane(tooltip);
    }
    
 
    public void editable(boolean value)
    {
    }    
    
    
    
    public void reload(RTZ32_ControllerConfiguration configuration)
    {
        this.configuration = configuration;
    }
    
    
    
 
    protected class MyTableCellRenderHeader extends FlatCellRender
    {
        private Border border = null;
        
        public MyTableCellRenderHeader(FlatTable table, Insets borderInsets)
        {
            super(table);
 
            border = new MatteBorder(borderInsets.top, borderInsets.left, borderInsets.bottom, borderInsets.right, flatTable.getLook().headerColorBorder.darker());
        
            this.flatLabel.getLook().opaque = true;
            this.flatLabel.getLook().font = flatTable.getLook().headerFont;
            this.flatLabel.getLook().colorBackground =  flatTable.getLook().headerColorBackground;
            this.flatLabel.getLook().colorForeground = flatTable.getLook().headerColorForeground;
            this.flatLabel.getLook().horizontalAlignment = SwingConstants.CENTER;
 
 
            this.flatLabelSelected.getLook().font = flatTable.getLook().cellFontSelected;
            this.flatLabelSelected.getLook().opaque = flatTable.getLook().cellOpaqueSelected;
            this.flatLabelSelected.getLook().colorBackground = flatTable.getLook().cellColorBackgroundSelected;
            this.flatLabelSelected.getLook().colorForeground = flatTable.getLook().cellColorForegroundSelected;
            this.flatLabelSelected.getLook().horizontalAlignment = SwingConstants.CENTER;
        }
    
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
        {
            this.flatLabel.setBorder(border);  
            this.flatLabelSelected.setBorder(border);
            
            if (isSelected)
            {
                if (value != null)
                {
                    flatLabelSelected.setText(value.toString());
                }
                else
                {
                    flatLabelSelected.setText("");
                }
 
                return flatLabelSelected;
            } 
            else
            {
                if (value != null)
                {
                    flatLabel.setText(value.toString());
                }
                else
                {
                    flatLabel.setText("");
                }
 
                return flatLabel;
            }
        }
    }        
 
 
 
 
    protected class MyTableCellRenderValue extends FlatCellRender
    {
        private Border border = null;
 
        private FlatLabel flatLabel0 = new FlatLabel();
        private FlatLabel flatLabelSelected0 = new FlatLabel();
        
        public MyTableCellRenderValue(FlatTable table, Insets borderInsets)
        {
            super(table);
 
            border = new MatteBorder(borderInsets.top, borderInsets.left, borderInsets.bottom, borderInsets.right, flatTable.getLook().headerColorBorder.darker());
 
            this.flatLabel.getLook().opaque = true;
            this.flatLabel.getLook().font = flatTable.getLook().headerFont;
            this.flatLabel.getLook().colorBackground =  FlatGUI.lookDesign.getColor("table.color.background");
            this.flatLabel.getLook().colorForeground = flatTable.getLook().cellColorForeground;
            this.flatLabel.getLook().horizontalAlignment = SwingConstants.CENTER;
            this.flatLabel.getLook().border = true;
            
            this.flatLabelSelected.getLook().font = flatTable.getLook().cellFontSelected;
            this.flatLabelSelected.getLook().opaque = flatTable.getLook().cellOpaqueSelected;
            this.flatLabelSelected.getLook().colorBackground = flatTable.getLook().cellColorBackgroundSelected;
            this.flatLabelSelected.getLook().colorForeground = flatTable.getLook().cellColorForegroundSelected;
            this.flatLabelSelected.getLook().horizontalAlignment = SwingConstants.CENTER;
            this.flatLabelSelected.getLook().border = true;
            this.flatLabelSelected.revalidate();
            
            this.flatLabel0.getLook().opaque = true;
            this.flatLabel0.getLook().font = flatTable.getLook().headerFont;
            this.flatLabel0.getLook().colorBackground =  FlatGUI.lookDesign.getColor("table.color.background");
            this.flatLabel0.getLook().colorForeground = Color.lightGray;
            this.flatLabel0.getLook().horizontalAlignment = SwingConstants.CENTER;
            this.flatLabel0.getLook().border = true;
 
            this.flatLabelSelected0.getLook().font = flatTable.getLook().cellFontSelected;
            this.flatLabelSelected0.getLook().opaque = flatTable.getLook().cellOpaqueSelected;
            this.flatLabelSelected0.getLook().colorBackground = flatTable.getLook().cellColorBackgroundSelected;
            this.flatLabelSelected0.getLook().colorForeground = Color.lightGray;
            this.flatLabelSelected0.getLook().horizontalAlignment = SwingConstants.CENTER;
            this.flatLabelSelected0.getLook().border = true;
            
        }
    
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
        {
            this.flatLabel.setBorder(border);  
            this.flatLabelSelected.setBorder(border);
            this.flatLabel0.setBorder(border);  
            this.flatLabelSelected0.setBorder(border);
            
            if (isSelected)
            {
                if (value != null)
                {
                    if ((value instanceof Integer) && ((Integer)value == 0))
                    {
                        flatLabelSelected0.setText(value.toString());
                        return flatLabelSelected0;
                    }
 
                    flatLabelSelected.setText(value.toString());
                    return flatLabelSelected;
                }
 
                flatLabelSelected.setText("");
                return flatLabelSelected;
            } 
            else
            {
                if (value != null)
                {
                    if ((value instanceof Integer) && ((Integer)value == 0))
                    {
                        flatLabel0.setText(value.toString());
                        return flatLabel0;
                    }
 
                    flatLabel.setText(value.toString());
                    return flatLabel;
                }
                
                flatLabel.setText("");
                return flatLabel;
            }
            
        }
    }    
 
    
 
 
    
    
    protected class MyTableCellRenderBoolean extends FlatCellRender
    {
        private Border border = null;
 
        
        public MyTableCellRenderBoolean(FlatTable table, Insets borderInsets)
        {
            super(table);
 
            border = new MatteBorder(borderInsets.top, borderInsets.left, borderInsets.bottom, borderInsets.right, flatTable.getLook().headerColorBorder.darker());
 
            this.flatLabel.getLook().opaque = true;
            this.flatLabel.getLook().font = flatTable.getLook().headerFont;
            this.flatLabel.getLook().colorBackground =  FlatGUI.lookDesign.getColor("table.color.background");
            this.flatLabel.getLook().colorForeground = flatTable.getLook().cellColorForeground;
            this.flatLabel.getLook().horizontalAlignment = SwingConstants.CENTER;
            this.flatLabel.getLook().border = true;
 
            this.flatLabelSelected.getLook().font = flatTable.getLook().cellFontSelected;
            this.flatLabelSelected.getLook().opaque = flatTable.getLook().cellOpaqueSelected;
            this.flatLabelSelected.getLook().colorBackground = flatTable.getLook().cellColorBackgroundSelected;
            this.flatLabelSelected.getLook().colorForeground = flatTable.getLook().cellColorForegroundSelected;
            this.flatLabelSelected.getLook().horizontalAlignment = SwingConstants.CENTER;
            this.flatLabelSelected.getLook().border = true;
 
            this.flatCheck.getLook().opaque = true;
            this.flatCheck.getLook().font = flatTable.getLook().headerFont;
            this.flatCheck.getLook().colorBackground =  FlatGUI.lookDesign.getColor("table.color.background");
            this.flatCheck.getLook().colorForeground = flatTable.getLook().cellColorForeground;
            this.flatCheck.getLook().horizontalAlignment = SwingConstants.CENTER;
            this.flatCheck.getLook().border = true;
 
            this.flatCheckSelected.getLook().font = flatTable.getLook().cellFontSelected;
            this.flatCheckSelected.getLook().opaque = flatTable.getLook().cellOpaqueSelected;
            this.flatCheckSelected.getLook().colorBackground = flatTable.getLook().cellColorBackgroundSelected;
            this.flatCheckSelected.getLook().colorForeground = flatTable.getLook().cellColorForegroundSelected;
            this.flatCheckSelected.getLook().horizontalAlignment = SwingConstants.CENTER;
            this.flatCheckSelected.getLook().border = true;
 
        }
    
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
        {
            this.flatLabel.setBorder(border);  
            this.flatLabelSelected.setBorder(border);
            this.flatCheck.setBorder(border);  
            this.flatCheckSelected.setBorder(border);
            
            if (value == null)
            {
                if (isSelected)
                {
                    flatLabelSelected.setText("");
                    return flatLabelSelected;
                }
                else
                {
                    flatLabel.setText("");
                    return flatLabel;
                }
            }
            
            if (isSelected)
            {
                flatCheckSelected.setSelected(((Boolean)value).booleanValue());
                return flatCheckSelected;
            } 
            else
            {
                flatCheck.setSelected(((Boolean)value).booleanValue());
                return flatCheck;
            }
        }
    }    
 
 
    
 
    
    protected TableDataColumn newTableDataColumn(String name, String field, float width, boolean editable, boolean visibility, int alingnment, int min, int max)
    {
        TableDataColumn data = TableDataColumn.newTableDataColumnNumeric(name, field, width, editable, visibility, alingnment);
        
        try
        {
            data.markChanges = true;
            data.renderType = TableDataColumn.CELL_RENDER_NUMERIC;
            data.editorType = TableDataColumn.CELL_EDITOR_NUMERIC;
            data.minValue = min;
            data.maxValue = max;
            data.numeric = true;
        }
        catch (Exception exception)
        {
            exception.printStackTrace();
        }
        
        return data;
    }
       
    
    
    
 
     
//                table.tableCellEditor.addCellEditorListener(new CellEditorListener() 
//                {
//                    public void editingCanceled(ChangeEvent e) {
//                        System.out.println("The user canceled editing.");
//                    }
//
//                    public void editingStopped(ChangeEvent e) {
//                        System.out.println("The user stopped editing successfully.");
//                    }
//                });
//
//                
    
}