Package javax.swing.text

Examples of javax.swing.text.MaskFormatter


   * @throws java.text.ParseException if the conversion fails
   */
  public static Calendar convertStringHHMM2TimeCalendarTolerant(String toConvert) throws ParseException {
    if (toConvert != null) {
      // check if the string matches the mask
      MaskFormatter mf = new MaskFormatter(Converter.TIME_MASK);
      mf.stringToValue(toConvert);
      int pos = toConvert.indexOf(Converter.TIME_SEPARATOR);
      String h_str = toConvert.substring(0, pos);
      Integer h = new Integer(h_str);
      String min_str = toConvert.substring(pos + 1);
      Integer min = new Integer(min_str);
View Full Code Here


   * @throws java.text.ParseException if the conversion fails
   */
  public static BigDecimal convertStringHHMM2BigDecimalTolerant(String toConvert) throws ParseException {
    if (toConvert != null) {
      // check if the string matches the mask
      MaskFormatter mf = new MaskFormatter(Converter.TIME_MASK);
      mf.stringToValue(toConvert);
      int pos = toConvert.indexOf(Converter.TIME_SEPARATOR);
      String h = toConvert.substring(0, pos);
      String m = toConvert.substring(pos + 1);
      BigDecimal t = new BigDecimal(m + ".00");
      t = t.divide(new BigDecimal("60.00"), BigDecimal.ROUND_HALF_UP);
View Full Code Here

        minimum = new Double(min);
        maximum = new Double(max);
        this.pmStr = pmStr;
       
        //Set up the editor for the cells.
        MaskFormatter formatter=null;
        try {
            formatter = new MaskFormatter("###�##.#### *");
        } catch (java.text.ParseException exc) {
            System.err.println("formatter is bad: " + exc.getMessage());
            System.exit(-1);
        }
//        integerFormat = NumberFormat.getIntegerInstance();
View Full Code Here

            }
        });

        txtTaskTime.setColumns(6);
        try {
            MaskFormatter mfX = new javax.swing.text.MaskFormatter("##:##:##");
            mfX.setPlaceholderCharacter('0');
            txtTaskTime.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(mfX));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        txtTaskTime.setText("12:29:30");
        txtTaskTime.setName("timeInput"); // NOI18N

        txtTaskDate.setColumns(8);
        try {
            MaskFormatter mfX = new javax.swing.text.MaskFormatter("####.##.##");
            mfX.setPlaceholderCharacter('0');
            txtTaskDate.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(mfX));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        txtTaskDate.setText("2013.11.15");
View Full Code Here

            listaRozwijalna.add(zdarzenie.getId()+"");
        }
       
        panel.add(listaRozwijalna);
       
        MaskFormatter f = new MaskFormatter("****");
        final JFormattedTextField idField = new JFormattedTextField(f);
        idField.setColumns(4);
       
        panel.add(idField);
       
        JButton noweZdarzenie = new JButton("Nowe");
        panel.add(noweZdarzenie);
       
        JButton zapiszZdarzenie = new JButton("Zapisz");
        panel.add(zapiszZdarzenie);
       
        JButton nowaOpcja = new JButton("+Opcja");
        panel.add(nowaOpcja);
       
        this.add(panel, BorderLayout.PAGE_START);
       
        final JTextArea tresc = new JTextArea();
        JScrollPane scroll = new JScrollPane(tresc);
       
        tresc.setLineWrap(true);
        this.add(scroll, BorderLayout.CENTER);
       
        final JPanel dolPanel = new JPanel();
        dolPanel.setLayout(new GridLayout(0,1));
        this.add(dolPanel, BorderLayout.PAGE_END);
       
        this.validate();
        this.repaint();
       
        listaRozwijalna.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                idField.setText(listaRozwijalna.getSelectedItem());
                String trescZdarzenia = listaZdarzen.get(listaRozwijalna.getSelectedIndex()).getZdarzenieText();
                trescZdarzenia = clearText(trescZdarzenia);
                tresc.setText(trescZdarzenia);
               
                ArrayList<SyberiadaOpcja> opcje = listaZdarzen.get(listaRozwijalna.getSelectedIndex()).getListaOpcji();
               
                dolPanel.removeAll();
               
                for (int i = 0; i < opcje.size(); i++) {
                    SyberiadaOpcja opcja = opcje.get(i);
                   
                    JPanel panel = new JPanel();
                    panel.setLayout(new BorderLayout());
                   
                    String opcjaText = opcja.getOpcjatext();
                    JTextField opcjaField = new JTextField();
                    opcjaField.setText(opcjaText);
                    panel.add(opcjaField, BorderLayout.CENTER);
                   
                    int opcjaIdText = opcja.getOpcjaDo();
                    MaskFormatter f;
                    try {
                        f = new MaskFormatter("****");
                        final JFormattedTextField opcjaId = new JFormattedTextField(f);
                        opcjaId.setColumns(4);
                        opcjaId.setText(opcjaIdText+"");
                        panel.add(opcjaId, BorderLayout.LINE_END);
                    } catch (ParseException ex) {
                        Logger.getLogger(Frame.class.getName()).log(Level.SEVERE, null, ex);
                    }
                   
                    dolPanel.add(panel);
                }
                validate();
                repaint();
            }
        });
       
        noweZdarzenie.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                int max = 0;
                for (int i = 0; i < listaRozwijalna.getItemCount(); i++) {
                    if (max<Integer.parseInt(listaRozwijalna.getItem(i))) {
                        max = Integer.parseInt(listaRozwijalna.getItem(i));
                    }
                }
                SyberiadaOpcja newOpcja = new SyberiadaOpcja("",0);
                ArrayList<SyberiadaOpcja> listaOpcji = new ArrayList<SyberiadaOpcja>();
                listaOpcji.add(newOpcja);
               
                max++;
               
                SyberiadaZdarzenie noweZdarzenie = new SyberiadaZdarzenie("", listaOpcji, max);
                listaZdarzen.add(noweZdarzenie);
               
                listaRozwijalna.removeAll();
               
                Collections.sort(listaZdarzen);
                for (int i = 0; i < listaZdarzen.size(); i++) {
                    SyberiadaZdarzenie zdarzenie = listaZdarzen.get(i);
                    listaRozwijalna.add(zdarzenie.getId() + "");
                }
            }
        });
       
         zapiszZdarzenie.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                int selectedID = listaRozwijalna.getSelectedIndex();
                SyberiadaZdarzenie zdarzenieDoZmiany = listaZdarzen.get(selectedID);
                String noweIdStr = idField.getText().replaceAll("[\\D]", "");
                zdarzenieDoZmiany.setId(Integer.parseInt(noweIdStr));
               
                String text = tresc.getText();
                text = text.replaceAll("\n", "<br/>");
                text = text.replaceAll("\t", "&nbsp");
                zdarzenieDoZmiany.setZdarzenieText(text);

                ArrayList<SyberiadaOpcja> opcje = new ArrayList<SyberiadaOpcja>();
               
                for (int i = 0; i < dolPanel.getComponentCount(); i++) {
                    JPanel panel = (JPanel) dolPanel.getComponent(i);
                    String trescOpcji = ((JTextField)panel.getComponent(0)).getText();
                    if (trescOpcji.equalsIgnoreCase("")) {
                       
                    } else {
                        String trescDo = ((JFormattedTextField)panel.getComponent(1)).getText();
                        System.out.println(trescDo);
                        String doKad = ((JFormattedTextField)panel.getComponent(1)).getText().replaceAll("[\\D]", "");
                        int doKadInt = Integer.parseInt(doKad);
                        SyberiadaOpcja nowaOpcja  = new SyberiadaOpcja(trescOpcji, doKadInt);
                        opcje.add(nowaOpcja);
                    }
                }
                zdarzenieDoZmiany.setListaOpcji(opcje);
               
                listaRozwijalna.removeAll();
                Collections.sort(listaZdarzen);
                for (int i = 0; i < listaZdarzen.size(); i++) {
                    SyberiadaZdarzenie zdarzenie = listaZdarzen.get(i);
                    listaRozwijalna.add(zdarzenie.getId() + "");
                }
                listaRozwijalna.select(selectedID);
                try {
                    XMLParser.getXMLParser().saveXML(listaZdarzen);
                } catch (ParserConfigurationException ex) {
                    Logger.getLogger(Frame.class.getName()).log(Level.SEVERE, null, ex);
                } catch (TransformerConfigurationException ex) {
                    Logger.getLogger(Frame.class.getName()).log(Level.SEVERE, null, ex);
                } catch (TransformerException ex) {
                    Logger.getLogger(Frame.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
        
         nowaOpcja.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JPanel panel = new JPanel();
                panel.setLayout(new BorderLayout());
                String opcjaText = "";
                JTextField opcjaField = new JTextField();
                opcjaField.setText(opcjaText);
                panel.add(opcjaField, BorderLayout.CENTER);

                int opcjaIdText = 0;
                MaskFormatter f;
                try {
                    f = new MaskFormatter("****");
                    final JFormattedTextField opcjaId = new JFormattedTextField(f);
                    opcjaId.setColumns(4);
                    opcjaId.setText(opcjaIdText + "");
                    panel.add(opcjaId, BorderLayout.LINE_END);
                } catch (ParseException ex) {
View Full Code Here

  public void setMaskVisible(boolean isMaskVisible) {
    this.isMaskVisible = isMaskVisible;
    if (isMaskVisible) {
      if (maskFormatter == null) {
        try {
          maskFormatter = new MaskFormatter(createMaskFromDatePattern(datePattern));
          maskFormatter.setPlaceholderCharacter(this.placeholder);
          maskFormatter.install(this);
        } catch (ParseException e) {
          e.printStackTrace();
        }
View Full Code Here

   */
  public MaskConverter(String mask, Class/* <?> */type)
  {
    try
    {
      maskFormatter = new MaskFormatter(mask);
      maskFormatter.setValueClass(type);
      maskFormatter.setAllowsInvalid(true);
      maskFormatter.setValueContainsLiteralCharacters(true);
    }
    catch (ParseException e)
View Full Code Here

     * Metoda vytvari formatovaci objekt pro IP adresy.
     *
     * @return instance tridy MaskFormatter
     */
    private MaskFormatter getIPFormat() {
        MaskFormatter maskIP = null;
        try {
            maskIP = new MaskFormatter("###.###.###.###");
            maskIP.setPlaceholder("000.000.000.000");
            maskIP.setValidCharacters("0123456789");
            maskIP.setAllowsInvalid(false);
        } catch (ParseException ex) {
            ex.printStackTrace();
        }
        return maskIP;
    }
View Full Code Here

     * @throws java.text.ParseException if the conversion fails
     */
    public static Calendar convertStringHHMM2TimeCalendarTolerant(String toConvert) throws ParseException {
        if (toConvert != null) {
            // check if the string matches the mask
            MaskFormatter mf = new MaskFormatter(Converter.TIME_MASK);
            mf.stringToValue(toConvert);
            int pos = toConvert.indexOf(Converter.TIME_SEPARATOR);
            String h_str = toConvert.substring(0, pos);
            Integer h = new Integer(h_str);
            String min_str = toConvert.substring(pos + 1);
            Integer min = new Integer(min_str);
View Full Code Here

     * @throws java.text.ParseException if the conversion fails
     */
    public static BigDecimal convertStringHHMM2BigDecimalTolerant(String toConvert) throws ParseException {
        if (toConvert != null) {
            // check if the string matches the mask
            MaskFormatter mf = new MaskFormatter(Converter.TIME_MASK);
            mf.stringToValue(toConvert);
            int pos = toConvert.indexOf(Converter.TIME_SEPARATOR);
            String h = toConvert.substring(0, pos);
            String m = toConvert.substring(pos + 1);
            BigDecimal t = new BigDecimal(m + ".00");
            t = t.divide(new BigDecimal("60.00"), BigDecimal.ROUND_HALF_UP);
View Full Code Here

TOP

Related Classes of javax.swing.text.MaskFormatter

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.