Source Code Cross Referenced for ImportInMemoryCreditCardBBAction.java in  » ERP-CRM-Financial » Personal-Finance-Manager » br » com » gfp » ofc » actions » 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.gfp.ofc.actions 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on 23/03/2007
003:         * 
004:         * Swing Components - visit http://sf.net/projects/gfd
005:         * 
006:         * Copyright (C) 2007  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.gfp.ofc.actions;
024:
025:        import java.awt.Toolkit;
026:        import java.awt.datatransfer.Clipboard;
027:        import java.awt.datatransfer.DataFlavor;
028:        import java.awt.datatransfer.Transferable;
029:        import java.awt.datatransfer.UnsupportedFlavorException;
030:        import java.awt.event.ActionEvent;
031:        import java.awt.event.ActionListener;
032:        import java.io.IOException;
033:        import java.util.ArrayList;
034:        import java.util.Calendar;
035:        import java.util.Date;
036:        import java.util.StringTokenizer;
037:
038:        import javax.swing.JFrame;
039:        import javax.swing.JOptionPane;
040:
041:        import br.com.gfp.dao.GFPController;
042:        import br.com.gfp.data.PendingTransaction;
043:        import br.com.gfp.internationalization.ActionsMessages;
044:        import br.com.gfp.ofc.tools.ImportUtils;
045:        import br.com.gfp.ofc.windows.SelectAccountDialog;
046:        import br.com.gfp.util.SimpleLog;
047:        import br.com.gfp.windows.ConfirmImportedTransactionsWindow;
048:
049:        public class ImportInMemoryCreditCardBBAction implements  ActionListener {
050:            private static ImportInMemoryCreditCardBBAction action;
051:
052:            private Descricao descricao = null;
053:
054:            public void actionPerformed(ActionEvent e) {
055:                new Thread() {
056:                    @Override
057:                    public void run() {
058:                        StringTokenizer text = new StringTokenizer(
059:                                getClipboardContents(), "\n");
060:                        ArrayList<PendingTransaction> transactions = parseTransactions(text);
061:                        defineAccount(transactions);
062:                        ImportUtils.defineTypeForTransactions(transactions);
063:                        ImportUtils.conciliate(transactions);
064:                        GFPController.getGFPController().create(
065:                                ConfirmImportedTransactionsWindow.class);
066:                    }
067:                }.start();
068:            }
069:
070:            public static void main(String[] args) {
071:                new ImportInMemoryCreditCardBBAction().actionPerformed(null);
072:            }
073:
074:            private void defineAccount(
075:                    ArrayList<PendingTransaction> transactions) {
076:                SelectAccountDialog dialog = new SelectAccountDialog("");
077:                dialog.setVisible(true);
078:
079:                for (PendingTransaction transaction : transactions) {
080:                    transaction.setConta(dialog.getConta());
081:                    transaction.setTipoConta(dialog.getTipoConta());
082:                }
083:            }
084:
085:            private ArrayList<PendingTransaction> parseTransactions(
086:                    StringTokenizer text) {
087:                ArrayList<PendingTransaction> result = new ArrayList<PendingTransaction>();
088:                while (text.hasMoreTokens()) {
089:                    String temp = text.nextElement().toString();
090:                    result.add(parseTransaction(temp));
091:                    if (descricao != null && descricao.getParcelasFuturas() > 0)
092:                        for (int i = 0; i < descricao.getParcelasFuturas(); i++) {
093:                            Calendar day = Calendar.getInstance();
094:                            day.setTime(parseDay(temp.substring(6, 12)));
095:                            day.add(Calendar.MONTH, 1);
096:                            temp = temp
097:                                    .replace(
098:                                            temp.substring(6, 12).trim(),
099:                                            ajustaZero(""
100:                                                    + day
101:                                                            .get(Calendar.DAY_OF_MONTH))
102:                                                    + "."
103:                                                    + ajustaZero(""
104:                                                            + (day
105:                                                                    .get(Calendar.MONTH) + 1)));
106:                            PendingTransaction transaction = parseTransaction(temp);
107:                            transaction.setDia(day.getTime());
108:                            result.add(transaction);
109:                        }
110:                }
111:                return result;
112:            }
113:
114:            private String ajustaZero(String dataField) {
115:                if (dataField.trim().length() == 1)
116:                    return "0" + dataField;
117:                return dataField;
118:            }
119:
120:            private PendingTransaction parseTransaction(String temp) {
121:                PendingTransaction pendingTransaction = new PendingTransaction();
122:                pendingTransaction
123:                        .setDia(parseDay(temp.substring(6, 12).trim()));
124:                descricao = parseDescricao(temp.substring(12, 39).trim());
125:                pendingTransaction.setDescricao(descricao.getText());
126:                pendingTransaction.setValor(parseValue(temp.substring(39)
127:                        .trim()));
128:                return pendingTransaction;
129:            }
130:
131:            private Descricao parseDescricao(String string) {
132:                Descricao retorno = new Descricao();
133:                if (string.toUpperCase().indexOf("PARC") != -1) {
134:                    String temp = string.substring(string.toUpperCase()
135:                            .indexOf("PARC")
136:                            + "PARC".length());
137:                    retorno.setParcelasFuturas(Integer.parseInt(temp.substring(
138:                            4).trim())
139:                            - Integer.parseInt(temp.substring(1, 4).trim()));
140:                    retorno.setText(string.substring(0,
141:                            string.toUpperCase().indexOf("PARC")).trim());
142:                } else
143:                    retorno.setText(string.substring(0, string.length() - 3)
144:                            .trim());
145:                return retorno;
146:            }
147:
148:            private Double parseValue(String string) {
149:                String temp = string.substring(0, string.lastIndexOf(",") + 3);
150:                temp = temp.replace('.', 'p').replace(',', 'v');
151:                temp = temp.replace("p", "").replace('v', '.');
152:                double value = Double.parseDouble(temp);
153:                if (!string.endsWith("-"))
154:                    value *= -1;
155:                return value;
156:            }
157:
158:            private Date parseDay(String str) {
159:                Calendar dia = Calendar.getInstance();
160:                dia.set(Calendar.DAY_OF_MONTH, Integer.parseInt(str.substring(
161:                        0, 2)));
162:                dia.set(Calendar.MONTH,
163:                        Integer.parseInt(str.substring(3, 5)) - 1);
164:                return dia.getTime();
165:            }
166:
167:            /**
168:             * Here we get the clipboard contents if it is of text type  
169:             * @return
170:             */
171:            public String getClipboardContents() {
172:                String result = "";
173:                Clipboard clipboard = Toolkit.getDefaultToolkit()
174:                        .getSystemClipboard();
175:                // the Object param of getContents is not currently used
176:                Transferable contents = clipboard.getContents(null);
177:                boolean hasTransferableText = (contents != null)
178:                        && contents
179:                                .isDataFlavorSupported(DataFlavor.stringFlavor);
180:                if (hasTransferableText) {
181:                    try {
182:                        result = (String) contents
183:                                .getTransferData(DataFlavor.stringFlavor);
184:                    } catch (UnsupportedFlavorException e) {
185:                        // highly unlikely since we are using a standard DataFlavor
186:                        ((SimpleLog) GFPController.getGFPController()
187:                                .getContexto().get(GFPController.LOG))
188:                                .log("Error when importing transactions from ClipBoard!");
189:                        ((SimpleLog) GFPController.getGFPController()
190:                                .getContexto().get(GFPController.LOG)).log(e
191:                                .getLocalizedMessage());
192:                        ((SimpleLog) GFPController.getGFPController()
193:                                .getContexto().get(GFPController.LOG)).log(e);
194:                    } catch (IOException e) {
195:                        ((SimpleLog) GFPController.getGFPController()
196:                                .getContexto().get(GFPController.LOG))
197:                                .log("Error when importing transactions from ClipBoard!");
198:                        ((SimpleLog) GFPController.getGFPController()
199:                                .getContexto().get(GFPController.LOG)).log(e
200:                                .getLocalizedMessage());
201:                        ((SimpleLog) GFPController.getGFPController()
202:                                .getContexto().get(GFPController.LOG)).log(e);
203:                        JOptionPane.showMessageDialog((JFrame) GFPController
204:                                .getGFPController().getContexto().get(
205:                                        GFPController.FRAME_PRINCIPAL),
206:                                ActionsMessages.getMessages().getString(
207:                                        "ErroImportacaoClipboard"));
208:                    }
209:                }
210:                return result;
211:            }
212:
213:            public static ImportInMemoryCreditCardBBAction getAction() {
214:                return action;
215:            }
216:
217:            public static void initializeAction() {
218:                if (action == null)
219:                    action = new ImportInMemoryCreditCardBBAction();
220:            }
221:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.