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


0001:        /*
0002:         * Created on 07/10/2004
0003:         * 
0004:         * ============================================================================
0005:         * GNU Lesser General Public License
0006:         * ============================================================================
0007:         *
0008:         * Swing Components - visit http://sf.net/projects/gfd
0009:         * 
0010:         * Copyright (C) 2004  Igor Regis da Silva Simões
0011:         * 
0012:         * This library is free software; you can redistribute it and/or
0013:         * modify it under the terms of the GNU Lesser General Public
0014:         * License as published by the Free Software Foundation; either
0015:         * version 2.1 of the License, or (at your option) any later version.
0016:         * 
0017:         * This library is distributed in the hope that it will be useful,
0018:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
0019:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0020:         * Lesser General Public License for more details.
0021:         * 
0022:         * You should have received a copy of the GNU Lesser General Public
0023:         * License along with this library; if not, write to the Free Software
0024:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
0025:         */
0026:
0027:        package br.com.gfpshare.beans;
0028:
0029:        import java.awt.AWTEvent;
0030:        import java.awt.BorderLayout;
0031:        import java.awt.Color;
0032:        import java.awt.Dimension;
0033:        import java.awt.Font;
0034:        import java.awt.GridBagConstraints;
0035:        import java.awt.GridBagLayout;
0036:        import java.awt.Insets;
0037:        import java.awt.Toolkit;
0038:        import java.awt.event.AWTEventListener;
0039:        import java.awt.event.ActionEvent;
0040:        import java.awt.event.ActionListener;
0041:        import java.awt.event.KeyEvent;
0042:        import java.awt.font.TextAttribute;
0043:        import java.text.NumberFormat;
0044:        import java.text.ParseException;
0045:        import java.util.Map;
0046:
0047:        import javax.swing.ImageIcon;
0048:        import javax.swing.JButton;
0049:        import javax.swing.JLabel;
0050:        import javax.swing.JPanel;
0051:        import javax.swing.JTextField;
0052:        import javax.swing.SwingConstants;
0053:        import javax.swing.UIManager;
0054:        import javax.swing.border.SoftBevelBorder;
0055:        import javax.swing.event.EventListenerList;
0056:        import javax.swing.text.NumberFormatter;
0057:
0058:        import br.com.gfpshare.beans.event.CalculatorEvent;
0059:        import br.com.gfpshare.beans.event.MoneyCalculatorEventListener;
0060:
0061:        /**
0062:         * @author Igor Regis da Silva Simoes
0063:         */
0064:        public class MoneyCalculatorPanel extends JPanel {
0065:
0066:            private JPanel jpDisplay = null;
0067:
0068:            private JPanel jpPainelCentral = null;
0069:
0070:            private JTextField jftfDisplay = null;
0071:
0072:            private JPanel jpPainelSuperior = null;
0073:
0074:            private JPanel jPanel3 = null;
0075:
0076:            private JPanel jPanel4 = null;
0077:
0078:            private JButton jbBackspace = null;
0079:
0080:            private JButton jbCE = null;
0081:
0082:            private JButton jbC = null;
0083:
0084:            private JButton jbMC = null;
0085:
0086:            private JButton jbMR = null;
0087:
0088:            private JButton jbMS = null;
0089:
0090:            private JButton jbMMais = null;
0091:
0092:            private JButton jb7 = null;
0093:
0094:            private JButton jb8 = null;
0095:
0096:            private JButton jb9 = null;
0097:
0098:            private JButton jbDivisao = null;
0099:
0100:            private JButton jbSQRT = null;
0101:
0102:            private JButton jb4 = null;
0103:
0104:            private JButton jb5 = null;
0105:
0106:            private JButton jb6 = null;
0107:
0108:            private JButton jbMultiplicacao = null;
0109:
0110:            private JButton jbPotenciacao = null;
0111:
0112:            private JButton jb1 = null;
0113:
0114:            private JButton jb0 = null;
0115:
0116:            private JButton jb2 = null;
0117:
0118:            private JButton jbMaisMenos = null;
0119:
0120:            private JButton jb3 = null;
0121:
0122:            private JButton jbMenos = null;
0123:
0124:            private JButton jbUmPorX = null;
0125:
0126:            private JButton jbVirgula = null;
0127:
0128:            private JButton jbMais = null;
0129:
0130:            private JButton jbIgual = null;
0131:
0132:            private JLabel jlMemoria = null;
0133:
0134:            private EventListenerList listeners = new EventListenerList();
0135:
0136:            private JButton jbOk = null;
0137:
0138:            private CalculatorActionListener listenerValores = new CalculatorActionListener();
0139:
0140:            private NumberFormatter mascaraView = null;
0141:
0142:            private String valorAtual = "";
0143:
0144:            private String valorEmCache = "";
0145:
0146:            private String valorEmMemoria = "";
0147:
0148:            private boolean ativo = false;
0149:
0150:            private int operacao = SOMA;
0151:
0152:            private final static int SOMA = 0;
0153:
0154:            private final static int SUBTRACAO = 1;
0155:
0156:            private final static int MULTIPLICACAO = 2;
0157:
0158:            private final static int DIVISAO = 3;
0159:
0160:            private final static int RAIZ_QUADRADA = 4;
0161:
0162:            private final static int POTENCIACAO = 5;
0163:
0164:            private final static int IGUAL = 6;
0165:
0166:            /**
0167:             * This is the default constructor
0168:             */
0169:            public MoneyCalculatorPanel() {
0170:                super ();
0171:                initialize();
0172:            }
0173:
0174:            /**
0175:             * This method initializes this
0176:             */
0177:            private void initialize() {
0178:                this .setLayout(new BorderLayout()); // Generated
0179:                this .setSize(185, 178);
0180:                this .add(getJpDisplay(), java.awt.BorderLayout.NORTH); // Generated
0181:                this .add(getJpPainelCentral(), java.awt.BorderLayout.CENTER); // Generated
0182:                Toolkit.getDefaultToolkit().addAWTEventListener(
0183:                        new MoneyCalculatorEventProxy(),
0184:                        AWTEvent.KEY_EVENT_MASK);
0185:            }
0186:
0187:            /**
0188:             * @return mascaraView
0189:             */
0190:            public NumberFormatter getFormatter() {
0191:                if (mascaraView == null) {
0192:                    mascaraView = new NumberFormatter(NumberFormat
0193:                            .getCurrencyInstance());
0194:                    mascaraView.setAllowsInvalid(false);
0195:                    mascaraView.setValueClass(Double.class);
0196:                }
0197:                return mascaraView;
0198:            }
0199:
0200:            /**
0201:             * This method initializes jpDisplay
0202:             * 
0203:             * @return javax.swing.JPanel
0204:             */
0205:            private JPanel getJpDisplay() {
0206:                if (jpDisplay == null) {
0207:                    GridBagConstraints gridBagConstraints110 = new GridBagConstraints();
0208:                    GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
0209:                    jpDisplay = new JPanel();
0210:                    jpDisplay.setLayout(new GridBagLayout()); // Generated
0211:                    gridBagConstraints1.gridx = 0; // Generated
0212:                    gridBagConstraints1.gridy = 0; // Generated
0213:                    gridBagConstraints1.weightx = 1.0; // Generated
0214:                    gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; // Generated
0215:                    gridBagConstraints1.insets = new java.awt.Insets(5, 5, 5, 5); // Generated
0216:                    gridBagConstraints110.gridx = 1; // Generated
0217:                    gridBagConstraints110.gridy = 0; // Generated
0218:                    gridBagConstraints110.insets = new java.awt.Insets(2, 2, 2,
0219:                            2); // Generated
0220:                    gridBagConstraints110.fill = java.awt.GridBagConstraints.NONE; // Generated
0221:                    jpDisplay.add(getJftfDisplay(), gridBagConstraints1); // Generated
0222:                    jpDisplay.add(getJbOk(), gridBagConstraints110); // Generated
0223:                }
0224:                return jpDisplay;
0225:            }
0226:
0227:            /**
0228:             * This method initializes jpPainelCentral
0229:             * 
0230:             * @return javax.swing.JPanel
0231:             */
0232:            private JPanel getJpPainelCentral() {
0233:                if (jpPainelCentral == null) {
0234:                    jpPainelCentral = new JPanel();
0235:                    jpPainelCentral.setLayout(new BorderLayout()); // Generated
0236:                    jpPainelCentral.add(getJpPainelSuperior(),
0237:                            java.awt.BorderLayout.NORTH); // Generated
0238:                    jpPainelCentral.add(getJPanel3(),
0239:                            java.awt.BorderLayout.WEST); // Generated
0240:                    jpPainelCentral.add(getJPanel4(),
0241:                            java.awt.BorderLayout.CENTER); // Generated
0242:                }
0243:                return jpPainelCentral;
0244:            }
0245:
0246:            /**
0247:             * This method initializes jftfDisplay
0248:             * 
0249:             * @return javax.swing.JTextField
0250:             */
0251:            private JTextField getJftfDisplay() {
0252:                if (jftfDisplay == null) {
0253:                    jftfDisplay = new JTextField();
0254:                    jftfDisplay.setEditable(false);
0255:                }
0256:                return jftfDisplay;
0257:            }
0258:
0259:            /**
0260:             * This method initializes jpPainelSuperior
0261:             * 
0262:             * @return javax.swing.JPanel
0263:             */
0264:            private JPanel getJpPainelSuperior() {
0265:                if (jpPainelSuperior == null) {
0266:                    GridBagConstraints gridBagConstraints30 = new GridBagConstraints();
0267:                    GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
0268:                    GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
0269:                    GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
0270:                    jpPainelSuperior = new JPanel();
0271:                    jpPainelSuperior.setLayout(new GridBagLayout()); // Generated
0272:                    jpPainelSuperior.setPreferredSize(new java.awt.Dimension(
0273:                            34, 26)); // Generated
0274:                    gridBagConstraints3.gridx = 2; // Generated
0275:                    gridBagConstraints3.gridy = 0; // Generated
0276:                    gridBagConstraints3.anchor = java.awt.GridBagConstraints.EAST; // Generated
0277:                    gridBagConstraints3.insets = new java.awt.Insets(2, 2, 2, 2); // Generated
0278:                    gridBagConstraints4.gridx = 3; // Generated
0279:                    gridBagConstraints4.gridy = 0; // Generated
0280:                    gridBagConstraints4.anchor = java.awt.GridBagConstraints.EAST; // Generated
0281:                    gridBagConstraints4.weightx = 0.0D; // Generated
0282:                    gridBagConstraints4.insets = new java.awt.Insets(2, 2, 2, 2); // Generated
0283:                    gridBagConstraints5.anchor = java.awt.GridBagConstraints.EAST; // Generated
0284:                    gridBagConstraints5.weightx = 0.0D; // Generated
0285:                    gridBagConstraints5.insets = new java.awt.Insets(2, 2, 2, 2); // Generated
0286:                    gridBagConstraints5.gridy = 0; // Generated
0287:                    gridBagConstraints5.gridx = 1; // Generated
0288:                    gridBagConstraints30.gridx = 0; // Generated
0289:                    gridBagConstraints30.gridy = 0; // Generated
0290:                    gridBagConstraints30.insets = new java.awt.Insets(2, 2, 2,
0291:                            2); // Generated
0292:                    gridBagConstraints30.anchor = java.awt.GridBagConstraints.EAST; // Generated
0293:                    gridBagConstraints30.weightx = 1.0D; // Generated
0294:                    gridBagConstraints30.fill = java.awt.GridBagConstraints.BOTH; // Generated
0295:
0296:                    jlMemoria = new JLabel();
0297:                    jlMemoria
0298:                            .setHorizontalAlignment(javax.swing.SwingConstants.CENTER); // Generated
0299:                    jlMemoria.setBorder(new javax.swing.border.SoftBevelBorder(
0300:                            javax.swing.border.SoftBevelBorder.LOWERED)); // Generated
0301:
0302:                    jpPainelSuperior.add(getJbBakspace(), gridBagConstraints5); // Generated
0303:                    jpPainelSuperior.add(getJbCe(), gridBagConstraints3); // Generated
0304:                    jpPainelSuperior.add(getJbC(), gridBagConstraints4); // Generated
0305:                    jpPainelSuperior.add(jlMemoria, gridBagConstraints30); // Generated
0306:                }
0307:                return jpPainelSuperior;
0308:            }
0309:
0310:            /**
0311:             * This method initializes jPanel3
0312:             * 
0313:             * @return javax.swing.JPanel
0314:             */
0315:            private JPanel getJPanel3() {
0316:                if (jPanel3 == null) {
0317:                    GridBagConstraints gridBagConstraints9 = new GridBagConstraints();
0318:                    GridBagConstraints gridBagConstraints8 = new GridBagConstraints();
0319:                    GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
0320:                    GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
0321:                    jPanel3 = new JPanel();
0322:                    jPanel3.setLayout(new GridBagLayout()); // Generated
0323:                    jPanel3.setPreferredSize(new java.awt.Dimension(30, 0)); // Generated
0324:                    gridBagConstraints6.gridx = 0; // Generated
0325:                    gridBagConstraints6.gridy = 0; // Generated
0326:                    gridBagConstraints6.ipadx = 0; // Generated
0327:                    gridBagConstraints6.ipady = 0; // Generated
0328:                    gridBagConstraints6.insets = new java.awt.Insets(2, 2, 2, 2); // Generated
0329:                    gridBagConstraints6.anchor = java.awt.GridBagConstraints.NORTH; // Generated
0330:                    gridBagConstraints7.gridx = 0; // Generated
0331:                    gridBagConstraints7.gridy = 1; // Generated
0332:                    gridBagConstraints7.insets = new java.awt.Insets(2, 2, 2, 2); // Generated
0333:                    gridBagConstraints7.anchor = java.awt.GridBagConstraints.NORTH; // Generated
0334:                    gridBagConstraints8.gridx = 0; // Generated
0335:                    gridBagConstraints8.gridy = 2; // Generated
0336:                    gridBagConstraints8.insets = new java.awt.Insets(2, 2, 2, 2); // Generated
0337:                    gridBagConstraints8.anchor = java.awt.GridBagConstraints.NORTH; // Generated
0338:                    gridBagConstraints9.gridx = 0; // Generated
0339:                    gridBagConstraints9.gridy = 3; // Generated
0340:                    gridBagConstraints9.insets = new java.awt.Insets(2, 2, 2, 2); // Generated
0341:                    gridBagConstraints9.anchor = java.awt.GridBagConstraints.NORTH; // Generated
0342:                    jPanel3.add(getJbMC(), gridBagConstraints6); // Generated
0343:                    jPanel3.add(getJbMR(), gridBagConstraints7); // Generated
0344:                    jPanel3.add(getJbMS(), gridBagConstraints8); // Generated
0345:                    jPanel3.add(getJbMMais(), gridBagConstraints9); // Generated
0346:                }
0347:                return jPanel3;
0348:            }
0349:
0350:            /**
0351:             * This method initializes jPanel4
0352:             * 
0353:             * @return javax.swing.JPanel
0354:             */
0355:            private JPanel getJPanel4() {
0356:                if (jPanel4 == null) {
0357:                    GridBagConstraints gridBagConstraints29 = new GridBagConstraints();
0358:                    GridBagConstraints gridBagConstraints28 = new GridBagConstraints();
0359:                    GridBagConstraints gridBagConstraints27 = new GridBagConstraints();
0360:                    GridBagConstraints gridBagConstraints26 = new GridBagConstraints();
0361:                    GridBagConstraints gridBagConstraints25 = new GridBagConstraints();
0362:                    GridBagConstraints gridBagConstraints24 = new GridBagConstraints();
0363:                    GridBagConstraints gridBagConstraints23 = new GridBagConstraints();
0364:                    GridBagConstraints gridBagConstraints22 = new GridBagConstraints();
0365:                    GridBagConstraints gridBagConstraints21 = new GridBagConstraints();
0366:                    GridBagConstraints gridBagConstraints20 = new GridBagConstraints();
0367:                    GridBagConstraints gridBagConstraints19 = new GridBagConstraints();
0368:                    GridBagConstraints gridBagConstraints18 = new GridBagConstraints();
0369:                    GridBagConstraints gridBagConstraints17 = new GridBagConstraints();
0370:                    GridBagConstraints gridBagConstraints16 = new GridBagConstraints();
0371:                    GridBagConstraints gridBagConstraints15 = new GridBagConstraints();
0372:                    GridBagConstraints gridBagConstraints14 = new GridBagConstraints();
0373:                    GridBagConstraints gridBagConstraints13 = new GridBagConstraints();
0374:                    GridBagConstraints gridBagConstraints12 = new GridBagConstraints();
0375:                    GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
0376:                    GridBagConstraints gridBagConstraints10 = new GridBagConstraints();
0377:                    jPanel4 = new JPanel();
0378:                    jPanel4.setLayout(new GridBagLayout()); // Generated
0379:                    gridBagConstraints10.gridx = 0; // Generated
0380:                    gridBagConstraints10.gridy = 0; // Generated
0381:                    gridBagConstraints10.insets = new java.awt.Insets(2, 2, 2,
0382:                            2); // Generated
0383:                    gridBagConstraints11.gridx = 1; // Generated
0384:                    gridBagConstraints11.gridy = 0; // Generated
0385:                    gridBagConstraints11.insets = new java.awt.Insets(2, 2, 2,
0386:                            2); // Generated
0387:                    gridBagConstraints12.gridx = 2; // Generated
0388:                    gridBagConstraints12.gridy = 0; // Generated
0389:                    gridBagConstraints12.insets = new java.awt.Insets(2, 2, 2,
0390:                            2); // Generated
0391:                    gridBagConstraints13.gridx = 3; // Generated
0392:                    gridBagConstraints13.gridy = 0; // Generated
0393:                    gridBagConstraints13.insets = new java.awt.Insets(2, 2, 2,
0394:                            2); // Generated
0395:                    gridBagConstraints14.gridx = 4; // Generated
0396:                    gridBagConstraints14.gridy = 0; // Generated
0397:                    gridBagConstraints14.insets = new java.awt.Insets(2, 2, 2,
0398:                            2); // Generated
0399:                    gridBagConstraints15.gridx = 0; // Generated
0400:                    gridBagConstraints15.gridy = 1; // Generated
0401:                    gridBagConstraints15.insets = new java.awt.Insets(2, 2, 2,
0402:                            2); // Generated
0403:                    gridBagConstraints16.gridx = 1; // Generated
0404:                    gridBagConstraints16.gridy = 1; // Generated
0405:                    gridBagConstraints16.insets = new java.awt.Insets(2, 2, 2,
0406:                            2); // Generated
0407:                    gridBagConstraints17.gridx = 2; // Generated
0408:                    gridBagConstraints17.gridy = 1; // Generated
0409:                    gridBagConstraints17.insets = new java.awt.Insets(2, 2, 2,
0410:                            2); // Generated
0411:                    gridBagConstraints18.gridx = 3; // Generated
0412:                    gridBagConstraints18.gridy = 1; // Generated
0413:                    gridBagConstraints18.insets = new java.awt.Insets(2, 2, 2,
0414:                            2); // Generated
0415:                    gridBagConstraints19.gridx = 4; // Generated
0416:                    gridBagConstraints19.gridy = 1; // Generated
0417:                    gridBagConstraints19.insets = new java.awt.Insets(2, 2, 2,
0418:                            2); // Generated
0419:                    gridBagConstraints19.fill = java.awt.GridBagConstraints.BOTH; // Generated
0420:                    gridBagConstraints20.gridx = 0; // Generated
0421:                    gridBagConstraints20.gridy = 2; // Generated
0422:                    gridBagConstraints20.insets = new java.awt.Insets(2, 2, 2,
0423:                            2); // Generated
0424:                    gridBagConstraints21.gridx = 0; // Generated
0425:                    gridBagConstraints21.gridy = 3; // Generated
0426:                    gridBagConstraints21.insets = new java.awt.Insets(2, 2, 2,
0427:                            2); // Generated
0428:                    gridBagConstraints22.gridx = 1; // Generated
0429:                    gridBagConstraints22.gridy = 2; // Generated
0430:                    gridBagConstraints22.insets = new java.awt.Insets(2, 2, 2,
0431:                            2); // Generated
0432:                    gridBagConstraints23.gridx = 1; // Generated
0433:                    gridBagConstraints23.gridy = 3; // Generated
0434:                    gridBagConstraints23.insets = new java.awt.Insets(2, 2, 2,
0435:                            2); // Generated
0436:                    gridBagConstraints24.gridx = 2; // Generated
0437:                    gridBagConstraints24.gridy = 2; // Generated
0438:                    gridBagConstraints24.insets = new java.awt.Insets(2, 2, 2,
0439:                            2); // Generated
0440:                    gridBagConstraints25.gridx = 3; // Generated
0441:                    gridBagConstraints25.gridy = 2; // Generated
0442:                    gridBagConstraints25.insets = new java.awt.Insets(2, 2, 2,
0443:                            2); // Generated
0444:                    gridBagConstraints26.gridx = 4; // Generated
0445:                    gridBagConstraints26.gridy = 2; // Generated
0446:                    gridBagConstraints26.insets = new java.awt.Insets(2, 2, 2,
0447:                            2); // Generated
0448:                    gridBagConstraints26.fill = java.awt.GridBagConstraints.BOTH; // Generated
0449:                    gridBagConstraints27.gridx = 2; // Generated
0450:                    gridBagConstraints27.gridy = 3; // Generated
0451:                    gridBagConstraints27.insets = new java.awt.Insets(2, 2, 2,
0452:                            2); // Generated
0453:                    gridBagConstraints28.gridx = 3; // Generated
0454:                    gridBagConstraints28.gridy = 3; // Generated
0455:                    gridBagConstraints28.insets = new java.awt.Insets(2, 2, 2,
0456:                            2); // Generated
0457:                    gridBagConstraints29.gridx = 4; // Generated
0458:                    gridBagConstraints29.gridy = 3; // Generated
0459:                    gridBagConstraints29.insets = new java.awt.Insets(2, 2, 2,
0460:                            2); // Generated
0461:                    gridBagConstraints29.fill = java.awt.GridBagConstraints.BOTH; // Generated
0462:                    jPanel4.add(getJb7(), gridBagConstraints10); // Generated
0463:                    jPanel4.add(getJb8(), gridBagConstraints11); // Generated
0464:                    jPanel4.add(getJb9(), gridBagConstraints12); // Generated
0465:                    jPanel4.add(getJbDivisao(), gridBagConstraints13); // Generated
0466:                    jPanel4.add(getJbSqrt(), gridBagConstraints14); // Generated
0467:                    jPanel4.add(getJb4(), gridBagConstraints15); // Generated
0468:                    jPanel4.add(getJb5(), gridBagConstraints16); // Generated
0469:                    jPanel4.add(getJb6(), gridBagConstraints17); // Generated
0470:                    jPanel4.add(getJbMultiplicacao(), gridBagConstraints18); // Generated
0471:                    jPanel4.add(getJbPotenciacao(), gridBagConstraints19); // Generated
0472:                    jPanel4.add(getJb1(), gridBagConstraints20); // Generated
0473:                    jPanel4.add(getJb0(), gridBagConstraints21); // Generated
0474:                    jPanel4.add(getJb2(), gridBagConstraints22); // Generated
0475:                    jPanel4.add(getJbMaisMenos(), gridBagConstraints23); // Generated
0476:                    jPanel4.add(getJb3(), gridBagConstraints24); // Generated
0477:                    jPanel4.add(getJbMenos(), gridBagConstraints25); // Generated
0478:                    jPanel4.add(getJbUmPorX(), gridBagConstraints26); // Generated
0479:                    jPanel4.add(getJbVirgula(), gridBagConstraints27); // Generated
0480:                    jPanel4.add(getJbMais(), gridBagConstraints28); // Generated
0481:                    jPanel4.add(getJbIgual(), gridBagConstraints29); // Generated
0482:                }
0483:                return jPanel4;
0484:            }
0485:
0486:            /**
0487:             * This method initializes jbOk
0488:             * 
0489:             * @return javax.swing.JButton
0490:             */
0491:            public JButton getJbBakspace() {
0492:                if (jbBackspace == null) {
0493:                    jbBackspace = new RedButton("Backspace");
0494:                    jbBackspace
0495:                            .setPreferredSize(new java.awt.Dimension(70, 25)); // Generated
0496:                    jbBackspace.setMaximumSize(new java.awt.Dimension(70, 25)); // Generated
0497:                    jbBackspace.setMinimumSize(new java.awt.Dimension(70, 25)); // Generated
0498:                }
0499:                return jbBackspace;
0500:            }
0501:
0502:            /**
0503:             * This method initializes jButton1
0504:             * 
0505:             * @return javax.swing.JButton
0506:             */
0507:            public JButton getJbCe() {
0508:                if (jbCE == null) {
0509:                    jbCE = new RedButton("CE");
0510:                    jbCE.setPreferredSize(new java.awt.Dimension(35, 25)); // Generated
0511:                    jbCE.setMaximumSize(new java.awt.Dimension(35, 25)); // Generated
0512:                    jbCE.setMinimumSize(new java.awt.Dimension(35, 25)); // Generated
0513:                }
0514:                return jbCE;
0515:            }
0516:
0517:            /**
0518:             * This method initializes jButton2
0519:             * 
0520:             * @return javax.swing.JButton
0521:             */
0522:            public JButton getJbC() {
0523:                if (jbC == null) {
0524:                    jbC = new RedButton("C");
0525:                    jbC.setPreferredSize(new java.awt.Dimension(35, 25)); // Generated
0526:                    jbC.setMaximumSize(new java.awt.Dimension(35, 25)); // Generated
0527:                    jbC.setMinimumSize(new java.awt.Dimension(35, 25)); // Generated
0528:                }
0529:                return jbC;
0530:            }
0531:
0532:            /**
0533:             * This method initializes jButton3
0534:             * 
0535:             * @return javax.swing.JButton
0536:             */
0537:            public JButton getJbMC() {
0538:                if (jbMC == null) {
0539:                    jbMC = new RedButton("MC");
0540:                }
0541:                return jbMC;
0542:            }
0543:
0544:            /**
0545:             * This method initializes jButton4
0546:             * 
0547:             * @return javax.swing.JButton
0548:             */
0549:            public JButton getJbMR() {
0550:                if (jbMR == null) {
0551:                    jbMR = new RedButton("MR");
0552:                }
0553:                return jbMR;
0554:            }
0555:
0556:            /**
0557:             * This method initializes jButton5
0558:             * 
0559:             * @return javax.swing.JButton
0560:             */
0561:            public JButton getJbMS() {
0562:                if (jbMS == null) {
0563:                    jbMS = new RedButton("MS");
0564:                }
0565:                return jbMS;
0566:            }
0567:
0568:            /**
0569:             * This method initializes jButton6
0570:             * 
0571:             * @return javax.swing.JButton
0572:             */
0573:            public JButton getJbMMais() {
0574:                if (jbMMais == null) {
0575:                    jbMMais = new RedButton("M+");
0576:                }
0577:                return jbMMais;
0578:            }
0579:
0580:            /**
0581:             * This method initializes jButton7
0582:             * 
0583:             * @return javax.swing.JButton
0584:             */
0585:            public JButton getJb7() {
0586:                if (jb7 == null) {
0587:                    jb7 = new BlueButton("7");
0588:                }
0589:                return jb7;
0590:            }
0591:
0592:            /**
0593:             * This method initializes jButton8
0594:             * 
0595:             * @return javax.swing.JButton
0596:             */
0597:            public JButton getJb8() {
0598:                if (jb8 == null) {
0599:                    jb8 = new BlueButton("8");
0600:                }
0601:                return jb8;
0602:            }
0603:
0604:            /**
0605:             * This method initializes jButton9
0606:             * 
0607:             * @return javax.swing.JButton
0608:             */
0609:            public JButton getJb9() {
0610:                if (jb9 == null) {
0611:                    jb9 = new BlueButton("9");
0612:                }
0613:                return jb9;
0614:            }
0615:
0616:            /**
0617:             * This method initializes jButton10
0618:             * 
0619:             * @return javax.swing.JButton
0620:             */
0621:            public JButton getJbDivisao() {
0622:                if (jbDivisao == null) {
0623:                    jbDivisao = new RedButton("/");
0624:                }
0625:                return jbDivisao;
0626:            }
0627:
0628:            /**
0629:             * This method initializes jButton11
0630:             * 
0631:             * @return javax.swing.JButton
0632:             */
0633:            public JButton getJbSqrt() {
0634:                if (jbSQRT == null) {
0635:                    jbSQRT = new RedButton("sqrt");
0636:                    Font fonte = jbSQRT.getFont();
0637:                    jbSQRT.setFont(fonte.deriveFont(6));
0638:                }
0639:                return jbSQRT;
0640:            }
0641:
0642:            /**
0643:             * This method initializes jButton12
0644:             * 
0645:             * @return javax.swing.JButton
0646:             */
0647:            public JButton getJb4() {
0648:                if (jb4 == null) {
0649:                    jb4 = new BlueButton("4");
0650:                }
0651:                return jb4;
0652:            }
0653:
0654:            /**
0655:             * This method initializes jButton13
0656:             * 
0657:             * @return javax.swing.JButton
0658:             */
0659:            public JButton getJb5() {
0660:                if (jb5 == null) {
0661:                    jb5 = new BlueButton("5");
0662:                }
0663:                return jb5;
0664:            }
0665:
0666:            /**
0667:             * This method initializes jButton14
0668:             * 
0669:             * @return javax.swing.JButton
0670:             */
0671:            public JButton getJb6() {
0672:                if (jb6 == null) {
0673:                    jb6 = new BlueButton("6");
0674:                }
0675:                return jb6;
0676:            }
0677:
0678:            /**
0679:             * This method initializes jButton15
0680:             * 
0681:             * @return javax.swing.JButton
0682:             */
0683:            public JButton getJbMultiplicacao() {
0684:                if (jbMultiplicacao == null) {
0685:                    jbMultiplicacao = new RedButton("*");
0686:                }
0687:                return jbMultiplicacao;
0688:            }
0689:
0690:            /**
0691:             * This method initializes jButton16
0692:             * 
0693:             * @return javax.swing.JButton
0694:             */
0695:            public JButton getJbPotenciacao() {
0696:                if (jbPotenciacao == null) {
0697:                    jbPotenciacao = new RedButton("x^y");
0698:                }
0699:                return jbPotenciacao;
0700:            }
0701:
0702:            /**
0703:             * This method initializes jButton17
0704:             * 
0705:             * @return javax.swing.JButton
0706:             */
0707:            public JButton getJb1() {
0708:                if (jb1 == null) {
0709:                    jb1 = new BlueButton("1");
0710:                }
0711:                return jb1;
0712:            }
0713:
0714:            /**
0715:             * This method initializes jButton18
0716:             * 
0717:             * @return javax.swing.JButton
0718:             */
0719:            public JButton getJb0() {
0720:                if (jb0 == null) {
0721:                    jb0 = new BlueButton("0");
0722:                }
0723:                return jb0;
0724:            }
0725:
0726:            /**
0727:             * This method initializes jButton19
0728:             * 
0729:             * @return javax.swing.JButton
0730:             */
0731:            public JButton getJb2() {
0732:                if (jb2 == null) {
0733:                    jb2 = new BlueButton("2");
0734:                }
0735:                return jb2;
0736:            }
0737:
0738:            /**
0739:             * This method initializes jButton20
0740:             * 
0741:             * @return javax.swing.JButton
0742:             */
0743:            public JButton getJbMaisMenos() {
0744:                if (jbMaisMenos == null) {
0745:                    jbMaisMenos = new BlueButton("+/-");
0746:                }
0747:                return jbMaisMenos;
0748:            }
0749:
0750:            /**
0751:             * This method initializes jButton21
0752:             * 
0753:             * @return javax.swing.JButton
0754:             */
0755:            public JButton getJb3() {
0756:                if (jb3 == null) {
0757:                    jb3 = new BlueButton("3");
0758:                }
0759:                return jb3;
0760:            }
0761:
0762:            /**
0763:             * This method initializes jButton22
0764:             * 
0765:             * @return javax.swing.JButton
0766:             */
0767:            public JButton getJbMenos() {
0768:                if (jbMenos == null) {
0769:                    jbMenos = new RedButton("-");
0770:                }
0771:                return jbMenos;
0772:            }
0773:
0774:            /**
0775:             * This method initializes jButton23
0776:             * 
0777:             * @return javax.swing.JButton
0778:             */
0779:            public JButton getJbUmPorX() {
0780:                if (jbUmPorX == null) {
0781:                    jbUmPorX = new RedButton("1/x");
0782:                }
0783:                return jbUmPorX;
0784:            }
0785:
0786:            /**
0787:             * This method initializes jButton24
0788:             * 
0789:             * @return javax.swing.JButton
0790:             */
0791:            public JButton getJbVirgula() {
0792:                if (jbVirgula == null) {
0793:                    jbVirgula = new BlueButton(",");
0794:                }
0795:                return jbVirgula;
0796:            }
0797:
0798:            /**
0799:             * This method initializes jButton25
0800:             * 
0801:             * @return javax.swing.JButton
0802:             */
0803:            public JButton getJbMais() {
0804:                if (jbMais == null) {
0805:                    jbMais = new RedButton("+");
0806:                }
0807:                return jbMais;
0808:            }
0809:
0810:            /**
0811:             * This method initializes jButton26
0812:             * 
0813:             * @return javax.swing.JButton
0814:             */
0815:            public JButton getJbIgual() {
0816:                if (jbIgual == null) {
0817:                    jbIgual = new RedButton("=");
0818:                }
0819:                return jbIgual;
0820:            }
0821:
0822:            /**
0823:             * This method initializes jbOk
0824:             * 
0825:             * @return javax.swing.JButton
0826:             */
0827:            public JButton getJbOk() {
0828:                if (jbOk == null) {
0829:                    jbOk = new JButton();
0830:                    jbOk.setBorder(new javax.swing.border.SoftBevelBorder(
0831:                            javax.swing.border.SoftBevelBorder.RAISED)); // Generated
0832:                    jbOk.setPreferredSize(new java.awt.Dimension(15, 15)); // Generated
0833:                    jbOk.setMaximumSize(new java.awt.Dimension(15, 15)); // Generated
0834:                    jbOk.setMinimumSize(new java.awt.Dimension(15, 15)); // Generated
0835:                    jbOk.setIcon(new ImageIcon(getClass().getResource(
0836:                            "/icones/16x16/apply.png")));
0837:                    jbOk.addActionListener(listenerValores);
0838:                }
0839:                return jbOk;
0840:            }
0841:
0842:            /**
0843:             * @return Retorna o valor exibido pela calculadora
0844:             */
0845:            public String getValue() {
0846:                return valorAtual;
0847:            }
0848:
0849:            /**
0850:             * @param value o valor exibido pela calculadora
0851:             */
0852:            public void setValue(Object value) {
0853:                if (value != null) {
0854:                    valorAtual = value.toString();
0855:                    fireValorAlterado();
0856:                }
0857:            }
0858:
0859:            /**
0860:             * @return Returns the ativo.
0861:             */
0862:            public boolean isAtivo() {
0863:                return ativo;
0864:            }
0865:
0866:            /**
0867:             * @param ativo The ativo to set.
0868:             */
0869:            public void setAtivo(boolean ativo) {
0870:                this .ativo = ativo;
0871:            }
0872:
0873:            /**
0874:             * Adiciona um listener para trtatar os eventos do calendário
0875:             * 
0876:             * @param listener Novo listener a ser adicionado
0877:             */
0878:            public void addMoneyCalculatorEventListener(
0879:                    MoneyCalculatorEventListener listener) {
0880:                listeners.add(MoneyCalculatorEventListener.class, listener);
0881:            }
0882:
0883:            /**
0884:             * Remove um listener da lista de listeners do calendário
0885:             * 
0886:             * @param listener listener a ser removido
0887:             */
0888:            public void removeMoneyCalculatorEventListener(
0889:                    MoneyCalculatorEventListener listener) {
0890:                listeners.remove(MoneyCalculatorEventListener.class, listener);
0891:            }
0892:
0893:            /**
0894:             * Notifica todos os listeners que o calendário está abrindo
0895:             */
0896:            private void fireAbrindoCalculadora() {
0897:                Object[] listeners = this .listeners
0898:                        .getListeners(MoneyCalculatorEventListener.class);
0899:
0900:                for (int i = 0; i < listeners.length; i++)
0901:                    ((MoneyCalculatorEventListener) listeners[i])
0902:                            .abrindoCalculadora(new CalculatorEvent(this ));
0903:            }
0904:
0905:            /**
0906:             * Notifica todos os listeners que o calendário está fechando
0907:             */
0908:            private void fireFechandoCalculadora() {
0909:                Object[] listeners = this .listeners
0910:                        .getListeners(MoneyCalculatorEventListener.class);
0911:
0912:                for (int i = 0; i < listeners.length; i++)
0913:                    ((MoneyCalculatorEventListener) listeners[i])
0914:                            .fechandoCalculadora(new CalculatorEvent(this ));
0915:            }
0916:
0917:            /**
0918:             * Notifica todos os listener que novo ano foi selecionado
0919:             */
0920:            private void fireValorAlterado() {
0921:                Object[] listeners = this .listeners
0922:                        .getListeners(MoneyCalculatorEventListener.class);
0923:
0924:                for (int i = 0; i < listeners.length; i++)
0925:                    ((MoneyCalculatorEventListener) listeners[i])
0926:                            .valorAlterado(new CalculatorEvent(this ));
0927:            }
0928:
0929:            /**
0930:             *
0931:             */
0932:            private class MoneyCalculatorEventProxy implements  AWTEventListener {
0933:                /**
0934:                 * @see java.awt.event.AWTEventListener#eventDispatched(java.awt.AWTEvent)
0935:                 */
0936:                public void eventDispatched(AWTEvent event) {
0937:                    if (!isAtivo())
0938:                        return;
0939:                    if (event instanceof  KeyEvent)
0940:                        if (((((KeyEvent) event).getKeyCode() == KeyEvent.VK_NUMPAD0)
0941:                                || (((KeyEvent) event).getKeyCode() == KeyEvent.VK_NUMPAD1)
0942:                                || (((KeyEvent) event).getKeyCode() == KeyEvent.VK_NUMPAD2)
0943:                                || (((KeyEvent) event).getKeyCode() == KeyEvent.VK_NUMPAD3)
0944:                                || (((KeyEvent) event).getKeyCode() == KeyEvent.VK_NUMPAD4)
0945:                                || (((KeyEvent) event).getKeyCode() == KeyEvent.VK_NUMPAD5)
0946:                                || (((KeyEvent) event).getKeyCode() == KeyEvent.VK_NUMPAD6)
0947:                                || (((KeyEvent) event).getKeyCode() == KeyEvent.VK_NUMPAD7)
0948:                                || (((KeyEvent) event).getKeyCode() == KeyEvent.VK_NUMPAD8) || (((KeyEvent) event)
0949:                                .getKeyCode() == KeyEvent.VK_NUMPAD9))
0950:                                && event.getID() == KeyEvent.KEY_RELEASED) {
0951:                            try {
0952:                                JButton jb = (JButton) MoneyCalculatorPanel.this 
0953:                                        .getClass().getMethod(
0954:                                                "getJb"
0955:                                                        + ((KeyEvent) event)
0956:                                                                .getKeyChar(),
0957:                                                new Class[] {}).invoke(
0958:                                                MoneyCalculatorPanel.this ,
0959:                                                new Object[] {});
0960:                                jb.doClick(2);
0961:                            } catch (Exception e) {
0962:                                // TODO Auto-generated catch block
0963:                                e.printStackTrace();
0964:                            }
0965:                        } else if (((KeyEvent) event).getKeyCode() == KeyEvent.VK_DECIMAL
0966:                                && event.getID() == KeyEvent.KEY_RELEASED) {
0967:                            getJbVirgula().doClick();
0968:                        } else if (((KeyEvent) event).getKeyCode() == KeyEvent.VK_MULTIPLY
0969:                                && event.getID() == KeyEvent.KEY_RELEASED) {
0970:                            getJbMultiplicacao().doClick();
0971:                        }
0972:
0973:                        else if (((KeyEvent) event).getKeyCode() == KeyEvent.VK_DIVIDE
0974:                                && event.getID() == KeyEvent.KEY_RELEASED) {
0975:                            getJbDivisao().doClick();
0976:                        } else if (((KeyEvent) event).getKeyCode() == KeyEvent.VK_ADD
0977:                                && event.getID() == KeyEvent.KEY_RELEASED) {
0978:                            getJbMais().doClick();
0979:                        } else if (((KeyEvent) event).getKeyCode() == KeyEvent.VK_SUBTRACT
0980:                                && event.getID() == KeyEvent.KEY_RELEASED) {
0981:                            getJbMenos().doClick();
0982:                        } else if (((KeyEvent) event).getKeyCode() == KeyEvent.VK_ENTER
0983:                                && ((KeyEvent) event).getModifiersEx() == KeyEvent.CTRL_DOWN_MASK) {
0984:                            getJbOk().doClick();
0985:                        } else if (((KeyEvent) event).getKeyCode() == KeyEvent.VK_ENTER
0986:                                && event.getID() == KeyEvent.KEY_RELEASED) {
0987:                            getJbIgual().doClick();
0988:                        } else if (((KeyEvent) event).getKeyCode() == KeyEvent.VK_BACK_SPACE
0989:                                && event.getID() == KeyEvent.KEY_RELEASED) {
0990:                            getJbBakspace().doClick();
0991:                        } else if (((KeyEvent) event).getKeyCode() == KeyEvent.VK_ESCAPE
0992:                                && ((KeyEvent) event).getModifiersEx() == KeyEvent.CTRL_DOWN_MASK) {
0993:                            getJbCe().doClick();
0994:                        } else if (((KeyEvent) event).getKeyCode() == KeyEvent.VK_ESCAPE
0995:                                && event.getID() == KeyEvent.KEY_RELEASED) {
0996:                            getJbC().doClick();
0997:                        }
0998:                }
0999:            }
1000:
1001:            private class CalculatorActionListener implements  ActionListener {
1002:                private String temp = "";
1003:
1004:                /**
1005:                 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
1006:                 */
1007:                public void actionPerformed(ActionEvent e) {
1008:                    boolean alterouValor = false;
1009:                    if (e.getSource() == getJbBakspace()) {
1010:                        if (valorAtual.length() >= 1) {
1011:                            valorAtual = valorAtual.substring(0, valorAtual
1012:                                    .length() - 1);
1013:                            alterouValor = true;
1014:                        }
1015:                    } else if (e.getSource() == getJbMais()) {
1016:                        if (!valorEmCache.equals("")) {
1017:                            actionPerformed(new ActionEvent(getJbIgual(), 0, ""));
1018:                        }
1019:                        operacao = SOMA;
1020:                        valorEmCache = valorAtual.trim();
1021:                        valorAtual = "";
1022:                        return;
1023:                    } else if (e.getSource() == getJbMenos()) {
1024:                        if (!valorEmCache.equals("")) {
1025:                            actionPerformed(new ActionEvent(getJbIgual(), 0, ""));
1026:                        }
1027:                        operacao = SUBTRACAO;
1028:                        valorEmCache = valorAtual.trim();
1029:                        valorAtual = "";
1030:                        return;
1031:                    } else if (e.getSource() == getJbMultiplicacao()) {
1032:                        if (!valorEmCache.equals("")) {
1033:                            actionPerformed(new ActionEvent(getJbIgual(), 0, ""));
1034:                        }
1035:                        operacao = MULTIPLICACAO;
1036:                        valorEmCache = valorAtual.trim();
1037:                        valorAtual = "";
1038:                        return;
1039:                    } else if (e.getSource() == getJbDivisao()) {
1040:                        if (!valorEmCache.equals("")) {
1041:                            actionPerformed(new ActionEvent(getJbIgual(), 0, ""));
1042:                        }
1043:                        operacao = DIVISAO;
1044:                        valorEmCache = valorAtual.trim();
1045:                        valorAtual = "";
1046:                        return;
1047:                    } else if (e.getSource() == getJbPotenciacao()) {
1048:                        if (!valorEmCache.equals("")) {
1049:                            actionPerformed(new ActionEvent(getJbIgual(), 0, ""));
1050:                        }
1051:                        operacao = POTENCIACAO;
1052:                        valorEmCache = valorAtual.trim();
1053:                        valorAtual = "";
1054:                        return;
1055:                    } else if (e.getSource() == getJbSqrt()) {
1056:                        if (!valorEmCache.equals("")) {
1057:                            actionPerformed(new ActionEvent(getJbIgual(), 0, ""));
1058:                        }
1059:                        operacao = RAIZ_QUADRADA;
1060:                        valorEmCache = valorAtual.trim();
1061:                        valorAtual = "";
1062:                        return;
1063:                    } else if (e.getSource() == getJbMMais()) {
1064:                        if (!valorEmMemoria.equals("")
1065:                                && !valorAtual.equals("")) {
1066:                            valorEmMemoria = ""
1067:                                    + (Double.parseDouble(valorEmMemoria) + Double
1068:                                            .parseDouble(valorAtual));
1069:                            jlMemoria.setText("M");
1070:                        } else if (!valorAtual.equals("")) {
1071:                            valorEmMemoria = valorAtual;
1072:                        }
1073:                        return;
1074:                    } else if (e.getSource() == getJbMS()) {
1075:                        valorEmMemoria = valorAtual.trim();
1076:                        jlMemoria.setText("M");
1077:                        return;
1078:                    } else if (e.getSource() == getJbMR()) {
1079:                        valorAtual = valorEmMemoria;
1080:                        alterouValor = true;
1081:                    } else if (e.getSource() == getJbMC()) {
1082:                        valorEmMemoria = "";
1083:                        jlMemoria.setText("");
1084:                        return;
1085:                    } else if (e.getSource() == getJbIgual()) {
1086:                        switch (operacao) {
1087:                        case SOMA:
1088:                            if (!valorEmCache.equals("")
1089:                                    && !valorAtual.equals("")) {
1090:                                valorAtual = ""
1091:                                        + (Double.parseDouble(valorEmCache) + Double
1092:                                                .parseDouble(valorAtual));
1093:                                alterouValor = true;
1094:                            }
1095:                            break;
1096:                        case SUBTRACAO:
1097:                            if (!valorEmCache.equals("")
1098:                                    && !valorAtual.equals("")) {
1099:                                valorAtual = ""
1100:                                        + (Double.parseDouble(valorEmCache) - Double
1101:                                                .parseDouble(valorAtual));
1102:                                alterouValor = true;
1103:                            }
1104:                            break;
1105:                        case MULTIPLICACAO:
1106:                            if (!valorEmCache.equals("")
1107:                                    && !valorAtual.equals("")) {
1108:                                valorAtual = ""
1109:                                        + (Double.parseDouble(valorEmCache) * Double
1110:                                                .parseDouble(valorAtual));
1111:                                alterouValor = true;
1112:                            }
1113:                            break;
1114:                        case DIVISAO:
1115:                            if (!valorEmCache.equals("")
1116:                                    && !valorAtual.equals("")) {
1117:                                valorAtual = ""
1118:                                        + (Double.parseDouble(valorEmCache) / Double
1119:                                                .parseDouble(valorAtual));
1120:                                alterouValor = true;
1121:                            }
1122:                            break;
1123:                        case POTENCIACAO:
1124:                            if (!valorEmCache.equals("")
1125:                                    && !valorAtual.equals("")) {
1126:                                valorAtual = ""
1127:                                        + Math.pow(Double
1128:                                                .parseDouble(valorEmCache),
1129:                                                Double.parseDouble(valorAtual));
1130:                                alterouValor = true;
1131:                            }
1132:                            break;
1133:                        case RAIZ_QUADRADA:
1134:                            if (!valorEmCache.equals("")) {
1135:                                valorAtual = ""
1136:                                        + Math.sqrt(Double
1137:                                                .parseDouble(valorEmCache));
1138:                                alterouValor = true;
1139:                            }
1140:                            break;
1141:                        }
1142:                        valorEmCache = valorAtual;
1143:                        operacao = IGUAL;
1144:                        if (valorAtual.equals(""))
1145:                            return;
1146:                    } else if (e.getSource() == getJbC()) {
1147:                        operacao = IGUAL;
1148:                        valorEmCache = "";
1149:                        valorAtual = "";
1150:                        alterouValor = true;
1151:                    } else if (e.getSource() == getJbCe()) {
1152:                        valorAtual = "";
1153:                    } else if (e.getSource() == getJbOk()) {
1154:                        fireFechandoCalculadora();
1155:                    } else {
1156:                        int index = valorAtual.indexOf(',') != -1 ? valorAtual
1157:                                .indexOf(',')
1158:                                : valorAtual.indexOf('.') != -1 ? valorAtual
1159:                                        .indexOf('.') : -1;
1160:                        if (index != -1
1161:                                && valorAtual.substring(index).length() <= 2) {
1162:                            valorAtual += e.getActionCommand();
1163:                            alterouValor = true;
1164:                        } else if (index == -1) {
1165:                            valorAtual += e.getActionCommand();
1166:                            alterouValor = true;
1167:                        }
1168:                    }
1169:
1170:                    temp = valorAtual;
1171:
1172:                    int index = valorAtual.indexOf(',') != -1 ? valorAtual
1173:                            .indexOf(',')
1174:                            : valorAtual.indexOf('.') != -1 ? valorAtual
1175:                                    .indexOf('.') : -1;
1176:
1177:                    if (index != -1 && valorAtual.substring(index).length() < 2) {
1178:                        if (valorAtual.substring(index).length() < 1) {
1179:                            temp = valorAtual + "0";
1180:                        } else if (valorAtual.substring(index).length() < 2) {
1181:                            temp = valorAtual + "00";
1182:                        }
1183:                    }
1184:
1185:                    temp = temp.replace(',', '.');
1186:                    if (alterouValor) {
1187:                        String swap = valorAtual;
1188:                        valorAtual = temp;
1189:                        fireValorAlterado();
1190:                        valorAtual = swap.replace(',', '.');
1191:                        ;
1192:                    }
1193:
1194:                    try {
1195:                        if (temp == null || temp.equals(""))
1196:                            getJftfDisplay().setText("");
1197:                        else
1198:                            getJftfDisplay().setText(
1199:                                    getFormatter().valueToString(
1200:                                            Double.valueOf(temp)));
1201:                    } catch (ParseException e1) {
1202:                        //Não fazemos nada
1203:                    }
1204:                }
1205:            }
1206:
1207:            /**
1208:             * Botão com texto azul
1209:             * @author Igor Regis da Silva Simoes
1210:             */
1211:            private class BlueButton extends JButton {
1212:
1213:                /**
1214:                 * Cria um novo Botão azul
1215:                 * @param text
1216:                 */
1217:                public BlueButton(String text) {
1218:                    super (text);
1219:                    setPreferredSize(new Dimension(26, 25));
1220:                    setHorizontalTextPosition(SwingConstants.CENTER);
1221:                    setBorder(new SoftBevelBorder(SoftBevelBorder.RAISED));
1222:                    setMinimumSize(new Dimension(26, 25));
1223:                    addActionListener(listenerValores);
1224:                    setForeground(Color.BLUE);
1225:                    if (UIManager.getLookAndFeel().getName().toLowerCase()
1226:                            .indexOf("windows") != -1) {
1227:                        setBorder(null);
1228:                        this .setMargin(new Insets(0, 0, 0, 0));
1229:                        Map map = getFont().getAttributes();
1230:                        map.put(TextAttribute.SIZE,
1231:                                (float) getFont().getSize() - 2);
1232:                        setFont(new Font(map));
1233:                    }
1234:                }
1235:            }
1236:
1237:            /**
1238:             * Botão com texto azul
1239:             * @author Igor Regis da Silva Simoes
1240:             */
1241:            private class RedButton extends BlueButton {
1242:
1243:                /**
1244:                 * Cria um novo Botão azul
1245:                 * @param text
1246:                 */
1247:                public RedButton(String text) {
1248:                    super (text);
1249:                    setForeground(Color.RED);
1250:                }
1251:            }
1252:        } //  @jve:decl-index=0:visual-constraint="10,10"
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.