001
002 /*****************************************************************************
003
004 jBudget.
005 Copyright (C) 2006 Dmitri Petrov
006
007 This program is free software: you can redistribute it and/or modify
008 it under the terms of the GNU General Public License as published by
009 the Free Software Foundation, either version 3 of the License, or
010 (at your option) any later version.
011
012 This program is distributed in the hope that it will be useful,
013 but WITHOUT ANY WARRANTY; without even the implied warranty of
014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015 GNU General Public License for more details.
016
017 You should have received a copy of the GNU General Public License
018 along with this program. If not, see <http://www.gnu.org/licenses/>.
019
020 /*****************************************************************************
021
022 /*
023 * AccountEditorDialog.java
024 *
025 * Created on July 17, 2006, 9:40 PM
026 */
027
028 package org.jbudget.gui.budget;
029
030 import java.awt.Dimension;
031 import java.text.ParseException;
032 import javax.swing.JButton;
033 import org.jbudget.Core.Account;
034 import org.jbudget.gui.BasicDialog;
035
036 /**
037 *
038 * @author petrov
039 */
040 public class AccountEditorDialog extends BasicDialog
041 {
042
043 /** Button that shows and hides details */
044 private final JButton detailsButton = new JButton("Details");
045
046 /** Account editor panel */
047 private final AccountEditorPanel accountPanel;
048
049 /** set to true when the OK button is pressed */
050 private volatile boolean okPressed = false;
051
052 /** Creates a new instance of AccountEditorDialog
053 * for creating a new account.
054 */
055 public AccountEditorDialog(java.awt.Frame parent)
056 {
057 this(parent, false);
058 }
059
060 /** Creates a new instance of AccountEditorDialog
061 * for creating a new account.
062 */
063 public AccountEditorDialog(java.awt.Frame parent, boolean isModal)
064 {
065 super(parent, isModal);
066 accountPanel = new AccountEditorPanel();
067 inputPanel.add(accountPanel);
068 setTitle("New Account");
069 setPreferredSize(new Dimension(400, 500));
070 pack();
071 if (parent != null)
072 setLocation(parent.getX() + parent.getWidth()/2 - getWidth()/2,
073 parent.getY() + parent.getHeight()/2 - getHeight()/2);
074 setVisible(true);
075 }
076
077 /** Creates a new instance of AccountEditorDialog for viewing or editing
078 * an existing account.
079 **/
080 public AccountEditorDialog(java.awt.Frame parent,
081 Account account,
082 boolean editable)
083 {
084 super(parent, false);
085 accountPanel = new AccountEditorPanel(account, editable);
086 inputPanel.add(accountPanel);
087 setTitle("Account " + account.getName());
088 setPreferredSize(new Dimension(400, 500));
089 pack();
090 if (parent != null)
091 setLocation(parent.getX() + parent.getWidth()/2 - getWidth()/2,
092 parent.getY() + parent.getHeight()/2 - getHeight()/2);
093 setVisible(true);
094 }
095
096 @Override
097 public void dispose(){
098 accountPanel.dispose();
099 super.dispose();
100 }
101
102 /** What do we do when the OK button is pressed? */
103 public boolean okAction() throws ParseException {
104 boolean readNewAccount = accountPanel.updateAccount();
105 okPressed = true;
106 return readNewAccount;
107 }
108
109 /** Get the updated value of the account */
110 public Account getAccount (){
111 if (!okPressed)
112 return null;
113 return accountPanel.getAccount();
114 }
115
116 /** Displays the dialog and returns the [new] account */
117 public static Account showDilaog(java.awt.Frame parent)
118 {
119 AccountEditorDialog dialog = new AccountEditorDialog(parent, true);
120 dialog.dispose();
121 return dialog.getAccount();
122 }
123
124 }
125