00001 package clientswing.UI;
00002
00003 import javax.swing.*;
00004 import java.util.*;
00005 import java.awt.*;
00006 import java.awt.event.*;
00007 import clientswing.model.*;
00008
00015 public class OptionPanelWhere
00016 extends BaseForm {
00017
00019 JLabel[] labels =null;
00023 JLabel errore = new JLabel();
00025 JTextField[] textFields=null;
00027 Column[] columns=new Column[3];
00029 JButton invia = new JButton("invia");
00031 JTextField columnNumSet;
00033 boolean isError;
00034
00036 JLabel[] labelsValue =null;
00038 JTextField[] textFieldsValue=null;
00039
00043 public OptionPanelWhere(JTextField columnNumSet) {
00044
00045 Toolkit kit = Toolkit.getDefaultToolkit();
00046 Dimension screenSize = kit.getScreenSize();
00047
00048 int screenHeight = screenSize.height;
00049 int screenWidth = screenSize.width;
00050
00051 setSize(screenWidth / 2, screenHeight / 2);
00052 setLocation(screenWidth / 4 + 350, screenHeight / 4);
00053
00054 this.getContentPane().setLayout(null);
00055
00056 int num = 0;
00057 isError = false;
00058 try {
00059 num = Integer.parseInt(columnNumSet.getText());
00060 try {
00061 labels = new JLabel[num];
00062 textFields = new JTextField[num];
00063 labelsValue = new JLabel[num];
00064 textFieldsValue = new JTextField[num];
00065
00066 }
00067 catch (Exception ex1) {
00068 columnNumSet.setBackground(Color.pink);
00069
00070
00071
00072
00073 JOptionPane.showMessageDialog(null, "errore di inserimento",
00074 "errore di inserimento",
00075 JOptionPane.WARNING_MESSAGE);
00076 isError = true;
00077 return;
00078
00079 }
00080 }
00081 catch (NumberFormatException ex) {
00082 columnNumSet.setBackground(Color.pink);
00083
00084 JOptionPane.showMessageDialog(null, "errore di inserimento",
00085 "errore di inserimento",
00086 JOptionPane.WARNING_MESSAGE);
00087 invia.setVisible(false);
00088 isError = true;
00089 return;
00090 }
00091
00092 int i;
00093
00094
00095
00096 columnNumSet.setBackground(Color.white);
00097 for (i = 0; i < labels.length; i++) {
00098
00099 labels[i] = new JLabel();
00100 labels[i].setText("Nome campo");
00101
00102 labels[i].setBounds(new Rectangle(10, 40 + 25 * i, 90, 20));
00103 labels[i].setForeground(Color.black);
00104 textFields[i] = new JTextField();
00105 textFields[i].setBounds(new Rectangle(110, 40 + 25 * i, 70, 20));
00106 this.getContentPane().add(labels[i]);
00107 this.getContentPane().add(textFields[i]);
00108
00109 labelsValue[i] = new JLabel();
00110 labelsValue[i].setText("Valore campo");
00111
00112 labelsValue[i].setBounds(new Rectangle(190, 40 + 25 * i, 90, 20));
00113 labelsValue[i].setForeground(Color.black);
00114 textFieldsValue[i] = new JTextField();
00115 textFieldsValue[i].setBounds(new Rectangle(300, 40 + 25 * i, 70, 20));
00116 this.getContentPane().add(labelsValue[i]);
00117 this.getContentPane().add(textFieldsValue[i]);
00118
00119 }
00120 int height = 140 + num * 20;
00121 this.setSize(400, height);
00122 invia.setBounds(new Rectangle(150, 45 + 25 * i, 80, 20));
00123 invia.setBackground(Color.white);
00124 invia.setForeground(Color.gray);
00125 this.getContentPane().add(invia);
00126 this.getContentPane().add(errore);
00127
00128 invia.addMouseListener(new OptionPanelWhere_invia_mouseAdapter(this));
00129
00130 }
00131
00132 void invia_mouseClicked(MouseEvent e) {
00133
00134 System.out.println("num=" + labels.length + "\n");
00135 columns = new Column[labels.length];
00136 for (int i = 0; i < labels.length; i++) {
00137 columns[i] = new Column(textFields[i].getText(),
00138 textFieldsValue[i].getText());
00139 System.out.println("column valore = " + columns[i].getValue() +
00140 "column Nome = " + columns[i].getName());
00141 }
00142 this.hide();
00143 }
00144
00145 public boolean getIsError() {
00146 return isError;
00147 }
00148
00149 public Column[] getColumns() {
00150 return columns;
00151 }
00152 }
00153
00154 class OptionPanelWhere_invia_mouseAdapter
00155 extends java.awt.event.MouseAdapter {
00156 OptionPanelWhere adaptee;
00157
00158 OptionPanelWhere_invia_mouseAdapter(OptionPanelWhere adaptee) {
00159 this.adaptee = adaptee;
00160 }
00161
00162 public void mouseClicked(MouseEvent e) {
00163 adaptee.invia_mouseClicked(e);
00164 }
00165 }