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 EVolve.visualization.*; 027 import EVolve.util.OverlapVisualization; 028 import java.awt.*; 029 import javax.swing.*; 030 import javax.swing.event.*; 031 032 public class Window extends JInternalFrame { 033 private Visualization visualization; 034 private OverlapVisualization oVisual; 035 036 public Window(OverlapVisualization oVisual) { 037 super("Overlapped visualization",true,true,true,true); 038 this.visualization = null; 039 this.oVisual = oVisual; 040 this.getContentPane().setLayout(new BorderLayout()); 041 this.getContentPane().add(oVisual.getPanel(), BorderLayout.CENTER); 042 043 this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 044 this.addInternalFrameListener(new InternalFrameAdapter() { 045 public void internalFrameClosing(InternalFrameEvent e) { 046 cleanup(); 047 } 048 }); 049 } 050 051 public Window(Visualization visualization) { 052 super(visualization.getName() + " - " + visualization.getSubjectDefinition().getName(), true, true, true, true); 053 054 this.visualization = visualization; 055 this.getContentPane().setLayout(new BorderLayout()); 056 this.getContentPane().add(visualization.getPanel(), BorderLayout.CENTER); 057 058 this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 059 this.addInternalFrameListener(new InternalFrameAdapter() { 060 public void internalFrameClosing(InternalFrameEvent e) { 061 unregisterLinkedViz(); 062 cleanup(); 063 } 064 }); 065 } 066 067 public Visualization getVisualization() { 068 return visualization; 069 } 070 071 private void cleanup() { 072 Scene.getUIManager().removeWindow(this); 073 if (visualization!=null) 074 visualization.cleanup(); 075 else 076 oVisual.cleanup(); 077 } 078 079 private void unregisterLinkedViz() { 080 Scene.getToolsManager().getLinkedVisualizationRunner().unregisterLinkedViz(visualization); 081 } 082 083 private void unregisterOverlappedViz() { 084 Scene.getToolsManager().getOverlapVisualizationRunner().unregisterOverlappedViz(visualization); 085 } 086 }