Subversion Repositories jheat

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 andreas 1
package heizung;
2
 
3
import java.awt.event.ActionEvent;
4
import java.awt.event.ActionListener;
5
import java.util.Calendar;
6
import java.util.Date;
7
 
4 andreas 8
import javax.swing.GroupLayout;
9
import javax.swing.ImageIcon;
10
import javax.swing.JButton;
11
import javax.swing.JComboBox;
12
import javax.swing.JFrame;
13
import javax.swing.JLabel;
14
import javax.swing.JTextField;
15
import javax.swing.LayoutStyle;
16
 
17
public class heizung implements ActionListener
18
{
19
	private boolean DEBUG = false;
20
 
2 andreas 21
	// Network
22
	private String strServerName = "www.theosys.at";
1 andreas 23
	// Head
24
	private JComboBox cmbWDay = new JComboBox();
4 andreas 25
	// Info
26
	private JTextField tfActTemp = new JTextField();
27
	private JTextField tfPressure = new JTextField();
1 andreas 28
	// Spalte 2 - Von
29
	private JTextField tfVon_1 = new JTextField();
30
	private JTextField tfVon_2 = new JTextField();
31
	private JTextField tfVon_3 = new JTextField();
32
	private JTextField tfVon_4 = new JTextField();
33
	private JTextField tfVon_5 = new JTextField();
34
	private JTextField tfVon_6 = new JTextField();
35
	private JTextField tfVon_7 = new JTextField();
36
	private JTextField tfVon_8 = new JTextField();
37
	private JTextField tfVon_9 = new JTextField();
38
	private JTextField tfVon_10 = new JTextField();
39
	// Spalte 3 - Bis
40
	private JTextField tfBis_1 = new JTextField();
41
	private JTextField tfBis_2 = new JTextField();
42
	private JTextField tfBis_3 = new JTextField();
43
	private JTextField tfBis_4 = new JTextField();
44
	private JTextField tfBis_5 = new JTextField();
45
	private JTextField tfBis_6 = new JTextField();
46
	private JTextField tfBis_7 = new JTextField();
47
	private JTextField tfBis_8 = new JTextField();
48
	private JTextField tfBis_9 = new JTextField();
49
	private JTextField tfBis_10 = new JTextField();
50
	// Spalte 4 - Temperatur
51
	private JTextField tfTemp_1 = new JTextField();
52
	private JTextField tfTemp_2 = new JTextField();
53
	private JTextField tfTemp_3 = new JTextField();
54
	private JTextField tfTemp_4 = new JTextField();
55
	private JTextField tfTemp_5 = new JTextField();
56
	private JTextField tfTemp_6 = new JTextField();
57
	private JTextField tfTemp_7 = new JTextField();
58
	private JTextField tfTemp_8 = new JTextField();
59
	private JTextField tfTemp_9 = new JTextField();
60
	private JTextField tfTemp_10 = new JTextField();
2 andreas 61
	// Bottom line with buttons
62
	private JButton btSave = new JButton();
63
	private JButton btExit = new JButton();
64
	private JButton btSchema = new JButton();
4 andreas 65
	// Window
66
	public JFrame frame = null;
1 andreas 67
 
68
	private int actWDay = 0;
69
 
70
	private void createAndShowGUI() {
71
		// The main window
4 andreas 72
		frame = new JFrame("Heizung");
1 andreas 73
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
4 andreas 74
		frame.setTitle("Heizung");
75
		java.net.URL imgURL = heizung.class.getResource("images/icon_heizung.png");
1 andreas 76
 
4 andreas 77
		if (imgURL != null)
78
		{
79
			ImageIcon img = new ImageIcon(imgURL);
80
			frame.setIconImage(img.getImage());
81
		}
82
 
1 andreas 83
		// The content of the window
4 andreas 84
		tfActTemp.setEditable(false);
85
		tfPressure.setEditable(false);
86
 
87
		// Headline
1 andreas 88
		JLabel lbl_WDay = new JLabel("Wochentag");
89
		JLabel lbl_top1 = new JLabel("#");
90
		JLabel lbl_top2 = new JLabel("Von");
91
		JLabel lbl_top3 = new JLabel("Bis");
92
		JLabel lbl_top4 = new JLabel("Temp");
93
 
4 andreas 94
		// Infos
95
		JLabel lbl_ActTemp = new JLabel("Raumtemperatur");
96
		JLabel lbl_Pressure = new JLabel("Luftdruck");
97
 
1 andreas 98
		// Spalte 1
99
		JLabel lbl_1 = new JLabel("1");
100
		JLabel lbl_2 = new JLabel("2");
101
		JLabel lbl_3 = new JLabel("3");
102
		JLabel lbl_4 = new JLabel("4");
103
		JLabel lbl_5 = new JLabel("5");
104
		JLabel lbl_6 = new JLabel("6");
105
		JLabel lbl_7 = new JLabel("7");
106
		JLabel lbl_8 = new JLabel("8");
107
		JLabel lbl_9 = new JLabel("9");
108
		JLabel lbl_10 = new JLabel("10");
109
		// Initialize the combo box
110
		cmbWDay.addActionListener(this);
111
		cmbWDay.addItem("Montag");
112
		cmbWDay.addItem("Dienstag");
113
		cmbWDay.addItem("Mittwoch");
114
		cmbWDay.addItem("Donnerstag");
115
		cmbWDay.addItem("Freitag");
116
		cmbWDay.addItem("Samstag");
117
		cmbWDay.addItem("Sonntag");
118
 
119
		Calendar cal = Calendar.getInstance();
120
		cal.setTime(new Date());
121
		actWDay = cal.get(Calendar.DAY_OF_WEEK);
122
 
123
		if (actWDay == Calendar.SUNDAY)
124
			actWDay = 7;
125
		else
126
			actWDay--;
127
 
128
		cmbWDay.setSelectedIndex(actWDay - 1);
2 andreas 129
		// Initialize the buttons
130
		btSave.setText("Speichern");
131
		btSave.addActionListener(new java.awt.event.ActionListener() {
132
			public void actionPerformed(java.awt.event.ActionEvent e) {
133
				saveButtonActionPerformed(e);
134
			}
135
		});
136
 
137
		btExit.setText("Exit");
138
		btExit.addActionListener(new java.awt.event.ActionListener() {
139
            public void actionPerformed(java.awt.event.ActionEvent e) {
140
            	exitButtonActionPerformed(e);
141
            }
142
		});
143
 
144
		btSchema.setText("Schema");
145
		btSchema.addActionListener(new java.awt.event.ActionListener() {
146
            public void actionPerformed(java.awt.event.ActionEvent e) {
4 andreas 147
            	schemaButtonActionPerformed(e);
2 andreas 148
            }
149
		});
150
 
1 andreas 151
		// Define and initialize the layout
152
		GroupLayout layout = new GroupLayout(frame.getContentPane());
153
		frame.getContentPane().setLayout(layout);
154
		layout.setHorizontalGroup(
155
	            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
156
	            .addGroup(layout.createSequentialGroup()
157
	                .addContainerGap()
158
	                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
159
	                	.addGroup(layout.createSequentialGroup()
160
	                		.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
4 andreas 161
	                		.addComponent(lbl_WDay, GroupLayout.PREFERRED_SIZE, lbl_ActTemp.getPreferredSize().width, GroupLayout.PREFERRED_SIZE)
1 andreas 162
	                		.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
163
	                		.addComponent(cmbWDay, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE))
4 andreas 164
	                	.addGroup(layout.createSequentialGroup()
165
	                		.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
166
	                		.addComponent(lbl_ActTemp, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
167
	                		.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
168
	                		.addComponent(tfActTemp, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE))
169
	                	.addGroup(layout.createSequentialGroup()
170
	                		.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
171
	                		.addComponent(lbl_Pressure, GroupLayout.PREFERRED_SIZE, lbl_ActTemp.getPreferredSize().width, GroupLayout.PREFERRED_SIZE)
172
	                		.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
173
	                		.addComponent(tfPressure, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE))
1 andreas 174
	                    .addGroup(layout.createSequentialGroup()
175
	                    	.addComponent(lbl_top1, GroupLayout.PREFERRED_SIZE, 10, GroupLayout.PREFERRED_SIZE)
176
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
177
	                    	.addComponent(lbl_top2, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
178
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
179
	                    	.addComponent(lbl_top3, GroupLayout.PREFERRED_SIZE, 45, GroupLayout.PREFERRED_SIZE)
180
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
181
	                    	.addComponent(lbl_top4, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE))
182
	                    .addGroup(layout.createSequentialGroup()
183
	                    	.addComponent(lbl_1, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE)
184
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
185
	                    	.addComponent(tfVon_1, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
186
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
187
	                    	.addComponent(tfBis_1, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
188
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
189
	                    	.addComponent(tfTemp_1, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
190
	                    .addGroup(layout.createSequentialGroup()
191
	                    	.addComponent(lbl_2, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE)
192
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
193
	                    	.addComponent(tfVon_2, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
194
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
195
	                    	.addComponent(tfBis_2, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
196
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
197
	                    	.addComponent(tfTemp_2, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
198
	                    .addGroup(layout.createSequentialGroup()
199
	                    	.addComponent(lbl_3, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE)
200
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
201
	                    	.addComponent(tfVon_3, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
202
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
203
	                    	.addComponent(tfBis_3, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
204
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
205
	                    	.addComponent(tfTemp_3, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
206
	                    .addGroup(layout.createSequentialGroup()
207
	                    	.addComponent(lbl_4, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE)
208
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
209
	                    	.addComponent(tfVon_4, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
210
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
211
	                    	.addComponent(tfBis_4, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
212
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
213
	                    	.addComponent(tfTemp_4, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
214
	                    .addGroup(layout.createSequentialGroup()
215
	                    	.addComponent(lbl_5, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE)
216
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
217
	                    	.addComponent(tfVon_5, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
218
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
219
	                    	.addComponent(tfBis_5, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
220
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
221
	                    	.addComponent(tfTemp_5, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
222
	                    .addGroup(layout.createSequentialGroup()
223
	                    	.addComponent(lbl_6, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE)
224
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
225
	                    	.addComponent(tfVon_6, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
226
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
227
	                    	.addComponent(tfBis_6, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
228
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
229
	                    	.addComponent(tfTemp_6, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
230
	                    .addGroup(layout.createSequentialGroup()
231
	                    	.addComponent(lbl_7, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE)
232
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
233
	                    	.addComponent(tfVon_7, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
234
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
235
	                    	.addComponent(tfBis_7, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
236
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
237
	                    	.addComponent(tfTemp_7, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
238
	                    .addGroup(layout.createSequentialGroup()
239
	                    	.addComponent(lbl_8, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE)
240
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
241
	                    	.addComponent(tfVon_8, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
242
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
243
	                    	.addComponent(tfBis_8, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
244
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
245
	                    	.addComponent(tfTemp_8, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
246
	                    .addGroup(layout.createSequentialGroup()
247
	                    	.addComponent(lbl_9, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE)
248
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
249
	                    	.addComponent(tfVon_9, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
250
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
251
	                    	.addComponent(tfBis_9, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
252
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
253
	                    	.addComponent(tfTemp_9, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
254
	                    .addGroup(layout.createSequentialGroup()
255
	                    	.addComponent(lbl_10, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE)
256
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
257
	                    	.addComponent(tfVon_10, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
258
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
259
	                    	.addComponent(tfBis_10, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
260
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
2 andreas 261
	                    	.addComponent(tfTemp_10, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
262
	                    .addGroup(layout.createSequentialGroup()
263
	                    	.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
264
	                    	.addComponent(btSave, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
265
	                    	.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
266
	                    	.addComponent(btSchema, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
267
	                    	.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
268
	                    	.addComponent(btExit, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
1 andreas 269
	                .addContainerGap(27, Short.MAX_VALUE))
270
	        );
271
 
272
 
273
        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {lbl_top1, lbl_top2, lbl_top3, lbl_top4});
274
 
275
        layout.setVerticalGroup(
276
                layout.createParallelGroup(GroupLayout.Alignment.LEADING)
277
                .addGroup(layout.createSequentialGroup()
278
                    .addContainerGap()
279
                    .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
4 andreas 280
                		.addComponent(lbl_WDay)
281
                		.addComponent(cmbWDay))
282
                    .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
283
                		.addComponent(lbl_ActTemp)
284
                		.addComponent(tfActTemp))
285
                    .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
286
                		.addComponent(lbl_Pressure)
287
                		.addComponent(tfPressure))
1 andreas 288
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
289
                    	.addComponent(lbl_top1)
290
                    	.addComponent(lbl_top2)
291
                    	.addComponent(lbl_top3)
292
                    	.addComponent(lbl_top4))
293
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
294
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
295
                    	.addComponent(lbl_1)
296
                    	.addComponent(tfVon_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
297
                    	.addComponent(tfBis_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
298
                    	.addComponent(tfTemp_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
299
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
300
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
301
                    	.addComponent(lbl_2)
302
                    	.addComponent(tfVon_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
303
                    	.addComponent(tfBis_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
304
                    	.addComponent(tfTemp_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
305
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
306
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
307
                    	.addComponent(lbl_3)
308
                    	.addComponent(tfVon_3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
309
                    	.addComponent(tfBis_3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
310
                    	.addComponent(tfTemp_3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
311
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
312
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
313
                    	.addComponent(lbl_4)
314
                    	.addComponent(tfVon_4, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
315
                    	.addComponent(tfBis_4, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
316
                    	.addComponent(tfTemp_4, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
317
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
318
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
319
                    	.addComponent(lbl_5)
320
                    	.addComponent(tfVon_5, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
321
                    	.addComponent(tfBis_5, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
322
                    	.addComponent(tfTemp_5, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
323
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
324
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
325
                    	.addComponent(lbl_6)
326
                    	.addComponent(tfVon_6, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
327
                    	.addComponent(tfBis_6, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
328
                    	.addComponent(tfTemp_6, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
329
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
330
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
331
                    	.addComponent(lbl_7)
332
                    	.addComponent(tfVon_7, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
333
                    	.addComponent(tfBis_7, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
334
                    	.addComponent(tfTemp_7, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
335
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
336
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
337
                    	.addComponent(lbl_8)
338
                    	.addComponent(tfVon_8, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
339
                    	.addComponent(tfBis_8, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
340
                    	.addComponent(tfTemp_8, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
341
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
342
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
343
                    	.addComponent(lbl_9)
344
                    	.addComponent(tfVon_9, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
345
                    	.addComponent(tfBis_9, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
346
                    	.addComponent(tfTemp_9, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
347
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
348
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
349
                    	.addComponent(lbl_10)
350
                    	.addComponent(tfVon_10, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
351
                    	.addComponent(tfBis_10, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
352
                    	.addComponent(tfTemp_10, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
353
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
2 andreas 354
	                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
355
	                    	.addComponent(btSave, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
356
	                    	.addComponent(btSchema, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
357
	                    	.addComponent(btExit, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
358
	                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
1 andreas 359
	                .addContainerGap(21, Short.MAX_VALUE))
360
	        );
361
		//Display the window.
362
        frame.pack();
363
        frame.setVisible(true);
364
	}
365
 
2 andreas 366
	/**
367
     * This method performs saveButtonActionPerformed   
368
     */
4 andreas 369
	private void saveButtonActionPerformed(ActionEvent evt)
370
	{
2 andreas 371
		int idx = cmbWDay.getSelectedIndex();
372
 
373
		saveDay(idx + 1);
374
		clearLines();
375
		readDay(idx + 1);
376
	}
4 andreas 377
 
378
	private void schemaButtonActionPerformed(ActionEvent evt)
379
	{
380
		schema sch = new schema(frame.getOwner());
381
		sch.setModal(true);
382
		sch.setVisible(true);
383
 
384
		if (sch.getState())
385
		{
386
			clearLines();
387
			readDay(cmbWDay.getSelectedIndex() + 1);
388
		}
389
	}
390
 
391
	private void exitButtonActionPerformed(ActionEvent evt)
392
	{
2 andreas 393
		System.exit(0);
394
	}
1 andreas 395
 
396
	private String timeToString(long tm) {
397
		int hour, min;
398
 
399
		hour = (int)(tm / 3600);
400
		min = (int)((tm - (hour * 3600)) / 60);
401
		return String.format("%02d:%02d",hour, min);
402
	}
403
 
2 andreas 404
	private boolean isDigit(int ch)
405
	{
406
		if (ch < '0' || ch > '9')
407
			return false;
408
 
409
		return true;
410
	}
411
	private long stringToTime(String stm)
412
	{
413
		int hour, min, i;
414
		long tm;
415
 
416
		if (stm.length() != 5 || !stm.contains(":") || stm.indexOf(':') != 2)
417
			return 0;
418
 
419
		for (i = 0; i < stm.length(); i++)
420
		{
421
			if (i != 2 && !isDigit(stm.charAt(i)))
422
				return 0;
423
		}
424
 
425
		hour = Integer.parseInt(stm.substring(0, 2));
426
		min = Integer.parseInt(stm.substring(3, 5));
427
 
428
		if (hour < 0 || hour > 23 || min < 0 || min > 59)
429
			return 0;
430
 
431
		tm = (long)(hour * 3600 + min * 60);
432
		return tm;
433
	}
434
 
4 andreas 435
	private void decode(String str)
436
	{
1 andreas 437
		// Check for initial key word
438
		if (str.startsWith("LINE:"))
439
		{
440
		rm_str lr = new rm_str();
441
		String work;
442
		int line;
443
		int wday;
444
		long start;
445
		long end;
446
		float temp;
447
 
448
			if (str.startsWith("ERROR:"))
449
			{
450
				System.out.println(str);
451
				return;
452
			}
453
 
454
			lr.remove_string(str, "LINE:");
455
			str = lr.getRight();
456
			work = lr.remove_string(str, ":");
457
			str = lr.getRight();
458
			line = Integer.parseInt(work.substring(0, work.length() - 1));
459
 
460
			work = lr.remove_string(str, ":");
461
			str = lr.getRight();
462
			wday = Integer.parseInt(work.substring(0, work.length() - 1));
463
 
464
			work = lr.remove_string(str, ":");
465
			str = lr.getRight();
466
			start = Integer.parseInt(work.substring(0, work.length() - 1));
467
 
468
			work = lr.remove_string(str, ":");
469
			str = lr.getRight();
470
			end = Integer.parseInt(work.substring(0, work.length() - 1));
471
 
472
			temp = Float.parseFloat(str);
473
 
474
			if (line >= 1 && line <= 10 && wday >= 1 && wday <= 7 && start >= 0 && end >= 0 && start != end && temp > 0.0)
475
			{
476
				switch(line)
477
				{
478
					case 1:
479
						tfVon_1.setText(timeToString(start));
480
						tfBis_1.setText(timeToString(end));
481
						tfTemp_1.setText(String.format("%.1f",temp));
482
					break;
483
 
484
					case 2:
485
						tfVon_2.setText(timeToString(start));
486
						tfBis_2.setText(timeToString(end));
487
						tfTemp_2.setText(String.format("%.1f",temp));
488
					break;
489
 
490
					case 3:
491
						tfVon_3.setText(timeToString(start));
492
						tfBis_3.setText(timeToString(end));
493
						tfTemp_3.setText(String.format("%.1f",temp));
494
					break;
495
 
496
					case 4:
497
						tfVon_4.setText(timeToString(start));
498
						tfBis_4.setText(timeToString(end));
499
						tfTemp_4.setText(String.format("%.1f",temp));
500
					break;
501
 
502
					case 5:
503
						tfVon_5.setText(timeToString(start));
504
						tfBis_5.setText(timeToString(end));
505
						tfTemp_5.setText(String.format("%.1f",temp));
506
					break;
507
 
508
					case 6:
509
						tfVon_6.setText(timeToString(start));
510
						tfBis_6.setText(timeToString(end));
511
						tfTemp_6.setText(String.format("%.1f",temp));
512
					break;
513
 
514
					case 7:
515
						tfVon_7.setText(timeToString(start));
516
						tfBis_7.setText(timeToString(end));
517
						tfTemp_7.setText(String.format("%.1f",temp));
518
					break;
519
 
520
					case 8:
521
						tfVon_8.setText(timeToString(start));
522
						tfBis_8.setText(timeToString(end));
523
						tfTemp_8.setText(String.format("%.1f",temp));
524
					break;
525
 
526
					case 9:
527
						tfVon_9.setText(timeToString(start));
528
						tfBis_9.setText(timeToString(end));
529
						tfTemp_9.setText(String.format("%.1f",temp));
530
					break;
531
 
532
					case 10:
533
						tfVon_10.setText(timeToString(start));
534
						tfBis_10.setText(timeToString(end));
535
						tfTemp_10.setText(String.format("%.1f",temp));
536
					break;
537
				}
538
			}
539
		}
540
	}
541
 
542
	private void clearLines()
543
	{
544
		tfVon_1.setText("");
545
		tfBis_1.setText("");
546
		tfTemp_1.setText("");
547
		tfVon_2.setText("");
548
		tfBis_2.setText("");
549
		tfTemp_2.setText("");
550
		tfVon_3.setText("");
551
		tfBis_3.setText("");
552
		tfTemp_3.setText("");
553
		tfVon_4.setText("");
554
		tfBis_4.setText("");
555
		tfTemp_4.setText("");
556
		tfVon_5.setText("");
557
		tfBis_5.setText("");
558
		tfTemp_5.setText("");
559
		tfVon_6.setText("");
560
		tfBis_6.setText("");
561
		tfTemp_6.setText("");
562
		tfVon_7.setText("");
563
		tfBis_7.setText("");
564
		tfTemp_7.setText("");
565
		tfVon_8.setText("");
566
		tfBis_8.setText("");
567
		tfTemp_8.setText("");
568
		tfVon_9.setText("");
569
		tfBis_9.setText("");
570
		tfTemp_9.setText("");
571
		tfVon_10.setText("");
572
		tfBis_10.setText("");
573
		tfTemp_10.setText("");
574
	}
575
 
576
	private boolean readDay(int wday) {
4 andreas 577
		network nw = new network(strServerName);
1 andreas 578
		String answer;
579
 
580
		if (wday < 1 || wday > 7)
581
			return false;
582
 
4 andreas 583
		if (nw.connect())
1 andreas 584
		{
4 andreas 585
			boolean ok = false;
586
			int cmd = 0;
1 andreas 587
 
4 andreas 588
			// Request a particular day
589
			nw.write("GET WDAY:"+wday+";GET TEMP;GET PRESSURE;");
590
			answer = "";
1 andreas 591
 
4 andreas 592
			do
593
			{
594
				answer = nw.read();
595
				ok = false;
1 andreas 596
 
4 andreas 597
				if (answer.equals("OK"))
1 andreas 598
				{
4 andreas 599
					if (cmd >= 3)
1 andreas 600
						break;
4 andreas 601
					else
602
						ok = true;
603
				}
604
				else if (answer.equals("NAK") || answer.contains("ERROR:"))
605
					break;
606
				else if (answer.contains("LINE:"))
607
				{
608
					ok = true;
1 andreas 609
					decode(answer);
4 andreas 610
					cmd = 1;
1 andreas 611
				}
4 andreas 612
				else if (answer.contains("TEMP:"))
613
				{
614
					rm_str rm = new rm_str();
615
 
616
					rm.remove_string(answer, "TEMP:");
617
					tfActTemp.setText(rm.getRight()+" °C");
618
					ok = true;
619
					cmd = 2;
620
				}
621
				else if (answer.contains("PRESSURE:"))
622
				{
623
					rm_str rm = new rm_str();
624
 
625
					rm.remove_string(answer, "PRESSURE:");
626
					tfPressure.setText(rm.getRight()+" hPa");
627
					ok = true;
628
					cmd = 3;
629
				}
1 andreas 630
			}
4 andreas 631
			while(ok);
1 andreas 632
 
4 andreas 633
			nw.close();
1 andreas 634
		}
635
 
636
		return true;
637
	}
638
 
2 andreas 639
	public boolean saveDay(int wday)
640
	{
4 andreas 641
		network nw = new network(strServerName);
2 andreas 642
		String answer;
643
		int i, numLines = 0;
644
		int err = 0;
645
		float tp;
646
 
647
		if (wday < 1 || wday > 7)
648
			return false;
649
 
650
		// Find the number of complete lines
651
		if (!tfVon_1.getText().isEmpty() && !tfTemp_1.getText().isEmpty())
652
			numLines = 1;
653
 
654
		if (!tfVon_2.getText().isEmpty() && !tfTemp_2.getText().isEmpty())
655
			numLines = 2;
656
 
657
		if (!tfVon_3.getText().isEmpty() && !tfTemp_3.getText().isEmpty())
658
			numLines = 3;
659
 
660
		if (!tfVon_4.getText().isEmpty() && !tfTemp_4.getText().isEmpty())
661
			numLines = 4;
662
 
663
		if (!tfVon_5.getText().isEmpty() && !tfTemp_5.getText().isEmpty())
664
			numLines = 5;
665
 
666
		if (!tfVon_6.getText().isEmpty() && !tfTemp_6.getText().isEmpty())
667
			numLines = 6;
668
 
669
		if (!tfVon_7.getText().isEmpty() && !tfTemp_7.getText().isEmpty())
670
			numLines = 7;
671
 
672
		if (!tfVon_8.getText().isEmpty() && !tfTemp_8.getText().isEmpty())
673
			numLines = 8;
674
 
675
		if (!tfVon_9.getText().isEmpty() && !tfTemp_9.getText().isEmpty())
676
			numLines = 9;
677
 
678
		if (!tfVon_10.getText().isEmpty() && !tfTemp_10.getText().isEmpty())
679
			numLines = 10;
680
 
4 andreas 681
		if (nw.connect())
682
		{
683
			// Write out the actual day
684
			answer = "SET DAY:"+numLines+":"+wday;
2 andreas 685
 
4 andreas 686
			for (i = 0; i < numLines; i++)
2 andreas 687
			{
4 andreas 688
				String st;
2 andreas 689
 
4 andreas 690
				switch(i)
691
				{
692
					case 0:
693
						st = tfTemp_1.getText().replace(",", ".");
694
						tp = Float.parseFloat(st);
2 andreas 695
 
4 andreas 696
						if (stringToTime(tfBis_1.getText()) > 0 && tp > 5.0 && tp <= 30.0)
697
							answer += ":"+stringToTime(tfBis_1.getText())+":"+tp;
698
						else
699
							err = 1;
700
						break;
2 andreas 701
 
4 andreas 702
					case 1:
703
						st = tfTemp_2.getText().replace(",", ".");
704
						tp = Float.parseFloat(st);
705
 
706
						if (stringToTime(tfBis_2.getText()) > 0 && tp > 5.0 && tp <= 30.0)
707
							answer += ":"+stringToTime(tfBis_2.getText())+":"+tp;
708
						else
709
							err = 1;
710
					break;
711
 
712
					case 2:
713
						st = tfTemp_3.getText().replace(",", ".");
714
						tp = Float.parseFloat(st);
715
 
716
						if (stringToTime(tfBis_3.getText()) > 0 && tp > 5.0 && tp <= 30.0)
717
							answer += ":"+stringToTime(tfBis_3.getText())+":"+tp;
718
						else
719
							err = 1;
720
					break;
721
 
722
					case 3:
723
						st = tfTemp_4.getText().replace(",", ".");
724
						tp = Float.parseFloat(st);
725
 
726
						if (stringToTime(tfBis_4.getText()) > 0 && tp > 5.0 && tp <= 30.0)
727
							answer += ":"+stringToTime(tfBis_4.getText())+":"+tp;
728
						else
729
							err = 1;
730
					break;
731
 
732
					case 4:
733
						st = tfTemp_5.getText().replace(",", ".");
734
						tp = Float.parseFloat(st);
735
 
736
						if (stringToTime(tfBis_5.getText()) > 0 && tp > 5.0 && tp <= 30.0)
737
							answer += ":"+stringToTime(tfBis_5.getText())+":"+tp;
738
						else
739
							err = 1;
740
					break;
741
 
742
					case 5:
743
						st = tfTemp_6.getText().replace(",", ".");
744
						tp = Float.parseFloat(st);
745
 
746
						if (stringToTime(tfBis_6.getText()) > 0 && tp > 5.0 && tp <= 30.0)
747
							answer += ":"+stringToTime(tfBis_6.getText())+":"+tp;
748
						else
749
							err = 1;
750
					break;
751
 
752
					case 6:
753
						st = tfTemp_7.getText().replace(",", ".");
754
						tp = Float.parseFloat(st);
755
 
756
						if (stringToTime(tfBis_7.getText()) > 0 && tp > 5.0 && tp <= 30.0)
757
							answer += ":"+stringToTime(tfBis_7.getText())+":"+tp;
758
						else
759
							err = 1;
760
					break;
761
 
762
					case 7:
763
						st = tfTemp_8.getText().replace(",", ".");
764
						tp = Float.parseFloat(st);
765
 
766
						if (stringToTime(tfBis_8.getText()) > 0 && tp > 5.0 && tp <= 30.0)
767
							answer += ":"+stringToTime(tfBis_8.getText())+":"+tp;
768
						else
769
							err = 1;
770
					break;
771
 
772
					case 8:
773
						st = tfTemp_9.getText().replace(",", ".");
774
						tp = Float.parseFloat(st);
775
 
776
						if (stringToTime(tfBis_9.getText()) > 0 && tp > 5.0 && tp <= 30.0)
777
							answer += ":"+stringToTime(tfBis_9.getText())+":"+tp;
778
						else
779
							err = 1;
780
					break;
781
 
782
					case 9:
783
						st = tfTemp_10.getText().replace(",", ".");
784
						tp = Float.parseFloat(st);
785
 
786
						if (stringToTime(tfBis_10.getText()) > 0 && tp > 5.0 && tp <= 30.0)
787
							answer += ":"+stringToTime(tfBis_10.getText())+":"+tp;
788
						else
789
							err = 1;
790
					break;
791
				}
792
			}
793
 
794
			answer += ";";
795
 
796
			if (err == 0)
797
			{
798
				boolean ok = false;
2 andreas 799
 
4 andreas 800
				nw.write(answer);
2 andreas 801
 
4 andreas 802
				if (DEBUG)
803
					System.out.println("Send:"+answer);
2 andreas 804
 
4 andreas 805
				answer = "";
2 andreas 806
 
4 andreas 807
				do
808
				{
809
					answer = nw.read();
810
					ok = false;
811
 
812
					if (!answer.isEmpty())
813
					{
814
						ok = true;
2 andreas 815
 
4 andreas 816
						if (answer.contains("OK") || answer.contains("NAK") || answer.contains("ERROR:"))
817
							ok = false;
818
					}
819
				}
820
				while(ok);
2 andreas 821
 
4 andreas 822
				nw.close();
2 andreas 823
			}
824
 
4 andreas 825
			if (err == 0)
826
				return true;
827
			else
828
				return false;
2 andreas 829
		}
830
 
4 andreas 831
		return false;
2 andreas 832
	}
833
 
4 andreas 834
	public static void main(String[] args)
835
	{
2 andreas 836
		//Schedule a job for the event-dispatching thread:
1 andreas 837
        //creating and showing this application's GUI.
4 andreas 838
        javax.swing.SwingUtilities.invokeLater(new Runnable()
839
        {
840
            public void run()
841
            {
1 andreas 842
            	heizung thisClass = new heizung();
843
                thisClass.createAndShowGUI();
844
                thisClass.readDay(thisClass.actWDay);
845
            }
846
        });
847
	}
848
 
849
	@Override
4 andreas 850
	public void actionPerformed(ActionEvent e)
851
	{
1 andreas 852
		JComboBox cb = (JComboBox)e.getSource();
853
        int wday = cb.getSelectedIndex();
854
 
855
        if (wday >= 0 && wday < 7)
856
        {
857
        	actWDay = wday + 1;
858
        	clearLines();
859
        	readDay(actWDay);
860
        }
861
	}
862
}
863