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
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
package art.servers.gui;
 
import art.library.gui.FlatGUI;
import art.library.gui.flat.FlatButton;
import art.library.gui.flat.FlatDialog;
import art.library.gui.flat.FlatMenu;
import art.library.gui.flat.FlatMenuBar;
import art.library.gui.flat.FlatMenuItem;
import art.library.gui.flat.FlatToggleButton;
import art.library.gui.flat.FlatWindow;
import art.library.model.transactions.traces.Trace;
import art.library.utils.resources.Resources;
import art.servers.Shared;
import art.servers.gui.components.PanelClock;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.MenuItem;
import java.awt.MouseInfo;
import java.awt.PointerInfo;
import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.TrayIcon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JToolBar;
import javax.swing.SwingUtilities;
 
public class ArticWindow extends FlatWindow
{
    protected ArticWindow window;
    protected MenuListener menuListener;
    protected MyActionListener myActionListener;
    protected javax.swing.Timer secondTimer = null;
    private FlatButton buttonExit = null;
    private FlatButton buttonHide = null;
    private FlatMenuItem menuExit = null;
    private FlatMenuItem menuHide = null;
    private PanelClock panelReloj;
    private ArticPanel articPanel;
 
    
    
    public ArticWindow()
    {
        super();
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.window = this;
        myActionListener = new MyActionListener();
        this.setIcon(Resources.getResourceURL(Shared.configuration.general.windowIcon));
        this.setTitle(Shared.configuration.general.windowTitle);
        this.setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
 
        secondTimer = new javax.swing.Timer(1000, new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                timer();
            }
        });
 
        menuWindow();
        menuBar();
        menuButtons();
        content();
        footer();
        reload();
        secondTimer.start();
        systemTry();
        
        addWindowListener(new WindowAdapter()
        {
            @Override
            public void windowClosing(WindowEvent evt)
            {
                int answer = FlatDialog.showDialog(ArticWindow.this, Shared.getMessage("Closing"), Shared.getMessage("Do you really want to close?"), true, FlatDialog.DIALOG_QUESTION);
 
                if (answer == JOptionPane.YES_OPTION)
                {
                    Shared.exit();
                }
            }
        });
    }
    
    
 
 
    public void addTrace(Object object)
    {
        if (object instanceof Trace)
        {
            articPanel.panelTraces.addTrace(object);    
        }
            
        articPanel.panelLogger.addTrace(object);
    }
        
        
    
    
    public ArticPanel getArticPanel()
    {
        return articPanel;
    }
    
    
    private void menuWindow() 
    {
    }
    
    
    private void menuBar()
    {
        FlatMenuBar menuBar = new FlatMenuBar();
 
        FlatMenu menu = new FlatMenu();
        menu.setText(Shared.getMessage("&File"));
 
        menuExit = new FlatMenuItem();
        menuExit.setText(Shared.getMessage("E&xit"));
        menuExit.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                salir(true);
            }
        });
 
        menuHide = new FlatMenuItem();
        menuHide.setText(Shared.getMessage("&Hide"));
        menuHide.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                setVisible(false);
            }
        });
 
        menu.add(menuHide);
        menu.addSeparator();
        menu.add(menuExit);
        menuBar.add(menu);
        this.setMenuBar(menuBar);
 
    }
    
    
    
 
    private void menuButtons()
    {
        JToolBar toolbar = new JToolBar();
        this.setMenuButtons(toolbar);
 
        buttonExit = new FlatButton(Shared.getMessage("E&xit"));
        buttonExit.setIcon(Resources.getResourceURL("data/art.library.server/icons/24x24/exit10.png"));
        buttonExit.setPreferredSize(new Dimension(buttonExit.getStringWidth(), 0));
        buttonExit.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                salir(true);
            }
        });
 
        buttonHide = new FlatButton(Shared.getMessage("&Hide"));
        buttonHide.setIcon(Resources.getResourceURL("data/art.library.server/icons/24x24/hide.png"));
        buttonHide.setPreferredSize(new Dimension(buttonHide.getStringWidth(), 0));
        buttonHide.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                setVisible(false);
            }
        });
 
        
        this.addButtonMenu(buttonExit);
        this.addButtonMenu(buttonHide);
        this.addButtonSeparator();
        
    }
    
    
    
    private void footer()
    {
        panelReloj = new PanelClock();
        setFooter(panelReloj, new Dimension(24, 24));        
    }
    
 
    public void messageFooter(String text)
    {
        panelReloj.message(text);
    }    
 
    private void content()
    {
        articPanel = new ArticPanel(this);
        this.setContent(articPanel);
        articPanel.selection();
    }
    
    
    
    private void salir(boolean ask)
    {
        if (ask == true)
        {
            int answer = FlatDialog.showDialog(ArticWindow.this, Shared.getMessage("Closing"), Shared.getMessage("Do you really want to close?"), true, FlatDialog.DIALOG_QUESTION);
            if (answer != JOptionPane.YES_OPTION) return;
        }
        
        Shared.traceInformation(Shared.getMessage("Graphic interface"), "Finishing");
        Shared.exit();
    }
    
    
    
    public void reload() 
    {
        articPanel.reload();
        panelReloj.reload();
    };
    
    
    
    
    public void grants() {};
    public void help() {};
    
    
    public void timer() 
    {
        if (this.isShowing() == true)
        {
            panelReloj.timer();
            articPanel.timer();
        }
    }    
    
    public void edit(boolean value) {};
 
    public void setMenuListener(MenuListener menuListener)
    {
        this.menuListener = menuListener;
    }
 
    public MenuListener getMenuListener()
    {
        return menuListener;
    }
 
    public void startGUI()
    {
        Runnable runnable = new Runnable()
        {
            public void run()
            {
                showGUI(true);
            }
        };
 
        SwingUtilities.invokeLater(runnable);
    }
 
 
    public void showGUI(int x, int y, int w, int h, boolean resizable, boolean automaticSystemLocation)
    {
        setLocation(x, y);
        if (automaticSystemLocation == true)
        {
            setLocationByPlatform(true);
        }
        setPreferredSize(new Dimension(w, h));
        setResizable(resizable);
        setVisible(true);
        pack();
    }
 
    
    public void showGUI(boolean automaticSystemLocation)
    {
        PointerInfo pointerInfo = MouseInfo.getPointerInfo();
        GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
        int x = (int) pointerInfo.getLocation().getX();
        int y = (int) pointerInfo.getLocation().getY();
        int screenWidth = gd.getDisplayMode().getWidth();
        int screenHeight = gd.getDisplayMode().getHeight();
        int w = screenWidth - (x % screenWidth);
        int h = screenHeight - (y % screenHeight);
        setLocation(x, y);
        if (automaticSystemLocation == true)
        {
            setLocationByPlatform(true);
        }
        setPreferredSize(new Dimension(w, h));
        setResizable(true);
        setVisible(true);
        pack();
 
    }
 
    
    
    private class MyActionListener implements ActionListener
    {
 
        public void actionPerformed(ActionEvent e)
        {
            String action = null;
 
            if (e.getSource() instanceof FlatMenuItem)
            {
                FlatMenuItem menuItem = (FlatMenuItem) e.getSource();
                action = menuItem.getName();
            } 
            else if (e.getSource() instanceof FlatButton)
            {
                FlatButton button = (FlatButton) e.getSource();
                action = button.getName();
            } 
            else if (e.getSource() instanceof FlatToggleButton)
            {
                FlatToggleButton button = (FlatToggleButton) e.getSource();
                action = button.getName();
            }
 
            MenuListener listener = window.getMenuListener();
 
            if ((action != null) && (listener != null))
            {
                if (listener != null)
                {
                    listener.menuSelection(action);
                }
            }
 
        }
 
    }
    
 
    
    private SystemTray tray = null;
    private TrayIcon trayIcon = null;
    private Image icon_STATUS = Resources.getResourceImage("data/" + Shared.getApplicationName() + "/icons/16x16/status-white.png");
    
    
    private void systemTry()
    {
        try
        {
            if (!SystemTray.isSupported()) 
            {
                return;
            }       
 
            PopupMenu popup = new PopupMenu();
            trayIcon = new TrayIcon(icon_STATUS, Shared.configuration.general.windowTitle);
            trayIcon.setPopupMenu(popup);
            tray = SystemTray.getSystemTray();        
 
            MenuItem aboutItem = new MenuItem(Shared.configuration.general.windowTitle);
            aboutItem.setFont(getFont().deriveFont(Font.BOLD));
            MenuItem lookItem = new MenuItem(Shared.getMessage("Look"));
            MenuItem showItem = new MenuItem(Shared.getMessage("Show"));
            MenuItem hideItem = new MenuItem(Shared.getMessage("Hide"));
            MenuItem exitItem = new MenuItem(Shared.getMessage("Exit")); 
 
            //Add components to pop-up menu
 
            popup.add(aboutItem);
            popup.addSeparator();
            popup.add(lookItem);
            popup.addSeparator();
            popup.add(showItem);
            popup.add(hideItem);
            popup.addSeparator();
            popup.add(exitItem);
            
            
            lookItem.addActionListener(new java.awt.event.ActionListener() 
            {
                public void actionPerformed(java.awt.event.ActionEvent evt) 
                {
                    FlatGUI.initialise();
                    repaint();
                }
            });
            
            showItem.addActionListener(new java.awt.event.ActionListener() 
            {
                public void actionPerformed(java.awt.event.ActionEvent evt) 
                {
                    setExtendedState(JFrame.NORMAL);
                    setVisible(true);
                }
            });
            
            hideItem.addActionListener(new java.awt.event.ActionListener() 
            {
                public void actionPerformed(java.awt.event.ActionEvent evt) 
                {
                    setVisible(false);
                }
            });
            
            exitItem.addActionListener(new java.awt.event.ActionListener() 
            {
                public void actionPerformed(java.awt.event.ActionEvent evt) 
                {
                    salir(false);
                }
            });
            
            tray.add(trayIcon);
            
        }
        catch (Exception e)
        {
        }
    }
    
    
 
    public abstract class MenuListener
    {
        public abstract void menuSelection(String option);
    }
 
}