Source Code Cross Referenced for ConfiguravelTableCellRenderer.java in  » ERP-CRM-Financial » Personal-Finance-Manager » br » com » gfpshare » beans » table » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » Personal Finance Manager » br.com.gfpshare.beans.table 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on 01/01/2004
003:         * 
004:         * Swing Components - visit http://sf.net/projects/gfd
005:         * 
006:         * Copyright (C) 2004  Igor Regis da Silva Simões
007:         * 
008:         * This program is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU General Public License
010:         * as published by the Free Software Foundation; either version 2
011:         * of the License, or (at your option) any later version.
012:         *
013:         * This program is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016:         * GNU General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU General Public License
019:         * along with this program; if not, write to the Free Software
020:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
021:         * 
022:         */
023:        package br.com.gfpshare.beans.table;
024:
025:        import java.awt.Color;
026:        import java.awt.Component;
027:        import java.text.DateFormat;
028:        import java.text.NumberFormat;
029:        import java.text.ParseException;
030:        import java.text.SimpleDateFormat;
031:        import java.util.Locale;
032:
033:        import javax.swing.JLabel;
034:        import javax.swing.JTable;
035:        import javax.swing.text.MaskFormatter;
036:
037:        import br.com.gfpshare.util.CNPJ;
038:        import br.com.gfpshare.util.CPF;
039:
040:        /**
041:         * This is a general propose table cell renderer that can render
042:         * data from generic types that don't need database access to be
043:         * represented
044:         * 
045:         * @author Igor Regis da Silva Simões
046:         */
047:        public class ConfiguravelTableCellRenderer extends
048:                TableCellRendererListradoCinza {
049:            /**
050:             * The money format
051:             */
052:            public static final int DINHEIRO = 1;
053:
054:            /**
055:             * The percentage format
056:             */
057:            public static final int PORCENTAGEM = 2;
058:
059:            /**
060:             * The Date format
061:             */
062:            public static final int DATA = 3;
063:
064:            /**
065:             * The Brazilian CPF format
066:             */
067:            public static final int CPF = 4;
068:
069:            /**
070:             * The BRazilian CNPJ format
071:             */
072:            public static final int CNPJ = 5;
073:
074:            /**
075:             * The boolean format
076:             */
077:            public static final int BOOLEANO = 6;
078:
079:            private int formato;
080:
081:            private int subformato = -1;
082:
083:            @SuppressWarnings("unused")
084:            private Locale local = Locale.getDefault();
085:
086:            /**
087:             * This is a general propose table cell renderer that can render
088:             * data from generic types that don't need database access to be
089:             * represented
090:             * 
091:             * @param formato The format that will be used to represent the data
092:             * @param subformato The sub-format to be used (if exists)
093:             */
094:            public ConfiguravelTableCellRenderer(int formato, int subformato) {
095:                setFormato(formato, subformato);
096:            }
097:
098:            /**
099:             * Determina o formato de dados queeste renderer irá exibir
100:             * 
101:             * @param formato Formato aplicado ao dado
102:             * @param subformato Subformata a ser aplicado
103:             */
104:            public void setFormato(int formato, int subformato) {
105:                this .formato = formato;
106:                this .subformato = subformato;
107:            }
108:
109:            /**
110:             * Retorna o subformato atual
111:             * 
112:             * @return int representando o subformato atual
113:             */
114:            public int getSubformato() {
115:                return this .subformato;
116:            }
117:
118:            /**
119:             * Retorna o formato atual
120:             * 
121:             * @return int representando o formato atual
122:             */
123:            public int getFormato() {
124:                return this .formato;
125:            }
126:
127:            /**
128:             * Determina a localização dos formatos
129:             * 
130:             * @param local
131:             */
132:            @Override
133:            public void setLocale(Locale local) {
134:                this .local = local;
135:            }
136:
137:            /**
138:             * Sobrescreve o método da superclasse para retornar um renderer formatado, conforme descrito acima
139:             * 
140:             * @param table JTable Tabela que será configurada por este renderer
141:             * @param value Object Valor que será exibido pelo renderer
142:             * @param isSelected boolean Indicando se a célula está selecionada
143:             * @param hasFocus boolean indicando se a célual possui o foco
144:             * @param row int Linha da célula
145:             * @param column int Coluna da célula
146:             * @return Retorna o Compoment responsável por renderizar o valor da célula
147:             */
148:            @Override
149:            public Component getTableCellRendererComponent(JTable table,
150:                    Object value, boolean isSelected, boolean hasFocus,
151:                    int row, int column) {
152:                super .getTableCellRendererComponent(table, value, isSelected,
153:                        hasFocus, row, column);
154:
155:                setForeground(Color.BLACK);
156:
157:                String valor = null;
158:
159:                if (value != null) {
160:                    switch (formato) {//TODO Adicionar internacionalização
161:                    case DINHEIRO: {
162:                        try {
163:
164:                            valor = NumberFormat.getCurrencyInstance().format(
165:                                    value);
166:                            if (Double.parseDouble(value.toString()) < 0)
167:                                setForeground(Color.RED);
168:                            else
169:                                setForeground(Color.BLACK);
170:                        } catch (Exception e) {
171:                            //Não Fazemos anda
172:                        }
173:                        break;
174:                    }
175:                    case PORCENTAGEM: {
176:                        NumberFormat formatter = NumberFormat
177:                                .getPercentInstance();
178:                        formatter.setMaximumFractionDigits(5);
179:                        formatter.setMinimumFractionDigits(5);
180:                        valor = formatter.format((Double.parseDouble(value
181:                                .toString()) / 100d));
182:                        setHorizontalAlignment(JLabel.RIGHT);
183:                        break;
184:                    }
185:                    case DATA: {
186:                        valor = DateFormat.getDateInstance(DateFormat.MEDIUM)
187:                                .format(value);
188:                        setHorizontalAlignment(JLabel.CENTER);
189:                        setToolTipText(new SimpleDateFormat("EEEEEE").format(value)); //$NON-NLS-1$
190:                        break;
191:                    }
192:                    case BOOLEANO: {
193:                        if (value instanceof  Boolean)
194:                            if (((Boolean) value).booleanValue() == true) {
195:                                valor = ConfiguravelTableCellRendererMessages
196:                                        .getMessages().getString("sim"); //$NON-NLS-1$
197:                            } else {
198:                                valor = ConfiguravelTableCellRendererMessages
199:                                        .getMessages().getString("nao"); //$NON-NLS-1$
200:                            }
201:                        setHorizontalAlignment(JLabel.CENTER);
202:                        break;
203:                    }
204:                    case CPF:
205:                    case CNPJ: {
206:                        if (new CNPJ(value.toString()).isValido()) {
207:                            try {
208:                                MaskFormatter cnpj = new MaskFormatter(
209:                                        "##.###.###/####-##"); //$NON-NLS-1$
210:                                cnpj.setValueContainsLiteralCharacters(false);
211:                                valor = cnpj.valueToString(value.toString());
212:                                setHorizontalAlignment(JLabel.RIGHT);
213:                                break;
214:                            } catch (ParseException pe) {
215:                                //TODO Excecao
216:                                pe.printStackTrace();
217:                            }
218:                        } else if (new CPF(value.toString()).isValido()) {
219:                            try {
220:                                MaskFormatter cpf = new MaskFormatter(
221:                                        "###.###.###-##"); //$NON-NLS-1$
222:                                cpf.setValueContainsLiteralCharacters(false);
223:                                valor = cpf.valueToString(value.toString());
224:                                setHorizontalAlignment(JLabel.RIGHT);
225:                                break;
226:                            } catch (ParseException pe) {
227:                                //TODO Excecao
228:                                pe.printStackTrace();
229:                            }
230:                        }
231:                    }
232:                    }
233:                }
234:
235:                if (valor != null)
236:                    setValue(valor);
237:
238:                return this;
239:            }
240:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.