Package javax.swing.text

Examples of javax.swing.text.NumberFormatter


     * @param boleto
     *
     */
    public InputStream transform(Boleto... boletos) {

        NumberFormatter formatter = new NumberFormatter(new DecimalFormat(
                "#,##0.00"));

        // gera template com o fundo do boleto
        URL imagemTitulo = BoletoTransformer.class
                .getResource("/br/com/caelum/stella/boleto/img/template.png");

        boolean firstPage = true;
        for (Boleto boleto : boletos) {
            if (!firstPage) {
                this.writer.newPage();
            }
            try {
                this.writer.writeImage(0, 55, imageFor(imagemTitulo), 514.22f,
                        385.109f);
                this.writer.writeImage(0, 805 - 486, imageFor(boleto.getBanco()
                        .getImage()), 100, 23);
            } catch (IOException e) {
                throw new GeracaoBoletoException(
                        "Erro na leitura das imagens do boleto", e);
            }

            for (int i = 0; i < boleto.getDescricoes().size(); i++) {
                this.writer.writeBold(5, 805 - 70 - i * 15, boleto
                        .getDescricoes().get(i));
            }

            this.writer.write(50, LINHA1, boleto.getEmissor().getCedente());

            this.writer.write(5, LINHA2, boleto.getSacado().getNome());

            this.writer.write(230, LINHA2, formatDate(boleto.getDatas()
                    .getVencimento()));

            try {
                this.writer.write(400, LINHA2, formatter.valueToString(boleto
                        .getValorBoleto().doubleValue()));
            } catch (NumberFormatException e) {
                throw new CriacaoBoletoException(
                        "Erro na formatação do valor do boleto", e);
            } catch (ParseException e) {
                throw new CriacaoBoletoException(
                        "Erro na formatação do valor do boleto", e);
            }

            this.writer.write(5, LINHA3, boleto.getEmissor()
                    .getAgenciaFormatado()
                    + "-"
                    + boleto.getEmissor().getDvAgencia()
                    + " / "
                    + boleto.getBanco().getContaCorrenteDoEmissorFormatado(
                            boleto.getEmissor())
                    + "-"
                    + boleto.getEmissor().getDvContaCorrente());

            this.writer.write(146, LINHA3, boleto.getBanco()
                    .getNossoNumeroDoEmissorFormatado(boleto.getEmissor()));

            this.writer.writeBold(125, LINHA4, boleto.getBanco()
                    .getNumeroFormatado());

            LinhaDigitavelGenerator linhaDigitavelGenerator = new LinhaDigitavelGenerator();
            this.writer.writeBold(175, LINHA4, linhaDigitavelGenerator
                    .geraLinhaDigitavelPara(boleto));

            for (int i = 0; i < boleto.getLocaisDePagamento().size(); i++) {
                this.writer.write(5, LINHA5 - (i - 1) * 10, boleto
                        .getLocaisDePagamento().get(i));
            }

            this.writer.write(425, LINHA5, formatDate(boleto.getDatas()
                    .getVencimento()));

            this.writer.write(5, LINHA6, boleto.getEmissor().getCedente());

            this.writer.write(420, LINHA6, boleto.getEmissor()
                    .getAgenciaFormatado()
                    + " - "
                    + boleto.getEmissor().getDvAgencia()
                    + " / "
                    + boleto.getBanco().getContaCorrenteDoEmissorFormatado(
                            boleto.getEmissor())
                    + "-"
                    + boleto.getEmissor().getDvContaCorrente());

            this.writer.write(5, LINHA7, formatDate(boleto.getDatas()
                    .getDocumento()));

            this.writer.write(70, LINHA7,
                    !boleto.getNoDocumento().equals("") ? boleto
                            .getNoDocumentoFormatado() : boleto.getBanco()
                            .getNossoNumeroDoEmissorFormatado(
                                    boleto.getEmissor()));

            this.writer.write(180, LINHA7, boleto.getEspecieDocumento());

            this.writer.write(250, LINHA7, boleto.getAceite() ? "S" : "N");

            this.writer.write(300, LINHA7, formatDate(boleto.getDatas()
                    .getProcessamento()));

            this.writer.write(410, LINHA7, boleto.getEmissor().getCarteira()
                    + " / "
                    + boleto.getBanco().getNossoNumeroDoEmissorFormatado(
                            boleto.getEmissor()));

            this.writer.write(122, LINHA8, boleto.getBanco()
                    .getCarteiraDoEmissorFormatado(boleto.getEmissor()));

            this.writer.write(190, LINHA8, boleto.getEspecieMoeda());

            try {
                this.writer.write(430, LINHA8, formatter.valueToString(boleto
                        .getValorBoleto().doubleValue()));
            } catch (NumberFormatException e) {
                throw new CriacaoBoletoException(
                        "Erro na formatação do valor do boleto", e);
            } catch (ParseException e) {
View Full Code Here


      distPanel.setBorder(title);
      distPanel.add(distBox);

      java.text.NumberFormat numberFormat = java.text.NumberFormat
            .getIntegerInstance();
      formatter = new NumberFormatter(numberFormat);
      formatter.setMinimum(new Integer(1));
      formatter.setMaximum(new Integer(MAX_RECT));

      textField = new JFormattedTextField(formatter);
      textField.setValue(new Integer(MAX_RECT / 2));
View Full Code Here

    {
      DefaultFormatterFactory factory;
      if (child instanceof DateFormat)
        factory = new DefaultFormatterFactory(new DateFormatter((DateFormat)child));
      else if (child instanceof NumberFormat)
        factory = new DefaultFormatterFactory(new NumberFormatter((NumberFormat)child));
      else
        factory = new DefaultFormatterFactory(new InternationalFormatter((Format)child));
      ((JFormattedTextField)parent).setFormatterFactory (factory);
    }
    else if (child instanceof JFormattedTextField.AbstractFormatter)
View Full Code Here

            throw new IllegalArgumentException(
                      "model not a SpinnerBigNumberModel");
        }

        SpinnerBigDecimalModel model = (SpinnerBigDecimalModel)spinner.getModel();
        NumberFormatter formatter = new NumberEditorFormatter(model, format);
        DefaultFormatterFactory factory = new DefaultFormatterFactory(formatter);
        JFormattedTextField ftf = getTextField();
        ftf.setEditable(true);
        ftf.setFormatterFactory(factory);
        ftf.setHorizontalAlignment(JTextField.RIGHT);

        /* TBD - initializing the column width of the text field
         * is imprecise and doing it here is tricky because
         * the developer may configure the formatter later.
         */
        try {
            String maxString = formatter.valueToString(model.getMinimum());
            String minString = formatter.valueToString(model.getMaximum());
            ftf.setColumns(Math.max(maxString.length(), minString.length()));
        }
        catch (ParseException e) {
            // TBD should throw a chained error here
        }
View Full Code Here

      c.weightx = 0.0;
      serverSelectPanel.add(label, c);

      NumberFormat nf = NumberFormat.getIntegerInstance();
      nf.setGroupingUsed(false);
      serverPortField = new JFormattedTextField(new NumberFormatter(nf));
      serverPortField.setColumns(5);
      serverPortField.setText(String.valueOf(SERVER_DEFAULT_PORT));
      c.gridx++;
      serverSelectPanel.add(serverPortField, c);
View Full Code Here

      c.anchor = GridBagConstraints.EAST;
      socketPanel.add(label, c);
     
      NumberFormat nf = NumberFormat.getIntegerInstance();
      nf.setGroupingUsed(false);
      listenPortField = new JFormattedTextField(new NumberFormatter(nf));
      listenPortField.setColumns(5);
      listenPortField.setText(String.valueOf(SERVER_DEFAULT_PORT));
      c.gridx++;
      c.weightx = 0.0;
      socketPanel.add(listenPortField, c);
View Full Code Here

TOP

Related Classes of javax.swing.text.NumberFormatter

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.