Subversion Repositories jheat

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 4
Line 1... Line 1...
1
package heizung;
1
package heizung;
2
 
2
 
3
import javax.swing.JButton;
-
 
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;
3
import java.awt.event.ActionEvent;
11
import java.awt.event.ActionListener;
4
import java.awt.event.ActionListener;
12
import java.io.*;
-
 
13
import java.net.*;
-
 
14
import java.lang.Float;
-
 
15
import java.util.Calendar;
5
import java.util.Calendar;
16
import java.util.Date;
6
import java.util.Date;
17
 
7
 
-
 
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
 
18
public class heizung implements ActionListener {
17
public class heizung implements ActionListener
-
 
18
{
-
 
19
	private boolean DEBUG = false;
-
 
20
 
19
	// Network
21
	// Network
20
	private String strServerName = "www.theosys.at";
22
	private String strServerName = "www.theosys.at";
21
	// Head
23
	// Head
22
	private JComboBox cmbWDay = new JComboBox();
24
	private JComboBox cmbWDay = new JComboBox();
-
 
25
	// Info
-
 
26
	private JTextField tfActTemp = new JTextField();
-
 
27
	private JTextField tfPressure = new JTextField();
23
	// Spalte 2 - Von
28
	// Spalte 2 - Von
24
	private JTextField tfVon_1 = new JTextField();
29
	private JTextField tfVon_1 = new JTextField();
25
	private JTextField tfVon_2 = new JTextField();
30
	private JTextField tfVon_2 = new JTextField();
26
	private JTextField tfVon_3 = new JTextField();
31
	private JTextField tfVon_3 = new JTextField();
27
	private JTextField tfVon_4 = new JTextField();
32
	private JTextField tfVon_4 = new JTextField();
Line 55... Line 60...
55
	private JTextField tfTemp_10 = new JTextField();
60
	private JTextField tfTemp_10 = new JTextField();
56
	// Bottom line with buttons
61
	// Bottom line with buttons
57
	private JButton btSave = new JButton();
62
	private JButton btSave = new JButton();
58
	private JButton btExit = new JButton();
63
	private JButton btExit = new JButton();
59
	private JButton btSchema = new JButton();
64
	private JButton btSchema = new JButton();
-
 
65
	// Window
-
 
66
	public JFrame frame = null;
60
 
67
 
61
	private int actWDay = 0;
68
	private int actWDay = 0;
62
 
69
 
63
	private void createAndShowGUI() {
70
	private void createAndShowGUI() {
64
		// The main window
71
		// The main window
65
		JFrame frame = new JFrame("Heizung");
72
		frame = new JFrame("Heizung");
66
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
73
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
 
74
		frame.setTitle("Heizung");
-
 
75
		java.net.URL imgURL = heizung.class.getResource("images/icon_heizung.png");
-
 
76
 
-
 
77
		if (imgURL != null)
-
 
78
		{
-
 
79
			ImageIcon img = new ImageIcon(imgURL);
-
 
80
			frame.setIconImage(img.getImage());
-
 
81
		}
67
 
82
 
68
		// The content of the window
83
		// The content of the window
-
 
84
		tfActTemp.setEditable(false);
-
 
85
		tfPressure.setEditable(false);
-
 
86
 
-
 
87
		// Headline
69
		JLabel lbl_WDay = new JLabel("Wochentag");
88
		JLabel lbl_WDay = new JLabel("Wochentag");
70
		JLabel lbl_top1 = new JLabel("#");
89
		JLabel lbl_top1 = new JLabel("#");
71
		JLabel lbl_top2 = new JLabel("Von");
90
		JLabel lbl_top2 = new JLabel("Von");
72
		JLabel lbl_top3 = new JLabel("Bis");
91
		JLabel lbl_top3 = new JLabel("Bis");
73
		JLabel lbl_top4 = new JLabel("Temp");
92
		JLabel lbl_top4 = new JLabel("Temp");
74
 
93
 
-
 
94
		// Infos
-
 
95
		JLabel lbl_ActTemp = new JLabel("Raumtemperatur");
-
 
96
		JLabel lbl_Pressure = new JLabel("Luftdruck");
-
 
97
 
75
		// Spalte 1
98
		// Spalte 1
76
		JLabel lbl_1 = new JLabel("1");
99
		JLabel lbl_1 = new JLabel("1");
77
		JLabel lbl_2 = new JLabel("2");
100
		JLabel lbl_2 = new JLabel("2");
78
		JLabel lbl_3 = new JLabel("3");
101
		JLabel lbl_3 = new JLabel("3");
79
		JLabel lbl_4 = new JLabel("4");
102
		JLabel lbl_4 = new JLabel("4");
Line 119... Line 142...
119
		});
142
		});
120
		
143
		
121
		btSchema.setText("Schema");
144
		btSchema.setText("Schema");
122
		btSchema.addActionListener(new java.awt.event.ActionListener() {
145
		btSchema.addActionListener(new java.awt.event.ActionListener() {
123
            public void actionPerformed(java.awt.event.ActionEvent e) {
146
            public void actionPerformed(java.awt.event.ActionEvent e) {
124
            	/* To do */
147
            	schemaButtonActionPerformed(e);
125
            }
148
            }
126
		});
149
		});
127
 
150
 
128
		// Define and initialize the layout
151
		// Define and initialize the layout
129
		GroupLayout layout = new GroupLayout(frame.getContentPane());
152
		GroupLayout layout = new GroupLayout(frame.getContentPane());
Line 133... Line 156...
133
	            .addGroup(layout.createSequentialGroup()
156
	            .addGroup(layout.createSequentialGroup()
134
	                .addContainerGap()
157
	                .addContainerGap()
135
	                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
158
	                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
136
	                	.addGroup(layout.createSequentialGroup()
159
	                	.addGroup(layout.createSequentialGroup()
137
	                		.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
160
	                		.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
138
	                		.addComponent(lbl_WDay, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
161
	                		.addComponent(lbl_WDay, GroupLayout.PREFERRED_SIZE, lbl_ActTemp.getPreferredSize().width, GroupLayout.PREFERRED_SIZE)
139
	                		.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
162
	                		.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
140
	                		.addComponent(cmbWDay, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE))
163
	                		.addComponent(cmbWDay, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE))
-
 
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))
141
	                    .addGroup(layout.createSequentialGroup()
174
	                    .addGroup(layout.createSequentialGroup()
142
	                    	.addComponent(lbl_top1, GroupLayout.PREFERRED_SIZE, 10, GroupLayout.PREFERRED_SIZE)
175
	                    	.addComponent(lbl_top1, GroupLayout.PREFERRED_SIZE, 10, GroupLayout.PREFERRED_SIZE)
143
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
176
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
144
	                    	.addComponent(lbl_top2, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
177
	                    	.addComponent(lbl_top2, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
145
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
178
	                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
Line 242... Line 275...
242
        layout.setVerticalGroup(
275
        layout.setVerticalGroup(
243
                layout.createParallelGroup(GroupLayout.Alignment.LEADING)
276
                layout.createParallelGroup(GroupLayout.Alignment.LEADING)
244
                .addGroup(layout.createSequentialGroup()
277
                .addGroup(layout.createSequentialGroup()
245
                    .addContainerGap()
278
                    .addContainerGap()
246
                    .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
279
                    .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
-
 
280
                		.addComponent(lbl_WDay)
-
 
281
                		.addComponent(cmbWDay))
247
                		.addComponent(lbl_WDay, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
282
                    .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
-
 
283
                		.addComponent(lbl_ActTemp)
-
 
284
                		.addComponent(tfActTemp))
248
                		.addComponent(cmbWDay, GroupLayout.PREFERRED_SIZE, 60, GroupLayout.PREFERRED_SIZE))
285
                    .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
-
 
286
                		.addComponent(lbl_Pressure)
-
 
287
                		.addComponent(tfPressure))
249
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
288
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
250
                    	.addComponent(lbl_top1)
289
                    	.addComponent(lbl_top1)
251
                    	.addComponent(lbl_top2)
290
                    	.addComponent(lbl_top2)
252
                    	.addComponent(lbl_top3)
291
                    	.addComponent(lbl_top3)
253
                    	.addComponent(lbl_top4))
292
                    	.addComponent(lbl_top4))
Line 325... Line 364...
325
	}
364
	}
326
	
365
	
327
	/**
366
	/**
328
     * This method performs saveButtonActionPerformed   
367
     * This method performs saveButtonActionPerformed   
329
     */
368
     */
330
	private void saveButtonActionPerformed(ActionEvent evt) {
369
	private void saveButtonActionPerformed(ActionEvent evt)
-
 
370
	{
331
		int idx = cmbWDay.getSelectedIndex();
371
		int idx = cmbWDay.getSelectedIndex();
332
 
372
 
333
		saveDay(idx + 1);
373
		saveDay(idx + 1);
334
		clearLines();
374
		clearLines();
335
		readDay(idx + 1);
375
		readDay(idx + 1);
336
	}
376
	}
-
 
377
 
-
 
378
	private void schemaButtonActionPerformed(ActionEvent evt)
337
	
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
 
338
	private void exitButtonActionPerformed(ActionEvent evt) {
391
	private void exitButtonActionPerformed(ActionEvent evt)
-
 
392
	{
339
		System.exit(0);
393
		System.exit(0);
340
	}
394
	}
341
 
395
 
342
	private String timeToString(long tm) {
396
	private String timeToString(long tm) {
343
		int hour, min;
397
		int hour, min;
Line 376... Line 430...
376
 
430
 
377
		tm = (long)(hour * 3600 + min * 60);
431
		tm = (long)(hour * 3600 + min * 60);
378
		return tm;
432
		return tm;
379
	}
433
	}
380
 
434
 
381
	private void decode(String str) {
435
	private void decode(String str)
-
 
436
	{
382
		// Check for initial key word
437
		// Check for initial key word
383
		if (str.startsWith("LINE:"))
438
		if (str.startsWith("LINE:"))
384
		{
439
		{
385
		rm_str lr = new rm_str();
440
		rm_str lr = new rm_str();
386
		String work;
441
		String work;
Line 517... Line 572...
517
		tfBis_10.setText("");
572
		tfBis_10.setText("");
518
		tfTemp_10.setText("");
573
		tfTemp_10.setText("");
519
	}
574
	}
520
 
575
 
521
	private boolean readDay(int wday) {
576
	private boolean readDay(int wday) {
522
		Socket s = null;
-
 
523
		PrintWriter out = null;
577
		network nw = new network(strServerName);
524
		BufferedReader in = null;
-
 
525
		char[] ch;
-
 
526
		String answer;
578
		String answer;
527
 
579
 
528
		if (wday < 1 || wday > 7)
580
		if (wday < 1 || wday > 7)
529
			return false;
581
			return false;
530
 
582
 
531
		ch = new char[2];
583
		if (nw.connect())
532
 
-
 
533
		try {
-
 
534
            s = new Socket(strServerName, 11001);
-
 
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
		{
584
		{
545
			System.err.println("Could't set timeout: "+e.getMessage());
-
 
546
			System.exit(1);
585
			boolean ok = false;
547
		}
-
 
548
		catch (IOException e) {
-
 
549
            System.err.println("Couldn't get I/O for the connection to: "+strServerName+": "+e.getMessage());
-
 
550
            System.exit(1);
-
 
551
        }
-
 
552
 
-
 
553
		// Just wait a little to let daemon initialize
-
 
554
		try {
-
 
555
			Thread.sleep(500);
586
			int cmd = 0;
556
		} catch (InterruptedException e1) {
-
 
557
			System.out.println("Error: "+e1.getMessage());
-
 
558
		}
-
 
559
 
587
 
560
		// Request a particular day
588
			// Request a particular day
561
		out.print("GET WDAY:"+wday+";");
589
			nw.write("GET WDAY:"+wday+";GET TEMP;GET PRESSURE;");
562
		out.flush();
-
 
563
		answer = "";
590
			answer = "";
564
 
591
 
565
		try {
592
			do
566
			while (in.read(ch, 0, 1) != -1)
-
 
567
			{
593
			{
-
 
594
				answer = nw.read();
-
 
595
				ok = false;
-
 
596
 
568
				if (ch[0] == ';')
597
				if (answer.equals("OK"))
569
				{
598
				{
570
System.out.println("Found answer:"+answer);
-
 
571
					if (answer.equals("OK") || answer.equals("NAK"))
599
					if (cmd >= 3)
572
						break;
600
						break;
-
 
601
					else
-
 
602
						ok = true;
-
 
603
				}
-
 
604
				else if (answer.equals("NAK") || answer.contains("ERROR:"))
-
 
605
					break;
-
 
606
				else if (answer.contains("LINE:"))
573
 
607
				{
-
 
608
					ok = true;
574
					decode(answer);
609
					decode(answer);
575
					answer = "";
610
					cmd = 1;
-
 
611
				}
-
 
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");
576
					continue;
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;
577
				}
629
				}
578
 
-
 
579
				answer = answer+ch[0];
-
 
580
			}
630
			}
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();
631
			while(ok);
590
			System.exit(1);
-
 
591
		}
-
 
592
 
-
 
593
		out.print("quit;");
-
 
594
		out.close();
-
 
595
 
632
 
596
		try {
-
 
597
			in.close();
633
			nw.close();
598
			s.close();
-
 
599
		}
-
 
600
		catch (IOException e) {
-
 
601
			System.err.println("Error closing a socket: "+e.getMessage());
-
 
602
			System.exit(1);
-
 
603
		}
634
		}
604
 
635
 
605
		return true;
636
		return true;
606
	}
637
	}
607
 
638
 
608
	public boolean saveDay(int wday)
639
	public boolean saveDay(int wday)
609
	{
640
	{
610
		Socket s = null;
-
 
611
		PrintWriter out = null;
641
		network nw = new network(strServerName);
612
		BufferedReader in = null;
-
 
613
		char[] ch;
-
 
614
		String answer;
642
		String answer;
615
		int i, numLines = 0;
643
		int i, numLines = 0;
616
		int err = 0;
644
		int err = 0;
617
		float tp;
645
		float tp;
618
 
646
 
619
		if (wday < 1 || wday > 7)
647
		if (wday < 1 || wday > 7)
620
			return false;
648
			return false;
621
 
649
 
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
650
		// Find the number of complete lines
652
		if (!tfVon_1.getText().isEmpty() && !tfTemp_1.getText().isEmpty())
651
		if (!tfVon_1.getText().isEmpty() && !tfTemp_1.getText().isEmpty())
653
			numLines = 1;
652
			numLines = 1;
654
 
653
 
655
		if (!tfVon_2.getText().isEmpty() && !tfTemp_2.getText().isEmpty())
654
		if (!tfVon_2.getText().isEmpty() && !tfTemp_2.getText().isEmpty())
Line 677... Line 676...
677
			numLines = 9;
676
			numLines = 9;
678
 
677
 
679
		if (!tfVon_10.getText().isEmpty() && !tfTemp_10.getText().isEmpty())
678
		if (!tfVon_10.getText().isEmpty() && !tfTemp_10.getText().isEmpty())
680
			numLines = 10;
679
			numLines = 10;
681
 
680
 
682
		// Write out the actual day
681
		if (nw.connect())
683
		answer = "SET DAY:"+numLines+":"+wday;
-
 
684
		
-
 
685
		for (i = 0; i < numLines; i++)
-
 
686
		{
682
		{
687
			String st;
683
			// Write out the actual day
-
 
684
			answer = "SET DAY:"+numLines+":"+wday;
688
 
685
		
689
			switch(i)
686
			for (i = 0; i < numLines; i++)
690
			{
687
			{
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;
688
				String st;
759
				break;
-
 
760
 
689
 
-
 
690
				switch(i)
-
 
691
				{
761
				case 7:
692
					case 0:
762
					st = tfTemp_8.getText().replace(",", ".");
693
						st = tfTemp_1.getText().replace(",", ".");
763
					tp = Float.parseFloat(st);
694
						tp = Float.parseFloat(st);
764
 
695
 
765
					if (stringToTime(tfBis_8.getText()) > 0 && tp > 5.0 && tp <= 30.0)
696
						if (stringToTime(tfBis_1.getText()) > 0 && tp > 5.0 && tp <= 30.0)
766
						answer += ":"+stringToTime(tfBis_8.getText())+":"+tp;
697
							answer += ":"+stringToTime(tfBis_1.getText())+":"+tp;
767
					else
698
						else
768
						err = 1;
699
							err = 1;
769
				break;
700
						break;
770
 
701
 
-
 
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
	
771
				case 8:
772
					case 8:
772
					st = tfTemp_9.getText().replace(",", ".");
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(",", ".");
773
					tp = Float.parseFloat(st);
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;
774
 
799
 
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;
800
				nw.write(answer);
780
 
801
 
781
				case 9:
802
				if (DEBUG)
782
					st = tfTemp_10.getText().replace(",", ".");
-
 
783
					tp = Float.parseFloat(st);
803
					System.out.println("Send:"+answer);
784
 
804
 
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;
805
				answer = "";
789
				break;
-
 
790
			}
-
 
791
		}
-
 
792
 
806
 
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 {
807
				do
803
				while (in.read(ch, 0, 1) != -1)
-
 
804
				{
808
				{
-
 
809
					answer = nw.read();
-
 
810
					ok = false;
-
 
811
					
805
					if (ch[0] == ';')
812
					if (!answer.isEmpty())
806
						{
813
					{
-
 
814
						ok = true;
-
 
815
 
807
System.out.println("Found answer:"+answer);
816
						if (answer.contains("OK") || answer.contains("NAK") || answer.contains("ERROR:"))
808
						break;
817
							ok = false;
809
					}
818
					}
810
		
-
 
811
					answer = answer+ch[0];
-
 
812
				}
819
				}
-
 
820
				while(ok);
-
 
821
 
-
 
822
				nw.close();
813
			}
823
			}
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
 
824
 
826
		out.print("quit;");
825
			if (err == 0)
827
		out.close();
826
				return true;
828
	
-
 
829
		try {
827
			else
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);
828
				return false;
836
		}
829
		}
837
	
830
 
838
		if (err == 0)
-
 
839
			return true;
-
 
840
		else
-
 
841
			return false;
831
		return false;
842
	}
832
	}
843
 
833
 
844
	public static void main(String[] args) {
834
	public static void main(String[] args)
-
 
835
	{
845
		//Schedule a job for the event-dispatching thread:
836
		//Schedule a job for the event-dispatching thread:
846
        //creating and showing this application's GUI.
837
        //creating and showing this application's GUI.
847
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
838
        javax.swing.SwingUtilities.invokeLater(new Runnable()
-
 
839
        {
848
            public void run() {
840
            public void run()
-
 
841
            {
849
            	heizung thisClass = new heizung();
842
            	heizung thisClass = new heizung();
850
                thisClass.createAndShowGUI();
843
                thisClass.createAndShowGUI();
851
                thisClass.readDay(thisClass.actWDay);
844
                thisClass.readDay(thisClass.actWDay);
852
            }
845
            }
853
        });
846
        });
854
	}
847
	}
855
 
848
 
856
	@Override
849
	@Override
857
	public void actionPerformed(ActionEvent e) {
850
	public void actionPerformed(ActionEvent e)
-
 
851
	{
858
		JComboBox cb = (JComboBox)e.getSource();
852
		JComboBox cb = (JComboBox)e.getSource();
859
        int wday = cb.getSelectedIndex();
853
        int wday = cb.getSelectedIndex();
860
		
854
		
861
        if (wday >= 0 && wday < 7)
855
        if (wday >= 0 && wday < 7)
862
        {
856
        {