001 /* 002 * Copyright (C) 2008-2010 by Holger Arndt 003 * 004 * This file is part of the Universal Java Matrix Package (UJMP). 005 * See the NOTICE file distributed with this work for additional 006 * information regarding copyright ownership and licensing. 007 * 008 * UJMP is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU Lesser General Public License as 010 * published by the Free Software Foundation; either version 2 011 * of the License, or (at your option) any later version. 012 * 013 * UJMP 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 Lesser General Public License for more details. 017 * 018 * You should have received a copy of the GNU Lesser General Public 019 * License along with UJMP; if not, write to the 020 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 021 * Boston, MA 02110-1301 USA 022 */ 023 024 package org.ujmp.gui.util; 025 026 import java.util.Collection; 027 import java.util.HashMap; 028 import java.util.Map; 029 030 import javax.swing.JFrame; 031 032 import org.ujmp.core.interfaces.GUIObject; 033 034 public abstract class FrameManager { 035 036 private static final Map<GUIObject, JFrame> frames = new HashMap<GUIObject, JFrame>(); 037 038 public static final JFrame showFrame(GUIObject o) { 039 JFrame frame = o.getFrame(); 040 frames.put(o, frame); 041 frame.setVisible(true); 042 return frame; 043 } 044 045 public static final Collection<JFrame> getFrameList() { 046 return frames.values(); 047 } 048 049 public static final Map<GUIObject, JFrame> getFrames() { 050 return frames; 051 } 052 053 public static final void hideFrame(GUIObject m) { 054 JFrame frame = frames.get(m); 055 if (frame != null) { 056 frame.setVisible(false); 057 } 058 } 059 060 public static final void closeFrame(GUIObject m) { 061 JFrame frame = frames.get(m); 062 if (frame != null) { 063 frame.setVisible(false); 064 frame.dispose(); 065 frame = null; 066 frames.put(m, null); 067 } 068 } 069 070 public static final void registerFrame(GUIObject object, JFrame frame) { 071 frames.put(object, frame); 072 } 073 074 }