001/**
002 *  '$RCSfile$'
003 *  '$Author: barseghian $'
004 *  '$Date: 2010-10-13 19:22:12 +0000 (Wed, 13 Oct 2010) $'
005 *  '$Revision: 26060 $'
006 *
007 *  For Details:
008 *  http://www.kepler-project.org
009 *
010 *  Copyright (c) 2010 The Regents of the
011 *  University of California. All rights reserved. Permission is hereby granted,
012 *  without written agreement and without license or royalty fees, to use, copy,
013 *  modify, and distribute this software and its documentation for any purpose,
014 *  provided that the above copyright notice and the following two paragraphs
015 *  appear in all copies of this software. IN NO EVENT SHALL THE UNIVERSITY OF
016 *  CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL,
017 *  OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
018 *  DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE
019 *  POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY
020 *  DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
021 *  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
022 *  SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
023 *  CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
024 *  ENHANCEMENTS, OR MODIFICATIONS.
025 */
026
027package org.kepler.kar;
028
029import java.util.HashMap;
030import java.util.Iterator;
031import java.util.Map;
032
033import javax.swing.JFrame;
034
035/**
036 * This singleton keeps a mapping of JFrames to KARFiles.
037 */
038public class KARManager {
039
040        static private KARManager _instance = null;
041        private Map<JFrame, KARFile> _mapping = new HashMap<JFrame, KARFile>();
042        
043        public KARManager() {
044        
045        }
046        
047        public synchronized static KARManager getInstance() {
048                if (_instance == null) {
049                        _instance = new KARManager();
050                }
051                return _instance;
052        }
053
054        /**
055         * Add mapping of karFile to jFrame
056         * @param karFile
057         * @param tableau
058         */
059        public synchronized void add(JFrame jFrame, KARFile karFile){
060                if (jFrame == null && karFile == null){
061                        System.out.println("KARManager add WARNING adding null => null mapping");
062                }else if (jFrame == null){
063                        System.out.println("KARManager add WARNING adding null =>"+karFile.getName()+" mapping");
064                }else if (karFile == null){
065                        System.out.println("KARManager add WARNING adding "+jFrame.getName()+" => null mapping");
066                }
067                _mapping.put(jFrame, karFile);
068                //debug();
069        }
070        
071        public synchronized KARFile get(JFrame jFrame){
072                return _mapping.get(jFrame);
073        }
074        
075        public synchronized void remove(JFrame jFrame){
076                _mapping.remove(jFrame);
077                //debug();
078        }
079        
080        public void debug(){
081                System.out.println("------KARManager _mapping:");
082                Iterator<JFrame> itr = _mapping.keySet().iterator();
083                while (itr.hasNext()){
084                        JFrame jFrame = itr.next();
085                        KARFile karFile = _mapping.get(jFrame);
086                        System.out.println(jFrame.getName()+"=>"+karFile.getName());
087                }
088                System.out.println("------");
089        }
090}