Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package heizung;
import heizung.rm_str;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.Window;
public class schema extends JDialog {
private static final long serialVersionUID = 1L;
private boolean state = false; // true if a schema was loaded
private String strSchema = ""; // the name of the last loaded schema
@SuppressWarnings("unused")
private int selSchema = 0; // The selected line
private String strServerName = "www.theosys.at";
private JPanel jContentPane = null;
private JCheckBox cbCheck_1 = null;
private JCheckBox cbCheck_2 = null;
private JCheckBox cbCheck_3 = null;
private JCheckBox cbCheck_4 = null;
private JCheckBox cbCheck_5 = null;
private JCheckBox cbCheck_6 = null;
private JCheckBox cbCheck_7 = null;
private JCheckBox cbCheck_8 = null;
private JCheckBox cbCheck_9 = null;
private JCheckBox cbCheck_10 = null;
private JTextField tfSchema_1 = null;
private JTextField tfSchema_2 = null;
private JTextField tfSchema_3 = null;
private JTextField tfSchema_4 = null;
private JTextField tfSchema_5 = null;
private JTextField tfSchema_6 = null;
private JTextField tfSchema_7 = null;
private JTextField tfSchema_8 = null;
private JTextField tfSchema_9 = null;
private JTextField tfSchema_10 = null;
private JButton btSave = null;
private JButton btDelete = null;
private JButton btLoad = null;
private JButton btClose = null;
public boolean getState() { return state; }
public String getSchemaName() { return strSchema; }
public schema(Window owner)
{
super(owner);
initialize();
}
private void initialize()
{
this.setSize(300, 400);
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setTitle("Schemas");
this.setContentPane(getJContentPane());
network nw = new network(strServerName);
if (nw.connect())
{
String answer;
boolean ok = false;
int line = 0;
nw.write("LIST SCHEMA;");
do
{
answer = nw.read();
ok = false;
if (!answer.isEmpty())
{
ok = true;
if (answer.contains("OK") || answer.contains("NAK"))
ok = false;
else if (answer.contains("SCHEMA FILE:"))
{
String sh;
rm_str rm = new rm_str();
rm.remove_string(answer, "SCHEMA FILE:");
sh = rm.getRight();
switch(line)
{
case 0: tfSchema_1.setText(sh); break;
case 1: tfSchema_2.setText(sh); break;
case 2: tfSchema_3.setText(sh); break;
case 3: tfSchema_4.setText(sh); break;
case 4: tfSchema_5.setText(sh); break;
case 5: tfSchema_6.setText(sh); break;
case 6: tfSchema_7.setText(sh); break;
case 7: tfSchema_8.setText(sh); break;
case 8: tfSchema_9.setText(sh); break;
case 9: tfSchema_10.setText(sh); break;
}
line++;
}
}
}
while(ok);
nw.close();
}
}
private JPanel getJContentPane()
{
if (jContentPane == null)
{
this.setTitle("Schemas");
java.net.URL imgURL = schema.class.getResource("images/icon_heizung.png");
if (imgURL != null)
{
ImageIcon img = new ImageIcon(imgURL);
this.setIconImage(img.getImage());
}
jContentPane = new JPanel();
GridBagLayout gridLayout = new GridBagLayout();
jContentPane.setLayout(gridLayout);
tfSchema_1 = new JTextField();
tfSchema_2 = new JTextField();
tfSchema_3 = new JTextField();
tfSchema_4 = new JTextField();
tfSchema_5 = new JTextField();
tfSchema_6 = new JTextField();
tfSchema_7 = new JTextField();
tfSchema_8 = new JTextField();
tfSchema_9 = new JTextField();
tfSchema_10 = new JTextField();
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.insets = new Insets(2, 0, 2, 0);
c.weightx = 1.0;
c.weighty = 1.0;
c.anchor = GridBagConstraints.NORTHWEST;
// Headline
c.gridwidth = 2;
jContentPane.add(new JLabel("Act."), c);
c.gridwidth = GridBagConstraints.REMAINDER;
jContentPane.add(new JLabel("Schema name"), c);
// Line 1
c.gridwidth = 2;
jContentPane.add(getCbCheck_1(), c);
c.gridwidth = GridBagConstraints.REMAINDER;
jContentPane.add(tfSchema_1, c);
// Line 2
c.gridwidth = 2;
jContentPane.add(getCbCheck_2(), c);
c.gridwidth = GridBagConstraints.REMAINDER;
jContentPane.add(tfSchema_2, c);
// Line 3
c.gridwidth = 2;
jContentPane.add(getCbCheck_3(), c);
c.gridwidth = GridBagConstraints.REMAINDER;
jContentPane.add(tfSchema_3, c);
// Line 4
c.gridwidth = 2;
jContentPane.add(getCbCheck_4(), c);
c.gridwidth = GridBagConstraints.REMAINDER;
jContentPane.add(tfSchema_4, c);
// Line 5
c.gridwidth = 2;
jContentPane.add(getCbCheck_5(), c);
c.gridwidth = GridBagConstraints.REMAINDER;
jContentPane.add(tfSchema_5, c);
// Line 6
c.gridwidth = 2;
jContentPane.add(getCbCheck_6(), c);
c.gridwidth = GridBagConstraints.REMAINDER;
jContentPane.add(tfSchema_6, c);
// Line 7
c.gridwidth = 2;
jContentPane.add(getCbCheck_7(), c);
c.gridwidth = GridBagConstraints.REMAINDER;
jContentPane.add(tfSchema_7, c);
// Line 8
c.gridwidth = 2;
jContentPane.add(getCbCheck_8(), c);
c.gridwidth = GridBagConstraints.REMAINDER;
jContentPane.add(tfSchema_8, c);
// Line 9
c.gridwidth = 2;
jContentPane.add(getCbCheck_9(), c);
c.gridwidth = GridBagConstraints.REMAINDER;
jContentPane.add(tfSchema_9, c);
// Line 10
c.gridwidth = 2;
jContentPane.add(getCbCheck_10(), c);
c.gridwidth = GridBagConstraints.REMAINDER;
jContentPane.add(tfSchema_10, c);
// Buttons
c.gridwidth = 2;
jContentPane.add(getBtLoad(), c);
c.gridwidth = GridBagConstraints.REMAINDER;
jContentPane.add(getBtSave(), c);
c.gridwidth = 2;
jContentPane.add(getBtDelete(), c);
c.gridwidth = GridBagConstraints.REMAINDER;
jContentPane.add(getBtClose(), c);
}
return jContentPane;
}
private JButton getBtClose()
{
if (btClose == null)
{
btClose = new JButton();
btClose.setText("Schließen");
btClose.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
dispose();
}
});
}
return btClose;
}
private JButton getBtLoad()
{
if (btLoad == null)
{
btLoad = new JButton();
btLoad.setText("Laden");
btLoad.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent e)
{
if (strSchema.isEmpty())
return;
network nw = new network(strServerName);
if (nw.connect())
{
String answer;
boolean ok = false;
nw.write("LOAD SCHEMA:"+strSchema+";");
do
{
answer = nw.read();
ok = false;
if (!answer.isEmpty())
{
ok = true;
if (answer.contains("OK") || answer.contains("NAK"))
ok = false;
}
}
while(ok);
nw.close();
state = true;
dispose();
}
}
});
}
return btLoad;
}
private JButton getBtSave()
{
if (btSave == null)
{
btSave = new JButton();
btSave.setText("Speichern");
btSave.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent e)
{
if (strSchema.isEmpty())
return;
network nw = new network(strServerName);
if (nw.connect())
{
String answer;
boolean ok = false;
nw.write("SAVE SCHEMA:"+strSchema+";");
do
{
answer = nw.read();
ok = false;
if (!answer.isEmpty())
{
ok = true;
if (answer.contains("OK") || answer.contains("NAK"))
ok = false;
}
}
while(ok);
nw.close();
}
}
});
}
return btSave;
}
private void clearLines()
{
tfSchema_1.setText("");
tfSchema_2.setText("");
tfSchema_3.setText("");
tfSchema_4.setText("");
tfSchema_5.setText("");
tfSchema_6.setText("");
tfSchema_7.setText("");
tfSchema_8.setText("");
tfSchema_9.setText("");
tfSchema_10.setText("");
}
private JButton getBtDelete()
{
if (btDelete == null)
{
btDelete = new JButton();
btDelete.setText("Löschen");
btDelete.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent e)
{
if (strSchema.isEmpty())
return;
network nw = new network(strServerName);
if (nw.connect())
{
String answer;
boolean ok = false;
int line = 0;
nw.write("DELETE SCHEMA:"+strSchema+";");
clearLines();
do
{
answer = nw.read();
ok = false;
if (!answer.isEmpty())
{
ok = true;
if (answer.contains("OK") || answer.contains("NAK"))
ok = false;
else if (answer.contains("SCHEMA FILE:"))
{
String sh;
rm_str rm = new rm_str();
rm.remove_string(answer, "SCHEMA FILE:");
sh = rm.getRight();
switch(line)
{
case 0: tfSchema_1.setText(sh); break;
case 1: tfSchema_2.setText(sh); break;
case 2: tfSchema_3.setText(sh); break;
case 3: tfSchema_4.setText(sh); break;
case 4: tfSchema_5.setText(sh); break;
case 5: tfSchema_6.setText(sh); break;
case 6: tfSchema_7.setText(sh); break;
case 7: tfSchema_8.setText(sh); break;
case 8: tfSchema_9.setText(sh); break;
case 9: tfSchema_10.setText(sh); break;
}
line++;
}
}
}
while(ok);
nw.close();
}
}
});
}
return btDelete;
}
private void cbSelect(int sel)
{
cbCheck_1.setSelected((sel == 1)?true:false);
cbCheck_2.setSelected((sel == 2)?true:false);
cbCheck_3.setSelected((sel == 3)?true:false);
cbCheck_4.setSelected((sel == 4)?true:false);
cbCheck_5.setSelected((sel == 5)?true:false);
cbCheck_6.setSelected((sel == 6)?true:false);
cbCheck_7.setSelected((sel == 7)?true:false);
cbCheck_8.setSelected((sel == 8)?true:false);
cbCheck_9.setSelected((sel == 9)?true:false);
cbCheck_10.setSelected((sel == 10)?true:false);
switch(sel)
{
case 1:
if (!tfSchema_1.getText().isEmpty())
strSchema = tfSchema_1.getText();
else
strSchema = "";
break;
case 2:
if (!tfSchema_2.getText().isEmpty())
strSchema = tfSchema_2.getText();
else
strSchema = "";
break;
case 3:
if (!tfSchema_3.getText().isEmpty())
strSchema = tfSchema_3.getText();
else
strSchema = "";
break;
case 4:
if (!tfSchema_4.getText().isEmpty())
strSchema = tfSchema_4.getText();
else
strSchema = "";
break;
case 5:
if (!tfSchema_5.getText().isEmpty())
strSchema = tfSchema_5.getText();
else
strSchema = "";
break;
case 6:
if (!tfSchema_6.getText().isEmpty())
strSchema = tfSchema_6.getText();
else
strSchema = "";
break;
case 7:
if (!tfSchema_7.getText().isEmpty())
strSchema = tfSchema_7.getText();
else
strSchema = "";
break;
case 8:
if (!tfSchema_8.getText().isEmpty())
strSchema = tfSchema_8.getText();
else
strSchema = "";
break;
case 9:
if (!tfSchema_9.getText().isEmpty())
strSchema = tfSchema_9.getText();
else
strSchema = "";
break;
case 10:
if (!tfSchema_10.getText().isEmpty())
strSchema = tfSchema_10.getText();
else
strSchema = "";
break;
}
selSchema = sel;
}
private JCheckBox getCbCheck_1()
{
if (cbCheck_1 == null)
{
cbCheck_1 = new JCheckBox();
cbCheck_1.setSelected(false);
cbCheck_1.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent e)
{
if (cbCheck_1.isSelected())
cbSelect(1);
else
selSchema = 0;
}
});
}
return cbCheck_1;
}
private JCheckBox getCbCheck_2()
{
if (cbCheck_2 == null)
{
cbCheck_2 = new JCheckBox();
cbCheck_2.setSelected(false);
cbCheck_2.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent e)
{
if (cbCheck_2.isSelected())
cbSelect(2);
else
selSchema = 0;
}
});
}
return cbCheck_2;
}
private JCheckBox getCbCheck_3()
{
if (cbCheck_3 == null)
{
cbCheck_3 = new JCheckBox();
cbCheck_3.setSelected(false);
cbCheck_3.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent e)
{
if (cbCheck_3.isSelected())
cbSelect(3);
else
selSchema = 0;
}
});
}
return cbCheck_3;
}
private JCheckBox getCbCheck_4()
{
if (cbCheck_4 == null)
{
cbCheck_4 = new JCheckBox();
cbCheck_4.setSelected(false);
cbCheck_4.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent e)
{
if (cbCheck_4.isSelected())
cbSelect(4);
else
selSchema = 0;
}
});
}
return cbCheck_4;
}
private JCheckBox getCbCheck_5()
{
if (cbCheck_5 == null)
{
cbCheck_5 = new JCheckBox();
cbCheck_5.setSelected(false);
cbCheck_5.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent e)
{
if (cbCheck_5.isSelected())
cbSelect(5);
else
selSchema = 0;
}
});
}
return cbCheck_5;
}
private JCheckBox getCbCheck_6()
{
if (cbCheck_6 == null)
{
cbCheck_6 = new JCheckBox();
cbCheck_6.setSelected(false);
cbCheck_6.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent e)
{
if (cbCheck_6.isSelected())
cbSelect(6);
else
selSchema = 0;
}
});
}
return cbCheck_6;
}
private JCheckBox getCbCheck_7()
{
if (cbCheck_7 == null)
{
cbCheck_7 = new JCheckBox();
cbCheck_7.setSelected(false);
cbCheck_7.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent e)
{
if (cbCheck_7.isSelected())
cbSelect(7);
else
selSchema = 0;
}
});
}
return cbCheck_7;
}
private JCheckBox getCbCheck_8()
{
if (cbCheck_8 == null)
{
cbCheck_8 = new JCheckBox();
cbCheck_8.setSelected(false);
cbCheck_8.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent e)
{
if (cbCheck_8.isSelected())
cbSelect(8);
else
selSchema = 0;
}
});
}
return cbCheck_8;
}
private JCheckBox getCbCheck_9()
{
if (cbCheck_9 == null)
{
cbCheck_9 = new JCheckBox();
cbCheck_9.setSelected(false);
cbCheck_9.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent e)
{
if (cbCheck_9.isSelected())
cbSelect(9);
else
selSchema = 0;
}
});
}
return cbCheck_9;
}
private JCheckBox getCbCheck_10()
{
if (cbCheck_10 == null)
{
cbCheck_10 = new JCheckBox();
cbCheck_10.setSelected(false);
cbCheck_10.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent e)
{
if (cbCheck_10.isSelected())
cbSelect(10);
else
selSchema = 0;
}
});
}
return cbCheck_10;
}
}