Object [][] oRows = new Object[numRows][4];
JTextField jtf = null;
JComboBox jcb = null;
JTextArea jta = null;
JScrollPane jsp = null;
JFormattedTextField jftf = null;
DatePickerObserver dpo = null;
int posY = 0;
int incremento = 22;
Dimension dimTitulo = new Dimension(100,22);
Dimension dimTexto = new Dimension(355,22);
Dimension dimTexto2 = new Dimension(355,88);
Dimension dimTipo = new Dimension(120,22);
Dimension dimTipo2 = new Dimension(88,22);
FocusListener flTextField = new FocusListener(){
public void focusGained(FocusEvent e) {
((JTextField)e.getSource()).selectAll();
}
public void focusLost(FocusEvent e) {
}
};
FocusListener flTextArea = new FocusListener(){
public void focusGained(FocusEvent e) {
}
public void focusLost(FocusEvent e) {
String cadena = ((JTextArea)e.getSource()).getText();
if(cadena.length() > 0 && cadena.charAt(cadena.length() - 1) == '\t')
((JTextArea)e.getSource()).setText(cadena.substring(0,cadena.length() - 1));
}
};
KeyListener commandKeyListener = new KeyListener() {
public void keyTyped(KeyEvent e) {
}
public void keyPressed(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
if(e.isControlDown() && e.isShiftDown() && e.getKeyCode() == e.VK_ENTER)
{
jbCrearYContinuarActionPerformed(null);
}
else if(e.isControlDown() && e.getKeyCode() == e.VK_ENTER)
{
jbCrearActionPerformed(null);
}
else if(e.getKeyCode() == e.VK_ESCAPE)
{
jbCancelarActionPerformed(null);
}
}
};
class LimiteKeyListener implements KeyListener {
private int limiteDelTexto = -1;
public LimiteKeyListener(int limiteDelTexto)
{
this.limiteDelTexto = limiteDelTexto;
}
public void keyTyped(KeyEvent e) {
}
public void keyPressed(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
if(((JTextField)e.getSource()).getText().length() > limiteDelTexto)
{
Toolkit.getDefaultToolkit().beep();
}
}
};
for(int i=0, limite = vResulSet.size(); i < limite; i++)
{
hmTemp = vResulSet.elementAt(i);
if(((String)hmTemp.get("IS_AUTOINCREMENT")).equals("YES") == false)
{
incremento = 22;
JPanel jp = new JPanel();
jp.setLayout(new FlowLayout());
JPanel jp2 = new JPanel(new BorderLayout());
JLabel jl = new JLabel((String)hmTemp.get("COLUMN_NAME"));
jl.setPreferredSize(dimTitulo);
jp2.add(jl,BorderLayout.WEST);
int tiposql = ((Integer)hmTemp.get("DATA_TYPE")).intValue();
if(tiposql == java.sql.Types.OTHER)
{
String type_name = (String)hmTemp.get("TYPE_NAME");
if(type_name.toLowerCase().equals("float") || type_name.toLowerCase().equals("real") || type_name.toLowerCase().equals("double"))
{
hmTemp.put("DATA_TYPE2", String.valueOf(java.sql.Types.REAL));
tiposql = java.sql.Types.REAL;
}
else if(type_name.toLowerCase().equals("clob"))
{
hmTemp.put("DATA_TYPE2", String.valueOf(java.sql.Types.CLOB));
tiposql = java.sql.Types.CLOB;
}
else if(type_name.toLowerCase().equals("nclob"))
{
hmTemp.put("DATA_TYPE2", String.valueOf(java.sql.Types.NCLOB));
tiposql = java.sql.Types.NCLOB;
}
else if(type_name.toLowerCase().equals("blob"))
{
hmTemp.put("DATA_TYPE2", String.valueOf(java.sql.Types.BLOB));
tiposql = java.sql.Types.BLOB;
}
else if(type_name.toLowerCase().equals("nvarchar2"))
{
hmTemp.put("DATA_TYPE2", String.valueOf(java.sql.Types.NVARCHAR));
tiposql = java.sql.Types.NVARCHAR;
}
else if(type_name.toLowerCase().equals("nchar"))
{
hmTemp.put("DATA_TYPE2", String.valueOf(java.sql.Types.NCHAR));
tiposql = java.sql.Types.NCHAR;
}
}
switch(tiposql)
{
case java.sql.Types.BOOLEAN:
case java.sql.Types.BIT:
jcb = new JComboBox(bool);
jcb.setOpaque(true);
jcb.setPreferredSize(dimTexto);
jcb.addKeyListener(commandKeyListener);
jp2.add(jcb,BorderLayout.CENTER);
hmTemp.put("contenido", jcb);
jl = new JLabel(hmTemp.get("TYPE_NAME").toString());
jl.setPreferredSize(dimTipo);
jp2.add(jl,BorderLayout.EAST);
break;
case java.sql.Types.DECIMAL:
case java.sql.Types.DOUBLE:
case java.sql.Types.FLOAT:
case java.sql.Types.NUMERIC:
case java.sql.Types.REAL:
NumberFormat nf = NumberFormat.getNumberInstance();
if(jdbcDriverURL.indexOf("cubrid") == -1) // si no es cubrid ponemos los limites, cubrid retorna siempre 0
{
nf.setMaximumIntegerDigits(((Integer)hmTemp.get("COLUMN_SIZE")).intValue());
nf.setMaximumFractionDigits(((Integer)hmTemp.get("DECIMAL_DIGITS")).intValue());
}
nf.setRoundingMode(RoundingMode.FLOOR);
jftf = new JFormattedTextField (nf);
jftf.setPreferredSize(dimTexto);
jftf.addFocusListener(flTextField);
jftf.addKeyListener(commandKeyListener);
jp2.add(jftf,BorderLayout.CENTER);
hmTemp.put("contenido", jftf);
jl = new JLabel(hmTemp.get("TYPE_NAME") + " (" + hmTemp.get("COLUMN_SIZE") + "," + hmTemp.get("DECIMAL_DIGITS") + ")");
jl.setPreferredSize(dimTipo);
jp2.add(jl,BorderLayout.EAST);
break;
case java.sql.Types.INTEGER:
case java.sql.Types.ROWID:
case java.sql.Types.SMALLINT:
case java.sql.Types.TINYINT:
nf = NumberFormat.getNumberInstance();
int tamanioColumna = Math.max(((Integer)hmTemp.get("COLUMN_SIZE")).intValue(), 3);
nf.setMaximumIntegerDigits(tamanioColumna);
nf.setMaximumFractionDigits(0);
jftf = new JFormattedTextField (nf);
jftf.setPreferredSize(dimTexto);
jftf.addFocusListener(flTextField);
jftf.addKeyListener(commandKeyListener);
jp2.add(jftf,BorderLayout.CENTER);
hmTemp.put("contenido", jftf);
jl = new JLabel(hmTemp.get("TYPE_NAME") + " (" + hmTemp.get("COLUMN_SIZE") + ")");
jl.setPreferredSize(dimTipo);
jp2.add(jl,BorderLayout.EAST);
break;
case java.sql.Types.BIGINT:
nf = NumberFormat.getNumberInstance();
tamanioColumna = Math.max(((Integer)hmTemp.get("COLUMN_SIZE")).intValue(), 19);
nf.setMaximumIntegerDigits(tamanioColumna);
nf.setMaximumFractionDigits(0);
jftf = new JFormattedTextField (nf);
jftf.setValue(new Long(0));
jftf.setPreferredSize(dimTexto);
jftf.addFocusListener(flTextField);
jftf.addKeyListener(commandKeyListener);
jp2.add(jftf,BorderLayout.CENTER);
hmTemp.put("contenido", jftf);
jl = new JLabel(hmTemp.get("TYPE_NAME") + " (" + hmTemp.get("COLUMN_SIZE") + ")");
jl.setPreferredSize(dimTipo);
jp2.add(jl,BorderLayout.EAST);
break;
case java.sql.Types.DATE:
case java.sql.Types.TIME:
case java.sql.Types.TIMESTAMP:
DateFormatter df = new DateFormatter(DateFormat.getDateInstance());
if(tiposql == java.sql.Types.TIME)
df = new DateFormatter(DateFormat.getTimeInstance());
else if(tiposql == java.sql.Types.TIMESTAMP || jdbcDriverURL.indexOf("oracle") != -1)
df = new DateFormatter(DateFormat.getDateTimeInstance());
if(tiposql != java.sql.Types.TIME)
{
dpo = new DatePickerObserver (df);
dpo.setValue(new Date());
dpo.setPreferredSize(dimTexto);
dpo.jtf.addFocusListener(flTextField);
dpo.jtf.addKeyListener(commandKeyListener);
jp2.add(dpo,BorderLayout.CENTER);
hmTemp.put("contenido", dpo.jtf);
}
else
{
jftf = new JFormattedTextField (df);
jftf.setValue(new Date());
jftf.setPreferredSize(dimTexto);
jftf.addFocusListener(flTextField);
jftf.addKeyListener(commandKeyListener);
jp2.add(jftf,BorderLayout.CENTER);
}
jl = new JLabel(hmTemp.get("TYPE_NAME").toString());