import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.util.Vector;
import javax.swing.*;
public class TestScreen {
/**
* @param args
* @throws ClassNotFoundException
*/
@SuppressWarnings("unchecked")
public static void main(String[] args) throws ClassNotFoundException {
System.out.println("Gestartet");
Connection con = WinkConnection.getWinkConnection();
System.out.println(con);
Vector adrbuch = TableData.adrb(con, 1720);
System.out.println(adrbuch);
Vector forward = getWL_adresse(adrbuch);
System.out.println(forward);
if (forward.get(0).toString().equalsIgnoreCase("Cancel")){
JOptionPane.showMessageDialog(null, "Es erfolgt keine Weiterleitung", "Warnung", javax.swing.JOptionPane.INFORMATION_MESSAGE);}
}
@SuppressWarnings("unchecked")
private static Vector getWL_adresse(Vector adrbuch){
System.out.println("getWL_adresse gerufen");
Vector forward = new Vector();
/*****************
Komponenten
******************/
ButtonGroup weiterleitungsArt = new javax.swing.ButtonGroup();
ButtonGroup weiterleitungsZiel = new javax.swing.ButtonGroup();
JLabel jLabel1 = new javax.swing.JLabel();
JLabel jLabel2 = new javax.swing.JLabel();
JLabel jLabel3 = new javax.swing.JLabel();
final JRadioButton jRadioButton1 = new javax.swing.JRadioButton();
final JRadioButton jRadioButton2 = new javax.swing.JRadioButton();
final JRadioButton jRadioButton3 = new javax.swing.JRadioButton();
final JRadioButton jRadioButton4 = new javax.swing.JRadioButton();
JScrollPane jScrollPane2 = new javax.swing.JScrollPane();
final JTextField mailadresse = new javax.swing.JTextField();
final JTextField suchfeld = new javax.swing.JTextField();
final JTable jTable1 = new javax.swing.JTable(){public boolean isCellEditable(int x, int y) {
return false;
};};
/*****************
Komponenten setzen
******************/
String ArtderWeiterleitung = "default";
weiterleitungsArt.add(jRadioButton1);
jRadioButton1.setText("Weiterleitung");
weiterleitungsArt.add(jRadioButton2);
jRadioButton2.setText("Urgenz");
weiterleitungsArt.setSelected(jRadioButton1.getModel() , true);
String ZielderWeiterleitung = "default";
weiterleitungsZiel.add(jRadioButton3);
jRadioButton3.setText("Filiale");
weiterleitungsZiel.add(jRadioButton4);
jRadioButton4.setText("Fachabteilung");
weiterleitungsZiel.setSelected(jRadioButton3.getModel() , true);
jLabel2.setLabelFor(mailadresse);
jLabel2.setText("Weiterleitung an:");
jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel3.setText("Adressauswahl");
jLabel3.setLabelFor(suchfeld);
suchfeld.addActionListener( new ActionListener() {public void actionPerformed(ActionEvent e)
{
System.out.println("---ActionEvent---");
System.out.println(suchfeld.getText());
try {
javax.swing.table.DefaultTableModel tabmo = (javax.swing.table.DefaultTableModel) jTable1.getModel();
tabmo.setDataVector((TableData.adraus(WinkConnection.getWinkConnection(), 1720, suchfeld.getText())), COLUMN_IDENTIFIERS);
System.out.println("c");
tabmo.fireTableDataChanged();
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}});
jLabel1.setText("Art der Weiterleitung:");
jScrollPane2.setViewportView(jTable1);
/*****************
Tabelle
******************/
javax.swing.table.DefaultTableModel tableMod = new javax.swing.table.DefaultTableModel(adrbuch, COLUMN_IDENTIFIERS);
jTable1.setModel(tableMod);
jTable1.setColumnSelectionAllowed( false );
jTable1.setRowSelectionAllowed( true );
jTable1.setAutoCreateRowSorter(true);
jTable1.getSelectionModel().addListSelectionListener(new javax.swing.event.ListSelectionListener() {
public void valueChanged(javax.swing.event.ListSelectionEvent getValueIsAdjusting) {
//System.out.println((jTable1.getModel()).getValueAt(jTable1.getSelectedRow(), 3));
mailadresse.setText((String) (jTable1.getValueAt(jTable1.getSelectedRow(), 3)));
}});
/*****************
Dialogfenster
******************/
final JPanel panel1 =new JPanel();
//panel1.setPreferredSize (new java.awt.Dimension (400, 400));
java.awt.Container c = panel1;
java.awt.GridBagLayout gbl = new java.awt.GridBagLayout ();
c.setLayout( gbl );
addComponent( c, gbl, jLabel3 , 0, 0, 1, 1, 0 , 0 );
addComponent( c, gbl, suchfeld , 1, 0, 5, 1, 0 , 0 );
addComponent( c, gbl, jScrollPane2 , 0, 2, 6, 1, 0 , 0 );
addComponent( c, gbl, jLabel2 , 0, 3, 1, 1, 0 , 0 );
addComponent( c, gbl, mailadresse , 1, 3, 5, 1, 0 , 0 );
addComponent( c, gbl, jRadioButton1, 2, 5, 2, 1, 0 , 0 );
addComponent( c, gbl, jRadioButton2, 2, 6, 2, 1, 0 , 0 );
addComponent( c, gbl, jLabel1 , 0, 4, 1, 2, 0 , 0 );
addComponent( c, gbl, jRadioButton3, 4, 5, 2, 1, 0 , 0 );
addComponent( c, gbl, jRadioButton4, 4, 6, 2, 1, 0 , 0 );
Boolean b = false;
do {
JOptionPane pane = new JOptionPane (panel1, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
final JDialog dialog = pane.createDialog (null, "Weiterleitung an Bank Austria Betreuer");
dialog.setSize (800, 600);
dialog.setResizable (true);
dialog.setVisible(true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowActivated(java.awt.event.WindowEvent e) {
//dialog.requestFocusInWindow();
}});
Object value = pane.getValue ();
if (value != null) {
if (value.toString().equals("0")){if (testadresse(mailadresse.getText())){
b=true;
forward.add(0,"ok");}}
if (value.toString().equals("2")){
b=true;
forward.add(0,"cancel");}
};
}while (!b);
if (jRadioButton1.isSelected()){ArtderWeiterleitung = jRadioButton1.getText();};
if (jRadioButton2.isSelected()){ArtderWeiterleitung = jRadioButton2.getText();};
if (jRadioButton3.isSelected()){ZielderWeiterleitung = jRadioButton3.getText();};
if (jRadioButton4.isSelected()){ZielderWeiterleitung = jRadioButton4.getText();};
/**System.out.println(mailadresse.getText());
System.out.println(ArtderWeiterleitung);
System.out.println(ZielderWeiterleitung);**/
forward.add(1, mailadresse.getText());
forward.add(2, ArtderWeiterleitung);
forward.add(3, ZielderWeiterleitung);
return forward;
}
@SuppressWarnings("unchecked")
final static Vector COLUMN_IDENTIFIERS = new Vector() {
{ add("firma");
add("vorname");
add("name");
add("email"); }};
static void addComponent( java.awt.Container cont,
java.awt.GridBagLayout gbl,
java.awt.Component c,
int x, int y,
int width, int height,
double weightx, double weighty )
{ java.awt.GridBagConstraints gbc = new java.awt.GridBagConstraints();
gbc.fill = java.awt.GridBagConstraints.BOTH;
gbc.gridx = x; gbc.gridy = y;
gbc.gridwidth = width; gbc.gridheight = height;
gbc.weightx = weightx; gbc.weighty = weighty;
gbl.setConstraints( c, gbc );
cont.add( c );
}
static boolean testadresse(String adresse){
boolean c = adresse.matches("[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6}");
return c;
}
public static void warnung(){}
public static javax.swing.table.DefaultTableModel tableMod (){
javax.swing.table.DefaultTableModel tableMod = new javax.swing.table.DefaultTableModel();
return tableMod;
}
}