Package javax.swing

Examples of javax.swing.JFormattedTextField$AbstractFormatter


            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());
View Full Code Here


   
    public DatePickerObserver(DateFormatter df) {
        super();
       
        this.setLayout(new java.awt.BorderLayout());
        jtf = new JFormattedTextField (df);
        jtf.addActionListener(this);
        jtf.setFocusLostBehavior(JFormattedTextField.COMMIT);
        this.add(jtf,java.awt.BorderLayout.CENTER);
       
        jbPick = new JButton(new javax.swing.ImageIcon(getClass().getResource("/com/GestDB/images/calendar.png")));
View Full Code Here

        setTitleMsgNumber(TitleMsgNum.intValue());
    }

    public ArrayColumn(int alignment, int maxCharacters, TextData Name, int sizePolicy, int state, TextData title) {
        super();
        int width = UIutils.colsToPixels(maxCharacters, new JFormattedTextField());
        this.assignedWidth = width;
        this.setWidth(width);
        this.setMinWidth(width);
       
        if ((Name == null) || Name.isEqual("").getBooleanValue())
View Full Code Here

          if (table != null) {
            if (ArrayFieldCellHelper.getArrayEditorComponent(table) == focusOwner) {
              // TF:08/06/2008:LIB-17:If this is a formatted field, we must use the getValue method,
              // otherwise we will potentially have formatting errors on masked fields.
              if (focusOwner instanceof JFormattedTextField) {
                JFormattedTextField formattedField = (JFormattedTextField)focusOwner;
                try {
                  formattedField.commitEdit();
                  //GK/DK: convert column index to a model index to set value
                  table.setValueAt(formattedField.getValue(), table.getEditingRow(), table.getEditingColumn());
                }
                catch (ParseException e) {
                  _log.error("Unhandled parse exception committing field edit: ", e);
                }
              }
View Full Code Here

          if (table != null) {
            if (ArrayFieldCellHelper.getArrayEditorComponent(table) == focusOwner) {
              // TF:08/06/2008:LIB-17:If this is a formatted field, we must use the getValue method,
              // otherwise we will potentially have formatting errors on masked fields.
              if (focusOwner instanceof JFormattedTextField) {
                JFormattedTextField formattedField = (JFormattedTextField)focusOwner;
                try {
                  formattedField.commitEdit();
                  //GK/DK: convert column index to a model index to set value
                  table.setValueAt(formattedField.getValue(), table.getEditingRow(), table.getEditingColumn());
                }
                catch (ParseException e) {
                  _log.error("Unhandled parse exception committing field edit: ", e);
                }
              }
View Full Code Here

    private JFormattedTextField textField;

    public JFormattedTextFieldEditor()
    {
        textField = new JFormattedTextField();
        textField.setFocusLostBehavior(JFormattedTextField.PERSIST);
    }
View Full Code Here

        this.textField.setFocusLostBehavior(JFormattedTextField.PERSIST);
    }

    public JFormattedTextFieldEditor(DefaultFormatter formatter)
    {
        textField = new JFormattedTextField(formatter);
        textField.setFocusLostBehavior(JFormattedTextField.PERSIST);
    }
View Full Code Here

    public <T> T input(T defaultValue) {

      TaskDialog dlg = questionDialog(parent, getTitle(TaskDialog.makeKey("Input")), null, instruction, text);
      dlg.setIcon(getIcon(TaskDialog.StandardIcon.INFO));

      JFormattedTextField tfInput = new JFormattedTextField();
      tfInput.setColumns(inputColumns == null ? 25 : inputColumns);
      tfInput.setValue(defaultValue);
      dlg.setFixedComponent(tfInput);

      dlg.setCommands(StandardCommand.OK, StandardCommand.CANCEL);

      return (T) (dlg.show().equals(StandardCommand.OK) ? tfInput.getValue() : null);

    }
View Full Code Here

    public <T> T input( T defaultValue ) {

      TaskDialog dlg = questionDialog( parent, getTitle( TaskDialog.makeKey("Input")), null, instruction, text);
      dlg.setIcon( getIcon( TaskDialog.StandardIcon.INFO ));

      JFormattedTextField tfInput = new JFormattedTextField();
      tfInput.setColumns( inputColumns == null? 25: inputColumns );
      tfInput.setValue( defaultValue );
      dlg.setFixedComponent( tfInput );

          dlg.setCommands( StandardCommand.OK, StandardCommand.CANCEL );

      return (T) (dlg.show().equals(StandardCommand.OK)? tfInput.getValue(): null);

    }
View Full Code Here

    public <T> T input(T defaultValue) {

      TaskDialog dlg = questionDialog(parent, getTitle(TaskDialog.makeKey("Input")), null, instruction, text);
      dlg.setIcon(getIcon(TaskDialog.StandardIcon.INFO));

      JFormattedTextField tfInput = new JFormattedTextField();
      tfInput.setColumns(inputColumns == null ? 25 : inputColumns);
      tfInput.setValue(defaultValue);
      dlg.setFixedComponent(tfInput);

      dlg.setCommands(StandardCommand.OK, StandardCommand.CANCEL);

      return (T) (dlg.show().equals(StandardCommand.OK) ? tfInput.getValue() : null);

    }
View Full Code Here

TOP

Related Classes of javax.swing.JFormattedTextField$AbstractFormatter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.