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     * CategoryEditor.java
024     *
025     * Created on April 5, 2006, 8:50 PM
026     */
027    
028    package org.jbudget.gui.budget;
029    
030    import java.awt.BorderLayout;
031    import org.jbudget.Core.ExpenseCategory;
032    import org.jbudget.gui.BasicDialog;
033    
034    /**
035     * A GUI widget that changes/names a budget category.
036     * @author petrov
037     */
038    public class CategoryEditor extends BasicDialog
039    { 
040      private final CategoryEditorPanel editor;
041      
042      /** Creates a new instance of CategoryEditor
043       * @param parent the parent GUI component.
044       * @param theCategory The category to edit. If this is null a new category
045       *         will be created. In the opposite case a new category will be 
046       *         created.
047       */
048      public CategoryEditor(java.awt.Frame parent,
049          ExpenseCategory theCategory)
050      {
051        super(parent, false);
052        setTitle("Expense Category Editor");
053        
054        editor = new CategoryEditorPanel(theCategory);
055        
056        inputPanel.add(editor, BorderLayout.CENTER);
057        
058        pack();
059        
060        if (parent != null)
061        {
062          setLocation(parent.getX() + parent.getWidth()/2 - getWidth()/2,
063              parent.getY() + parent.getHeight()/2 - getHeight()/2);
064        }
065        
066        setVisible(true);
067      }
068      
069      /** Used to get a new or updated Expense Category. It makes sense only after
070       * okAction() was called.
071       */
072      public ExpenseCategory getCategory(){
073        return editor.getCategory();
074      }
075      
076      /** Called when the OK button is pressed */
077      protected boolean okAction()
078      {
079        return editor.updateCategory();
080      }
081      
082    }