001 /* EVolve - an Extensible Software Visualization Framework 002 * Copyright (C) 2001-2002 Qin Wang 003 * 004 * This library is free software; you can redistribute it and/or 005 * modify it under the terms of the GNU Library General Public 006 * License as published by the Free Software Foundation; either 007 * version 2 of the License, or (at your option) any later version. 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Library General Public License for more details. 013 * 014 * You should have received a copy of the GNU Library General Public 015 * License along with this library; if not, write to the 016 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 017 * Boston, MA 02111-1307, USA. 018 */ 019 020 /* 021 * EVolve is distributed at http://www.sable.mcgill.ca/EVolve/ 022 */ 023 024 package EVolve; 025 026 import java.awt.BorderLayout; 027 028 import javax.swing.JInternalFrame; 029 import javax.swing.WindowConstants; 030 import javax.swing.event.InternalFrameAdapter; 031 import javax.swing.event.InternalFrameEvent; 032 033 import EVolve.util.overlappers.OverlapVisualization; 034 import EVolve.visualization.Visualization; 035 036 public class Window extends JInternalFrame { 037 private Visualization visualization; 038 private OverlapVisualization oVisual; 039 040 public Window(OverlapVisualization oVisual) { 041 super("Overlapped visualization",true,true,true,true); 042 this.visualization = null; 043 this.oVisual = oVisual; 044 this.getContentPane().setLayout(new BorderLayout()); 045 this.getContentPane().add(oVisual.getPanel(), BorderLayout.CENTER); 046 047 this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 048 this.addInternalFrameListener(new InternalFrameAdapter() { 049 public void internalFrameClosing(InternalFrameEvent e) { 050 cleanup(); 051 } 052 }); 053 } 054 055 public Window(Visualization visualization) { 056 super(visualization.getName() + " - " + visualization.getSubjectDefinition().getName(), true, true, true, true); 057 058 this.visualization = visualization; 059 this.getContentPane().setLayout(new BorderLayout()); 060 this.getContentPane().add(visualization.getPanel(), BorderLayout.CENTER); 061 062 this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 063 this.addInternalFrameListener(new InternalFrameAdapter() { 064 public void internalFrameClosing(InternalFrameEvent e) { 065 unregisterLinkedViz(); 066 cleanup(); 067 } 068 }); 069 } 070 071 public Visualization getVisualization() { 072 return visualization; 073 } 074 075 private void cleanup() { 076 Scene.getUIManager().removeWindow(this); 077 if (visualization!=null) 078 visualization.cleanup(); 079 else 080 oVisual.cleanup(); 081 } 082 083 private void unregisterLinkedViz() { 084 Scene.getToolsManager().getLinkedVisualizationRunner().unregisterLinkedViz(visualization); 085 } 086 087 private void unregisterOverlappedViz() { 088 Scene.getToolsManager().getOverlapVisualizationRunner().unregisterOverlappedViz(visualization); 089 } 090 091 }