-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebWait.java
More file actions
executable file
·201 lines (187 loc) · 7.1 KB
/
WebWait.java
File metadata and controls
executable file
·201 lines (187 loc) · 7.1 KB
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
/*
* Projet : Trustopics
* Version : 0.2.1
* Fichier : WebWait.java
*/
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.font.FontRenderContext;
import java.awt.font.TextAttribute;
import java.awt.font.TextLayout;
import java.awt.geom.AffineTransform;
import java.text.AttributedCharacterIterator;
import java.text.AttributedString;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JWindow;
public class WebWait extends Thread {
private final int glb_widthBorder = 6;
private final int glb_fontSize = 12;
private final String glb_text = "Connexion en cours...";
private JTextField glb_textField;
private JPanelCenter glb_centerPanel;
private JWindow glb_window;
private Font glb_font;
public WebWait() { start(); }
public void run() {
float lcl_cptCloseBox = Defines.WebWaitClose;
boolean lcl_stop = false;
int lcl_cpt = 0; while(lcl_cpt < Defines.WebWaitDialog) {
if (Defines.connectionIsOk) { lcl_stop = true; break; }
try { sleep(1000); }
catch(InterruptedException prm_ie) {}
lcl_cpt ++;
}
if (!lcl_stop) {
OpenBox();
while(!Defines.connectionIsOk) {
glb_centerPanel.SetColor(Color.WHITE);
glb_centerPanel.update(glb_centerPanel.getGraphics());
try { sleep(250); }
catch(InterruptedException prm_ie) {}
glb_centerPanel.SetColor(Color.BLACK);
glb_centerPanel.update(glb_centerPanel.getGraphics());
try { sleep(250); }
catch(InterruptedException prm_ie) {}
glb_textField.setText(" >> Délai : " + (int)lcl_cptCloseBox + " <<");
lcl_cptCloseBox -= 0.5;
if (lcl_cptCloseBox < 0) {
glb_window.dispose();
new TrustException("-= ERREUR =-",true).Action();
System.exit(1);
}
}
CloseBox();
}
}
private void CloseBox() {
glb_window.dispose();
}
private void OpenBox() {
glb_font = new Font("Dialog",Font.BOLD,glb_fontSize);
JPanelTop lcl_topPanel = new JPanelTop();
lcl_topPanel.setLayout(null);
lcl_topPanel.setBackground(Defines.UIcolForeGDrawingCDE1);
lcl_topPanel.setPreferredSize(new Dimension(1,glb_widthBorder));
JPanelBottom lcl_BottomPanel = new JPanelBottom();
lcl_BottomPanel.setLayout(null);
lcl_BottomPanel.setBackground(Defines.UIcolForeGDrawingCDE1);
lcl_BottomPanel.setPreferredSize(new Dimension(1,glb_widthBorder));
JPanelRight lcl_topRight = new JPanelRight();
lcl_topRight.setLayout(null);
lcl_topRight.setBackground(Defines.UIcolForeGDrawingCDE1);
lcl_topRight.setPreferredSize(new Dimension(glb_widthBorder,1));
JPanelLeft lcl_topLeft = new JPanelLeft();
lcl_topLeft.setLayout(null);
lcl_topLeft.setBackground(Defines.UIcolForeGDrawingCDE1);
lcl_topLeft.setPreferredSize(new Dimension(glb_widthBorder,1));
glb_centerPanel = new JPanelCenter();
glb_centerPanel.setLayout(null);
glb_centerPanel.setBackground(Defines.UIcolBackGDrawing);
glb_window = new JWindow();
glb_window.setSize(300,100);
glb_window.setLocationRelativeTo(null);
glb_window.getContentPane().setLayout(new BorderLayout());
glb_window.getContentPane().add(lcl_topPanel,BorderLayout.NORTH);
glb_window.getContentPane().add(lcl_BottomPanel,BorderLayout.SOUTH);
glb_window.getContentPane().add(lcl_topRight,BorderLayout.EAST);
glb_window.getContentPane().add(glb_centerPanel,BorderLayout.CENTER);
glb_window.getContentPane().add(lcl_topLeft,BorderLayout.WEST);
glb_window.setVisible(true);
}
public class JPanelTop extends JPanel {
public JPanelTop() {}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
g2.setPaint(Defines.UIcolForeGDrawingCDE1.brighter());
g2.drawLine(0,0,getWidth(),0);
g2.drawLine(0,0,0,getHeight());
g2.setPaint(Defines.UIcolForeGDrawingCDE1.darker());
g2.drawLine(glb_widthBorder,getHeight()-1,getWidth()-glb_widthBorder,getHeight()-1);
g2.drawLine(getWidth()-1,1,getWidth()-1,getHeight());
}
}
public class JPanelBottom extends JPanel {
public JPanelBottom() {}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
g2.setPaint(Defines.UIcolForeGDrawingCDE1.brighter());
g2.drawLine(glb_widthBorder,0,getWidth()-glb_widthBorder,0);
g2.drawLine(0,0,0,getHeight());
g2.setPaint(Defines.UIcolForeGDrawingCDE1.darker());
g2.drawLine(1,getHeight()-1,getWidth()-1,getHeight()-1);
g2.drawLine(getWidth()-1,0,getWidth()-1,getHeight()-1);
}
}
public class JPanelRight extends JPanel {
public JPanelRight() {}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
g2.setPaint(Defines.UIcolForeGDrawingCDE1.brighter());
g2.drawLine(0,0,0,getHeight());
g2.setPaint(Defines.UIcolForeGDrawingCDE1.darker());
g2.drawLine(getWidth()-1,0,getWidth()-1,getHeight()-1);
}
}
public class JPanelLeft extends JPanel {
public JPanelLeft() {}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
g2.setPaint(Defines.UIcolForeGDrawingCDE1.brighter());
g2.drawLine(0,0,0,getHeight());
g2.setPaint(Defines.UIcolForeGDrawingCDE1.darker());
g2.drawLine(getWidth()-1,0,getWidth()-1,getHeight()-1);
}
}
public class JPanelCenter extends JPanel {
private int glb_widthText;
private int glb_heightText;
private Color glb_color = Color.WHITE;
void SetColor(Color prm_color) { glb_color = prm_color; }
public JPanelCenter() {
GetTextDimensions();
glb_textField = new JTextField();
glb_textField.setEditable(false);
glb_textField.setBorder(BorderFactory.createEmptyBorder());
glb_textField.setBackground(Color.BLACK);
glb_textField.setForeground(Color.ORANGE);
glb_textField.setFont(new Font("Dialog",Font.BOLD,10));
glb_textField.setText("");
add(glb_textField);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
glb_textField.setBounds(0,0,getWidth(),16);
AffineTransform afT = new AffineTransform();
Font fontAffichage = glb_font.deriveFont(afT);
AttributedString ats = new AttributedString(glb_text);
ats.addAttribute(TextAttribute.FONT,fontAffichage);
AttributedCharacterIterator iter = ats.getIterator();
FontRenderContext frc = g2.getFontRenderContext();
TextLayout myLayout = new TextLayout(iter, frc);
g2.setPaint(glb_color);
myLayout.draw(g2,(getWidth() - glb_widthText) / 2,((getHeight() - glb_heightText) / 2) + (glb_heightText / 2));
}
public void GetTextDimensions() {
FontMetrics fontMetrics = getFontMetrics(glb_font);
glb_widthText = fontMetrics.stringWidth(glb_text);
glb_heightText = fontMetrics.getHeight();
}
}
}