Subversion Repositories jheat

Rev

Rev 1 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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