Subversion Repositories jheat

Rev

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

Rev Author Line No. Line
4 andreas 1
package heizung;
2
 
3
import heizung.rm_str;
4
 
5
import javax.swing.ImageIcon;
6
import javax.swing.JButton;
7
import javax.swing.JCheckBox;
8
import javax.swing.JDialog;
9
import javax.swing.JLabel;
10
import javax.swing.JPanel;
11
import javax.swing.JTextField;
12
import javax.swing.WindowConstants;
13
 
14
import java.awt.GridBagLayout;
15
import java.awt.GridBagConstraints;
16
import java.awt.Insets;
17
import java.awt.Window;
18
 
19
public class schema extends JDialog {
5 andreas 20
	private static final long serialVersionUID = 3789311458170961544L;
4 andreas 21
 
22
	private boolean state = false;			// true if a schema was loaded
23
	private String strSchema = "";			// the name of the last loaded schema
24
	@SuppressWarnings("unused")
25
	private int selSchema = 0;				// The selected line
26
	private String strServerName = "www.theosys.at";
27
 
28
	private JPanel jContentPane = null;
29
	private JCheckBox cbCheck_1 = null;
30
	private JCheckBox cbCheck_2 = null;
31
	private JCheckBox cbCheck_3 = null;
32
	private JCheckBox cbCheck_4 = null;
33
	private JCheckBox cbCheck_5 = null;
34
	private JCheckBox cbCheck_6 = null;
35
	private JCheckBox cbCheck_7 = null;
36
	private JCheckBox cbCheck_8 = null;
37
	private JCheckBox cbCheck_9 = null;
38
	private JCheckBox cbCheck_10 = null;
39
	private JTextField tfSchema_1 = null;
40
	private JTextField tfSchema_2 = null;
41
	private JTextField tfSchema_3 = null;
42
	private JTextField tfSchema_4 = null;
43
	private JTextField tfSchema_5 = null;
44
	private JTextField tfSchema_6 = null;
45
	private JTextField tfSchema_7 = null;
46
	private JTextField tfSchema_8 = null;
47
	private JTextField tfSchema_9 = null;
48
	private JTextField tfSchema_10 = null;
49
	private JButton btSave = null;
50
	private JButton btDelete = null;
51
	private JButton btLoad = null;
52
	private JButton btClose = null;
53
 
54
	public boolean getState() { return state; }
55
	public String getSchemaName() { return strSchema; }
56
 
57
	public schema(Window owner)
58
	{
59
		super(owner);
60
		initialize();
61
	}
62
 
63
	private void initialize()
64
	{
65
		this.setSize(300, 400);
66
		this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
67
		this.setTitle("Schemas");
68
		this.setContentPane(getJContentPane());
69
		network nw = new network(strServerName);
70
 
71
		if (nw.connect())
72
		{
73
			String answer;
74
			boolean ok = false;
75
			int line = 0;
76
 
77
			nw.write("LIST SCHEMA;");
78
 
79
			do
80
			{
81
				answer = nw.read();
82
				ok = false;
83
 
84
				if (!answer.isEmpty())
85
				{
86
					ok = true;
87
 
88
					if (answer.contains("OK") || answer.contains("NAK"))
89
						ok = false;
90
					else if (answer.contains("SCHEMA FILE:"))
91
					{
92
						String sh;
93
 
94
						rm_str rm = new rm_str();
95
						rm.remove_string(answer, "SCHEMA FILE:");
96
						sh = rm.getRight();
97
 
98
						switch(line)
99
						{
100
							case 0: tfSchema_1.setText(sh); break;
101
							case 1: tfSchema_2.setText(sh); break;
102
							case 2: tfSchema_3.setText(sh); break;
103
							case 3: tfSchema_4.setText(sh); break;
104
							case 4: tfSchema_5.setText(sh); break;
105
							case 5: tfSchema_6.setText(sh); break;
106
							case 6: tfSchema_7.setText(sh); break;
107
							case 7: tfSchema_8.setText(sh); break;
108
							case 8: tfSchema_9.setText(sh); break;
109
							case 9: tfSchema_10.setText(sh); break;
110
						}
111
 
112
						line++;
113
					}
114
				}
115
			}
116
			while(ok);
117
 
118
			nw.close();
119
		}
120
	}
121
 
122
	private JPanel getJContentPane()
123
	{
124
		if (jContentPane == null)
125
		{
126
			this.setTitle("Schemas");
127
			java.net.URL imgURL = schema.class.getResource("images/icon_heizung.png");
128
 
129
			if (imgURL != null)
130
			{
131
				ImageIcon img = new ImageIcon(imgURL);
132
				this.setIconImage(img.getImage());
133
			}
134
 
135
			jContentPane = new JPanel();
136
			GridBagLayout gridLayout = new GridBagLayout();
137
			jContentPane.setLayout(gridLayout);
138
 
139
			tfSchema_1 = new JTextField();
140
			tfSchema_2 = new JTextField();
141
			tfSchema_3 = new JTextField();
142
			tfSchema_4 = new JTextField();
143
			tfSchema_5 = new JTextField();
144
			tfSchema_6 = new JTextField();
145
			tfSchema_7 = new JTextField();
146
			tfSchema_8 = new JTextField();
147
			tfSchema_9 = new JTextField();
148
			tfSchema_10 = new JTextField();
149
 
150
			GridBagConstraints c = new GridBagConstraints();
151
			c.fill = GridBagConstraints.HORIZONTAL;
152
			c.insets = new Insets(2, 0, 2, 0);
153
			c.weightx = 1.0;
154
			c.weighty = 1.0;
155
			c.anchor = GridBagConstraints.NORTHWEST;
156
			// Headline
157
			c.gridwidth = 2;
158
			jContentPane.add(new JLabel("Act."), c);
159
			c.gridwidth = GridBagConstraints.REMAINDER;
160
			jContentPane.add(new JLabel("Schema name"), c);
161
			// Line 1
162
			c.gridwidth = 2;
163
			jContentPane.add(getCbCheck_1(), c);
164
			c.gridwidth = GridBagConstraints.REMAINDER;
165
			jContentPane.add(tfSchema_1, c);
166
			// Line 2
167
			c.gridwidth = 2;
168
			jContentPane.add(getCbCheck_2(), c);
169
			c.gridwidth = GridBagConstraints.REMAINDER;
170
			jContentPane.add(tfSchema_2, c);
171
			// Line 3
172
			c.gridwidth = 2;
173
			jContentPane.add(getCbCheck_3(), c);
174
			c.gridwidth = GridBagConstraints.REMAINDER;
175
			jContentPane.add(tfSchema_3, c);
176
			// Line 4
177
			c.gridwidth = 2;
178
			jContentPane.add(getCbCheck_4(), c);
179
			c.gridwidth = GridBagConstraints.REMAINDER;
180
			jContentPane.add(tfSchema_4, c);
181
			// Line 5
182
			c.gridwidth = 2;
183
			jContentPane.add(getCbCheck_5(), c);
184
			c.gridwidth = GridBagConstraints.REMAINDER;
185
			jContentPane.add(tfSchema_5, c);
186
			// Line 6
187
			c.gridwidth = 2;
188
			jContentPane.add(getCbCheck_6(), c);
189
			c.gridwidth = GridBagConstraints.REMAINDER;
190
			jContentPane.add(tfSchema_6, c);
191
			// Line 7
192
			c.gridwidth = 2;
193
			jContentPane.add(getCbCheck_7(), c);
194
			c.gridwidth = GridBagConstraints.REMAINDER;
195
			jContentPane.add(tfSchema_7, c);
196
			// Line 8
197
			c.gridwidth = 2;
198
			jContentPane.add(getCbCheck_8(), c);
199
			c.gridwidth = GridBagConstraints.REMAINDER;
200
			jContentPane.add(tfSchema_8, c);
201
			// Line 9
202
			c.gridwidth = 2;
203
			jContentPane.add(getCbCheck_9(), c);
204
			c.gridwidth = GridBagConstraints.REMAINDER;
205
			jContentPane.add(tfSchema_9, c);
206
			// Line 10
207
			c.gridwidth = 2;
208
			jContentPane.add(getCbCheck_10(), c);
209
			c.gridwidth = GridBagConstraints.REMAINDER;
210
			jContentPane.add(tfSchema_10, c);
211
			// Buttons
212
			c.gridwidth = 2;
213
			jContentPane.add(getBtLoad(), c);
214
			c.gridwidth = GridBagConstraints.REMAINDER;
215
			jContentPane.add(getBtSave(), c);
216
			c.gridwidth = 2;
217
			jContentPane.add(getBtDelete(), c);
218
			c.gridwidth = GridBagConstraints.REMAINDER;
219
			jContentPane.add(getBtClose(), c);
220
		}
221
 
222
		return jContentPane;
223
	}
224
 
225
	private JButton getBtClose()
226
	{
227
		if (btClose == null)
228
		{
229
			btClose = new JButton();
230
			btClose.setText("Schließen");
231
			btClose.addActionListener(new java.awt.event.ActionListener() {
232
				public void actionPerformed(java.awt.event.ActionEvent e) {
233
					dispose();
234
				}
235
			});
236
		}
237
 
238
		return btClose;
239
	}
240
 
241
	private JButton getBtLoad()
242
	{
243
		if (btLoad == null)
244
		{
245
			btLoad = new JButton();
246
			btLoad.setText("Laden");
247
			btLoad.addActionListener(new java.awt.event.ActionListener()
248
			{
249
				public void actionPerformed(java.awt.event.ActionEvent e) 
250
				{
251
					if (strSchema.isEmpty())
252
						return;
253
 
254
					network nw = new network(strServerName);
255
 
256
					if (nw.connect())
257
					{
258
						String answer;
259
						boolean ok = false;
260
 
261
						nw.write("LOAD SCHEMA:"+strSchema+";");
262
 
263
						do
264
						{
265
							answer = nw.read();
266
							ok = false;
267
 
268
							if (!answer.isEmpty())
269
							{
270
								ok = true;
271
 
272
								if (answer.contains("OK") || answer.contains("NAK"))
273
									ok = false;
274
							}
275
						}
276
						while(ok);
277
 
278
						nw.close();
279
						state = true;
280
						dispose();
281
					}
282
 
283
				}
284
			});
285
		}
286
 
287
		return btLoad;
288
	}
289
 
290
	private JButton getBtSave()
291
	{
292
		if (btSave == null)
293
		{
294
			btSave = new JButton();
295
			btSave.setText("Speichern");
296
			btSave.addActionListener(new java.awt.event.ActionListener()
297
			{
298
				public void actionPerformed(java.awt.event.ActionEvent e) 
299
				{
300
					if (strSchema.isEmpty())
301
						return;
302
 
303
					network nw = new network(strServerName);
304
 
305
					if (nw.connect())
306
					{
307
						String answer;
308
						boolean ok = false;
309
 
310
						nw.write("SAVE SCHEMA:"+strSchema+";");
311
 
312
						do
313
						{
314
							answer = nw.read();
315
							ok = false;
316
 
317
							if (!answer.isEmpty())
318
							{
319
								ok = true;
320
 
321
								if (answer.contains("OK") || answer.contains("NAK"))
322
									ok = false;
323
							}
324
						}
325
						while(ok);
326
 
327
						nw.close();
328
					}
329
 
330
				}
331
			});
332
		}
333
 
334
		return btSave;
335
	}
336
 
337
	private void clearLines()
338
	{
339
		tfSchema_1.setText("");
340
		tfSchema_2.setText("");
341
		tfSchema_3.setText("");
342
		tfSchema_4.setText("");
343
		tfSchema_5.setText("");
344
		tfSchema_6.setText("");
345
		tfSchema_7.setText("");
346
		tfSchema_8.setText("");
347
		tfSchema_9.setText("");
348
		tfSchema_10.setText("");
349
	}
350
 
351
	private JButton getBtDelete()
352
	{
353
		if (btDelete == null)
354
		{
355
			btDelete = new JButton();
356
			btDelete.setText("Löschen");
357
			btDelete.addActionListener(new java.awt.event.ActionListener()
358
			{
359
				public void actionPerformed(java.awt.event.ActionEvent e) 
360
				{
361
					if (strSchema.isEmpty())
362
						return;
363
 
364
					network nw = new network(strServerName);
365
 
366
					if (nw.connect())
367
					{
368
						String answer;
369
						boolean ok = false;
370
						int line = 0;
371
 
372
						nw.write("DELETE SCHEMA:"+strSchema+";");
373
						clearLines();
374
 
375
						do
376
						{
377
							answer = nw.read();
378
							ok = false;
379
 
380
							if (!answer.isEmpty())
381
							{
382
								ok = true;
383
 
384
								if (answer.contains("OK") || answer.contains("NAK"))
385
									ok = false;
386
								else if (answer.contains("SCHEMA FILE:"))
387
								{
388
									String sh;
389
 
390
									rm_str rm = new rm_str();
391
									rm.remove_string(answer, "SCHEMA FILE:");
392
									sh = rm.getRight();
393
 
394
									switch(line)
395
									{
396
										case 0: tfSchema_1.setText(sh); break;
397
										case 1: tfSchema_2.setText(sh); break;
398
										case 2: tfSchema_3.setText(sh); break;
399
										case 3: tfSchema_4.setText(sh); break;
400
										case 4: tfSchema_5.setText(sh); break;
401
										case 5: tfSchema_6.setText(sh); break;
402
										case 6: tfSchema_7.setText(sh); break;
403
										case 7: tfSchema_8.setText(sh); break;
404
										case 8: tfSchema_9.setText(sh); break;
405
										case 9: tfSchema_10.setText(sh); break;
406
									}
407
 
408
									line++;
409
								}
410
							}
411
						}
412
						while(ok);
413
 
414
						nw.close();
415
					}
416
 
417
				}
418
			});
419
		}
420
 
421
		return btDelete;
422
	}
423
 
424
	private void cbSelect(int sel)
425
	{
426
		cbCheck_1.setSelected((sel == 1)?true:false);
427
		cbCheck_2.setSelected((sel == 2)?true:false);
428
		cbCheck_3.setSelected((sel == 3)?true:false);
429
		cbCheck_4.setSelected((sel == 4)?true:false);
430
		cbCheck_5.setSelected((sel == 5)?true:false);
431
		cbCheck_6.setSelected((sel == 6)?true:false);
432
		cbCheck_7.setSelected((sel == 7)?true:false);
433
		cbCheck_8.setSelected((sel == 8)?true:false);
434
		cbCheck_9.setSelected((sel == 9)?true:false);
435
		cbCheck_10.setSelected((sel == 10)?true:false);
436
 
437
		switch(sel)
438
		{
439
			case 1:
440
				if (!tfSchema_1.getText().isEmpty())
441
					strSchema = tfSchema_1.getText();
442
				else
443
					strSchema = "";
444
			break;
445
 
446
			case 2:
447
				if (!tfSchema_2.getText().isEmpty())
448
					strSchema = tfSchema_2.getText();
449
				else
450
					strSchema = "";
451
			break;
452
 
453
			case 3:
454
				if (!tfSchema_3.getText().isEmpty())
455
					strSchema = tfSchema_3.getText();
456
				else
457
					strSchema = "";
458
			break;
459
 
460
			case 4:
461
				if (!tfSchema_4.getText().isEmpty())
462
					strSchema = tfSchema_4.getText();
463
				else
464
					strSchema = "";
465
			break;
466
 
467
			case 5:
468
				if (!tfSchema_5.getText().isEmpty())
469
					strSchema = tfSchema_5.getText();
470
				else
471
					strSchema = "";
472
			break;
473
 
474
			case 6:
475
				if (!tfSchema_6.getText().isEmpty())
476
					strSchema = tfSchema_6.getText();
477
				else
478
					strSchema = "";
479
			break;
480
 
481
			case 7:
482
				if (!tfSchema_7.getText().isEmpty())
483
					strSchema = tfSchema_7.getText();
484
				else
485
					strSchema = "";
486
			break;
487
 
488
			case 8:
489
				if (!tfSchema_8.getText().isEmpty())
490
					strSchema = tfSchema_8.getText();
491
				else
492
					strSchema = "";
493
			break;
494
 
495
			case 9:
496
				if (!tfSchema_9.getText().isEmpty())
497
					strSchema = tfSchema_9.getText();
498
				else
499
					strSchema = "";
500
			break;
501
 
502
			case 10:
503
				if (!tfSchema_10.getText().isEmpty())
504
					strSchema = tfSchema_10.getText();
505
				else
506
					strSchema = "";
507
			break;
508
		}
509
 
510
		selSchema = sel;
511
	}
512
 
513
	private JCheckBox getCbCheck_1()
514
	{
515
		if (cbCheck_1 == null)
516
		{
517
			cbCheck_1 = new JCheckBox();
518
			cbCheck_1.setSelected(false);
519
			cbCheck_1.addActionListener(new java.awt.event.ActionListener()
520
			{
521
				public void actionPerformed(java.awt.event.ActionEvent e)
522
				{
523
					if (cbCheck_1.isSelected())
524
						cbSelect(1);
525
					else
526
						selSchema = 0;
527
				}
528
			});
529
		}
530
 
531
		return cbCheck_1;
532
	}
533
 
534
	private JCheckBox getCbCheck_2()
535
	{
536
		if (cbCheck_2 == null)
537
		{
538
			cbCheck_2 = new JCheckBox();
539
			cbCheck_2.setSelected(false);
540
			cbCheck_2.addActionListener(new java.awt.event.ActionListener()
541
			{
542
				public void actionPerformed(java.awt.event.ActionEvent e)
543
				{
544
					if (cbCheck_2.isSelected())
545
						cbSelect(2);
546
					else
547
						selSchema = 0;
548
				}
549
			});
550
		}
551
 
552
		return cbCheck_2;
553
	}
554
 
555
	private JCheckBox getCbCheck_3()
556
	{
557
		if (cbCheck_3 == null)
558
		{
559
			cbCheck_3 = new JCheckBox();
560
			cbCheck_3.setSelected(false);
561
			cbCheck_3.addActionListener(new java.awt.event.ActionListener()
562
			{
563
				public void actionPerformed(java.awt.event.ActionEvent e)
564
				{
565
					if (cbCheck_3.isSelected())
566
						cbSelect(3);
567
					else
568
						selSchema = 0;
569
				}
570
			});
571
		}
572
 
573
		return cbCheck_3;
574
	}
575
 
576
	private JCheckBox getCbCheck_4()
577
	{
578
		if (cbCheck_4 == null)
579
		{
580
			cbCheck_4 = new JCheckBox();
581
			cbCheck_4.setSelected(false);
582
			cbCheck_4.addActionListener(new java.awt.event.ActionListener()
583
			{
584
				public void actionPerformed(java.awt.event.ActionEvent e)
585
				{
586
					if (cbCheck_4.isSelected())
587
						cbSelect(4);
588
					else
589
						selSchema = 0;
590
				}
591
			});
592
		}
593
 
594
		return cbCheck_4;
595
	}
596
 
597
	private JCheckBox getCbCheck_5()
598
	{
599
		if (cbCheck_5 == null)
600
		{
601
			cbCheck_5 = new JCheckBox();
602
			cbCheck_5.setSelected(false);
603
			cbCheck_5.addActionListener(new java.awt.event.ActionListener()
604
			{
605
				public void actionPerformed(java.awt.event.ActionEvent e)
606
				{
607
					if (cbCheck_5.isSelected())
608
						cbSelect(5);
609
					else
610
						selSchema = 0;
611
				}
612
			});
613
		}
614
 
615
		return cbCheck_5;
616
	}
617
 
618
	private JCheckBox getCbCheck_6()
619
	{
620
		if (cbCheck_6 == null)
621
		{
622
			cbCheck_6 = new JCheckBox();
623
			cbCheck_6.setSelected(false);
624
			cbCheck_6.addActionListener(new java.awt.event.ActionListener()
625
			{
626
				public void actionPerformed(java.awt.event.ActionEvent e)
627
				{
628
					if (cbCheck_6.isSelected())
629
						cbSelect(6);
630
					else
631
						selSchema = 0;
632
				}
633
			});
634
		}
635
 
636
		return cbCheck_6;
637
	}
638
 
639
	private JCheckBox getCbCheck_7()
640
	{
641
		if (cbCheck_7 == null)
642
		{
643
			cbCheck_7 = new JCheckBox();
644
			cbCheck_7.setSelected(false);
645
			cbCheck_7.addActionListener(new java.awt.event.ActionListener()
646
			{
647
				public void actionPerformed(java.awt.event.ActionEvent e)
648
				{
649
					if (cbCheck_7.isSelected())
650
						cbSelect(7);
651
					else
652
						selSchema = 0;
653
				}
654
			});
655
		}
656
 
657
		return cbCheck_7;
658
	}
659
 
660
	private JCheckBox getCbCheck_8()
661
	{
662
		if (cbCheck_8 == null)
663
		{
664
			cbCheck_8 = new JCheckBox();
665
			cbCheck_8.setSelected(false);
666
			cbCheck_8.addActionListener(new java.awt.event.ActionListener()
667
			{
668
				public void actionPerformed(java.awt.event.ActionEvent e)
669
				{
670
					if (cbCheck_8.isSelected())
671
						cbSelect(8);
672
					else
673
						selSchema = 0;
674
				}
675
			});
676
		}
677
 
678
		return cbCheck_8;
679
	}
680
 
681
	private JCheckBox getCbCheck_9()
682
	{
683
		if (cbCheck_9 == null)
684
		{
685
			cbCheck_9 = new JCheckBox();
686
			cbCheck_9.setSelected(false);
687
			cbCheck_9.addActionListener(new java.awt.event.ActionListener()
688
			{
689
				public void actionPerformed(java.awt.event.ActionEvent e)
690
				{
691
					if (cbCheck_9.isSelected())
692
						cbSelect(9);
693
					else
694
						selSchema = 0;
695
				}
696
			});
697
		}
698
 
699
		return cbCheck_9;
700
	}
701
 
702
	private JCheckBox getCbCheck_10()
703
	{
704
		if (cbCheck_10 == null)
705
		{
706
			cbCheck_10 = new JCheckBox();
707
			cbCheck_10.setSelected(false);
708
			cbCheck_10.addActionListener(new java.awt.event.ActionListener()
709
			{
710
				public void actionPerformed(java.awt.event.ActionEvent e)
711
				{
712
					if (cbCheck_10.isSelected())
713
						cbSelect(10);
714
					else
715
						selSchema = 0;
716
				}
717
			});
718
		}
719
 
720
		return cbCheck_10;
721
	}
722
}